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 SCons 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 |
11 import sys | 11 import sys |
12 | 12 |
13 from SCons.Script import * | 13 from SCons.Script import * |
14 | 14 |
15 import SCons.Node | 15 import SCons.Node |
16 import _Node_MSVS as MSVS | |
17 | 16 |
18 class Null(object): | 17 class Null(object): |
19 def __new__(cls, *args, **kwargs): | 18 def __new__(cls, *args, **kwargs): |
20 if '_inst' not in vars(cls): | 19 if '_inst' not in vars(cls): |
21 cls._inst = super(type, cls).__new__(cls, *args, **kwargs) | 20 cls._inst = super(type, cls).__new__(cls, *args, **kwargs) |
22 return cls._inst | 21 return cls._inst |
23 def __init__(self, *args, **kwargs): pass | 22 def __init__(self, *args, **kwargs): pass |
24 def __call__(self, *args, **kwargs): return self | 23 def __call__(self, *args, **kwargs): return self |
25 def __repr__(self): return "Null()" | 24 def __repr__(self): return "Null()" |
26 def __nonzero__(self): return False | 25 def __nonzero__(self): return False |
27 def __getattr__(self, name): return self | 26 def __getattr__(self, name): return self |
28 def __setattr__(self, name, val): return self | 27 def __setattr__(self, name, val): return self |
29 def __delattr__(self, name): return self | 28 def __delattr__(self, name): return self |
30 def __getitem__(self, name): return self | 29 def __getitem__(self, name): return self |
31 | 30 |
32 class ChromeFileList(MSVS.FileList): | 31 class FileList(object): |
| 32 def __init__(self, entries=None): |
| 33 if isinstance(entries, FileList): |
| 34 entries = entries.entries |
| 35 self.entries = entries or [] |
| 36 def __getitem__(self, i): |
| 37 return self.entries[i] |
| 38 def __setitem__(self, i, item): |
| 39 self.entries[i] = item |
| 40 def __delitem__(self, i): |
| 41 del self.entries[i] |
| 42 def __add__(self, other): |
| 43 if isinstance(other, FileList): |
| 44 return self.__class__(self.entries + other.entries) |
| 45 elif isinstance(other, type(self.entries)): |
| 46 return self.__class__(self.entries + other) |
| 47 else: |
| 48 return self.__class__(self.entries + list(other)) |
| 49 def __radd__(self, other): |
| 50 if isinstance(other, FileList): |
| 51 return self.__class__(other.entries + self.entries) |
| 52 elif isinstance(other, type(self.entries)): |
| 53 return self.__class__(other + self.entries) |
| 54 else: |
| 55 return self.__class__(list(other) + self.entries) |
| 56 def __iadd__(self, other): |
| 57 if isinstance(other, FileList): |
| 58 self.entries += other.entries |
| 59 elif isinstance(other, type(self.entries)): |
| 60 self.entries += other |
| 61 else: |
| 62 self.entries += list(other) |
| 63 return self |
| 64 def append(self, item): |
| 65 return self.entries.append(item) |
| 66 def extend(self, item): |
| 67 return self.entries.extend(item) |
| 68 def index(self, item, *args): |
| 69 return self.entries.index(item, *args) |
| 70 def remove(self, item): |
| 71 return self.entries.remove(item) |
| 72 |
| 73 def FileListWalk(top, topdown=True, onerror=None): |
| 74 """ |
| 75 """ |
| 76 try: |
| 77 entries = top.entries |
| 78 except AttributeError, err: |
| 79 if onerror is not None: |
| 80 onerror(err) |
| 81 return |
| 82 |
| 83 dirs, nondirs = [], [] |
| 84 for entry in entries: |
| 85 if hasattr(entry, 'entries'): |
| 86 dirs.append(entry) |
| 87 else: |
| 88 nondirs.append(entry) |
| 89 |
| 90 if topdown: |
| 91 yield top, dirs, nondirs |
| 92 for entry in dirs: |
| 93 for x in FileListWalk(entry, topdown, onerror): |
| 94 yield x |
| 95 if not topdown: |
| 96 yield top, dirs, nondirs |
| 97 |
| 98 class ChromeFileList(FileList): |
33 def Append(self, *args): | 99 def Append(self, *args): |
34 for element in args: | 100 for element in args: |
35 self.append(element) | 101 self.append(element) |
36 def Extend(self, *args): | 102 def Extend(self, *args): |
37 for element in args: | 103 for element in args: |
38 self.extend(element) | 104 self.extend(element) |
39 def Remove(self, *args): | 105 def Remove(self, *args): |
40 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): | 106 for top, lists, nonlists in FileListWalk(self, topdown=False): |
41 for element in args: | 107 for element in args: |
42 try: | 108 try: |
43 top.remove(element) | 109 top.remove(element) |
44 except ValueError: | 110 except ValueError: |
45 pass | 111 pass |
46 def Replace(self, old, new): | 112 def Replace(self, old, new): |
47 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): | 113 for top, lists, nonlists in FileListWalk(self, topdown=False): |
48 try: | 114 try: |
49 i = top.index(old) | 115 i = top.index(old) |
50 except ValueError: | 116 except ValueError: |
51 pass | 117 pass |
52 else: | 118 else: |
53 top[i] = new | 119 top[i] = new |
54 | 120 |
55 | 121 |
56 def FilterOut(self, **kw): | 122 def FilterOut(self, **kw): |
57 """Removes values from existing construction variables in an Environment. | 123 """Removes values from existing construction variables in an Environment. |
(...skipping 51 matching lines...) Loading... |
109 def compilable(env, file): | 175 def compilable(env, file): |
110 base, ext = os.path.splitext(str(file)) | 176 base, ext = os.path.splitext(str(file)) |
111 if ext in non_compilable_suffixes[env['TARGET_PLATFORM']]: | 177 if ext in non_compilable_suffixes[env['TARGET_PLATFORM']]: |
112 return False | 178 return False |
113 return True | 179 return True |
114 | 180 |
115 def compilable_files(env, sources): | 181 def compilable_files(env, sources): |
116 if not hasattr(sources, 'entries'): | 182 if not hasattr(sources, 'entries'): |
117 return [x for x in sources if compilable(env, x)] | 183 return [x for x in sources if compilable(env, x)] |
118 result = [] | 184 result = [] |
119 for top, folders, nonfolders in MSVS.FileListWalk(sources): | 185 for top, folders, nonfolders in FileListWalk(sources): |
120 result.extend([x for x in nonfolders if compilable(env, x)]) | 186 result.extend([x for x in nonfolders if compilable(env, x)]) |
121 return result | 187 return result |
122 | 188 |
123 def ChromeProgram(env, target, source, *args, **kw): | 189 def ChromeProgram(env, target, source, *args, **kw): |
124 source = compilable_files(env, source) | 190 source = compilable_files(env, source) |
125 if env.get('_GYP'): | 191 if env.get('_GYP'): |
126 prog = env.Program(target, source, *args, **kw) | 192 prog = env.Program(target, source, *args, **kw) |
127 result = env.Install('$DESTINATION_ROOT', prog) | 193 result = env.Install('$DESTINATION_ROOT', prog) |
128 else: | 194 else: |
129 result = env.ComponentProgram(target, source, *args, **kw) | 195 result = env.ComponentProgram(target, source, *args, **kw) |
(...skipping 52 matching lines...) Loading... |
182 env.Precious(result) | 248 env.Precious(result) |
183 return result | 249 return result |
184 | 250 |
185 def ChromeObject(env, *args, **kw): | 251 def ChromeObject(env, *args, **kw): |
186 if env.get('_GYP'): | 252 if env.get('_GYP'): |
187 result = env.Object(target, source, *args, **kw) | 253 result = env.Object(target, source, *args, **kw) |
188 else: | 254 else: |
189 result = env.ComponentObject(*args, **kw) | 255 result = env.ComponentObject(*args, **kw) |
190 return result | 256 return result |
191 | 257 |
192 def ChromeMSVSFolder(env, *args, **kw): | |
193 if not env.Bit('msvs'): | |
194 return Null() | |
195 return env.MSVSFolder(*args, **kw) | |
196 | |
197 def ChromeMSVSProject(env, *args, **kw): | |
198 if not env.Bit('msvs'): | |
199 return Null() | |
200 try: | |
201 dest = kw['dest'] | |
202 except KeyError: | |
203 dest = None | |
204 else: | |
205 del kw['dest'] | |
206 result = env.MSVSProject(*args, **kw) | |
207 env.AlwaysBuild(result) | |
208 if dest: | |
209 i = env.Command(dest, result, Copy('$TARGET', '$SOURCE')) | |
210 Alias('msvs', i) | |
211 return result | |
212 | |
213 def ChromeMSVSSolution(env, *args, **kw): | |
214 if not env.Bit('msvs'): | |
215 return Null() | |
216 try: | |
217 dest = kw['dest'] | |
218 except KeyError: | |
219 dest = None | |
220 else: | |
221 del kw['dest'] | |
222 result = env.MSVSSolution(*args, **kw) | |
223 env.AlwaysBuild(result) | |
224 if dest: | |
225 i = env.Command(dest, result, Copy('$TARGET', '$SOURCE')) | |
226 Alias('msvs', i) | |
227 return result | |
228 | |
229 def generate(env): | 258 def generate(env): |
230 env.AddMethod(ChromeProgram) | 259 env.AddMethod(ChromeProgram) |
231 env.AddMethod(ChromeTestProgram) | 260 env.AddMethod(ChromeTestProgram) |
232 env.AddMethod(ChromeLibrary) | 261 env.AddMethod(ChromeLibrary) |
233 env.AddMethod(ChromeLoadableModule) | 262 env.AddMethod(ChromeLoadableModule) |
234 env.AddMethod(ChromeStaticLibrary) | 263 env.AddMethod(ChromeStaticLibrary) |
235 env.AddMethod(ChromeSharedLibrary) | 264 env.AddMethod(ChromeSharedLibrary) |
236 env.AddMethod(ChromeObject) | 265 env.AddMethod(ChromeObject) |
237 env.AddMethod(ChromeMSVSFolder) | |
238 env.AddMethod(ChromeMSVSProject) | |
239 env.AddMethod(ChromeMSVSSolution) | |
240 | 266 |
241 env.AddMethod(FilterOut) | 267 env.AddMethod(FilterOut) |
242 | 268 |
243 # Add the grit tool to the base environment because we use this a lot. | 269 # 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) | 270 sys.path.append(env.Dir('$SRC_DIR/tools/grit').abspath) |
245 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/grit/grit')]) | 271 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/grit/grit')]) |
246 | 272 |
247 # Add the repack python script tool that we use in multiple places. | 273 # Add the repack python script tool that we use in multiple places. |
248 sys.path.append(env.Dir('$SRC_DIR/tools/data_pack').abspath) | 274 sys.path.append(env.Dir('$SRC_DIR/tools/data_pack').abspath) |
249 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/data_pack/')]) | 275 env.Tool('scons', toolpath=[env.Dir('$SRC_DIR/tools/data_pack/')]) |
250 | 276 |
251 def exists(env): | 277 def exists(env): |
252 return True | 278 return True |
OLD | NEW |