Armando Montanez | 72b9385 | 2020-11-10 15:33:22 -0800 | [diff] [blame] | 1 | # Copyright 2020 The Pigweed Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | # use this file except in compliance with the License. You may obtain a copy of |
| 5 | # the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations under |
| 13 | # the License. |
| 14 | |
| 15 | import("//build_overrides/pigweed.gni") |
| 16 | |
| 17 | import("$dir_pw_toolchain/generate_toolchain.gni") |
| 18 | |
| 19 | # Generates a toolchain using the currently active toolchain as a foundation. |
| 20 | # WARNING: Only works with toolchains generated by Pigweed's generate_toolchain. |
| 21 | # WARNING: This can quickly create an explosion of toolchains and compile times. |
| 22 | # Use sparingly! |
| 23 | # |
| 24 | # Args: |
| 25 | # build_args: (required) A scope setting GN build arg values to apply to GN |
| 26 | # targets in this toolchain. These take precedence over args.gni settings, |
| 27 | # and any build_args set by the currently active toolchain. |
| 28 | # (other): You can optionally override all other generate_toolchain args. See |
| 29 | # that template's documentation for more information. |
| 30 | template("pw_generate_subtoolchain") { |
| 31 | assert(defined(invoker.build_args), "Sub-toolchain is missing 'build_args'") |
| 32 | _original_scope = pw_toolchain_SCOPE |
| 33 | assert(defined(_original_scope.name), |
| 34 | "Sub-toolchain must be generated from a Pigweed toolchain") |
| 35 | |
| 36 | generate_toolchain(target_name) { |
| 37 | forward_variables_from(_original_scope, "*", [ "defaults" ]) |
| 38 | forward_variables_from(invoker, "*", [ "build_args" ]) |
| 39 | |
| 40 | # Subtoolchains must always be generated from the toolchain that parses |
| 41 | # them rather than relying on the default_toolchain. |
| 42 | generate_from = current_toolchain |
| 43 | defaults = { |
| 44 | forward_variables_from(_original_scope.defaults, "*") |
| 45 | forward_variables_from(invoker.build_args, "*") |
| 46 | } |
| 47 | } |
| 48 | } |