1#!/usr/bin/env python 2# Copyright 2013 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""" 7Replaces gyp files in tree with files from here that 8make the build use system libraries. 9""" 10 11 12import optparse 13import os.path 14import shutil 15import sys 16 17 18REPLACEMENTS = { 19 'use_system_expat': 'third_party/expat/expat.gyp', 20 'use_system_ffmpeg': 'third_party/ffmpeg/ffmpeg.gyp', 21 'use_system_flac': 'third_party/flac/flac.gyp', 22 'use_system_harfbuzz': 'third_party/harfbuzz-ng/harfbuzz.gyp', 23 'use_system_icu': 'third_party/icu/icu.gyp', 24 'use_system_jsoncpp': 'third_party/jsoncpp/jsoncpp.gyp', 25 'use_system_libevent': 'third_party/libevent/libevent.gyp', 26 'use_system_libjpeg': 'third_party/libjpeg/libjpeg.gyp', 27 'use_system_libpng': 'third_party/libpng/libpng.gyp', 28 'use_system_libusb': 'third_party/libusb/libusb.gyp', 29 'use_system_libvpx': 'third_party/libvpx/libvpx.gyp', 30 'use_system_libwebp': 'third_party/libwebp/libwebp.gyp', 31 'use_system_libxml': 'third_party/libxml/libxml.gyp', 32 'use_system_libxnvctrl' : 'third_party/libXNVCtrl/libXNVCtrl.gyp', 33 'use_system_libxslt': 'third_party/libxslt/libxslt.gyp', 34 'use_system_openssl': 'third_party/boringssl/boringssl.gyp', 35 'use_system_opus': 'third_party/opus/opus.gyp', 36 'use_system_protobuf': 'third_party/protobuf/protobuf.gyp', 37 'use_system_re2': 'third_party/re2/re2.gyp', 38 'use_system_snappy': 'third_party/snappy/snappy.gyp', 39 'use_system_speex': 'third_party/speex/speex.gyp', 40 'use_system_sqlite': 'third_party/sqlite/sqlite.gyp', 41 'use_system_v8': 'v8/tools/gyp/v8.gyp', 42 'use_system_zlib': 'third_party/zlib/zlib.gyp', 43} 44 45 46def DoMain(argv): 47 my_dirname = os.path.dirname(__file__) 48 source_tree_root = os.path.abspath( 49 os.path.join(my_dirname, '..', '..', '..')) 50 51 parser = optparse.OptionParser() 52 53 # Accept arguments in gyp command-line syntax, so that the caller can re-use 54 # command-line for this script and gyp. 55 parser.add_option('-D', dest='defines', action='append') 56 57 parser.add_option('--undo', action='store_true') 58 59 options, args = parser.parse_args(argv) 60 61 for flag, path in REPLACEMENTS.items(): 62 if '%s=1' % flag not in options.defines: 63 continue 64 65 if options.undo: 66 # Restore original file, and also remove the backup. 67 # This is meant to restore the source tree to its original state. 68 os.rename(os.path.join(source_tree_root, path + '.orig'), 69 os.path.join(source_tree_root, path)) 70 else: 71 # Create a backup copy for --undo. 72 shutil.copyfile(os.path.join(source_tree_root, path), 73 os.path.join(source_tree_root, path + '.orig')) 74 75 # Copy the gyp file from directory of this script to target path. 76 shutil.copyfile(os.path.join(my_dirname, os.path.basename(path)), 77 os.path.join(source_tree_root, path)) 78 79 return 0 80 81 82if __name__ == '__main__': 83 sys.exit(DoMain(sys.argv)) 84