| # Copyright 2023 The Fuchsia Authors. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| import("//build/compiled_action.gni") | |
| import("//build/dist/resource.gni") | |
| # Preprocesses an expectations JSON5 file in order to | |
| # resolve `include`s and check that the file is valid, and | |
| # produces a `resource` to be included in a fuchsia package. | |
| # | |
| # Parameters | |
| # expectations (required) | |
| # Path to a JSON5 test expectations file. | |
| # Type: path | |
| # | |
| # output_path (required) | |
| # Output path for the preprocessed file `resource`. | |
| # | |
| # cases_to_run (optional) | |
| # String specifier of which cases to run with | |
| # respect to whether or not they produce error logs. | |
| # Type: string | |
| # Options: | |
| # - "NoErrLogs" indicates that tests expected to | |
| # generate error logs should be skipped. | |
| # - "WithErrLogs" indicates that only those tests | |
| # expected to generate error logs should be run. | |
| # - By default, all test cases will be run. | |
| # | |
| # All other parameters are forwarded to the `compiled_action` | |
| # target acting on the expectations file. | |
| template("preprocess_expectations") { | |
| assert(defined(invoker.expectations)) | |
| assert(defined(invoker.output_path)) | |
| _base_target_name = target_name | |
| _preprocessed_target_name = "${_base_target_name}-preprocessed" | |
| compiled_action(_preprocessed_target_name) { | |
| forward_variables_from(invoker, | |
| [ | |
| "deps", | |
| "testonly", | |
| ]) | |
| tool = "//src/lib/testing/expectation/preprocess:bin" | |
| tool_output_name = "expectation_file_preprocessor" | |
| _preprocessed_expectations = | |
| "${target_gen_dir}/${_base_target_name}-expectations-preprocessed.json5" | |
| depfile = "$target_out_dir/${_preprocessed_target_name}.d" | |
| args = [ | |
| "--root-expectations-file", | |
| rebase_path(invoker.expectations, root_build_dir), | |
| "--preprocessed-expectations-file", | |
| rebase_path(_preprocessed_expectations, root_build_dir), | |
| "--depfile", | |
| rebase_path(depfile, root_build_dir), | |
| ] | |
| if (defined(invoker.cases_to_run)) { | |
| args += [ | |
| "--cases-to-run", | |
| invoker.cases_to_run, | |
| ] | |
| } | |
| outputs = [ _preprocessed_expectations ] | |
| sources = [ invoker.expectations ] | |
| visibility = [ ":*" ] | |
| } | |
| _preprocessed_target_name = ":$_preprocessed_target_name" | |
| resource(target_name) { | |
| forward_variables_from(invoker, [ "testonly" ]) | |
| sources = get_target_outputs(_preprocessed_target_name) | |
| outputs = [ invoker.output_path ] | |
| deps = [ _preprocessed_target_name ] | |
| visibility = [ ":*" ] | |
| } | |
| } |