diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index fca6c92950708..e579cc9a9d1fd 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -1636,22 +1636,74 @@ config("compiler_deterministic") { config("clang_revision") { if (is_clang && clang_base_path == default_clang_base_path && current_os != "zos") { - update_args = [ - "--print-revision", - "--verify-version=$clang_version", - ] + _perform_consistency_checks = current_toolchain == default_toolchain if (llvm_force_head_revision) { - update_args += [ "--llvm-force-head-revision" ] + _head_revision_stamp_path = "//third_party/llvm-build/force_head_revision" + _head_revision = "" + if (path_exists(_head_revision_stamp_path)) { + _head_revision = read_file(_head_revision_stamp_path, "trim string") + } + assert( + _head_revision != "", + "llvm_force_head_revision=true, but no locally built version was detected.") + _clang_revision = _head_revision + } else { + _clang_revision = read_file( + "//third_party/llvm-build/Release+Asserts/cr_build_revision", + "trim string") + + # Ensure that the synced clang version matches what's in git. + if (_perform_consistency_checks) { + # Parse the clang version from the Python script. + _clang_version_lines = filter_include( + read_file("//tools/clang/scripts/update.py", "list lines"), + [ "CLANG_*REVISION = *" ]) + _py_revision = + string_replace(_clang_version_lines[0], "CLANG_REVISION = '", "") + _py_revision = string_replace(_py_revision, "'", "") + _py_subrevision = + string_replace(_clang_version_lines[1], "CLANG_SUB_REVISION = ", "") + _expected_clang_revision = "$_py_revision-$_py_subrevision" + + assert( + _clang_revision == _expected_clang_revision, + "clang_revision=\"$_clang_revision\" but update.py expected \"$_expected_clang_revision\". Did you forget to gclient sync?") + } + } + + if (_perform_consistency_checks) { + # Ensure that the revision matches the version major expected by GN. + _versions_match = filter_include([ _clang_revision ], + [ "llvmorg-$clang_version-*" ]) != [] + assert( + _versions_match, + "clang_revision=\"$_clang_revision\" but clang_version=\"$clang_version\". clang_version in build/toolchain/toolchain.gni is likely outdated.") + } + + if (toolchain_has_rust && _perform_consistency_checks) { + # Ensure that the synced rust version matches what's in git. + _rust_revision_lines = + filter_include(read_file("//tools/rust/update_rust.py", "list lines"), + [ "RUST_*REVISION = *" ]) + _py_revision = + string_replace(_rust_revision_lines[0], "RUST_REVISION = '", "") + _py_revision = string_replace(_py_revision, "'", "") + _py_subrevision = + string_replace(_rust_revision_lines[1], "RUST_SUB_REVISION = ", "") + _expected_rust_revision = "$_py_revision-$_py_subrevision" + + # Ensure the rust version matches the clang version. + assert( + filter_include([ rustc_revision ], + [ "*-$_expected_rust_revision-*" ]) != [], + "rustc_revision=\"$rustc_revision\" but update_rust.py expected \"$_expected_rust_revision\". Run \"gclient sync\"?") } - clang_revision = exec_script("//tools/clang/scripts/update.py", - update_args, - "trim string") # This is here so that all files get recompiled after a clang roll and # when turning clang on or off. (defines are passed via the command line, # and build system rebuild things when their commandline changes). Nothing # should ever read this define. - defines = [ "CR_CLANG_REVISION=\"$clang_revision\"" ] + defines = [ "CR_CLANG_REVISION=\"$_clang_revision\"" ] } } diff --git a/build/config/rust.gni b/build/config/rust.gni index 4b66d4e8091a7..80ff972570e3c 100644 --- a/build/config/rust.gni +++ b/build/config/rust.gni @@ -125,10 +125,20 @@ if (enable_rust) { if (use_chromium_rust_toolchain) { toolchain_has_rust = chromium_toolchain_supports_platform if (toolchain_has_rust) { - update_rust_args = [ "--print-package-version" ] - rustc_revision = exec_script("//tools/rust/update_rust.py", - update_rust_args, - "trim string") + rustc_revision = + read_file("//third_party/rust-toolchain/VERSION", "trim string") + + # Example: + # rustc 1.88.0 c8f94230282a8e8c1148f3e657f0199aad909228 (c8f94230282a8e8c1148f3e657f0199aad909228-1-llvmorg-21-init-9266-g09006611 chromium) + # Trim it down as much as we can using GN. + rustc_revision = string_replace(rustc_revision, "rustc ", "") + rustc_revision = string_replace(rustc_revision, " chromium", "") + rustc_revision = string_replace(rustc_revision, "init-", "") + rustc_revision = string_replace(rustc_revision, "llvmorg-", "") + rustc_revision = string_replace(rustc_revision, " ", "") + rustc_revision = string_replace(rustc_revision, ".", "") + rustc_revision = string_replace(rustc_revision, "(", "-") + rustc_revision = string_replace(rustc_revision, ")", "") } # The same as written in `config.toml.template`. diff --git a/build/dotfile_settings.gni b/build/dotfile_settings.gni index bf0c43e299d10..4b8d16a5d5c83 100644 --- a/build/dotfile_settings.gni +++ b/build/dotfile_settings.gni @@ -11,7 +11,6 @@ build_dotfile_settings = { "//build/config/apple/mobile_config.gni", "//build/config/chromeos/rules.gni", "//build/config/clang/BUILD.gn", - "//build/config/compiler/BUILD.gn", "//build/config/compiler/pgo/BUILD.gn", "//build/config/gcc/gcc_version.gni", "//build/config/host_byteorder.gni", @@ -25,7 +24,6 @@ build_dotfile_settings = { "//build/config/mac/mac_sdk.gni", "//build/config/mac/rules.gni", "//build/config/posix/BUILD.gn", - "//build/config/rust.gni", "//build/config/win/BUILD.gn", "//build/config/win/visual_studio_version.gni", "//build/rust/analyze.gni", diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py index 8f419c43dcb0b..108d33c2e6380 100755 --- a/tools/clang/scripts/update.py +++ b/tools/clang/scripts/update.py @@ -36,6 +36,9 @@ import zlib # https://chromium.googlesource.com/chromium/src/+/main/docs/updating_clang.md # Reverting problematic clang rolls is safe, though. # This is the output of `git describe` and is usable as a commit-ish. +# These fields are written by //tools/clang/scripts/upload_revision.py, and +# should not be changed manually. +# They are also read by build/config/compiler/BUILD.gn. CLANG_REVISION = 'llvmorg-21-init-9266-g09006611' CLANG_SUB_REVISION = 1 @@ -328,16 +331,8 @@ def main(): parser.add_argument('--print-clang-version', action='store_true', help=('Print current clang release version (e.g. 9.0.0) ' 'and exit.')) - parser.add_argument('--verify-version', - help='Verify that clang has the passed-in version.') args = parser.parse_args() - if args.verify_version and args.verify_version != RELEASE_VERSION: - print('RELEASE_VERSION is %s but --verify-version argument was %s.' % ( - RELEASE_VERSION, args.verify_version)) - print('clang_version in build/toolchain/toolchain.gni is likely outdated.') - return 1 - if args.print_clang_version: print(RELEASE_VERSION) return 0 diff --git a/tools/rust/update_rust.py b/tools/rust/update_rust.py index 183e234c000b6..e4cf4e0c44d7c 100755 --- a/tools/rust/update_rust.py +++ b/tools/rust/update_rust.py @@ -31,6 +31,7 @@ sys.path.append( # These fields are written by //tools/clang/scripts/upload_revision.py, and # should not be changed manually. +# They are also read by build/config/compiler/BUILD.gn. RUST_REVISION = 'c8f94230282a8e8c1148f3e657f0199aad909228' RUST_SUB_REVISION = 1