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.
7 Removes bundled libraries to make sure they are not used.
9 See README for more details.
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.')
28 parser
= optparse
.OptionParser()
29 parser
.add_option('--do-remove', action
='store_true')
31 options
, args
= parser
.parse_args(argv
)
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
):
45 path
= os
.path
.join(root
, f
)
46 relpath
= os
.path
.relpath(path
, source_tree_root
)
49 for exclusion
in args
:
50 # Require precise exclusions. Find the right-most third_party
51 # in the relative path, and if there is more than one ignore
52 # the exclusion if it's completely contained within the part
53 # before right-most third_party path component.
54 split
= relpath
.rsplit(os
.sep
+ 'third_party' + os
.sep
, 1)
55 if len(split
) > 1 and split
[0].startswith(exclusion
):
58 if relpath
.startswith(exclusion
):
59 # Multiple exclusions can match the same path. Go through all of them
60 # and mark each one as used.
61 exclusion_used
[exclusion
] = True
66 # Deleting gyp files almost always leads to gyp failures.
67 # These files come from Chromium project, and can be replaced if needed.
68 if f
.endswith('.gyp') or f
.endswith('.gypi'):
71 # Deleting .isolate files leads to gyp failures. They are usually
72 # not used by a distro build anyway.
73 # See http://www.chromium.org/developers/testing/isolated-testing
75 if f
.endswith('.isolate'):
79 # Delete the file - best way to ensure it's not used during build.
82 # By default just print paths that would be removed.
87 # Fail if exclusion list contains stale entries - this helps keep it
89 for exclusion
, used
in exclusion_used
.iteritems():
91 print '%s does not exist' % exclusion
94 if not options
.do_remove
:
95 print ('To actually remove files printed above, please pass ' +
101 if __name__
== '__main__':
102 sys
.exit(DoMain(sys
.argv
[1:]))