Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 """ | |
| 7 Removes bundled libraries to make sure they are not used. | |
| 8 | |
| 9 See README for more details. | |
| 10 """ | |
| 11 | |
| 12 | |
| 13 import optparse | |
| 14 import os.path | |
| 15 import sys | |
| 16 | |
| 17 | |
| 18 def DoMain(argv): | |
| 19 my_dirname = os.path.abspath(os.path.dirname(__file__)) | |
| 20 source_tree_root = os.path.abspath( | |
| 21 os.path.join(my_dirname, '..', '..', '..')) | |
| 22 | |
| 23 if os.path.join(source_tree_root, 'build', 'linux', 'unbundle') != my_dirname: | |
| 24 print ('Sanity check failed: please run this script from ' + | |
| 25 'build/linux/unbundle directory.') | |
| 26 return 1 | |
| 27 | |
| 28 parser = optparse.OptionParser() | |
| 29 parser.add_option('--do-remove', action='store_true') | |
| 30 | |
| 31 options, args = parser.parse_args(argv) | |
|
Lei Zhang
2013/08/21 19:10:10
nit: parse_args() defaults to sys.argv[1:], so you
Paweł Hajdan Jr.
2013/08/21 20:14:26
I like the ability to have a function I can pass a
| |
| 32 | |
| 33 exclusion_used = {} | |
| 34 for exclusion in args: | |
| 35 exclusion_used[exclusion] = False | |
| 36 | |
| 37 for root, dirs, files in os.walk(source_tree_root, topdown=False): | |
| 38 # Only look at paths which contain a "third_party" component | |
| 39 # (note that e.g. third_party.png doesn't count). | |
| 40 root_relpath = os.path.relpath(root, source_tree_root) | |
| 41 if 'third_party' not in root_relpath.split(os.sep): | |
| 42 continue | |
| 43 | |
| 44 for f in files: | |
| 45 path = os.path.join(root, f) | |
| 46 relpath = os.path.relpath(path, source_tree_root) | |
| 47 | |
| 48 excluded = False | |
| 49 for exclusion in args: | |
| 50 if relpath.startswith(exclusion): | |
| 51 # Multiple exclusions can match the same path. Go through all of them | |
| 52 # and mark each one as used. | |
| 53 exclusion_used[exclusion] = True | |
| 54 excluded = True | |
| 55 if excluded: | |
| 56 continue | |
| 57 | |
| 58 # Deleting gyp files almost always leads to gyp failures. | |
| 59 # These files come from Chromium project, and can be replaced if needed. | |
| 60 if f.endswith('.gyp') or f.endswith('.gypi'): | |
| 61 continue | |
| 62 | |
| 63 if options.do_remove: | |
| 64 # Delete the file - best way to ensure it's not used during build. | |
| 65 os.remove(path) | |
| 66 else: | |
| 67 # By default just print paths that would be removed. | |
| 68 print path | |
| 69 | |
| 70 exit_code = 0 | |
| 71 | |
| 72 # Fail if exclusion list contains stale entries - this helps keep it | |
| 73 # up to date. | |
| 74 for exclusion, used in exclusion_used.iteritems(): | |
| 75 if not used: | |
| 76 print '%s does not exist' % exclusion | |
| 77 exit_code = 1 | |
| 78 | |
| 79 if not options.do_remove: | |
| 80 print ('To actually remove files printed above, please pass ' + | |
| 81 '--do-remove flag.') | |
| 82 | |
| 83 return exit_code | |
| 84 | |
| 85 | |
| 86 if __name__ == '__main__': | |
| 87 sys.exit(DoMain(sys.argv[1:])) | |
| OLD | NEW |