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 ast | |
| 5 import fnmatch | 6 import fnmatch |
| 6 import json | 7 import json |
| 7 import os | 8 import os |
| 8 import pipes | 9 import pipes |
| 9 import shlex | 10 import shlex |
| 10 import shutil | 11 import shutil |
| 11 import subprocess | 12 import subprocess |
| 12 import sys | 13 import sys |
| 14 import tempfile | |
| 15 import traceback | |
| 13 | 16 |
|
Nico
2014/05/05 22:08:10
nit: 2 newlines between toplevels
cjhopman
2014/06/25 01:20:03
Done.
| |
| 17 class TempDir(object): | |
| 18 def __init__(self): | |
| 19 self.dir = tempfile.mkdtemp() | |
| 20 | |
| 21 def __enter__(self): | |
| 22 return self.dir | |
| 23 | |
| 24 def __exit__(self, type, value, traceback): | |
| 25 shutil.rmtree(self.dir) | |
|
Nico
2014/05/05 22:08:10
nit: Maybe:
@contextmanager
def TempDir():
dir
cjhopman
2014/06/25 01:20:03
Done.
| |
| 14 | 26 |
|
Nico
2014/05/05 22:08:10
nit: 2 newlines between toplevels
cjhopman
2014/06/25 01:20:03
Done.
| |
| 15 def MakeDirectory(dir_path): | 27 def MakeDirectory(dir_path): |
| 16 try: | 28 try: |
| 17 os.makedirs(dir_path) | 29 os.makedirs(dir_path) |
| 18 except OSError: | 30 except OSError: |
| 19 pass | 31 pass |
| 20 | 32 |
| 21 | 33 |
| 22 def DeleteDirectory(dir_path): | 34 def DeleteDirectory(dir_path): |
| 23 if os.path.exists(dir_path): | 35 if os.path.exists(dir_path): |
| 24 shutil.rmtree(dir_path) | 36 shutil.rmtree(dir_path) |
| 25 | 37 |
| 26 | 38 |
| 27 def Touch(path): | 39 def Touch(path, fail_if_missing=False): |
| 40 if fail_if_missing and not os.path.exists(path): | |
| 41 raise Exception(path + ' doesn\'t exist.') | |
| 42 | |
| 28 MakeDirectory(os.path.dirname(path)) | 43 MakeDirectory(os.path.dirname(path)) |
| 29 with open(path, 'a'): | 44 with open(path, 'a'): |
| 30 os.utime(path, None) | 45 os.utime(path, None) |
| 31 | 46 |
| 32 | 47 |
| 33 def FindInDirectory(directory, filename_filter): | 48 def FindInDirectory(directory, filename_filter): |
| 34 files = [] | 49 files = [] |
| 35 for root, _dirnames, filenames in os.walk(directory): | 50 for root, _dirnames, filenames in os.walk(directory): |
| 36 matched_files = fnmatch.filter(filenames, filename_filter) | 51 matched_files = fnmatch.filter(filenames, filename_filter) |
| 37 files.extend((os.path.join(root, f) for f in matched_files)) | 52 files.extend((os.path.join(root, f) for f in matched_files)) |
| 38 return files | 53 return files |
| 39 | 54 |
| 40 | 55 |
| 41 def FindInDirectories(directories, filename_filter): | 56 def FindInDirectories(directories, filename_filter): |
| 42 all_files = [] | 57 all_files = [] |
| 43 for directory in directories: | 58 for directory in directories: |
| 44 all_files.extend(FindInDirectory(directory, filename_filter)) | 59 all_files.extend(FindInDirectory(directory, filename_filter)) |
| 45 return all_files | 60 return all_files |
| 46 | 61 |
| 47 | 62 |
| 63 def ParseGnList(gn_string): | |
| 64 return ast.literal_eval(gn_string) | |
| 65 | |
| 66 | |
| 48 def ParseGypList(gyp_string): | 67 def ParseGypList(gyp_string): |
| 49 # The ninja generator doesn't support $ in strings, so use ## to | 68 # The ninja generator doesn't support $ in strings, so use ## to |
| 50 # represent $. | 69 # represent $. |
| 51 # TODO(cjhopman): Remove when | 70 # TODO(cjhopman): Remove when |
| 52 # https://code.google.com/p/gyp/issues/detail?id=327 | 71 # https://code.google.com/p/gyp/issues/detail?id=327 |
| 53 # is addressed. | 72 # is addressed. |
| 54 gyp_string = gyp_string.replace('##', '$') | 73 gyp_string = gyp_string.replace('##', '$') |
| 55 return shlex.split(gyp_string) | 74 return shlex.split(gyp_string) |
| 56 | 75 |
| 57 | 76 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 162 |
| 144 | 163 |
| 145 def PrintWarning(message): | 164 def PrintWarning(message): |
| 146 print 'WARNING: ' + message | 165 print 'WARNING: ' + message |
| 147 | 166 |
| 148 | 167 |
| 149 def PrintBigWarning(message): | 168 def PrintBigWarning(message): |
| 150 print '***** ' * 8 | 169 print '***** ' * 8 |
| 151 PrintWarning(message) | 170 PrintWarning(message) |
| 152 print '***** ' * 8 | 171 print '***** ' * 8 |
| 172 | |
|
Nico
2014/05/05 22:08:10
nit: 2 newlines
cjhopman
2014/06/25 01:20:03
Done.
| |
| 173 def GetPythonDependencies(): | |
|
Nico
2014/05/05 22:08:10
docstring
cjhopman
2014/06/25 01:20:03
Done.
| |
| 174 module_paths = (m.__file__ for m in sys.modules.itervalues() | |
| 175 if m is not None and hasattr(m, '__file__')) | |
| 176 | |
| 177 abs_module_paths = map(os.path.abspath, module_paths) | |
| 178 | |
| 179 chromium_src = os.path.abspath( | |
| 180 os.path.join(__file__, '..', '..', '..', '..')) | |
|
Nico
2014/05/05 22:08:10
Can you put this in a constant at the top of the f
cjhopman
2014/06/25 01:20:03
Done.
| |
| 181 | |
| 182 non_system_module_paths = [p for p in abs_module_paths if p.startswith(chromiu m_src)] | |
|
Nico
2014/05/05 22:08:10
nit: 80 cols
cjhopman
2014/06/25 01:20:03
Done.
| |
| 183 def ConvertPycToPy(s): | |
| 184 if s.endswith('.pyc'): | |
| 185 return s[:-1] | |
| 186 return s | |
| 187 | |
| 188 non_system_module_paths = map(ConvertPycToPy, non_system_module_paths) | |
| 189 return list(set(non_system_module_paths)) | |
|
Nico
2014/05/05 22:08:10
Huh, so these are all absolute paths? Can we make
cjhopman
2014/06/25 01:20:03
Done.
| |
| 190 | |
|
Nico
2014/05/05 22:08:10
2 newlines
cjhopman
2014/06/25 01:20:03
Done.
| |
| 191 def WriteDepfile(path, dependencies): | |
| 192 with open(path, 'w') as depfile: | |
| 193 depfile.write(path) | |
| 194 depfile.write(': ') | |
| 195 depfile.write(' '.join(dependencies)) | |
| 196 depfile.write('\n') | |
| OLD | NEW |