Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions copied_base/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/sysroot.gni")
import("//build/config/ui.gni")
import("//build/nocompile.gni")
import("//build/timestamp.gni")
import("//build_overrides/build.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
Expand Down Expand Up @@ -103,6 +102,8 @@ if (is_fuchsia) {
import("//third_party/fuchsia-sdk/sdk/build/fidl_library.gni")
}

_build_date_header = "$target_gen_dir/generated_build_date.h"

if (is_cobalt) {
use_perfetto_client_library = true
enable_log_error_not_reached = false
Expand Down Expand Up @@ -943,6 +944,7 @@ component("base") {
"version.h",
"vlog.cc",
"vlog.h",
_build_date_header,
]


Expand Down Expand Up @@ -4181,15 +4183,11 @@ if (is_win && toolchain_has_rust) {
}
}

action("build_date") {
script = "write_build_date_header.py"

outputs = [ "$target_gen_dir/generated_build_date.h" ]

args = [
rebase_path("$target_gen_dir/generated_build_date.h", root_build_dir),
build_timestamp,
]
copy("build_date") {
# Reuse the file generated by //base:build_date_internal.
sources = [ "$root_build_dir/gen/base/generated_build_date_internal.h" ]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a hardcoded path for the source file is brittle as it assumes a specific directory structure within the build output. It is more robust to use get_label_info to dynamically determine the output directory of the dependency, especially when referencing a target in a different toolchain. This aligns with Chromium GN best practices for maintainability.

Suggested change
sources = [ "$root_build_dir/gen/base/generated_build_date_internal.h" ]
sources = [ get_label_info("//base:build_date_internal($default_toolchain)", "target_gen_dir") + "/generated_build_date_internal.h" ]
References
  1. Adhere to established upstream Chromium style guides for GN files, which prefer using get_label_info for cross-target path references to avoid brittle hardcoded paths. (link)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the same sources that //base:build_date uses.

outputs = [ _build_date_header ]
deps = [ "//base:build_date_internal($default_toolchain)" ]
}

if (is_android || is_robolectric) {
Expand Down
Loading