blob: 653b4a9121c155bc851ad1c2195ee02e4765e066 [file] [log] [blame]
Alexei Frolov9c35aac2020-10-28 12:36:41 -07001# 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
15import("python_action.gni")
16
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080017# Prints an error message and exits the build unsuccessfully. Either 'message'
18# or 'message_lines' must be specified, but not both.
Alexei Frolov9c35aac2020-10-28 12:36:41 -070019#
20# Args:
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080021# message: The message to print. Use \n for newlines.
22# message_lines: List of lines to use for the message.
Alexei Frolov9c35aac2020-10-28 12:36:41 -070023#
24template("pw_error") {
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080025 assert(
26 defined(invoker.message) != defined(invoker.message_lines),
27 "pw_error requires either a 'message' string or a 'message_lines' list")
Alexei Frolov9c35aac2020-10-28 12:36:41 -070028
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080029 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 Frolov9c35aac2020-10-28 12:36:41 -070037 script = "$dir_pw_build/py/pw_build/error.py"
38 args = [
39 "--target",
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080040 get_label_info(":$target_name", "label_with_toolchain"),
Alexei Frolov9c35aac2020-10-28 12:36:41 -070041 "--message",
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080042 _message,
43 "--root",
Michael Spangc8b93902021-05-30 15:53:56 -040044 rebase_path("//", root_build_dir),
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080045 "--out",
Michael Spangc8b93902021-05-30 15:53:56 -040046 ".",
Alexei Frolov9c35aac2020-10-28 12:36:41 -070047 ]
Wyatt Hepler0c84ab62021-03-09 08:37:19 -080048
49 # This output file is never created.
50 outputs = [ "$target_gen_dir/$target_name.build_error" ]
Alexei Frolov9c35aac2020-10-28 12:36:41 -070051 }
52}