| # Copyright 2019 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/compiled_action.gni") |
| import("config.gni") |
| |
| # Aggregates multiple SDKs into a single archive. |
| # |
| # Parameters |
| # |
| # deps (required) |
| # List of labels representing SDKs to merge. |
| # A label may point to an `sdk` instance. |
| |
| template("merged_sdk") { |
| assert(defined(invoker.deps), "Must define a 'deps' parameter") |
| assert(invoker.deps != [], "'deps' may not be empty") |
| |
| dep_count = 0 |
| foreach(dep, invoker.deps) { |
| dep_count = dep_count + 1 |
| } |
| |
| index = 0 |
| foreach(dep, invoker.deps) { |
| export_dir = "${root_out_dir}/sdk/exported" |
| name = get_label_info(dep, "name") |
| dep_dir = "${export_dir}/$name" |
| dep_gen_dir = get_label_info(dep, "target_gen_dir") |
| dep_stamp = "$dep_gen_dir/$name.exported" |
| _outputs = [] |
| |
| if (index == 0) { |
| latest_dir = dep_dir |
| latest_stamp = dep_stamp |
| } else { |
| step = "${target_name}_merge_${index}" |
| |
| # Produce an archive only on the last step. Intermediate merged SDKs are |
| # symlink forests, like the input exported SDKs, to save disk space. |
| merged = "$target_gen_dir/$target_name.$index" |
| merged_stamp = "$merged.stamp" |
| _outputs += [ merged_stamp ] |
| if (index < dep_count - 1) { |
| output_flag = "--output-directory" |
| } else { |
| output_flag = "--output-archive" |
| merged += ".tar.gz" |
| _outputs += [ merged ] |
| } |
| |
| action(step) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| #TODO(b/222339823): Switch to Rust merge tool when fixed. |
| script = "//scripts/sdk/merger/merge.py" |
| |
| sources = [ |
| dep_stamp, |
| latest_stamp, |
| ] |
| |
| outputs = _outputs |
| |
| depfile = merged_stamp + ".d" |
| |
| args = [ |
| "--first-directory", |
| rebase_path(latest_dir, root_build_dir), |
| "--second-directory", |
| rebase_path(dep_dir, root_build_dir), |
| output_flag, |
| rebase_path(merged, root_build_dir), |
| "--stamp-file", |
| rebase_path(merged_stamp, root_build_dir), |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| ] |
| |
| if (index == 1) { |
| public_deps = invoker.deps |
| } else { |
| public_deps = [ ":$latest_step" ] |
| } |
| } |
| |
| latest_dir = merged |
| latest_stamp = merged_stamp |
| latest_step = step |
| } |
| |
| index = index + 1 |
| } |
| |
| copy(target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| output_archive = "${root_out_dir}/sdk/archive/${target_name}.tar.gz" |
| |
| sources = [ latest_dir ] |
| |
| outputs = [ output_archive ] |
| |
| public_deps = [ ":$latest_step" ] |
| |
| metadata = { |
| sdk_archives = [ |
| { |
| name = target_name |
| os = current_os |
| cpu = current_cpu |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| path = rebase_path(output_archive, root_build_dir) |
| }, |
| ] |
| } |
| } |
| } |