third_party.pigweed.src/pw_build/error.gni

53 lines
1.6 KiB
Plaintext
Raw Normal View History

# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import("python_action.gni")
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
# Prints an error message and exits the build unsuccessfully. Either 'message'
# or 'message_lines' must be specified, but not both.
#
# Args:
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
# message: The message to print. Use \n for newlines.
# message_lines: List of lines to use for the message.
#
template("pw_error") {
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
assert(
defined(invoker.message) != defined(invoker.message_lines),
"pw_error requires either a 'message' string or a 'message_lines' list")
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
if (defined(invoker.message_lines)) {
_message = string_join("\n", invoker.message_lines)
} else {
_message = invoker.message
}
assert(_message != "", "The message cannot be empty")
action(target_name) {
script = "$dir_pw_build/py/pw_build/error.py"
args = [
"--target",
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
get_label_info(":$target_name", "label_with_toolchain"),
"--message",
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
_message,
"--root",
Remove absolute paths from build command lines The GN convention is to specify paths in command lines relative to the build directory. Unfortunately and contrary to pigweed's expectations this is not what rebase_path(path) does; that outputs an absolute path. Absolute paths are not desirable in most circumstances as they contain sources of nondeterminism such as the developer's home directory. Using them can for example reduce hit rate in build caches. Replace rebase_path(path) with rebase_path(path, root_build_dir) which is the correct idiom and matches GN's builtin behavior (e.g. for sources, include_dirs, etc). This also removes the --directory argument to python_action(). Changing the directory during the build while using relative paths is likely to result in confusion and should be discouraged. There's a couple more things to do on top of this for identical binaries between build directories / machines / developers: - pass options to avoid embedding the working directory - pass options to use relative paths for the vendored clang & libc++ See [1]-[2] for how to do that. [1] https://source.chromium.org/chromium/chromium/src/+/main:build/config/compiler/BUILD.gn;l=1170-1239;drc=ab531c265c533cba1c2f6d8240cc0bf7679f605a [2] https://cs.opensource.google/fuchsia/fuchsia/+/main:build/config/BUILD.gn;l=145-216;drc=f6d705f0937c778d5d5f807a4580113612b02f5a Change-Id: I17708102c03d6488d68c8571b6e9343191fd47de Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/47461 Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Michael Spang <spang@google.com>
2021-05-30 19:53:56 +00:00
rebase_path("//", root_build_dir),
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
"--out",
Remove absolute paths from build command lines The GN convention is to specify paths in command lines relative to the build directory. Unfortunately and contrary to pigweed's expectations this is not what rebase_path(path) does; that outputs an absolute path. Absolute paths are not desirable in most circumstances as they contain sources of nondeterminism such as the developer's home directory. Using them can for example reduce hit rate in build caches. Replace rebase_path(path) with rebase_path(path, root_build_dir) which is the correct idiom and matches GN's builtin behavior (e.g. for sources, include_dirs, etc). This also removes the --directory argument to python_action(). Changing the directory during the build while using relative paths is likely to result in confusion and should be discouraged. There's a couple more things to do on top of this for identical binaries between build directories / machines / developers: - pass options to avoid embedding the working directory - pass options to use relative paths for the vendored clang & libc++ See [1]-[2] for how to do that. [1] https://source.chromium.org/chromium/chromium/src/+/main:build/config/compiler/BUILD.gn;l=1170-1239;drc=ab531c265c533cba1c2f6d8240cc0bf7679f605a [2] https://cs.opensource.google/fuchsia/fuchsia/+/main:build/config/BUILD.gn;l=145-216;drc=f6d705f0937c778d5d5f807a4580113612b02f5a Change-Id: I17708102c03d6488d68c8571b6e9343191fd47de Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/47461 Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Michael Spang <spang@google.com>
2021-05-30 19:53:56 +00:00
".",
]
pw_build: Update pw_error template - Display full target names, including the toolchain, for build errors. - Print the dependency path that caused the error using gn path. - Add message_lines argument to simplify multi-line messages. - Replace null_backend.py with pw_error. - Ensure that pw_error works without the Pigweed Python packages installed. Example error if pw_log_BACKEND is unset: 9:28:27 ERR 9:28:27 ERR Build error for //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug): 9:28:27 ERR 9:28:27 ERR Attempted to build the //pw_log:pw_log facade with no backend. 9:28:27 ERR 9:28:27 ERR If you are using this facade, ensure you have configured a backend 9:28:27 ERR properly. The build arg for the facade must be set to a valid 9:28:27 ERR backend in the toolchain. For example, you may need to add a line 9:28:27 ERR like the following to the toolchain's .gni file: 9:28:27 ERR 9:28:27 ERR pw_log_BACKEND = "//path/to/the:backend" 9:28:27 ERR 9:28:27 ERR If you are NOT using this facade, this error may have been triggered 9:28:27 ERR by trying to build all targets. 9:28:27 ERR 9:28:28 ERR Dependency path to this target: 9:28:28 ERR 9:28:28 ERR gn path out //:default "//pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug)" //:default --[private]--> //:host --[private]--> //:pigweed_default(//targets/host:host_clang_debug) --[private]--> //pw_trace:trace_example_basic(//targets/host:host_clang_debug) --[private]--> //pw_log:pw_log(//targets/host:host_clang_debug) --[public]--> //pw_log:pw_log.NO_BACKEND_SET(//targets/host:host_clang_debug) Showing one of 75 "interesting" non-data paths. 0 of them are public. Use --all to print all paths. Fixed: 336 Change-Id: Ida252e1ae9956822ec0efbbfc82bad60f58de5e8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36240 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-09 16:37:19 +00:00
# This output file is never created.
outputs = [ "$target_gen_dir/$target_name.build_error" ]
}
}