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 module_paths = (m.__file__ for m in sys.modules.itervalues() | |
222 if m is not None and hasattr(m, '__file__')) | |
223 | |
224 abs_module_paths = map(os.path.abspath, module_paths) | |
225 | |
226 chromium_src = os.path.abspath( | |
227 os.path.join(__file__, '..', '..', '..', '..')) | |
228 | |
229 non_system_module_paths = [ | |
230 p for p in abs_module_paths if p.startswith(chromium_src)] | |
Nico
2014/06/23 15:32:00
See thread ".d files and absolute paths" on gn-dev
cjhopman
2014/06/23 17:26:56
Done.
| |
231 def ConvertPycToPy(s): | |
232 if s.endswith('.pyc'): | |
233 return s[:-1] | |
234 return s | |
235 | |
236 non_system_module_paths = map(ConvertPycToPy, non_system_module_paths) | |
237 return list(set(non_system_module_paths)) | |
Nico
2014/06/23 15:32:00
set() means this won't have a deterministic order
cjhopman
2014/06/23 17:26:56
Done.
| |
238 | |
239 | |
240 def AddDepfileOption(parser): | |
241 parser.add_option('--depfile', | |
242 help='Path to depfile. This should be specified as the ' | |
243 'action\'s first output.') | |
244 | |
245 | |
246 def WriteDepfile(path, dependencies): | |
247 with open(path, 'w') as depfile: | |
248 depfile.write(path) | |
249 depfile.write(': ') | |
250 depfile.write(' '.join(dependencies)) | |
251 depfile.write('\n') | |
OLD | NEW |