Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / build / linux / unbundle / remove_bundled_libraries.py
blob09a9c629fd9a09d974e11c617b8dbdf9506fe445
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.
6 """
7 Removes bundled libraries to make sure they are not used.
9 See README for more details.
10 """
13 import optparse
14 import os.path
15 import sys
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, '..', '..', '..'))
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
28 parser = optparse.OptionParser()
29 parser.add_option('--do-remove', action='store_true')
31 options, args = parser.parse_args(argv)
33 exclusion_used = {}
34 for exclusion in args:
35 exclusion_used[exclusion] = False
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
44 for f in files:
45 path = os.path.join(root, f)
46 relpath = os.path.relpath(path, source_tree_root)
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
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
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
70 exit_code = 0
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
79 if not options.do_remove:
80 print ('To actually remove files printed above, please pass ' +
81 '--do-remove flag.')
83 return exit_code
86 if __name__ == '__main__':
87 sys.exit(DoMain(sys.argv[1:]))