Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: site_scons/site_tools/environment_tools.py

Issue 6329: Dropping in software construction toolkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « site_scons/site_tools/distcc.py ('k') | site_scons/site_tools/gather_inputs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 # Copyright 2008, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 """Set up tools for environments for for software construction toolkit.
32
33 This module is a SCons tool which should be include in all environments. It
34 will automatically be included by the component_setup tool.
35 """
36
37
38 import SCons
39
40
41 #------------------------------------------------------------------------------
42
43
44 def FilterOut(self, **kw):
45 """Removes values from existing construction variables in an Environment.
46
47 The values to remove should be a list. For example:
48
49 self.FilterOut(CPPDEFINES=['REMOVE_ME', 'ME_TOO'])
50
51 Args:
52 self: Environment to alter.
53 kw: (Any other named arguments are values to remove).
54 """
55
56 kw = SCons.Environment.copy_non_reserved_keywords(kw)
57 for key, val in kw.items():
58 envval = self.get(key, None)
59 if envval is None:
60 # No existing variable in the environment, so nothing to delete.
61 continue
62
63 for vremove in val:
64 if vremove in envval:
65 envval.remove(vremove)
66
67 self[key] = envval
68
69 # TODO(sgk): SCons.Environment.Append() has much more logic to deal
70 # with various types of values. We should handle all those cases in here
71 # too.
72
73 #------------------------------------------------------------------------------
74
75
76 def Overlap(self, values1, values2):
77 """Checks for overlap between the values.
78
79 Args:
80 self: Environment to use for variable substitution.
81 values1: First value(s) to compare. May be a string or list of strings.
82 values2: Second value(s) to compare. May be a string or list of strings.
83
84 Returns:
85 The list of values in common after substitution, or an empty list if
86 the values do no overlap.
87
88 Converts the values to a set of plain strings via self.subst() before
89 comparison, so SCons $ variables are evaluated.
90 """
91
92 set1 = set()
93 for v in self.Flatten(values1):
94 set1.add(self.subst(v))
95
96 set2 = set()
97 for v in self.Flatten(values2):
98 set2.add(self.subst(v))
99
100 return list(set1.intersection(set2))
101
102
103 #------------------------------------------------------------------------------
104
105
106 def ApplySConscript(self, sconscript_file):
107 """Applies a SConscript to the current environment.
108
109 Args:
110 self: Environment to modify.
111 sconscript_file: Name of SConscript file to apply.
112
113 Returns:
114 The return value from the call to SConscript().
115
116 ApplySConscript() should be used when an existing SConscript which sets up an
117 environment gets too large, or when there is common setup between multiple
118 environments which can't be reduced into a parent environment which the
119 multiple child environments Clone() from. The latter case is necessary
120 because env.Clone() only enables single inheritance for environments.
121
122 ApplySConscript() is NOT intended to replace the Tool() method. If you need
123 to add methods or builders to one or more environments, do that as a tool
124 (and write unit tests for them).
125
126 ApplySConscript() is equivalent to the following SCons call:
127 SConscript(sconscript_file, exports={'env':self})
128
129 The called SConscript should import the 'env' variable to get access to the
130 calling environment:
131 Import('env')
132
133 Changes made to env in the called SConscript will be applied to the
134 environment calling ApplySConscript() - that is, env in the called SConscript
135 is a reference to the calling environment.
136
137 If you need to export multiple variables to the called SConscript, or return
138 variables from it, use the existing SConscript() function.
139 """
140 return SCons.Script.SConscript(sconscript_file, exports={'env':self})
141
142 #------------------------------------------------------------------------------
143
144
145 def BuildSConscript(self, sconscript_file):
146 """Builds a SConscript based on the current environment.
147
148 Args:
149 self: Environment to clone and pass to the called SConscript.
150 sconscript_file: Name of SConscript file to build. If this is a directory,
151 this method will look for sconscript_file+'/build.scons', and if that
152 is not found, sconscript_file+'/SConscript'.
153
154 Returns:
155 The return value from the call to SConscript().
156
157 BuildSConscript() should be used when an existing SConscript which builds a
158 project gets too large, or when a group of SConscripts are logically related
159 but should not directly affect each others' environments (for example, a
160 library might want to build a number of unit tests which exist in
161 subdirectories, but not allow those tests' SConscripts to affect/pollute the
162 library's environment.
163
164 BuildSConscript() is NOT intended to replace the Tool() method. If you need
165 to add methods or builders to one or more environments, do that as a tool
166 (and write unit tests for them).
167
168 BuildSConscript() is equivalent to the following SCons call:
169 SConscript(sconscript_file, exports={'env':self.Clone()})
170 or if sconscript_file is a directory:
171 SConscript(sconscript_file+'/build.scons', exports={'env':self.Clone()})
172
173 The called SConscript should import the 'env' variable to get access to the
174 calling environment:
175 Import('env')
176
177 Changes made to env in the called SConscript will NOT be applied to the
178 environment calling BuildSConscript() - that is, env in the called SConscript
179 is a clone/copy of the calling environment, not a reference to that
180 environment.
181
182 If you need to export multiple variables to the called SConscript, or return
183 variables from it, use the existing SConscript() function.
184 """
185 # Need to look for the source node, since by default SCons will look for the
186 # entry in the variant_dir, which won't exist (and thus won't be a directory
187 # or a file). This isn't a problem in BuildComponents(), since the variant
188 # dir is only set inside its call to SConscript().
189 if self.Entry(sconscript_file).srcnode().isdir():
190 # Building a subdirectory, so look for build.scons or SConscript
191 script_file = sconscript_file + '/build.scons'
192 if not self.File(script_file).srcnode().exists():
193 script_file = sconscript_file + '/SConscript'
194 else:
195 script_file = sconscript_file
196
197 self.SConscript(script_file, exports={'env':self.Clone()})
198
199 #------------------------------------------------------------------------------
200
201
202 def generate(env):
203 # NOTE: SCons requires the use of this name, which fails gpylint.
204 """SCons entry point for this tool."""
205
206 # Add methods to environment
207 env.AddMethod(ApplySConscript)
208 env.AddMethod(BuildSConscript)
209 env.AddMethod(FilterOut)
210 env.AddMethod(Overlap)
OLDNEW
« no previous file with comments | « site_scons/site_tools/distcc.py ('k') | site_scons/site_tools/gather_inputs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698