| # Copyright 2020 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/toolchain/default_tools.gni") |
| |
| # Define a basic GN toolchain() instance that only has the "stamp" and "copy" |
| # tools. Use this for toolchains that will only have action() targets. |
| # |
| # Parameters: |
| # expected_label: Optional |
| # If provided, this template will assert that the full toolchain label |
| # matches this value. This is useful when the definition should match |
| # a global variable (e.g. go_toolchain or dart_toolchain). |
| # Type: GN label |
| # |
| # toolchain_args: Optional |
| # A scope of extra toolchain_args keys for this toolchain instance. |
| # |
| # NOTE: This also ensures this defines the global `toolchain_variant.base` |
| # variable, allowing BUILDCONFIG.gn to detect that this is not the default |
| # toolchain (see the definition of in_default_toolchain in that file for |
| # more details). |
| template("basic_toolchain") { |
| if (current_toolchain == default_toolchain) { |
| # Basic toolchains should only be expanded once in the default toolchain. |
| toolchain(target_name) { |
| tool("stamp") { |
| command = stamp_command |
| description = stamp_description |
| } |
| tool("copy") { |
| command = copy_command |
| description = copy_description |
| } |
| toolchain_args = { |
| if (defined(invoker.toolchain_args)) { |
| forward_variables_from(invoker.toolchain_args, "*") |
| } |
| toolchain_variant = { |
| } |
| toolchain_variant = { |
| base = get_label_info(":$target_name", "label_no_toolchain") |
| if (defined(invoker.expected_label)) { |
| assert( |
| base == invoker.expected_label, |
| "Invalid toolchain label $base, expected ${invoker.expected_label}") |
| } |
| } |
| } |
| } |
| } else { |
| not_needed("*") |
| not_needed(invoker, "*") |
| } |
| } |