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 | |
10 | |
11 import os.path | |
12 import sys | |
13 | |
14 | |
15 def DoMain(argv): | |
16 my_dirname = os.path.dirname(__file__) | |
17 source_tree_root = os.path.abspath( | |
Lei Zhang
2013/08/21 01:27:03
Please add some sanity checks to prevent this scri
| |
18 os.path.join(my_dirname, '..', '..', '..')) | |
19 | |
20 exclusion_used = {} | |
21 for exclusion in argv: | |
22 exclusion_used[exclusion] = False | |
23 | |
24 for root, dirs, files in os.walk(source_tree_root, topdown=False): | |
25 # Only look at paths which contain a "third_party" component | |
26 # (note that e.g. third_party.png doesn't count). | |
27 root_relpath = os.path.relpath(root, source_tree_root) | |
28 if 'third_party' not in root_relpath.split(os.sep): | |
29 continue | |
30 | |
31 for f in files: | |
32 path = os.path.join(root, f) | |
33 relpath = os.path.relpath(path, source_tree_root) | |
34 | |
35 excluded = False | |
36 for exclusion in argv: | |
37 if relpath.startswith(exclusion): | |
38 # Multiple exclusions can match the same path. Go through all of them | |
39 # and mark each one as used. | |
40 exclusion_used[exclusion] = True | |
41 excluded = True | |
42 if excluded: | |
43 continue | |
44 | |
45 # Deleting gyp files almost always leads to gyp failures. | |
46 # These files come from Chromium project, and can be replaced if needed. | |
47 if f.endswith('.gyp') or f.endswith('.gypi'): | |
48 continue | |
49 | |
50 # Delete the file - best way to ensure it's not used during build. | |
51 os.remove(path) | |
52 | |
53 exit_code = 0 | |
54 | |
55 # Fail if exclusion list contains stale entries - this helps keep it | |
56 # up to date. | |
57 for exclusion, used in exclusion_used.iteritems(): | |
58 if not used: | |
59 print '%s does not exist' % exclusion | |
60 exit_code = 1 | |
61 | |
62 return exit_code | |
63 | |
64 | |
65 if __name__ == '__main__': | |
66 sys.exit(DoMain(sys.argv[1:])) | |
OLD | NEW |