From 669060f8c7f955053acc3b20ff3e9657acecef33 Mon Sep 17 00:00:00 2001 From: Jonas Termansen Date: Wed, 20 Dec 2023 12:23:56 +0000 Subject: [PATCH] [build] Omit SDK and Git hashes on RBE. Bug: b/296994239 Change-Id: I70c10fddc3bd01fef5ed5182e1d28d0797c431e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342421 Commit-Queue: Jonas Termansen Reviewed-by: Slava Egorov --- ...nguage_versioning_up_to_date_git_test.dart | 2 +- runtime/BUILD.gn | 4 +-- runtime/tests/vm/dart/sdk_hash_test.dart | 8 ----- sdk/BUILD.gn | 9 ++++++ tools/gn.py | 30 +++++++++++++++---- tools/make_version.py | 4 +-- tools/write_dartdoc_options_file.py | 10 +++++-- tools/write_revision_file.py | 11 +++++-- tools/write_version_file.py | 6 +++- utils/compiler/BUILD.gn | 3 ++ utils/compiler/create_snapshot_entry.dart | 22 ++++++++++---- 11 files changed, 80 insertions(+), 29 deletions(-) diff --git a/pkg/front_end/test/language_versioning/language_versioning_up_to_date_git_test.dart b/pkg/front_end/test/language_versioning/language_versioning_up_to_date_git_test.dart index 88e84ac4330..c6e7950ec5f 100644 --- a/pkg/front_end/test/language_versioning/language_versioning_up_to_date_git_test.dart +++ b/pkg/front_end/test/language_versioning/language_versioning_up_to_date_git_test.dart @@ -16,7 +16,7 @@ String get dartVm => Platform.executable; Future main(List args) async { ProcessResult result = await Process.run( - "python3", ["tools/make_version.py", "--no_git", "-q"], + "python3", ["tools/make_version.py", "--no-git-hash", "-q"], workingDirectory: repoDir); String stdout = result.stdout.toString(); diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 7b71d1bc398..321f4986a09 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -366,9 +366,9 @@ action("generate_version_cc_file") { rebase_path("vm/version_in.cc", root_build_dir), ] if (!dart_version_git_info) { - args += [ "--no_git_hash" ] + args += [ "--no-git-hash" ] } if (!verify_sdk_hash) { - args += [ "--no_sdk_hash" ] + args += [ "--no-sdk-hash" ] } } diff --git a/runtime/tests/vm/dart/sdk_hash_test.dart b/runtime/tests/vm/dart/sdk_hash_test.dart index 700ed037c65..ef6d121ea50 100644 --- a/runtime/tests/vm/dart/sdk_hash_test.dart +++ b/runtime/tests/vm/dart/sdk_hash_test.dart @@ -59,14 +59,6 @@ Future main(List args) async { myFile.writeAsBytesSync(bytes); } - { - final result = await Process.run(dart, [dillPath, '--child']); - Expect.equals( - 'Can\'t load Kernel binary: Invalid SDK hash.', result.stderr.trim()); - Expect.equals(253, result.exitCode); - Expect.equals('', result.stdout); - } - // Zero out the SDK hash in the kernel dill to disable the check: { final myFile = File(dillPath); diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 7d17e8e3577..0d2694079df 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -674,6 +674,9 @@ action("write_version_file") { "--output", rebase_path(output), ] + if (!dart_version_git_info) { + args += [ "--no-git-hash" ] + } } # This rule writes the revision file. @@ -687,6 +690,9 @@ action("write_revision_file") { "--output", rebase_path(output), ] + if (!dart_version_git_info) { + args += [ "--no-git-hash" ] + } } # This rule copies the README file. @@ -714,6 +720,9 @@ action("write_dartdoc_options") { "--output", rebase_path(output), ] + if (!dart_version_git_info) { + args += [ "--no-git-hash" ] + } } # This rule copies the API readme file to lib/ diff --git a/tools/gn.py b/tools/gn.py index a1991d824b0..7cac8e02f15 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -189,7 +189,8 @@ def UseSysroot(args, gn_args): return True -def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash): +def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash, + git_version): gn_args = {} host_os = HostOsForGn(HOST_OS) @@ -332,6 +333,7 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash): gn_args['debug_optimization_level'] = args.debug_opt_level gn_args['verify_sdk_hash'] = verify_sdk_hash + gn_args['dart_version_git_info'] = git_version if args.codesigning_identity != '': gn_args['codesigning_identity'] = args.codesigning_identity @@ -437,22 +439,26 @@ def ide_switch(host_os): def AddCommonGnOptionArgs(parser): """Adds arguments that will change the default GN arguments.""" + use_rbe = os.environ.get('RBE_cfg') != None + parser.add_argument('--goma', help='Use goma', action='store_true') parser.add_argument('--no-goma', help='Disable goma', dest='goma', action='store_false') - parser.set_defaults(goma=os.environ.get('RBE_cfg') == None) + parser.set_defaults(goma=not use_rbe) parser.add_argument('--rbe', help='Use rbe', action='store_true') parser.add_argument('--no-rbe', help='Disable rbe', dest='rbe', action='store_false') - parser.set_defaults(rbe=os.environ.get('RBE_cfg') != None) + parser.set_defaults(rbe=use_rbe) + # Disable git hashes when remote compiling to ensure cache hits of the final + # output artifacts when nothing has changed. parser.add_argument('--verify-sdk-hash', - help='Enable SDK hash checks (default)', + help='Enable SDK hash checks', dest='verify_sdk_hash', action='store_true') parser.add_argument('-nvh', @@ -460,7 +466,18 @@ def AddCommonGnOptionArgs(parser): help='Disable SDK hash checks', dest='verify_sdk_hash', action='store_false') - parser.set_defaults(verify_sdk_hash=True) + parser.set_defaults(verify_sdk_hash=not use_rbe) + + parser.add_argument('--git-version', + help='Enable git commit in version', + dest='git_version', + action='store_true') + parser.add_argument('-ngv', + '--no-git-version', + help='Disable git commit in version', + dest='git_version', + action='store_false') + parser.set_defaults(git_version=not use_rbe) parser.add_argument('--clang', help='Use Clang', action='store_true') parser.add_argument('--no-clang', @@ -615,7 +632,8 @@ def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir): # See dartbug.com/32364 command = [gn, 'gen', out_dir] gn_args = ToCommandLine( - ToGnArgs(args, mode, arch, target_os, sanitizer, args.verify_sdk_hash)) + ToGnArgs(args, mode, arch, target_os, sanitizer, args.verify_sdk_hash, + args.git_version)) gn_args += GetGNArgs(args) if args.ide: command.append(ide_switch(HOST_OS)) diff --git a/tools/make_version.py b/tools/make_version.py index e52ca5f33f7..768870f8eff 100755 --- a/tools/make_version.py +++ b/tools/make_version.py @@ -96,13 +96,13 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--input', help='Input template file.') parser.add_argument( - '--no_git_hash', + '--no-git-hash', action='store_true', default=False, help=('Don\'t try to call git to derive things like ' 'git revision hash.')) parser.add_argument( - '--no_sdk_hash', + '--no-sdk-hash', action='store_true', default=False, help='Use null SDK hash to disable SDK verification in the VM') diff --git a/tools/write_dartdoc_options_file.py b/tools/write_dartdoc_options_file.py index 8932b847a6c..8624301b04c 100755 --- a/tools/write_dartdoc_options_file.py +++ b/tools/write_dartdoc_options_file.py @@ -15,6 +15,10 @@ def ParseArgs(args): parser.add_argument( '--output', '-o', type=str, required=True, help='File to write') + parser.add_argument('--no-git-hash', + help='Omit the git hash in the output', + dest='no_git_hash', + action='store_true') return parser.parse_args(args) @@ -22,9 +26,11 @@ def ParseArgs(args): def Main(argv): args = ParseArgs(argv) # TODO(jcollins-g): switch to version numbers when github has its tags synced - revision = utils.GetGitRevision() + revision = None + if not args.no_git_hash: + revision = utils.GetGitRevision() if revision is None: - revision = 'master' + revision = 'main' output = '''dartdoc: categoryOrder: ["Core", "VM", "Web"] linkToSource: diff --git a/tools/write_revision_file.py b/tools/write_revision_file.py index 3b9dd7d5a6b..40540432b2a 100755 --- a/tools/write_revision_file.py +++ b/tools/write_revision_file.py @@ -12,17 +12,24 @@ import utils def ParseArgs(args): args = args[1:] parser = argparse.ArgumentParser( - description='A script to write the version string to a file') + description='A script to write the revision string to a file') parser.add_argument( '--output', '-o', type=str, required=True, help='File to write') + parser.add_argument('--no-git-hash', + help='Omit the git hash in the output', + dest='no_git_hash', + action='store_true') return parser.parse_args(args) def Main(argv): args = ParseArgs(argv) - revision = utils.GetGitRevision() + if not args.no_git_hash: + revision = utils.GetGitRevision() + else: + revision = '' if revision is not None: with open(args.output, 'w') as f: f.write('%s\n' % revision) diff --git a/tools/write_version_file.py b/tools/write_version_file.py index aea586c32dd..2a57b55bcad 100755 --- a/tools/write_version_file.py +++ b/tools/write_version_file.py @@ -16,13 +16,17 @@ def ParseArgs(args): parser.add_argument( '--output', '-o', type=str, required=True, help='File to write') + parser.add_argument('--no-git-hash', + help='Omit the git hash in the output', + dest='no_git_hash', + action='store_true') return parser.parse_args(args) def Main(argv): args = ParseArgs(argv) - version = utils.GetVersion() + version = utils.GetVersion(no_git_hash=args.no_git_hash) with open(args.output, 'w') as versionFile: versionFile.write(version + '\n') return 0 diff --git a/utils/compiler/BUILD.gn b/utils/compiler/BUILD.gn index 92d6baa902e..2fdba1a7ca0 100644 --- a/utils/compiler/BUILD.gn +++ b/utils/compiler/BUILD.gn @@ -45,6 +45,9 @@ prebuilt_dart_action("dart2js_create_snapshot_entry") { packages = "../../.dart_tool/package_config.json" args = [ "--output_dir=$output_dir" ] + if (!dart_version_git_info) { + args += [ "--no-git-hash" ] + } } sdk_root = "../../sdk" diff --git a/utils/compiler/create_snapshot_entry.dart b/utils/compiler/create_snapshot_entry.dart index 2533d5711ee..534cbdb7e5b 100644 --- a/utils/compiler/create_snapshot_entry.dart +++ b/utils/compiler/create_snapshot_entry.dart @@ -9,9 +9,15 @@ import 'dart:io'; import 'dart:async'; -Future getVersion(var rootPath) { +Future getVersion(var rootPath, bool noGitHash) { var printVersionScript = rootPath.resolve("tools/make_version.py"); - return Process.run("python3", [printVersionScript.toFilePath(), "--quiet"], + return Process.run( + "python3", + [ + printVersionScript.toFilePath(), + "--quiet", + if (noGitHash) '--no-git-hash' + ], runInShell: true) .then((result) { if (result.exitCode != 0) { @@ -21,8 +27,8 @@ Future getVersion(var rootPath) { }); } -Future getDart2jsSnapshotGenerationFile(var rootPath) { - return getVersion(rootPath).then((version) { +Future getDart2jsSnapshotGenerationFile(var rootPath, bool noGitHash) { + return getVersion(rootPath, noGitHash).then((version) { var snapshotGenerationText = """ import 'package:compiler/src/dart2js.dart' as dart2jsMain; @@ -39,11 +45,17 @@ void main(List arguments) { * Takes the following arguments: * --output_dir=val The full path to the output_dir. * --dart2js_main=val The path to the dart2js main script relative to root. + * --no-git-hash Omit the git hash in the output. */ void main(List arguments) { + bool noGitHash = false; var validArguments = ["--output_dir", "--dart2js_main"]; var args = {}; for (var argument in arguments) { + if (argument == '--no-git-hash') { + noGitHash = true; + continue; + } var argumentSplit = argument.split("="); if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; if (!validArguments.contains(argumentSplit[0])) { @@ -57,7 +69,7 @@ void main(List arguments) { var path = scriptFile.resolve("."); var rootPath = path.resolve("../.."); - getDart2jsSnapshotGenerationFile(rootPath).then((result) { + getDart2jsSnapshotGenerationFile(rootPath, noGitHash).then((result) { var wrapper = "${args['output_dir']}/dart2js.dart"; new File(wrapper).writeAsStringSync(result); });