Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [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("python_action.gni") |
| 16 | |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 17 | # Prints an error message and exits the build unsuccessfully. Either 'message' |
| 18 | # or 'message_lines' must be specified, but not both. |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 19 | # |
| 20 | # Args: |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 21 | # message: The message to print. Use \n for newlines. |
| 22 | # message_lines: List of lines to use for the message. |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 23 | # |
| 24 | template("pw_error") { |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 25 | assert( |
| 26 | defined(invoker.message) != defined(invoker.message_lines), |
| 27 | "pw_error requires either a 'message' string or a 'message_lines' list") |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 28 | |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 29 | if (defined(invoker.message_lines)) { |
| 30 | _message = string_join("\n", invoker.message_lines) |
| 31 | } else { |
| 32 | _message = invoker.message |
| 33 | } |
| 34 | assert(_message != "", "The message cannot be empty") |
| 35 | |
| 36 | action(target_name) { |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 37 | script = "$dir_pw_build/py/pw_build/error.py" |
| 38 | args = [ |
| 39 | "--target", |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 40 | get_label_info(":$target_name", "label_with_toolchain"), |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 41 | "--message", |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 42 | _message, |
| 43 | "--root", |
Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame] | 44 | rebase_path("//", root_build_dir), |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 45 | "--out", |
Michael Spang | c8b9390 | 2021-05-30 15:53:56 -0400 | [diff] [blame] | 46 | ".", |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 47 | ] |
Wyatt Hepler | 0c84ab6 | 2021-03-09 08:37:19 -0800 | [diff] [blame] | 48 | |
| 49 | # This output file is never created. |
| 50 | outputs = [ "$target_gen_dir/$target_name.build_error" ] |
Alexei Frolov | 9c35aac | 2020-10-28 12:36:41 -0700 | [diff] [blame] | 51 | } |
| 52 | } |