OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 ''' Verifies that builds of the embedded content_shell do not included | 6 ''' Verifies that builds of the embedded content_shell do not included |
7 unnecessary dependencies.''' | 7 unnecessary dependencies.''' |
8 | 8 |
9 import getopt | 9 import getopt |
10 import os | 10 import os |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 for message in errors: | 55 for message in errors: |
56 print message | 56 print message |
57 | 57 |
58 def bbmsg(final, errors): | 58 def bbmsg(final, errors): |
59 if errors: | 59 if errors: |
60 for message in errors: | 60 for message in errors: |
61 print '@@@STEP_TEXT@%s@@@' % message | 61 print '@@@STEP_TEXT@%s@@@' % message |
62 if final: | 62 if final: |
63 print '\n@@@STEP_%s@@@' % final | 63 print '\n@@@STEP_%s@@@' % final |
64 | 64 |
65 | |
66 def _main(): | 65 def _main(): |
67 output = { | 66 output = { |
68 'message': lambda x: stdmsg(None, x), | 67 'message': lambda x: stdmsg(None, x), |
69 'fail': lambda x: stdmsg('FAILED', x), | 68 'fail': lambda x: stdmsg('FAILED', x), |
70 'warn': lambda x: stdmsg('WARNING', x), | 69 'warn': lambda x: stdmsg('WARNING', x), |
71 'abend': lambda x: stdmsg('FAILED', x), | 70 'abend': lambda x: stdmsg('FAILED', x), |
72 'ok': lambda x: stdmsg('SUCCESS', x), | 71 'ok': lambda x: stdmsg('SUCCESS', x), |
72 'verbose': lambda x: None, | |
73 } | 73 } |
74 | 74 |
75 parser = optparse.OptionParser( | 75 parser = optparse.OptionParser( |
76 "usage: %prog -b <dir> --target <Debug|Release>") | 76 "usage: %prog -b <dir> --target <Debug|Release>") |
77 parser.add_option("", "--annotate", dest='annotate', action='store_true', | 77 parser.add_option("", "--annotate", dest='annotate', action='store_true', |
78 default=False, help="include buildbot annotations in output") | 78 default=False, help="include buildbot annotations in output") |
79 parser.add_option("", "--noannotate", dest='annotate', action='store_false') | 79 parser.add_option("", "--noannotate", dest='annotate', action='store_false') |
80 parser.add_option("-b", "--build-dir", | 80 parser.add_option("-b", "--build-dir", |
81 help="the location of the compiler output") | 81 help="the location of the compiler output") |
82 parser.add_option("--target", help="Debug or Release") | 82 parser.add_option("--target", help="Debug or Release") |
83 parser.add_option('-v', '--verbose', default=False, action='store_true') | |
83 | 84 |
84 options, args = parser.parse_args() | 85 options, args = parser.parse_args() |
85 # Bake target into build_dir. | 86 # Bake target into build_dir. |
86 if options.target and options.build_dir: | 87 if options.target and options.build_dir: |
87 assert (options.target != | 88 assert (options.target != |
88 os.path.basename(os.path.dirname(options.build_dir))) | 89 os.path.basename(os.path.dirname(options.build_dir))) |
89 options.build_dir = os.path.join(os.path.abspath(options.build_dir), | 90 options.build_dir = os.path.join(os.path.abspath(options.build_dir), |
90 options.target) | 91 options.target) |
91 | 92 |
92 if options.build_dir != None: | 93 if options.build_dir != None: |
93 target = os.path.join(options.build_dir, binary_target) | 94 target = os.path.join(options.build_dir, binary_target) |
94 else: | 95 else: |
95 target = binary_target | 96 target = binary_target |
96 | 97 |
97 if options.annotate: | 98 if options.annotate: |
98 output = { | 99 output.update({ |
99 'message': lambda x: bbmsg(None, x), | 100 'message': lambda x: bbmsg(None, x), |
100 'fail': lambda x: bbmsg('FAILURE', x), | 101 'fail': lambda x: bbmsg('FAILURE', x), |
101 'warn': lambda x: bbmsg('WARNINGS', x), | 102 'warn': lambda x: bbmsg('WARNINGS', x), |
102 'abend': lambda x: bbmsg('EXCEPTIONS', x), | 103 'abend': lambda x: bbmsg('EXCEPTIONS', x), |
103 'ok': lambda x: bbmsg(None, x), | 104 'ok': lambda x: bbmsg(None, x), |
104 } | 105 }) |
106 | |
107 if options.verbose: | |
108 output['verbose'] = lambda x: stdmsg(None, x) | |
105 | 109 |
106 forbidden_regexp = re.compile(string.join(map(re.escape, | 110 forbidden_regexp = re.compile(string.join(map(re.escape, |
107 kUndesiredLibraryList), '|')) | 111 kUndesiredLibraryList), '|')) |
108 mapping_regexp = re.compile(r"\s*([^/]*) => ") | 112 mapping_regexp = re.compile(r"\s*([^/]*) => (.*)") |
109 blessed_regexp = re.compile(r"(%s)[-0-9.]*\.so" % string.join(map(re.escape, | 113 blessed_regexp = re.compile(r"(%s)[-0-9.]*\.so" % string.join(map(re.escape, |
110 kAllowedLibraryList), '|')) | 114 kAllowedLibraryList), '|')) |
115 if options.build_dir != None: | |
116 built_regexp = re.compile(re.escape(options.build_dir)) | |
117 else: | |
118 built_regexp = re.compile(re.escape('lib')) | |
119 built_regexp | |
111 success = 0 | 120 success = 0 |
112 warning = 0 | 121 warning = 0 |
113 | 122 |
114 p = subprocess.Popen(['ldd', target], stdout=subprocess.PIPE, | 123 p = subprocess.Popen(['ldd', target], stdout=subprocess.PIPE, |
115 stderr=subprocess.PIPE) | 124 stderr=subprocess.PIPE) |
116 out, err = p.communicate() | 125 out, err = p.communicate() |
117 | 126 |
118 if err != '': | 127 if err != '': |
119 output['abend']([ | 128 output['abend']([ |
120 'Failed to execute ldd to analyze dependencies for ' + target + ':', | 129 'Failed to execute ldd to analyze dependencies for ' + target + ':', |
121 ' ' + err, | 130 ' ' + err, |
122 ]) | 131 ]) |
123 return 1 | 132 return 1 |
124 | 133 |
125 if out == '': | 134 if out == '': |
126 output['abend']([ | 135 output['abend']([ |
127 'No output to scan for forbidden dependencies.' | 136 'No output to scan for forbidden dependencies.' |
128 ]) | 137 ]) |
129 return 1 | 138 return 1 |
130 | 139 |
131 success = 1 | 140 success = 1 |
132 deps = string.split(out, '\n') | 141 deps = string.split(out, '\n') |
133 for d in deps: | 142 for d in deps: |
134 libmatch = mapping_regexp.match(d) | 143 libmatch = mapping_regexp.match(d) |
135 if libmatch: | 144 if libmatch: |
136 lib = libmatch.group(1) | 145 lib = libmatch.group(1) |
146 source = libmatch.group(2) | |
137 if forbidden_regexp.search(lib): | 147 if forbidden_regexp.search(lib): |
138 success = 0 | 148 success = 0 |
139 output['message'](['Forbidden library: ' + lib]) | 149 output['message'](['Forbidden library: ' + lib]) |
140 if not blessed_regexp.match(lib): | 150 elif built_regexp.match(source): |
rjkroege
2013/12/02 16:17:22
nit: why extra spaces before lib?
Peter Mayo (wrong one)
2013/12/02 16:42:01
Tyop : interesting, why no pylint?
| |
151 output['verbose'](['Built library: ' + lib]) | |
152 elif blessed_regexp.match(lib): | |
153 output['verbose'](['Blessed library: ' + lib]) | |
154 else: | |
141 warning = 1 | 155 warning = 1 |
142 output['message'](['Unexpected library: ' + lib]) | 156 output['message'](['Unexpected library: ' + lib]) |
143 | 157 |
144 if success == 1: | 158 if success == 1: |
145 if warning == 1: | 159 if warning == 1: |
146 output['warn'](None) | 160 output['warn'](None) |
147 else: | 161 else: |
148 output['ok'](None) | 162 output['ok'](None) |
149 return 0 | 163 return 0 |
150 else: | 164 else: |
151 output['fail'](None) | 165 output['fail'](None) |
152 return 1 | 166 return 1 |
153 | 167 |
154 if __name__ == "__main__": | 168 if __name__ == "__main__": |
155 # handle arguments... | 169 # handle arguments... |
156 # do something reasonable if not run with one... | 170 # do something reasonable if not run with one... |
157 sys.exit(_main()) | 171 sys.exit(_main()) |
OLD | NEW |