OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 """ |
| 7 Replaces GN files in tree with files from here that |
| 8 make the build use system libraries. |
| 9 """ |
| 10 |
| 11 from __future__ import print_function |
| 12 |
| 13 import argparse |
| 14 import os |
| 15 import shutil |
| 16 import sys |
| 17 |
| 18 |
| 19 REPLACEMENTS = { |
| 20 'ffmpeg': 'third_party/ffmpeg/BUILD.gn', |
| 21 'flac': 'third_party/flac/BUILD.gn', |
| 22 'harfbuzz-ng': 'third_party/harfbuzz-ng/BUILD.gn', |
| 23 'libevent': 'base/third_party/libevent/BUILD.gn', |
| 24 'libwebp': 'third_party/libwebp/BUILD.gn', |
| 25 'libxml': 'third_party/libxml/BUILD.gn', |
| 26 'libxslt': 'third_party/libxslt/BUILD.gn', |
| 27 'snappy': 'third_party/snappy/BUILD.gn', |
| 28 'yasm': 'third_party/yasm/yasm_assemble.gni', |
| 29 'zlib': 'third_party/zlib/BUILD.gn', |
| 30 } |
| 31 |
| 32 |
| 33 def DoMain(argv): |
| 34 my_dirname = os.path.dirname(__file__) |
| 35 source_tree_root = os.path.abspath( |
| 36 os.path.join(my_dirname, '..', '..', '..')) |
| 37 |
| 38 parser = argparse.ArgumentParser() |
| 39 parser.add_argument('--system-libraries', nargs='*', default=[]) |
| 40 parser.add_argument('--undo', action='store_true') |
| 41 |
| 42 args = parser.parse_args(argv) |
| 43 |
| 44 handled_libraries = set() |
| 45 for lib, path in REPLACEMENTS.items(): |
| 46 if lib not in args.system_libraries: |
| 47 continue |
| 48 handled_libraries.add(lib) |
| 49 |
| 50 if args.undo: |
| 51 # Restore original file, and also remove the backup. |
| 52 # This is meant to restore the source tree to its original state. |
| 53 os.rename(os.path.join(source_tree_root, path + '.orig'), |
| 54 os.path.join(source_tree_root, path)) |
| 55 else: |
| 56 # Create a backup copy for --undo. |
| 57 shutil.copyfile(os.path.join(source_tree_root, path), |
| 58 os.path.join(source_tree_root, path + '.orig')) |
| 59 |
| 60 # Copy the GN file from directory of this script to target path. |
| 61 shutil.copyfile(os.path.join(my_dirname, '%s.gn' % lib), |
| 62 os.path.join(source_tree_root, path)) |
| 63 |
| 64 unhandled_libraries = set(args.system_libraries) - handled_libraries |
| 65 if unhandled_libraries: |
| 66 print('Unrecognized system libraries requested: %s' % ', '.join( |
| 67 sorted(unhandled_libraries)), file=sys.stderr) |
| 68 return 1 |
| 69 |
| 70 return 0 |
| 71 |
| 72 |
| 73 if __name__ == '__main__': |
| 74 sys.exit(DoMain(sys.argv[1:])) |
OLD | NEW |