| # 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 config parser on a .yaml file containing Cobalt configuration |
| # for a single project. Generates a C++ header file containing the definition |
| # of a string containing the base64 encoding of the bytes of a serialized |
| # CobaltConfig proto message containing the data specified in the YAML. |
| # This is intended for use in tests. |
| # |
| # Args: |
| # input_yaml: Path to the .yaml config file to parse |
| # output_file: Name of the .h file to produce |
| # customer_id, project_id (optional, integers, default = 1 for both): These |
| # are inserted into the generated CobaltConfig. These values must be used |
| # in the code that fetches the config values. |
| # string_var_name (optional, string, default = 'cobalt_config_base64'): The |
| # C++ variable name to use in the .h file. |
| # |
| # example usage: |
| # |
| # cobalt_config_header("generate_encoder_test_config") { |
| # input_yaml = "encoder_test_config.yaml" |
| # output_file = "encoder_test_config.h" |
| # } |
| # |
| # This will parse the file "encoder_test_config.yaml" in the current source |
| # directory and generate a C++ .h file in the current gen directory |
| # named "encoder_test_config.h". The header file will contain the definition of |
| # a variable named |cobalt_config_base64| of type "const char[]" containing |
| # the base64 encoded bytes of a serialized CobaltConfig proto message |
| # corresponding to the configuration described in the YAML file, and for |
| # customer_id=1, project_id=1. |
| # |
| # To use this in a test one would #include encoder_test_config.h and then |
| # type something like the following: |
| # |
| # std::unique_ptr<ClientConfig> client_config = |
| # ClientConfig::CreateFromCobaltConfigBase64(cobalt_config_base64); |
| |
| template("cobalt_config_header") { |
| assert(defined(invoker.input_yaml), "input_yaml must be defined") |
| assert(defined(invoker.output_file), "output_file must be defined") |
| if (defined(invoker.customer_id)) { |
| customer_id = invoker.customer_id |
| } else { |
| customer_id = 1 |
| } |
| if (defined(invoker.project_id)) { |
| project_id = invoker.project_id |
| } else { |
| project_id = 1 |
| } |
| if (defined(invoker.string_var_name)) { |
| string_var_name = invoker.string_var_name |
| } else { |
| string_var_name = "cobalt_config_base64" |
| } |
| action(target_name) { |
| sources = [ invoker.input_yaml ] |
| output_file = "$target_gen_dir/" + invoker.output_file |
| outputs = [ output_file ] |
| |
| config_parser_target = "//third_party/cobalt/config/config_parser/src:bin($host_toolchain)" |
| config_parser_bin = get_label_info(config_parser_target, "root_out_dir") + "/config_parser" |
| |
| script = config_parser_bin |
| args = [ |
| "-output_file", |
| rebase_path(output_file), |
| "-config_file", |
| rebase_path(invoker.input_yaml), |
| "-customer_id", |
| "$customer_id", |
| "-project_id", |
| "$project_id", |
| "-out_format=cpp", |
| "-var_name", |
| string_var_name, |
| "-skip_validation", |
| ] |
| |
| deps = [ |
| config_parser_target, |
| "//third_party/cobalt:cobalt_proto" |
| ] |
| } |
| } |