| OLD | NEW |
| 1 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2008 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 """ | 5 """ |
| 6 Tool module for adding, to a construction environment, Chromium-specific | 6 Tool module for adding, to a construction environment, Chromium-specific |
| 7 wrappers around Hammer builders. This gives us a central place for any | 7 wrappers around Hammer builders. This gives us a central place for any |
| 8 customization we need to make to the different things we build. | 8 customization we need to make to the different things we build. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 return cls._inst | 22 return cls._inst |
| 23 def __init__(self, *args, **kwargs): pass | 23 def __init__(self, *args, **kwargs): pass |
| 24 def __call__(self, *args, **kwargs): return self | 24 def __call__(self, *args, **kwargs): return self |
| 25 def __repr__(self): return "Null()" | 25 def __repr__(self): return "Null()" |
| 26 def __nonzero__(self): return False | 26 def __nonzero__(self): return False |
| 27 def __getattr__(self, name): return self | 27 def __getattr__(self, name): return self |
| 28 def __setattr__(self, name, val): return self | 28 def __setattr__(self, name, val): return self |
| 29 def __delattr__(self, name): return self | 29 def __delattr__(self, name): return self |
| 30 def __getitem__(self, name): return self | 30 def __getitem__(self, name): return self |
| 31 | 31 |
| 32 class ChromeFileList(MSVS.FileList): | 32 class FileList(object): |
| 33 def __init__(self, entries=None): |
| 34 if isinstance(entries, FileList): |
| 35 entries = entries.entries |
| 36 self.entries = entries or [] |
| 37 def __getitem__(self, i): |
| 38 return self.entries[i] |
| 39 def __setitem__(self, i, item): |
| 40 self.entries[i] = item |
| 41 def __delitem__(self, i): |
| 42 del self.entries[i] |
| 43 def __add__(self, other): |
| 44 if isinstance(other, FileList): |
| 45 return self.__class__(self.entries + other.entries) |
| 46 elif isinstance(other, type(self.entries)): |
| 47 return self.__class__(self.entries + other) |
| 48 else: |
| 49 return self.__class__(self.entries + list(other)) |
| 50 def __radd__(self, other): |
| 51 if isinstance(other, FileList): |
| 52 return self.__class__(other.entries + self.entries) |
| 53 elif isinstance(other, type(self.entries)): |
| 54 return self.__class__(other + self.entries) |
| 55 else: |
| 56 return self.__class__(list(other) + self.entries) |
| 57 def __iadd__(self, other): |
| 58 if isinstance(other, FileList): |
| 59 self.entries += other.entries |
| 60 elif isinstance(other, type(self.entries)): |
| 61 self.entries += other |
| 62 else: |
| 63 self.entries += list(other) |
| 64 return self |
| 65 def append(self, item): |
| 66 return self.entries.append(item) |
| 67 def extend(self, item): |
| 68 return self.entries.extend(item) |
| 69 def index(self, item, *args): |
| 70 return self.entries.index(item, *args) |
| 71 def remove(self, item): |
| 72 return self.entries.remove(item) |
| 73 |
| 74 def FileListWalk(top, topdown=True, onerror=None): |
| 75 """ |
| 76 """ |
| 77 try: |
| 78 entries = top.entries |
| 79 except AttributeError, err: |
| 80 if onerror is not None: |
| 81 onerror(err) |
| 82 return |
| 83 |
| 84 dirs, nondirs = [], [] |
| 85 for entry in entries: |
| 86 if hasattr(entry, 'entries'): |
| 87 dirs.append(entry) |
| 88 else: |
| 89 nondirs.append(entry) |
| 90 |
| 91 if topdown: |
| 92 yield top, dirs, nondirs |
| 93 for entry in dirs: |
| 94 for x in FileListWalk(entry, topdown, onerror): |
| 95 yield x |
| 96 if not topdown: |
| 97 yield top, dirs, nondirs |
| 98 |
| 99 class ChromeFileList(FileList): |
| 33 def Append(self, *args): | 100 def Append(self, *args): |
| 34 for element in args: | 101 for element in args: |
| 35 self.append(element) | 102 self.append(element) |
| 36 def Extend(self, *args): | 103 def Extend(self, *args): |
| 37 for element in args: | 104 for element in args: |
| 38 self.extend(element) | 105 self.extend(element) |
| 39 def Remove(self, *args): | 106 def Remove(self, *args): |
| 40 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): | 107 for top, lists, nonlists in FileListWalk(self, topdown=False): |
| 41 for element in args: | 108 for element in args: |
| 42 try: | 109 try: |
| 43 top.remove(element) | 110 top.remove(element) |
| 44 except ValueError: | 111 except ValueError: |
| 45 pass | 112 pass |
| 46 def Replace(self, old, new): | 113 def Replace(self, old, new): |
| 47 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): | 114 for top, lists, nonlists in FileListWalk(self, topdown=False): |
| 48 try: | 115 try: |
| 49 i = top.index(old) | 116 i = top.index(old) |
| 50 except ValueError: | 117 except ValueError: |
| 51 pass | 118 pass |
| 52 else: | 119 else: |
| 53 top[i] = new | 120 top[i] = new |
| 54 | 121 |
| 55 | 122 |
| 56 def FilterOut(self, **kw): | 123 def FilterOut(self, **kw): |
| 57 """Removes values from existing construction variables in an Environment. | 124 """Removes values from existing construction variables in an Environment. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 def compilable(env, file): | 176 def compilable(env, file): |
| 110 base, ext = os.path.splitext(str(file)) | 177 base, ext = os.path.splitext(str(file)) |
| 111 if ext in non_compilable_suffixes[env['TARGET_PLATFORM']]: | 178 if ext in non_compilable_suffixes[env['TARGET_PLATFORM']]: |
| 112 return False | 179 return False |
| 113 return True | 180 return True |
| 114 | 181 |
| 115 def compilable_files(env, sources): | 182 def compilable_files(env, sources): |
| 116 if not hasattr(sources, 'entries'): | 183 if not hasattr(sources, 'entries'): |
| 117 return [x for x in sources if compilable(env, x)] | 184 return [x for x in sources if compilable(env, x)] |
| 118 result = [] | 185 result = [] |
| 119 for top, folders, nonfolders in MSVS.FileListWalk(sources): | 186 for top, folders, nonfolders in FileListWalk(sources): |
| 120 result.extend([x for x in nonfolders if compilable(env, x)]) | 187 result.extend([x for x in nonfolders if compilable(env, x)]) |
| 121 return result | 188 return result |
| 122 | 189 |
| 123 def ChromeProgram(env, target, source, *args, **kw): | 190 def ChromeProgram(env, target, source, *args, **kw): |
| 124 source = compilable_files(env, source) | 191 source = compilable_files(env, source) |
| 125 if env.get('_GYP'): | 192 if env.get('_GYP'): |
| 126 prog = env.Program(target, source, *args, **kw) | 193 prog = env.Program(target, source, *args, **kw) |
| 127 result = env.Install('$DESTINATION_ROOT', prog) | 194 result = env.Install('$DESTINATION_ROOT', prog) |
| 128 else: | 195 else: |
| 129 result = env.ComponentProgram(target, source, *args, **kw) | 196 result = env.ComponentProgram(target, source, *args, **kw) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 # Add the grit tool to the base environment because we use this a lot. | 310 # Add the grit tool to the base environment because we use this a lot. |
| 244 sys.path.append(env.Dir('$SRC_DIR/tools/grit').abspath) | 311 sys.path.append(env.Dir('$SRC_DIR/tools/grit').abspath) |
| 245 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/grit/grit')]) | 312 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/grit/grit')]) |
| 246 | 313 |
| 247 # Add the repack python script tool that we use in multiple places. | 314 # Add the repack python script tool that we use in multiple places. |
| 248 sys.path.append(env.Dir('$SRC_DIR/tools/data_pack').abspath) | 315 sys.path.append(env.Dir('$SRC_DIR/tools/data_pack').abspath) |
| 249 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/data_pack/')]) | 316 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/data_pack/')]) |
| 250 | 317 |
| 251 def exists(env): | 318 def exists(env): |
| 252 return True | 319 return True |
| OLD | NEW |