replace_gn_files.py 4.8 KB

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