Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import contextlib | 5 import contextlib |
| 6 import fnmatch | 6 import fnmatch |
| 7 import json | 7 import json |
| 8 import os | 8 import os |
| 9 import pipes | 9 import pipes |
| 10 import shlex | 10 import shlex |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 return shlex.split(gyp_string) | 75 return shlex.split(gyp_string) |
| 76 | 76 |
| 77 | 77 |
| 78 def CheckOptions(options, parser, required=None): | 78 def CheckOptions(options, parser, required=None): |
| 79 if not required: | 79 if not required: |
| 80 return | 80 return |
| 81 for option_name in required: | 81 for option_name in required: |
| 82 if getattr(options, option_name) is None: | 82 if getattr(options, option_name) is None: |
| 83 parser.error('--%s is required' % option_name.replace('_', '-')) | 83 parser.error('--%s is required' % option_name.replace('_', '-')) |
| 84 | 84 |
| 85 | |
| 85 def WriteJson(obj, path, only_if_changed=False): | 86 def WriteJson(obj, path, only_if_changed=False): |
| 86 old_dump = None | 87 old_dump = None |
| 87 if os.path.exists(path): | 88 if os.path.exists(path): |
| 88 with open(path, 'r') as oldfile: | 89 with open(path, 'r') as oldfile: |
| 89 old_dump = oldfile.read() | 90 old_dump = oldfile.read() |
| 90 | 91 |
| 91 new_dump = json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')) | 92 new_dump = json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')) |
| 92 | 93 |
| 93 if not only_if_changed or old_dump != new_dump: | 94 if not only_if_changed or old_dump != new_dump: |
| 94 with open(path, 'w') as outfile: | 95 with open(path, 'w') as outfile: |
| 95 outfile.write(new_dump) | 96 outfile.write(new_dump) |
| 96 | 97 |
| 98 | |
| 97 def ReadJson(path): | 99 def ReadJson(path): |
| 98 with open(path, 'r') as jsonfile: | 100 with open(path, 'r') as jsonfile: |
| 99 return json.load(jsonfile) | 101 return json.load(jsonfile) |
| 100 | 102 |
| 101 | 103 |
| 102 class CalledProcessError(Exception): | 104 class CalledProcessError(Exception): |
| 103 """This exception is raised when the process run by CheckOutput | 105 """This exception is raised when the process run by CheckOutput |
| 104 exits with a non-zero exit code.""" | 106 exits with a non-zero exit code.""" |
| 105 | 107 |
| 106 def __init__(self, cwd, args, output): | 108 def __init__(self, cwd, args, output): |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 207 |
| 206 | 208 |
| 207 def PrintWarning(message): | 209 def PrintWarning(message): |
| 208 print 'WARNING: ' + message | 210 print 'WARNING: ' + message |
| 209 | 211 |
| 210 | 212 |
| 211 def PrintBigWarning(message): | 213 def PrintBigWarning(message): |
| 212 print '***** ' * 8 | 214 print '***** ' * 8 |
| 213 PrintWarning(message) | 215 PrintWarning(message) |
| 214 print '***** ' * 8 | 216 print '***** ' * 8 |
| 217 | |
| 218 | |
| 219 def GetPythonDependencies(): | |
| 220 """Gets the paths of imported non-system python modules. | |
| 221 | |
| 222 A path is assumed to be a "system" import if it is outside of chromium's | |
| 223 src/. The paths will be relative to the current directory. | |
| 224 """ | |
| 225 module_paths = (m.__file__ for m in sys.modules.itervalues() | |
| 226 if m is not None and hasattr(m, '__file__')) | |
| 227 | |
| 228 abs_module_paths = map(os.path.abspath, module_paths) | |
| 229 | |
| 230 non_system_module_paths = [ | |
| 231 p for p in abs_module_paths if p.startswith(CHROMIUM_SRC)] | |
| 232 def ConvertPycToPy(s): | |
| 233 if s.endswith('.pyc'): | |
| 234 return s[:-1] | |
| 235 return s | |
| 236 | |
| 237 non_system_module_paths = map(ConvertPycToPy, non_system_module_paths) | |
| 238 non_system_module_paths = map(os.path.relpath, non_system_module_paths) | |
| 239 return sorted(set(non_system_module_paths)) | |
| 240 | |
| 241 | |
| 242 def AddDepfileOption(parser): | |
| 243 parser.add_option('--depfile', | |
| 244 help='Path to depfile. This should be specified as the ' | |
|
nyquist
2014/06/23 18:41:57
Should 'should' be 'must'?
cjhopman
2014/06/24 18:12:53
Done. I read this as "'Should' should be 'must'."
| |
| 245 'action\'s first output.') | |
| 246 | |
| 247 | |
| 248 def WriteDepfile(path, dependencies): | |
| 249 with open(path, 'w') as depfile: | |
| 250 depfile.write(path) | |
| 251 depfile.write(': ') | |
| 252 depfile.write(' '.join(dependencies)) | |
| 253 depfile.write('\n') | |
| OLD | NEW |