| # Copyright 2021 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/sdk/sdk_atom.gni") |
| import("//sdk/cts/build/cts_version.gni") |
| |
| # Copies specific sources to an SDK. |
| # |
| # This template should only be used directly to copy BUILD.gn files |
| # to the CTS SDK. All other uses should be through specific CTS build templates. |
| # |
| # Example: |
| # ``` |
| # # This will create :build_sdk, which should be added to an sdk_molecule in the |
| # # same file. |
| # cts_copy_to_sdk("build") { |
| # testonly = true |
| # sources = [ "BUILD.gn" ] |
| # } |
| # ``` |
| # |
| # Parameters |
| # |
| # sources (required) |
| # A list of sources to include in the atom. |
| # Type: list(labels) |
| # |
| # dest (optional) |
| # Location to copy this target to in the CTS archive. |
| # Dest should only be specified if the target is not in //sdk/cts. If the |
| # target is in //sdk/cts, it will be placed in the same path in the CTS |
| # archive. |
| # Type: string |
| template("cts_copy_to_sdk") { |
| assert(defined(invoker.sources), "Sources must be defined.") |
| |
| if (defined(invoker.dest)) { |
| file_base = invoker.dest |
| } else { |
| path = get_label_info(":${target_name}", "dir") |
| |
| # No need to specify 'dest' if the sources are in //sdk/cts (CTS at TOT) |
| # or a previously released CTS archive (//prebuilt/cts/...) |
| if (string_replace(path, "//sdk/cts", "") == path && |
| string_replace(path, "//prebuilt/cts", "") == path) { |
| assert(defined(invoker.dest), |
| "dest must be defined if the source file is not in //sdk/cts") |
| } |
| |
| file_base = "" |
| if (path != "//sdk/cts") { |
| file_base = string_replace(path, "//sdk/cts/", "") |
| } |
| } |
| |
| main_target_name = target_name |
| sdk_target_name = "${target_name}_sdk" |
| |
| relative_path = invoker.sources |
| relative_path = relative_path[0] |
| abspath = get_path_info(relative_path, "abspath") |
| |
| if (get_path_info(abspath, "extension") == "gn") { |
| transform_build_gn_target = "${target_name}_transform_build" |
| output_path = "${root_gen_dir}/cts/${abspath}" |
| action(transform_build_gn_target) { |
| script = "//sdk/cts/build/scripts/transform_build_gn.py" |
| inputs = [ relative_path ] |
| outputs = [ output_path ] |
| args = [ |
| "--source", |
| rebase_path(abspath), |
| "--dest", |
| rebase_path(output_path), |
| ] |
| if (cts_version != "") { |
| args += [ |
| "--cts_version", |
| cts_version, |
| ] |
| } |
| } |
| } |
| |
| sdk_files = [ |
| { |
| if (defined(transform_build_gn_target)) { |
| source = output_path |
| } else { |
| source = relative_path |
| } |
| |
| # If file_base is empty, the resource file will actually be copied into |
| # the '/' directory on the host instead of being copied into the SDK. |
| if (file_base != "") { |
| dest = "${file_base}/${relative_path}" |
| } else { |
| dest = relative_path |
| } |
| }, |
| ] |
| |
| sdk_atom(sdk_target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| non_sdk_deps = [] |
| if (defined(invoker.non_sdk_deps)) { |
| non_sdk_deps = invoker.non_sdk_deps |
| } |
| |
| category = "cts" |
| if (file_base != "") { |
| id = "sdk://${file_base}/${main_target_name}" |
| } else { |
| id = "sdk://${main_target_name}" |
| } |
| files = sdk_files |
| |
| meta = { |
| schema = "cts_resource" |
| if (file_base != "") { |
| dest = "${file_base}/json/${main_target_name}/meta.json" |
| } else { |
| dest = "json/${main_target_name}/meta.json" |
| } |
| value = { |
| type = "resource" |
| name = main_target_name |
| |
| # If file_base is empty, the resource file will actually be copied into |
| # the '/' directory on the host instead of being copied into the SDK. |
| if (file_base != "") { |
| resources = [ "${file_base}/${relative_path}" ] |
| } else { |
| resources = [ relative_path ] |
| } |
| } |
| } |
| |
| if (defined(transform_build_gn_target)) { |
| non_sdk_deps += [ ":${transform_build_gn_target}" ] |
| } |
| } |
| } |