blob: 77d415678c7fa968fea53497be82e6e85c7a10f8 [file] [log] [blame]
# 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
# CobaltRegistry 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 CobaltRegistry. These values must be used
# in the code that fetches the config values.
# string_var_name (optional, string, default = 'cobalt_registry_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_registry_base64| of type "const char[]" containing
# the base64 encoded bytes of a serialized CobaltRegistry 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::CreateFromCobaltRegistryBase64(cobalt_registry_base64);
import("//build/config/clang/clang.gni")
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_registry_base64"
}
action(target_name) {
sources = [
invoker.input_yaml,
]
output_file = "$target_gen_dir/" + invoker.output_file
outputs = [
output_file,
]
config_parser_target =
"$cobalt_root/config/config_parser/src:bin($host_toolchain)"
config_parser_bin =
get_label_info(config_parser_target, "root_out_dir") + "/config_parser"
script = "//build/gn_run_binary.sh"
args = [
clang_prefix,
rebase_path(config_parser_bin, root_build_dir),
"-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 = [
"$cobalt_root/src/pb",
config_parser_target,
]
}
}