| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Runs the Cobalt registry parser on either the entire (global) registry or |
| # the registry for a single project. This has the following effects: |
| # - Validates the registry entries |
| # - Populates the privacy encoding fields of each Cobalt 1.1 ReportDefinition |
| # - Optionally generates source code files in various programming languages |
| # containing definitions of constants that facilitate interacting with |
| # the Cobalt API. |
| # - Optionally generates a binary protocol buffer representation of the |
| # registry |
| # |
| # Args: |
| # global: (default: false) Should generate the global registry. If true then |
| # do not specify |customer_id| or |project_id|. |
| # customer_id: (default: 1) numeric customer_id of the project to generate. |
| # optional. |
| # project_id: numeric project_id of the project to generate the registry of |
| # output_name: base of the filename for the output. optional. |
| # generate_binarypb: (default: false) should we generate a *.pb file with a |
| # binary representation of the registry. |
| # generate_cc: (default: false) Should we generate a *.cb.h file and a library. |
| # generate_dart: (default: false) Should we generate a dart library. |
| # generate_rust: (default: false) Should we generate a rust crate. |
| # directories: (default: [//third_party/cobalt_config]) The directories to parse. |
| # exclude_projects: (default: []) A list of the projects to exclude from the |
| # parsed directories. Projects are identified by a colon |
| # separated "customer_id:project_id". |
| # privacy_encoding_params_file: (default: |
| # "$cobalt_root/src/algorithms/privacy/data/privacy_encoding_params") |
| # A file containing precomputed privacy encoding parameters. |
| # allow_empty_output: (default: false) Should we allow the output file to be empty. |
| # features: (default: []) The list of features to enable. |
| # dimension_name_maps_for_metric_ids: (default: []) The list of metric ids for |
| # which to generate name maps. |
| # |
| # Note: Other args are forwarded to dart_library when generate_dart is true. |
| # |
| # example usage: |
| # |
| # metrics_registry("generate_testapp_registry") { |
| # project_id = 2 |
| # } |
| |
| import("//build/compiled_action.gni") |
| |
| template("metrics_registry") { |
| forward_variables_from(invoker, [ "visibility" ]) |
| |
| if (defined(invoker.global)) { |
| global = invoker.global |
| } else { |
| global = false |
| } |
| |
| if (defined(invoker.customer_id)) { |
| not_needed([ "global" ]) |
| customer_id = invoker.customer_id |
| } else if (!global) { |
| # Customer is Fuchsia |
| customer_id = 1 |
| } |
| |
| if (defined(invoker.project_id)) { |
| not_needed([ "global" ]) |
| project_id = invoker.project_id |
| } else { |
| assert(global, "Exactly one of 'project_id' or 'global' must be defined") |
| } |
| |
| if (defined(invoker.namespace)) { |
| namespace = invoker.namespace |
| } else { |
| namespace = "" |
| } |
| |
| if (defined(invoker.generate_binarypb)) { |
| generate_binarypb = invoker.generate_binarypb |
| } else { |
| # If generate_binarypb has not been specified it defaults to false for |
| # non-global and true for global. |
| generate_binarypb = global |
| } |
| |
| if (defined(invoker.generate_cc)) { |
| generate_cc = invoker.generate_cc |
| } else { |
| generate_cc = false |
| } |
| |
| if (defined(invoker.generate_dart)) { |
| generate_dart = invoker.generate_dart |
| } else { |
| generate_dart = false |
| } |
| |
| if (defined(invoker.generate_go)) { |
| generate_go = invoker.generate_go |
| } else { |
| generate_go = false |
| } |
| |
| if (defined(invoker.go_package_name)) { |
| go_package_name = invoker.go_package_name |
| } |
| |
| if (defined(invoker.generate_rust)) { |
| generate_rust = invoker.generate_rust |
| } else { |
| generate_rust = false |
| } |
| |
| if (defined(invoker.source)) { |
| source = invoker.source |
| } |
| |
| if (defined(invoker.skip_validation)) { |
| skip_validation = invoker.skip_validation |
| } else { |
| skip_validation = false |
| } |
| |
| if (defined(invoker.features)) { |
| features = invoker.features |
| } |
| |
| if (defined(invoker.var_name)) { |
| var_name = invoker.var_name |
| } |
| |
| if (defined(invoker.use_target_name)) { |
| not_needed(invoker, [ "use_target_name" ]) |
| } |
| |
| if (defined(invoker.output_name)) { |
| output_name = invoker.output_name |
| } else { |
| output_name = target_name |
| } |
| |
| if (defined(invoker.directories)) { |
| cobalt_config_dirs = invoker.directories |
| } else { |
| cobalt_config_dirs = [ "//third_party/cobalt_config" ] |
| } |
| |
| if (defined(invoker.exclude_projects)) { |
| exclude_projects = invoker.exclude_projects |
| } else { |
| exclude_projects = [] |
| } |
| |
| if (defined(invoker.privacy_encoding_params_file)) { |
| privacy_encoding_params_file = invoker.privacy_encoding_params_file |
| } else { |
| privacy_encoding_params_file = |
| "$cobalt_root/src/algorithms/privacy/data/privacy_encoding_params" |
| } |
| |
| if (defined(invoker.allow_empty_output)) { |
| allow_empty_output = invoker.allow_empty_output |
| } else { |
| allow_empty_output = false |
| } |
| |
| if (defined(invoker.dimension_name_maps_for_metric_ids)) { |
| dimension_name_maps_for_metric_ids = |
| invoker.dimension_name_maps_for_metric_ids |
| } |
| |
| out_format = "" |
| generated_files = [] |
| if (generate_binarypb) { |
| out_format = "${out_format}bin " |
| generated_files += [ "$target_gen_dir/$output_name.pb" ] |
| } |
| if (generate_cc) { |
| out_format = "${out_format}cpp " |
| cc_source_file = "$target_gen_dir/$output_name.cb.h" |
| generated_files += [ cc_source_file ] |
| } |
| if (generate_dart) { |
| out_format = "${out_format}dart " |
| dart_out_dir = "$target_gen_dir/${target_name}_package" |
| dart_src_dir = "$dart_out_dir/lib" |
| dart_library_name = target_name |
| dart_source_file = "$dart_src_dir/$output_name.dart" |
| generated_files += [ dart_source_file ] |
| } |
| if (generate_rust) { |
| out_format = "${out_format}rust " |
| rust_source_file = "$target_gen_dir/$output_name.rs" |
| generated_files += [ rust_source_file ] |
| } |
| if (generate_go) { |
| out_format = "${out_format}go " |
| go_source_file = "$target_gen_dir/$output_name.go" |
| generated_files += [ go_source_file ] |
| } |
| |
| gen_target_name = "${target_name}_gen" |
| group_deps = [ ":${gen_target_name}" ] |
| |
| compiled_action(gen_target_name) { |
| tool = "$cobalt_root/src/bin/config_parser/src:bin" |
| tool_output_name = "config_parser" |
| |
| depfile = "$target_gen_dir/$output_name.d" |
| outputs = generated_files |
| inputs = [] |
| foreach(config_dir, cobalt_config_dirs) { |
| inputs += [ "$config_dir/projects.yaml" ] |
| } |
| |
| args = [ |
| "-out_format", |
| "$out_format", |
| "-out_filename", |
| "$output_name", |
| "-out_dir", |
| rebase_path(target_gen_dir, root_build_dir), |
| "-for_client", |
| "-dep_file", |
| rebase_path(depfile, root_build_dir), |
| ] |
| |
| if (skip_validation) { |
| args += [ "-skip_validation" ] |
| } |
| |
| if (defined(features)) { |
| args += [ |
| "-features", |
| string_join(",", features), |
| ] |
| } |
| |
| if (defined(dimension_name_maps_for_metric_ids)) { |
| args += [ |
| "-dimension_name_maps_for_metric_ids", |
| string_join(",", dimension_name_maps_for_metric_ids), |
| ] |
| } |
| |
| if (defined(var_name)) { |
| args += [ |
| "-var_name", |
| var_name, |
| ] |
| } |
| |
| if (defined(source)) { |
| args += [ |
| "-config_file", |
| rebase_path(source, root_build_dir), |
| ] |
| } else { |
| foreach(config_dir, cobalt_config_dirs) { |
| args += [ |
| "-config_dir", |
| rebase_path(config_dir, root_build_dir), |
| ] |
| } |
| } |
| |
| if (defined(exclude_projects)) { |
| foreach(exclude_project, exclude_projects) { |
| args += [ |
| "-exclude_project", |
| "$exclude_project", |
| ] |
| } |
| } |
| |
| if (defined(privacy_encoding_params_file)) { |
| args += [ |
| "-privacy_encoding_params_file", |
| rebase_path(privacy_encoding_params_file, root_build_dir), |
| ] |
| } |
| |
| if (allow_empty_output) { |
| args += [ "-allow_empty_output" ] |
| } |
| |
| if (defined(customer_id)) { |
| args += [ |
| "-customer_id", |
| "$customer_id", |
| ] |
| } |
| |
| if (namespace != "") { |
| args += [ |
| "-namespace", |
| "${namespace}", |
| ] |
| } |
| |
| if (defined(project_id)) { |
| args += [ |
| "-project_id", |
| "$project_id", |
| ] |
| } |
| |
| if (generate_dart) { |
| args += [ |
| "-dart_out_dir", |
| rebase_path(dart_src_dir, root_build_dir), |
| ] |
| } |
| |
| if (generate_go) { |
| args += [ |
| "-go_package", |
| go_package_name, |
| ] |
| } |
| |
| # The generated source code will have a stale timestamp if |
| # its contents do not change. This is ok, as it terminates |
| # the build early when downstream actions need not be re-run. |
| # The out-of-Fuchsia build is not trace-enabled. |
| if (is_fuchsia_tree) { |
| all_outputs_fresh = false |
| } |
| } |
| |
| if (generate_cc) { |
| cclib = "${target_name}_cc" |
| group_deps += [ ":${cclib}" ] |
| |
| source_set(cclib) { |
| output_name = cclib |
| |
| sources = [ cc_source_file ] |
| |
| public_deps = [ ":$gen_target_name" ] |
| } |
| } |
| |
| if (generate_dart) { |
| import("//build/dart/dart_library.gni") |
| |
| dartlib = "${target_name}_dartlib" |
| group_deps += [ ":${dartlib}" ] |
| |
| copy_pubspec_target_name = "${dartlib}_copy_pubspec" |
| copy_options_target_name = "${dartlib}_copy_options" |
| |
| copy(copy_pubspec_target_name) { |
| sources = [ "//build/dart/empty_pubspec.yaml" ] |
| |
| outputs = [ "$dart_out_dir/pubspec.yaml" ] |
| } |
| |
| copy(copy_options_target_name) { |
| sources = [ "//build/dart/analysis_options.yaml" ] |
| |
| outputs = [ "$dart_out_dir/analysis_options.yaml" ] |
| } |
| |
| dart_library(dartlib) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "sdk_category", |
| "visibility", |
| ]) |
| |
| package_root = dart_out_dir |
| |
| package_name = dart_library_name |
| |
| sources = [ rebase_path(dart_source_file, dart_src_dir) ] |
| |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| |
| if (defined(invoker.public_deps)) { |
| deps += invoker.public_deps |
| } |
| |
| non_dart_deps = [ |
| ":$copy_options_target_name", |
| ":$copy_pubspec_target_name", |
| ":$gen_target_name", |
| ] |
| } |
| } |
| |
| if (generate_rust) { |
| import("//build/rust/rustc_library.gni") |
| |
| rust_library_name = target_name |
| rustlib = "${target_name}_rustlib" |
| group_deps += [ ":${rustlib}" ] |
| rustc_library(rustlib) { |
| name = rust_library_name |
| |
| version = "1.0.0" |
| edition = "2018" |
| source_root = rust_source_file |
| |
| if (is_fuchsia_tree) { |
| sources = [ rust_source_file ] |
| } |
| |
| deps = [ "$cobalt_root/src/lib/client/rust:cobalt-client" ] |
| |
| non_rust_deps = [ ":$gen_target_name" ] |
| } |
| } |
| |
| if (generate_go) { |
| import("//build/go/go_library.gni") |
| |
| source_dir = target_gen_dir |
| go_library("${target_name}_golib") { |
| name = target_name |
| non_go_deps = [ ":$gen_target_name" ] |
| sources = [ rebase_path(go_source_file, target_gen_dir) ] |
| } |
| } |
| |
| group(target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| public_deps = group_deps |
| } |
| } |