| # Copyright 2024 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. |
| |
| import("//build/python/python_action.gni") |
| import("//build/sdk/sdk_atom.gni") |
| import("//sdk/categories/compatibility.gni") |
| |
| # Declares an in-tree Python E2E Mobly test for distribution in the SDK. |
| # |
| # Example: |
| # ``` |
| # python_mobly_test("my-test") { |
| # main_source = "main.py" |
| # testonly = false # Required for SDK inclusion. |
| # } |
| # |
| # sdk_python_mobly_test("my-sdk-test") { |
| # sdk_name = "my-test" |
| # test_label = ":my-test" |
| # category = "partner" |
| # } |
| # ``` |
| # |
| # Parameters |
| # |
| # test_label |
| # The Python E2E test to distribute. Must point to a python_mobly_test() |
| # target. |
| # Type: label. |
| # |
| # sdk_name |
| # Name of the test in the SDK. |
| # Type: string. |
| # |
| # category |
| # Publication level of the library in SDKs. |
| # See //build/sdk/sdk_atom.gni for more. |
| # Type: string. |
| # |
| # sdk_area (optional) |
| # [string] The API area responsible for maintaining this library. |
| # See //build/sdk/sdk_atom.gni. |
| template("sdk_python_mobly_test") { |
| visibility = [] |
| |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(defined(invoker.sdk_name), |
| "Must define a distribution name for this test.") |
| |
| _sdk_name = invoker.sdk_name |
| |
| _full_test_label = get_label_info(invoker.test_label, "label_no_toolchain") |
| |
| _labels = { |
| # IDK-bound targets cannot depend on `testonly` targets so instead of |
| # depending on the main python_mobly_test() target which is a host_test() |
| # with `testonly` hardcoded to true, we can instead depend on the |
| # `.binary_and_config` group target for bundling purposes. |
| full_test_bundle = "${_full_test_label}.binary_and_config" |
| |
| meta_json_and_file_list = "${target_name}_metadata_and_file_list" |
| } |
| |
| _files = { |
| meta_json = |
| "${target_gen_dir}/${target_name}_metadata_and_file_list.sdk_meta.json" |
| file_list = |
| "${target_gen_dir}/${target_name}_metadata_and_file_list.mapping.txt" |
| } |
| |
| _test_sources_target = "${target_name}_test_sources" |
| _test_sources_file = "${target_gen_dir}/${target_name}_test_sources.json" |
| generated_file(_test_sources_target) { |
| visibility = [ ":${_labels.meta_json_and_file_list}" ] |
| |
| public_deps = [ _labels.full_test_bundle ] |
| |
| outputs = [ _test_sources_file ] |
| output_conversion = "json" |
| data_keys = [ "hermetic_test_sources" ] |
| } |
| |
| python_action(_labels.meta_json_and_file_list) { |
| visibility = [ ":*" ] |
| binary_label = "//build/python:gen_sdk_metadata_and_file_sources" |
| |
| inputs = [ _test_sources_file ] |
| |
| outputs = [ |
| _files.file_list, |
| _files.meta_json, |
| ] |
| |
| args = [ |
| "--out-metadata", |
| rebase_path(_files.meta_json, root_build_dir), |
| "--out-sources", |
| rebase_path(_files.file_list, root_build_dir), |
| "--test-sources-list", |
| rebase_path(_test_sources_file, root_build_dir), |
| "--name", |
| _sdk_name, |
| "--root", |
| "python/${_sdk_name}", |
| ] |
| |
| deps = [ |
| ":${_test_sources_target}", |
| _labels.full_test_bundle, |
| ] |
| } |
| |
| sdk_atom(target_name) { |
| # TODO(https://fxbug.dev/347094435): Make `sdk_atom()` support `visibility` and uncomment. |
| # visibility = ["//sdk:*"] |
| |
| forward_variables_from(invoker, |
| [ |
| "category", |
| "sdk_area", |
| ]) |
| |
| id = "sdk://python/${_sdk_name}" |
| |
| meta = { |
| schema = "experimental_python_e2e_test" |
| dest = "python/${_sdk_name}/meta.json" |
| source = _files.meta_json |
| } |
| |
| non_sdk_deps = [ ":${_labels.meta_json_and_file_list}" ] |
| |
| file_list = _files.file_list |
| |
| # Ensure FIDL libraries with more restrictive visibility are not used. |
| # Note that not everything in categories with greater visibility is stable. |
| # TODO(https://fxbug.dev/314822328): Reframe the markers in terms of stability. |
| # Also, there are exceptions for host tests - see https://fxbug.dev/326090508. |
| assert(invoker.category == "partner") |
| assert_no_deps = markers_partner_idk_prebuilts_must_not_depend_on |
| } |
| } |