diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-21 20:17:42 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-21 20:17:42 +0000 |
commit | ed3b4ed2bda0c8e8af129983229dc5f6cafa06ab (patch) | |
tree | c3fbfec2c98c439493e82006d676819a8e4b63e8 | |
parent | 526ac920981cb7a866e40a6cf8296f198225cd50 (diff) | |
download | chromium_src-ed3b4ed2bda0c8e8af129983229dc5f6cafa06ab.zip chromium_src-ed3b4ed2bda0c8e8af129983229dc5f6cafa06ab.tar.gz chromium_src-ed3b4ed2bda0c8e8af129983229dc5f6cafa06ab.tar.bz2 |
Linux: add script to remove bundled libraries.
BUG=none
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/23037005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218816 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | build/linux/unbundle/README | 28 | ||||
-rwxr-xr-x | build/linux/unbundle/remove_bundled_libraries.py | 87 |
2 files changed, 109 insertions, 6 deletions
diff --git a/build/linux/unbundle/README b/build/linux/unbundle/README index 7027b9a..d1b2a96 100644 --- a/build/linux/unbundle/README +++ b/build/linux/unbundle/README @@ -17,12 +17,28 @@ libraries is the norm. Usage: -replace_gyp_files.py <gyp-flags> +1. remove_bundled_libraries.py <preserved-directories> -For example: replace_gyp_files.py -Duse_system_harfbuzz=1 + For example: remove_bundled_libraries.py third_party/mesa -The script ignores flags other than -D for convenience. This makes it possible -to have a variable e.g. ${myconf} with all the options, and execute: + The script scans sources looking for third_party directories. + Everything that is not explicitly preserved is removed (except for + gyp files), and the script fails if any directory passed on command + line does not exist (to ensure list is kept up to date). -build/linux/unbundle/replace_gyp_files.py ${myconf} -build/gyp_chromium ${myconf} + This is intended to be used on sources extracted from a tarball, + not a repository. + + NOTE: by default this will not remove anything (for safety). Pass + --do-remove flag to actually remove files. + +2. replace_gyp_files.py <gyp-flags> + + For example: replace_gyp_files.py -Duse_system_harfbuzz=1 + + The script ignores flags other than -D for convenience. This makes it + possible to have a variable e.g. ${myconf} with all the options, and + execute: + + build/linux/unbundle/replace_gyp_files.py ${myconf} + build/gyp_chromium ${myconf} diff --git a/build/linux/unbundle/remove_bundled_libraries.py b/build/linux/unbundle/remove_bundled_libraries.py new file mode 100755 index 0000000..09a9c62 --- /dev/null +++ b/build/linux/unbundle/remove_bundled_libraries.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# Copyright 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Removes bundled libraries to make sure they are not used. + +See README for more details. +""" + + +import optparse +import os.path +import sys + + +def DoMain(argv): + my_dirname = os.path.abspath(os.path.dirname(__file__)) + source_tree_root = os.path.abspath( + os.path.join(my_dirname, '..', '..', '..')) + + if os.path.join(source_tree_root, 'build', 'linux', 'unbundle') != my_dirname: + print ('Sanity check failed: please run this script from ' + + 'build/linux/unbundle directory.') + return 1 + + parser = optparse.OptionParser() + parser.add_option('--do-remove', action='store_true') + + options, args = parser.parse_args(argv) + + exclusion_used = {} + for exclusion in args: + exclusion_used[exclusion] = False + + for root, dirs, files in os.walk(source_tree_root, topdown=False): + # Only look at paths which contain a "third_party" component + # (note that e.g. third_party.png doesn't count). + root_relpath = os.path.relpath(root, source_tree_root) + if 'third_party' not in root_relpath.split(os.sep): + continue + + for f in files: + path = os.path.join(root, f) + relpath = os.path.relpath(path, source_tree_root) + + excluded = False + for exclusion in args: + if relpath.startswith(exclusion): + # Multiple exclusions can match the same path. Go through all of them + # and mark each one as used. + exclusion_used[exclusion] = True + excluded = True + if excluded: + continue + + # Deleting gyp files almost always leads to gyp failures. + # These files come from Chromium project, and can be replaced if needed. + if f.endswith('.gyp') or f.endswith('.gypi'): + continue + + if options.do_remove: + # Delete the file - best way to ensure it's not used during build. + os.remove(path) + else: + # By default just print paths that would be removed. + print path + + exit_code = 0 + + # Fail if exclusion list contains stale entries - this helps keep it + # up to date. + for exclusion, used in exclusion_used.iteritems(): + if not used: + print '%s does not exist' % exclusion + exit_code = 1 + + if not options.do_remove: + print ('To actually remove files printed above, please pass ' + + '--do-remove flag.') + + return exit_code + + +if __name__ == '__main__': + sys.exit(DoMain(sys.argv[1:])) |