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 |
| 11 import SCons.Node |
| 12 import _Node_MSVS as MSVS |
| 13 |
| 14 class Null(object): |
| 15 def __new__(cls, *args, **kwargs): |
| 16 if '_inst' not in vars(cls): |
| 17 cls._inst = super(type, cls).__new__(cls, *args, **kwargs) |
| 18 return cls._inst |
| 19 def __init__(self, *args, **kwargs): pass |
| 20 def __call__(self, *args, **kwargs): return self |
| 21 def __repr__(self): return "Null()" |
| 22 def __nonzero__(self): return False |
| 23 def __getattr__(self, name): return self |
| 24 def __setattr__(self, name, val): return self |
| 25 def __delattr__(self, name): return self |
| 26 def __getitem__(self, name): return self |
| 27 |
| 28 class ChromeFileList(MSVS.FileList): |
| 29 def Append(self, *args): |
| 30 for element in args: |
| 31 self.append(element) |
| 32 def Extend(self, *args): |
| 33 for element in args: |
| 34 self.extend(element) |
| 35 def Remove(self, *args): |
| 36 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): |
| 37 for element in args: |
| 38 try: |
| 39 top.remove(element) |
| 40 except ValueError: |
| 41 pass |
| 42 def Replace(self, old, new): |
| 43 for top, lists, nonlists in MSVS.FileListWalk(self, topdown=False): |
| 44 try: |
| 45 i = top.index(old) |
| 46 except ValueError: |
| 47 pass |
| 48 else: |
| 49 top[i] = new |
| 50 |
| 51 import __builtin__ |
| 52 __builtin__.ChromeFileList = ChromeFileList |
| 53 |
| 54 def compilable_files(sources): |
| 55 if not hasattr(sources, 'entries'): |
| 56 return [x for x in sources if not str(x).endswith('.h')] |
| 57 result = [] |
| 58 for top, folders, nonfolders in MSVS.FileListWalk(sources): |
| 59 result.extend([x for x in nonfolders if not str(x).endswith('.h')]) |
| 60 return result |
| 61 |
| 62 def ChromeProgram(env, target, source, *args, **kw): |
| 63 source = compilable_files(source) |
| 64 result = env.ComponentProgram(target, source, *args, **kw) |
| 65 if env.get('INCREMENTAL'): |
| 66 env.Precious(result) |
| 67 return result |
| 68 |
| 69 def ChromeTestProgram(env, target, source, *args, **kw): |
| 70 source = compilable_files(source) |
| 71 result = env.ComponentTestProgram(target, source, *args, **kw) |
| 72 if env.get('INCREMENTAL'): |
| 73 env.Precious(*result) |
| 74 return result |
| 75 |
| 76 def ChromeStaticLibrary(env, target, source, *args, **kw): |
| 77 source = compilable_files(source) |
| 78 kw['COMPONENT_STATIC'] = True |
| 79 return env.ComponentLibrary(target, source, *args, **kw) |
| 80 |
| 81 def ChromeSharedLibrary(env, target, source, *args, **kw): |
| 82 source = compilable_files(source) |
| 83 kw['COMPONENT_STATIC'] = False |
| 84 result = [env.ComponentLibrary(target, source, *args, **kw)[0]] |
| 85 if env.get('INCREMENTAL'): |
| 86 env.Precious(result) |
| 87 return result |
| 88 |
| 89 def ChromeObject(env, *args, **kw): |
| 90 return env.ComponentObject(*args, **kw) |
| 91 |
| 92 def ChromeMSVSFolder(env, *args, **kw): |
| 93 if not env.Bit('msvs'): |
| 94 return Null() |
| 95 return env.MSVSFolder(*args, **kw) |
| 96 |
| 97 def ChromeMSVSProject(env, *args, **kw): |
| 98 if not env.Bit('msvs'): |
| 99 return Null() |
| 100 return env.MSVSProject(*args, **kw) |
| 101 |
| 102 def ChromeMSVSSolution(env, *args, **kw): |
| 103 if not env.Bit('msvs'): |
| 104 return Null() |
| 105 return env.MSVSSolution(*args, **kw) |
| 106 |
11 def generate(env): | 107 def generate(env): |
12 def ChromeProgram(env, *args, **kw): | |
13 result = env.ComponentProgram(*args, **kw) | |
14 if env.get('INCREMENTAL'): | |
15 env.Precious(result) | |
16 return result | |
17 env.AddMethod(ChromeProgram) | 108 env.AddMethod(ChromeProgram) |
18 | |
19 def ChromeTestProgram(env, *args, **kw): | |
20 result = env.ComponentTestProgram(*args, **kw) | |
21 if env.get('INCREMENTAL'): | |
22 env.Precious(*result) | |
23 return result | |
24 env.AddMethod(ChromeTestProgram) | 109 env.AddMethod(ChromeTestProgram) |
25 | |
26 def ChromeStaticLibrary(env, *args, **kw): | |
27 kw['COMPONENT_STATIC'] = True | |
28 return env.ComponentLibrary(*args, **kw) | |
29 env.AddMethod(ChromeStaticLibrary) | 110 env.AddMethod(ChromeStaticLibrary) |
30 | |
31 def ChromeSharedLibrary(env, *args, **kw): | |
32 kw['COMPONENT_STATIC'] = False | |
33 result = [env.ComponentLibrary(*args, **kw)[0]] | |
34 if env.get('INCREMENTAL'): | |
35 env.Precious(result) | |
36 return result | |
37 env.AddMethod(ChromeSharedLibrary) | 111 env.AddMethod(ChromeSharedLibrary) |
38 | |
39 def ChromeObject(env, *args, **kw): | |
40 return env.ComponentObject(*args, **kw) | |
41 env.AddMethod(ChromeObject) | 112 env.AddMethod(ChromeObject) |
42 | |
43 def ChromeMSVSFolder(env, *args, **kw): | |
44 if env.Bit('msvs'): | |
45 return env.MSVSFolder(*args, **kw) | |
46 return [] | |
47 env.AddMethod(ChromeMSVSFolder) | 113 env.AddMethod(ChromeMSVSFolder) |
48 | |
49 def ChromeMSVSProject(env, *args, **kw): | |
50 if env.Bit('msvs'): | |
51 return env.MSVSProject(*args, **kw) | |
52 return [] | |
53 env.AddMethod(ChromeMSVSProject) | 114 env.AddMethod(ChromeMSVSProject) |
54 | |
55 def ChromeMSVSSolution(env, *args, **kw): | |
56 if env.Bit('msvs'): | |
57 return env.MSVSSolution(*args, **kw) | |
58 return [] | |
59 env.AddMethod(ChromeMSVSSolution) | 115 env.AddMethod(ChromeMSVSSolution) |
60 | 116 |
61 def exists(env): | 117 def exists(env): |
62 return True | 118 return True |
OLD | NEW |