Chromium Code Reviews| 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 |
|
Peter Mayo (wrong one)
2013/12/02 23:48:40
Unused, remove.
| |
| 10 import os | 10 import os |
| 11 import re | 11 import re |
| 12 import string | 12 import string |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 import optparse | 15 import optparse |
| 16 | 16 |
| 17 kUndesiredLibraryList = [ | 17 kUndesiredLibraryList = [ |
| 18 # 'libasound', # ALSA sound - needs to go eventually | 18 # 'libasound', # ALSA sound - needs to go eventually |
| 19 'libcairo', | 19 'libcairo', |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 43 'libpthread', | 43 'libpthread', |
| 44 'librt', | 44 'librt', |
| 45 'libsmime3', | 45 'libsmime3', |
| 46 'libstdc++', | 46 'libstdc++', |
| 47 'libz', | 47 'libz', |
| 48 'linux-vdso', | 48 'linux-vdso', |
| 49 ] | 49 ] |
| 50 | 50 |
| 51 binary_target = 'content_shell' | 51 binary_target = 'content_shell' |
| 52 | 52 |
| 53 def stdmsg(final, errors): | 53 def stdmsg(final, errors): |
|
Peter Mayo (wrong one)
2013/12/02 23:48:40
final is unused.
| |
| 54 if errors: | 54 if errors: |
| 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 | 65 |
| 66 def _main(): | 66 def _main(): |
| 67 output = { | 67 output = { |
| 68 'message': lambda x: stdmsg(None, x), | 68 'message': lambda x: stdmsg(None, x), |
| 69 'fail': lambda x: stdmsg('FAILED', x), | 69 'fail': lambda x: stdmsg('FAILED', x), |
| 70 'warn': lambda x: stdmsg('WARNING', x), | 70 'warn': lambda x: stdmsg('WARNING', x), |
| 71 'abend': lambda x: stdmsg('FAILED', x), | 71 'abend': lambda x: stdmsg('FAILED', x), |
| 72 'ok': lambda x: stdmsg('SUCCESS', x), | 72 'ok': lambda x: stdmsg('SUCCESS', x), |
| 73 'verbose': lambda x: None, | |
| 73 } | 74 } |
| 74 | 75 |
| 75 parser = optparse.OptionParser( | 76 parser = optparse.OptionParser( |
| 76 "usage: %prog -b <dir> --target <Debug|Release>") | 77 "usage: %prog -b <dir> --target <Debug|Release>") |
| 77 parser.add_option("", "--annotate", dest='annotate', action='store_true', | 78 parser.add_option("", "--annotate", dest='annotate', action='store_true', |
| 78 default=False, help="include buildbot annotations in output") | 79 default=False, help="include buildbot annotations in output") |
| 79 parser.add_option("", "--noannotate", dest='annotate', action='store_false') | 80 parser.add_option("", "--noannotate", dest='annotate', action='store_false') |
| 80 parser.add_option("-b", "--build-dir", | 81 parser.add_option("-b", "--build-dir", |
| 81 help="the location of the compiler output") | 82 help="the location of the compiler output") |
| 82 parser.add_option("--target", help="Debug or Release") | 83 parser.add_option("--target", help="Debug or Release") |
| 84 parser.add_option('-v', '--verbose', default=False, action='store_true') | |
| 83 | 85 |
| 84 options, args = parser.parse_args() | 86 options, args = parser.parse_args() |
|
Peter Mayo (wrong one)
2013/12/02 23:48:40
args is unused. Should Error on non options.
| |
| 85 # Bake target into build_dir. | 87 # Bake target into build_dir. |
| 86 if options.target and options.build_dir: | 88 if options.target and options.build_dir: |
| 87 assert (options.target != | 89 assert (options.target != |
| 88 os.path.basename(os.path.dirname(options.build_dir))) | 90 os.path.basename(os.path.dirname(options.build_dir))) |
| 89 options.build_dir = os.path.join(os.path.abspath(options.build_dir), | 91 options.build_dir = os.path.join(os.path.abspath(options.build_dir), |
| 90 options.target) | 92 options.target) |
| 91 | 93 |
| 92 if options.build_dir != None: | 94 if options.build_dir != None: |
| 93 target = os.path.join(options.build_dir, binary_target) | 95 target = os.path.join(options.build_dir, binary_target) |
|
Peter Mayo (wrong one)
2013/12/02 23:48:40
Wrong indent
| |
| 94 else: | 96 else: |
| 95 target = binary_target | 97 target = binary_target |
| 96 | 98 |
| 97 if options.annotate: | 99 if options.annotate: |
| 98 output = { | 100 output.update({ |
| 99 'message': lambda x: bbmsg(None, x), | 101 'message': lambda x: bbmsg(None, x), |
| 100 'fail': lambda x: bbmsg('FAILURE', x), | 102 'fail': lambda x: bbmsg('FAILURE', x), |
| 101 'warn': lambda x: bbmsg('WARNINGS', x), | 103 'warn': lambda x: bbmsg('WARNINGS', x), |
| 102 'abend': lambda x: bbmsg('EXCEPTIONS', x), | 104 'abend': lambda x: bbmsg('EXCEPTIONS', x), |
| 103 'ok': lambda x: bbmsg(None, x), | 105 'ok': lambda x: bbmsg(None, x), |
| 104 } | 106 }) |
| 107 | |
| 108 if options.verbose: | |
| 109 output['verbose'] = lambda x: stdmsg(None, x) | |
| 105 | 110 |
| 106 forbidden_regexp = re.compile(string.join(map(re.escape, | 111 forbidden_regexp = re.compile(string.join(map(re.escape, |
| 107 kUndesiredLibraryList), '|')) | 112 kUndesiredLibraryList), '|')) |
| 108 mapping_regexp = re.compile(r"\s*([^/]*) => ") | 113 mapping_regexp = re.compile(r"\s*([^/]*) => (.*)") |
| 109 blessed_regexp = re.compile(r"(%s)[-0-9.]*\.so" % string.join(map(re.escape, | 114 blessed_regexp = re.compile(r"(%s)[-0-9.]*\.so" % string.join(map(re.escape, |
| 110 kAllowedLibraryList), '|')) | 115 kAllowedLibraryList), '|')) |
| 116 if options.build_dir != None: | |
| 117 built_regexp = re.compile(re.escape(options.build_dir)) | |
| 118 else: | |
| 119 built_regexp = re.compile(re.escape('lib')) | |
| 120 built_regexp | |
|
spang
2013/12/02 23:25:39
extra line?
Peter Mayo (wrong one)
2013/12/02 23:48:40
This line should be blank.
On 2013/12/02 23:25:39
| |
| 111 success = 0 | 121 success = 0 |
| 112 warning = 0 | 122 warning = 0 |
| 113 | 123 |
| 114 p = subprocess.Popen(['ldd', target], stdout=subprocess.PIPE, | 124 p = subprocess.Popen(['ldd', target], stdout=subprocess.PIPE, |
| 115 stderr=subprocess.PIPE) | 125 stderr=subprocess.PIPE) |
| 116 out, err = p.communicate() | 126 out, err = p.communicate() |
| 117 | 127 |
| 118 if err != '': | 128 if err != '': |
| 119 output['abend']([ | 129 output['abend']([ |
| 120 'Failed to execute ldd to analyze dependencies for ' + target + ':', | 130 'Failed to execute ldd to analyze dependencies for ' + target + ':', |
| 121 ' ' + err, | 131 ' ' + err, |
| 122 ]) | 132 ]) |
| 123 return 1 | 133 return 1 |
| 124 | 134 |
| 125 if out == '': | 135 if out == '': |
| 126 output['abend']([ | 136 output['abend']([ |
| 127 'No output to scan for forbidden dependencies.' | 137 'No output to scan for forbidden dependencies.' |
| 128 ]) | 138 ]) |
| 129 return 1 | 139 return 1 |
| 130 | 140 |
| 131 success = 1 | 141 success = 1 |
| 132 deps = string.split(out, '\n') | 142 deps = string.split(out, '\n') |
| 133 for d in deps: | 143 for d in deps: |
|
Peter Mayo (wrong one)
2013/12/02 23:48:40
Wrong indent.
| |
| 134 libmatch = mapping_regexp.match(d) | 144 libmatch = mapping_regexp.match(d) |
| 135 if libmatch: | 145 if libmatch: |
| 136 lib = libmatch.group(1) | 146 lib = libmatch.group(1) |
| 147 source = libmatch.group(2) | |
| 137 if forbidden_regexp.search(lib): | 148 if forbidden_regexp.search(lib): |
| 138 success = 0 | 149 success = 0 |
| 139 output['message'](['Forbidden library: ' + lib]) | 150 output['message'](['Forbidden library: ' + lib]) |
| 140 if not blessed_regexp.match(lib): | 151 elif built_regexp.match(source): |
| 152 output['verbose'](['Built library: ' + lib]) | |
| 153 elif blessed_regexp.match(lib): | |
| 154 output['verbose'](['Blessed library: ' + lib]) | |
| 155 else: | |
| 141 warning = 1 | 156 warning = 1 |
| 142 output['message'](['Unexpected library: ' + lib]) | 157 output['message'](['Unexpected library: ' + lib]) |
| 143 | 158 |
| 144 if success == 1: | 159 if success == 1: |
| 145 if warning == 1: | 160 if warning == 1: |
| 146 output['warn'](None) | 161 output['warn'](None) |
| 147 else: | 162 else: |
| 148 output['ok'](None) | 163 output['ok'](None) |
| 149 return 0 | 164 return 0 |
| 150 else: | 165 else: |
| 151 output['fail'](None) | 166 output['fail'](None) |
| 152 return 1 | 167 return 1 |
| 153 | 168 |
| 154 if __name__ == "__main__": | 169 if __name__ == "__main__": |
| 155 # handle arguments... | 170 # handle arguments... |
| 156 # do something reasonable if not run with one... | 171 # do something reasonable if not run with one... |
| 157 sys.exit(_main()) | 172 sys.exit(_main()) |
| OLD | NEW |