tor-browser

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

replace_gn_files.py (5516B)


      1 #!/usr/bin/env python3
      2 # Copyright 2016 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 """
      7 Replaces GN files in tree with files from here that
      8 make the build use system libraries.
      9 """
     10 
     11 import argparse
     12 import os
     13 import shutil
     14 import sys
     15 
     16 
     17 REPLACEMENTS = {
     18    # Use system libabsl_2xxx. These 20 shims MUST be used together.
     19    'absl_algorithm': 'third_party/abseil-cpp/absl/algorithm/BUILD.gn',
     20    'absl_base': 'third_party/abseil-cpp/absl/base/BUILD.gn',
     21    'absl_cleanup': 'third_party/abseil-cpp/absl/cleanup/BUILD.gn',
     22    'absl_container': 'third_party/abseil-cpp/absl/container/BUILD.gn',
     23    'absl_crc': 'third_party/abseil-cpp/absl/crc/BUILD.gn',
     24    'absl_debugging': 'third_party/abseil-cpp/absl/debugging/BUILD.gn',
     25    'absl_flags': 'third_party/abseil-cpp/absl/flags/BUILD.gn',
     26    'absl_functional': 'third_party/abseil-cpp/absl/functional/BUILD.gn',
     27    'absl_hash': 'third_party/abseil-cpp/absl/hash/BUILD.gn',
     28    'absl_log': 'third_party/abseil-cpp/absl/log/BUILD.gn',
     29    'absl_log_internal': 'third_party/abseil-cpp/absl/log/internal/BUILD.gn',
     30    'absl_memory': 'third_party/abseil-cpp/absl/memory/BUILD.gn',
     31    'absl_meta': 'third_party/abseil-cpp/absl/meta/BUILD.gn',
     32    'absl_numeric': 'third_party/abseil-cpp/absl/numeric/BUILD.gn',
     33    'absl_random': 'third_party/abseil-cpp/absl/random/BUILD.gn',
     34    'absl_status': 'third_party/abseil-cpp/absl/status/BUILD.gn',
     35    'absl_strings': 'third_party/abseil-cpp/absl/strings/BUILD.gn',
     36    'absl_synchronization':
     37    'third_party/abseil-cpp/absl/synchronization/BUILD.gn',
     38    'absl_time': 'third_party/abseil-cpp/absl/time/BUILD.gn',
     39    'absl_types': 'third_party/abseil-cpp/absl/types/BUILD.gn',
     40    'absl_utility': 'third_party/abseil-cpp/absl/utility/BUILD.gn',
     41    #
     42    'brotli': 'third_party/brotli/BUILD.gn',
     43    'crc32c': 'third_party/crc32c/BUILD.gn',
     44    'dav1d': 'third_party/dav1d/BUILD.gn',
     45    'double-conversion': 'base/third_party/double_conversion/BUILD.gn',
     46    'ffmpeg': 'third_party/ffmpeg/BUILD.gn',
     47    'flac': 'third_party/flac/BUILD.gn',
     48    'flatbuffers': 'third_party/flatbuffers/BUILD.gn',
     49    'fontconfig': 'third_party/fontconfig/BUILD.gn',
     50    'freetype': 'build/config/freetype/freetype.gni',
     51    'harfbuzz-ng': 'third_party/harfbuzz-ng/harfbuzz.gni',
     52    'highway': 'third_party/highway/BUILD.gn',
     53    'icu': 'third_party/icu/BUILD.gn',
     54    'jsoncpp': 'third_party/jsoncpp/BUILD.gn',
     55    'libaom': 'third_party/libaom/BUILD.gn',
     56    'libdrm': 'third_party/libdrm/BUILD.gn',
     57    'libjpeg': 'third_party/libjpeg.gni',
     58    'libpng': 'third_party/libpng/BUILD.gn',
     59    'libsecret': 'third_party/libsecret/BUILD.gn',
     60    'libusb': 'third_party/libusb/BUILD.gn',
     61    'libvpx': 'third_party/libvpx/BUILD.gn',
     62    'libwebp': 'third_party/libwebp/BUILD.gn',
     63    'libxml': 'third_party/libxml/BUILD.gn',
     64    'libXNVCtrl': 'third_party/angle/src/third_party/libXNVCtrl/BUILD.gn',
     65    'libxslt': 'third_party/libxslt/BUILD.gn',
     66    'libyuv': 'third_party/libyuv/BUILD.gn',
     67    'openh264': 'third_party/openh264/BUILD.gn',
     68    'opus': 'third_party/opus/BUILD.gn',
     69    're2': 'third_party/re2/BUILD.gn',
     70    'simdutf': 'third_party/simdutf/BUILD.gn',
     71    'snappy': 'third_party/snappy/BUILD.gn',
     72    # Use system libSPIRV-Tools in Swiftshader.
     73    # These two shims MUST be used together.
     74    'swiftshader-SPIRV-Headers':
     75    'third_party/swiftshader/third_party/SPIRV-Headers/BUILD.gn',
     76    'swiftshader-SPIRV-Tools':
     77    'third_party/swiftshader/third_party/SPIRV-Tools/BUILD.gn',
     78    # Use system libSPIRV-Tools inside ANGLE.
     79    # These two shims MUST be used together
     80    # and can only be used if WebGPU is not compiled (use_dawn=false)
     81    'vulkan-SPIRV-Headers': 'third_party/spirv-headers/src/BUILD.gn',
     82    'vulkan-SPIRV-Tools': 'third_party/spirv-tools/src/BUILD.gn',
     83    #
     84    'vulkan_memory_allocator': 'third_party/vulkan_memory_allocator/BUILD.gn',
     85    'woff2': 'third_party/woff2/BUILD.gn',
     86    'zlib': 'third_party/zlib/BUILD.gn',
     87    'zstd': 'third_party/zstd/BUILD.gn',
     88 }
     89 
     90 
     91 def DoMain(argv):
     92  my_dirname = os.path.dirname(__file__)
     93  source_tree_root = os.path.abspath(
     94    os.path.join(my_dirname, '..', '..', '..'))
     95 
     96  parser = argparse.ArgumentParser()
     97  parser.add_argument('--system-libraries', nargs='*', default=[])
     98  parser.add_argument('--undo', action='store_true')
     99 
    100  args = parser.parse_args(argv)
    101 
    102  handled_libraries = set()
    103  for lib, path in REPLACEMENTS.items():
    104    if lib not in args.system_libraries:
    105      continue
    106    handled_libraries.add(lib)
    107 
    108    if args.undo:
    109      # Restore original file, and also remove the backup.
    110      # This is meant to restore the source tree to its original state.
    111      os.rename(os.path.join(source_tree_root, path + '.orig'),
    112                os.path.join(source_tree_root, path))
    113    else:
    114      # Create a backup copy for --undo.
    115      shutil.copyfile(os.path.join(source_tree_root, path),
    116                      os.path.join(source_tree_root, path + '.orig'))
    117 
    118      # Copy the GN file from directory of this script to target path.
    119      shutil.copyfile(os.path.join(my_dirname, '%s.gn' % lib),
    120                      os.path.join(source_tree_root, path))
    121 
    122  unhandled_libraries = set(args.system_libraries) - handled_libraries
    123  if unhandled_libraries:
    124    print('Unrecognized system libraries requested: %s' % ', '.join(
    125        sorted(unhandled_libraries)), file=sys.stderr)
    126    return 1
    127 
    128  return 0
    129 
    130 
    131 if __name__ == '__main__':
    132  sys.exit(DoMain(sys.argv[1:]))