tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

roll_abseil.py (4148B)


      1 #!/usr/bin/env python3
      2 
      3 """Script to do the first step of Abseil roll into chromium.
      4 """
      5 
      6 import logging
      7 import os
      8 import re
      9 import subprocess
     10 import tempfile
     11 from datetime import datetime
     12 
     13 ABSL_URI = 'https://github.com/abseil/abseil-cpp.git'
     14 
     15 def _PullAbseil(abseil_dir):
     16  logging.info('Updating abseil...')
     17  subprocess.check_call(['git', 'clone', ABSL_URI],
     18                        cwd=abseil_dir)
     19 
     20 def _SyncChromium(chromium_dir):
     21  logging.info('Updating chromium...')
     22  subprocess.check_call(['git', 'checkout', 'main'], cwd=chromium_dir)
     23  subprocess.check_call(['git', 'pull', '--rebase'], cwd=chromium_dir)
     24  subprocess.check_call(['gclient', 'sync'], cwd=chromium_dir)
     25 
     26 
     27 def _UpdateChromiumReadme(readme_filename, abseil_dir):
     28  logging.info('Updating ' + readme_filename)
     29 
     30  stdout = subprocess.check_output(['git', 'log', '-n1', '--pretty=short'],
     31                                   cwd=abseil_dir)
     32  new_revision = re.search('commit\\s(.{40})', str(stdout)).group(1)
     33 
     34  with open(readme_filename, 'r+') as f:
     35    content = f.read()
     36    prefix = 'Revision: '
     37    pos = content.find(prefix)
     38    assert(pos > 0)
     39    pos = pos + len(prefix)
     40    old_revision = content[pos:pos+40]
     41    f.seek(pos)
     42    f.write(new_revision)
     43 
     44  logging.info('Abseil old revision is ' + old_revision)
     45  logging.info('Abseil new revision is ' + new_revision)
     46  return old_revision[0:10] + '..' + new_revision[0:10]
     47 
     48 
     49 def _UpdateAbseilInChromium(abseil_dir, chromium_dir):
     50 logging.info('Syncing abseil in chromium/src/third_party...')
     51 exclude = [
     52   '*BUILD.gn',
     53   'DIR_METADATA',
     54   'README.chromium',
     55   'OWNERS',
     56   '.gitignore',
     57   '.git',
     58   '*.gni',
     59   '*clang-format',
     60   'patches/*',
     61   'patches',
     62   'absl_hardening_test.cc',
     63   'roll_abseil.py',
     64   'generate_def_files.py',
     65   '*.def',
     66 ]
     67 params = ['rsync', '-aP', abseil_dir, os.path.join(chromium_dir, 'third_party'), '--delete']
     68 for e in exclude:
     69   params.append('--exclude={}'.format(e))
     70 subprocess.check_call(params, cwd=chromium_dir)
     71 
     72 
     73 def _PatchAbseil(abseil_in_chromium_dir):
     74  logging.info('Patching abseil...')
     75  for patch in os.listdir(os.path.join(abseil_in_chromium_dir, 'patches')):
     76    subprocess.check_call(['patch', '--strip', '1', '-i', os.path.join(abseil_in_chromium_dir, 'patches', patch)])
     77 
     78  os.remove(os.path.join(abseil_in_chromium_dir, 'absl', 'base', 'internal', 'dynamic_annotations.h'))
     79 
     80 
     81 def _Commit(chromium_dir, hash_diff):
     82  logging.info('Commit...')
     83  desc="""Roll abseil_revision {0}
     84 
     85 Change Log:
     86 https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+log/{0}
     87 Full diff:
     88 https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+/{0}
     89 Bug: None""".format(hash_diff)
     90 
     91  subprocess.check_call(['git', 'add', 'third_party/abseil-cpp'], cwd=chromium_dir)
     92  subprocess.check_call(['git', 'commit', '-m', desc], cwd=chromium_dir)
     93 
     94  logging.info('Upload...')
     95  subprocess.check_call(['git', 'cl', 'upload', '-m', desc, '--bypass-hooks'], cwd=chromium_dir)
     96 
     97 
     98 def _Roll():
     99  chromium_dir = os.getcwd()
    100  abseil_in_chromium_dir = os.path.join(chromium_dir, 'third_party', 'abseil-cpp')
    101  _SyncChromium(chromium_dir)
    102 
    103  branch_name = datetime.today().strftime('rolling-absl-%Y%m%d')
    104  logging.info('Creating branch ' + branch_name + ' for the roll...')
    105  subprocess.check_call(['git', 'checkout', '-b', branch_name], cwd=chromium_dir)
    106 
    107  with tempfile.TemporaryDirectory() as abseil_root:
    108    _PullAbseil(abseil_root)
    109    abseil_dir = os.path.join(abseil_root, 'abseil-cpp')
    110    _UpdateAbseilInChromium(abseil_dir, chromium_dir)
    111    hash_diff = _UpdateChromiumReadme(os.path.join(abseil_in_chromium_dir, 'README.chromium'),
    112                                      abseil_dir)
    113 
    114  _PatchAbseil(abseil_in_chromium_dir)
    115  _Commit(chromium_dir, hash_diff)
    116 
    117 
    118 if __name__ == '__main__':
    119  logging.getLogger().setLevel(logging.INFO)
    120 
    121  if os.getcwd().endswith('src') and os.path.exists('chrome/browser'):
    122    _Roll()
    123 
    124    logging.info("Next step is manual: Fix BUILD.gn files to match BUILD.bazel changes.")
    125    logging.info("After that run generate_def_files.py. ")
    126  else:
    127    logging.error('Run this script from a chromium/src/ directory.')