Regenerate .def file from the main script when rolling abseil Now that BUILD files are converted automatically, next step after it can become part of the main rolling script too. Bug: 524565513 Change-Id: Ia89a0bc1bf48a9f2423e3a594464d412cc054557 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8203925 Commit-Queue: Danil Chapovalov <danilchap@chromium.org> Reviewed-by: Mirko Bonadei <mbonadei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1674808} NOKEYCHECK=True GitOrigin-RevId: f30aa66c781d94e25ea2300b5c1f21bdf5bfbaad
diff --git a/generate_def_files.py b/generate_def_files.py index c80356f..2e269da 100755 --- a/generate_def_files.py +++ b/generate_def_files.py
@@ -41,112 +41,129 @@ def _DebugOrRelease(is_debug): - return 'dbg' if is_debug else 'rel' + return 'dbg' if is_debug else 'rel' def _GenerateDefFileBuild(cpu, is_debug, use_cxx23, extra_gn_args, suffix, out_dir, cwd): - if extra_gn_args: - assert suffix != None, 'suffix is needed when extra_gn_args is used' + if extra_gn_args: + assert suffix != None, 'suffix is needed when extra_gn_args is used' - flavor = _DebugOrRelease(is_debug) - gn_args = [ - 'ffmpeg_branding = "Chrome"', - 'is_component_build = true', - 'is_debug = {}'.format(str(is_debug).lower()), - 'proprietary_codecs = true', - 'use_cxx23={}'.format(str(use_cxx23).lower()), - 'symbol_level = 0', - 'target_cpu = "{}"'.format(cpu), - 'target_os = "win"', - 'use_remoteexec = true', - ] - gn_args.extend(extra_gn_args) + flavor = _DebugOrRelease(is_debug) + gn_args = [ + 'ffmpeg_branding = "Chrome"', + 'is_component_build = true', + 'is_debug = {}'.format(str(is_debug).lower()), + 'proprietary_codecs = true', + 'use_cxx23={}'.format(str(use_cxx23).lower()), + 'symbol_level = 0', + 'target_cpu = "{}"'.format(cpu), + 'target_os = "win"', + 'use_remoteexec = true', + ] + gn_args.extend(extra_gn_args) - gn = 'gn' - autoninja = 'autoninja' - llvm_nm = ['third_party/llvm-build/Release+Asserts/bin/llvm-nm'] - if sys.platform == 'win32': - gn = 'gn.bat' - autoninja = 'autoninja.bat' - llvm_nm += '.exe' + gn = 'gn' + autoninja = 'autoninja' + llvm_nm = ['third_party/llvm-build/Release+Asserts/bin/llvm-nm'] + if sys.platform == 'win32': + gn = 'gn.bat' + autoninja = 'autoninja.bat' + llvm_nm += '.exe' - logging.info('[%s - %s] Creating tmp out dir in %s', cpu, flavor, out_dir) - subprocess.check_call([gn, 'gen', out_dir, '--args=' + ' '.join(gn_args)], - cwd=cwd) - logging.info('[%s - %s] gn gen completed', cpu, flavor) - subprocess.check_call( - [autoninja, '-C', out_dir, 'third_party/abseil-cpp:absl_component_deps'], - cwd=os.getcwd()) - logging.info('[%s - %s] autoninja completed', cpu, flavor) + logging.info('[%s - %s] Creating tmp out dir in %s', cpu, flavor, out_dir) + subprocess.check_call([gn, 'gen', out_dir, '--args=' + ' '.join(gn_args)], + cwd=cwd) + logging.info('[%s - %s] gn gen completed', cpu, flavor) + subprocess.check_call([ + autoninja, '-C', out_dir, 'third_party/abseil-cpp:absl_component_deps' + ], + cwd=os.getcwd()) + logging.info('[%s - %s] autoninja completed', cpu, flavor) - obj_files = [] - for root, _dirnames, filenames in os.walk( - os.path.join(out_dir, 'obj', 'third_party', 'abseil-cpp')): - matched_files = fnmatch.filter(filenames, '*.obj') - obj_files.extend((os.path.join(root, f) for f in matched_files)) + obj_files = [] + for root, _dirnames, filenames in os.walk( + os.path.join(out_dir, 'obj', 'third_party', 'abseil-cpp')): + matched_files = fnmatch.filter(filenames, '*.obj') + obj_files.extend((os.path.join(root, f) for f in matched_files)) - logging.info('[%s - %s] Found %d object files.', cpu, flavor, len(obj_files)) + logging.info('[%s - %s] Found %d object files.', cpu, flavor, + len(obj_files)) - absl_symbols = set() - for f in obj_files: - stdout = subprocess.check_output(llvm_nm + [f], cwd=os.getcwd()) - for line in stdout.splitlines(): - line = line.decode('utf-8') - match = re.match(ABSL_SYM_RE, line) - if match: - symbol = match.group('symbol') - assert symbol.count(' ') == 0, ('Regex matched too much, probably got ' - 'undecorated name as well') - # Avoid to export deleting dtors since they trigger - # "lld-link: error: export of deleting dtor" linker errors, see - # crbug.com/1201277. - if symbol.startswith('??_G'): - continue - # Strip any leading underscore for C names (as in __cdecl). It's only - # there on x86, but the x86 toolchain falls over when you include it! - if cpu == 'x86' and symbol.startswith('_'): - symbol = symbol[1:] - absl_symbols.add(symbol) + absl_symbols = set() + for f in obj_files: + stdout = subprocess.check_output(llvm_nm + [f], cwd=os.getcwd()) + for line in stdout.splitlines(): + line = line.decode('utf-8') + match = re.match(ABSL_SYM_RE, line) + if match: + symbol = match.group('symbol') + assert symbol.count(' ') == 0, ( + 'Regex matched too much, probably got ' + 'undecorated name as well') + # Avoid to export deleting dtors since they trigger + # "lld-link: error: export of deleting dtor" linker errors, see + # crbug.com/1201277. + if symbol.startswith('??_G'): + continue + # Strip any leading underscore for C names (as in __cdecl). It's only + # there on x86, but the x86 toolchain falls over when you include it! + if cpu == 'x86' and symbol.startswith('_'): + symbol = symbol[1:] + absl_symbols.add(symbol) - logging.info('[%s - %s] Found %d absl symbols.', cpu, flavor, len(absl_symbols)) + logging.info('[%s - %s] Found %d absl symbols.', cpu, flavor, + len(absl_symbols)) - if extra_gn_args: - def_file = os.path.join('third_party', 'abseil-cpp', - 'symbols_{}_{}_{}'.format(cpu, flavor, suffix)) - else: - def_file = os.path.join('third_party', 'abseil-cpp', - 'symbols_{}_{}'.format(cpu, flavor)) - if use_cxx23: - def_file += "_cxx23" - def_file += ".def" + if extra_gn_args: + def_file = os.path.join('third_party', 'abseil-cpp', + 'symbols_{}_{}_{}'.format(cpu, flavor, suffix)) + else: + def_file = os.path.join('third_party', 'abseil-cpp', + 'symbols_{}_{}'.format(cpu, flavor)) + if use_cxx23: + def_file += "_cxx23" + def_file += ".def" - with open(def_file, 'w', newline='') as f: - f.write('EXPORTS\n') - for s in sorted(absl_symbols): - f.write(' {}\n'.format(s)) + with open(def_file, 'w', newline='') as f: + f.write('EXPORTS\n') + for s in sorted(absl_symbols): + f.write(' {}\n'.format(s)) - logging.info('[%s - %s] .def file successfully generated.', cpu, flavor) + logging.info('[%s - %s] .def file successfully generated.', cpu, flavor) -def _GenerateDefFile(cpu, is_debug, use_cxx23, extra_gn_args=[], suffix=None): - """Generates a .def file for the absl component build on the specified CPU.""" - cwd = os.getcwd() - with tempfile.TemporaryDirectory(dir=os.path.join(cwd, 'out')) as out_dir: - _GenerateDefFileBuild(cpu, is_debug, use_cxx23, extra_gn_args, suffix, out_dir, cwd) +def _GenerateDefFile(chromium_dir, + cpu, + is_debug, + use_cxx23, + extra_gn_args=[], + suffix=None): + """Generates a .def file for the absl component build on the specified CPU.""" + with tempfile.TemporaryDirectory( + dir=os.path.join(chromium_dir, 'out')) as out_dir: + _GenerateDefFileBuild(cpu, is_debug, use_cxx23, extra_gn_args, suffix, + out_dir, chromium_dir) - # Hack, it looks like there is a race in the directory cleanup. - time.sleep(10) + # Hack, it looks like there is a race in the directory cleanup. + time.sleep(10) + + +def generate_all(chromium_dir): + for use_cxx23 in (True, False): + _GenerateDefFile(chromium_dir, 'x64', False, use_cxx23, + ['is_asan = true'], 'asan') + for arch in ('x86', 'x64', 'arm64'): + for is_debug in (True, False): + _GenerateDefFile(chromium_dir, arch, is_debug, use_cxx23) if __name__ == '__main__': - logging.getLogger().setLevel(logging.INFO) + logging.getLogger().setLevel(logging.INFO) + chromium_dir = os.getcwd() - if not os.getcwd().endswith('src') or not os.path.exists('chrome/browser'): - logging.error('Run this script from a chromium/src/ directory.') - exit(1) + if not chromium_dir.endswith('src') or not os.path.exists( + 'chrome/browser'): + logging.error('Run this script from a chromium/src/ directory.') + exit(1) - for use_cxx23 in (True, False): - _GenerateDefFile('x64', False, use_cxx23, ['is_asan = true'], 'asan') - for arch in ('x86', 'x64', 'arm64'): - for is_debug in (True, False): - _GenerateDefFile(arch, is_debug, use_cxx23) + generate_all(chromium_dir)
diff --git a/roll_abseil.py b/roll_abseil.py index b5bfa6c..15c1ed0 100755 --- a/roll_abseil.py +++ b/roll_abseil.py
@@ -1,10 +1,10 @@ #!/usr/bin/env python3 -"""Script to do the first step of Abseil roll into chromium. -""" +"""Script to roll Abseil into chromium.""" import argparse import convert_bazel_to_gn +import generate_def_files import logging import os import re @@ -115,17 +115,15 @@ if should_upload: logging.info('Upload...') - subprocess.check_call( - ['git', 'cl', 'upload', '-m', desc, '--bypass-hooks'], - cwd=chromium_dir) - - logging.info( - "Next step is manual: Fix BUILD.gn files to match BUILD.bazel changes." - ) - logging.info("After that run generate_def_files.py. ") + subprocess.check_call([ + 'git', 'cl', 'upload', '--commit-description=' + desc, + '--bypass-hooks' + ], + cwd=chromium_dir) -def _Roll(should_branch, should_pull, should_upload, revision): +def _Roll(should_branch, should_pull, should_generate_def, should_upload, + revision): chromium_dir = os.getcwd() abseil_in_chromium_dir = os.path.join(chromium_dir, 'third_party', 'abseil-cpp') @@ -148,6 +146,9 @@ _PatchAbseil(abseil_in_chromium_dir) convert_bazel_to_gn.convert_all(abseil_in_chromium_dir) + if should_generate_def: + generate_def_files.generate_all(chromium_dir) + _Commit(chromium_dir, hash_diff, should_upload) @@ -162,6 +163,9 @@ parser.add_argument('--no-pull', action='store_true', help='Skip pulling the latest Chromium revision.') + parser.add_argument('--no-def', + action='store_true', + help='Skip regenerating def files.') parser.add_argument('--no-upload', action='store_true', help='Skip uploading the change.') @@ -171,7 +175,7 @@ args = parser.parse_args() if os.getcwd().endswith('src') and os.path.exists('chrome/browser'): - _Roll(not args.no_branch, not args.no_pull, not args.no_upload, - args.revision) + _Roll(not args.no_branch, not args.no_pull, not args.no_def, + not args.no_upload, args.revision) else: logging.error('Run this script from a chromium/src/ directory.')