author | Daniel Jacobs <daniel.jacobs@nokia.com> |
Wed, 09 Dec 2009 11:47:38 +0000 | |
branch | wip |
changeset 72 | d106cce8a879 |
parent 29 | ee00c00df073 |
child 59 | 0f7d6c11c675 |
permissions | -rw-r--r-- |
3 | 1 |
# |
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
# All rights reserved. |
|
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# raptor module |
|
16 |
# This module represents the running Raptor program. Raptor is started |
|
17 |
# either by calling the Main() function, which creates an instance of |
|
18 |
# the raptor.Raptor class and calls its methods to perform a build based |
|
19 |
# on command-line parameters, or by explicitly creating a raptor.Raptor |
|
20 |
# instance and calling its methods to set-up and perform a build. |
|
21 |
# |
|
22 |
||
23 |
name = "sbs" # the public name for the raptor build tool |
|
24 |
env = "SBS_HOME" # the environment variable that locates us |
|
25 |
xml = "sbs_init.xml" # the primary initialisation file |
|
26 |
env2 = "HOME" # the environment variable that locates the user |
|
27 |
xml2 = ".sbs_init.xml" # the override initialisation file |
|
28 |
||
29 |
import generic_path |
|
30 |
import os |
|
31 |
import raptor_cache |
|
32 |
import raptor_cli |
|
33 |
import raptor_data |
|
34 |
import raptor_make |
|
5 | 35 |
import raptor_makefile |
3 | 36 |
import raptor_meta |
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
37 |
import raptor_timing |
3 | 38 |
import raptor_utilities |
39 |
import raptor_version |
|
40 |
import raptor_xml |
|
41 |
import filter_list |
|
42 |
import sys |
|
43 |
import types |
|
44 |
import time |
|
45 |
import re |
|
46 |
import traceback |
|
47 |
import pluginbox |
|
48 |
from xml.sax.saxutils import escape |
|
49 |
||
50 |
||
51 |
if not "HOSTPLATFORM" in os.environ or not "HOSTPLATFORM_DIR" in os.environ: |
|
52 |
print "Error: HOSTPLATFORM and HOSTPLATFORM_DIR must be set in the environment (this is usually done automatically by the startup script)." |
|
53 |
sys.exit(1) |
|
54 |
||
55 |
hostplatform = os.environ["HOSTPLATFORM"].split(" ") |
|
56 |
hostplatform_dir = os.environ["HOSTPLATFORM_DIR"] |
|
57 |
||
58 |
# defaults can use EPOCROOT |
|
5 | 59 |
|
3 | 60 |
if "EPOCROOT" in os.environ: |
5 | 61 |
epocroot = os.environ["EPOCROOT"].replace("\\","/") |
3 | 62 |
else: |
63 |
if 'linux' in hostplatform: |
|
64 |
epocroot=os.environ['HOME'] + os.sep + "epocroot" |
|
65 |
os.environ["EPOCROOT"] = epocroot |
|
66 |
else: |
|
67 |
epocroot = "/" |
|
68 |
os.environ["EPOCROOT"] = os.sep |
|
69 |
||
70 |
if "SBS_BUILD_DIR" in os.environ: |
|
71 |
sbs_build_dir = os.environ["SBS_BUILD_DIR"] |
|
72 |
else: |
|
73 |
sbs_build_dir = (epocroot + "/epoc32/build").replace("//","/") |
|
74 |
||
75 |
||
76 |
# only use default XML from the epoc32 tree if it exists |
|
77 |
defaultSystemConfig = "lib/config" |
|
78 |
epoc32UserConfigDir = generic_path.Join(epocroot, "epoc32/sbs_config") |
|
79 |
if epoc32UserConfigDir.isDir(): |
|
80 |
defaultSystemConfig = str(epoc32UserConfigDir) + os.pathsep + defaultSystemConfig |
|
81 |
||
82 |
# parameters that can be overriden by the sbs_init.xml file |
|
83 |
# or by the command-line. |
|
84 |
defaults = { |
|
85 |
"allowCommandLineOverrides" : True, |
|
86 |
"CLI" : "raptor_cli", |
|
87 |
"buildInformation" : generic_path.Path("bld.inf"), |
|
88 |
"defaultConfig" : "default", |
|
89 |
"jobs": 4, |
|
90 |
"keepGoing": False, |
|
91 |
"logFileName" : generic_path.Join(sbs_build_dir,"Makefile.%TIME.log"), |
|
92 |
"makeEngine" : "make", |
|
93 |
"preferBuildInfoToSystemDefinition" : False, |
|
94 |
"pruneDuplicateMakefiles": True, |
|
95 |
"quiet" : False, |
|
96 |
"systemConfig" : defaultSystemConfig, |
|
97 |
"systemDefinition" : generic_path.Path("System_Definition.xml"), |
|
98 |
"systemDefinitionBase" : generic_path.Path("."), |
|
99 |
"systemFLM" : generic_path.Path("lib/flm"), |
|
100 |
"systemPlugins" : generic_path.Path("python/plugins"), |
|
101 |
"topMakefile" : generic_path.Join(sbs_build_dir,"Makefile"), |
|
102 |
"tries": 1, |
|
103 |
"writeSingleMakefile": True, |
|
104 |
"ignoreOsDetection": False, |
|
105 |
"toolcheck": "on", |
|
106 |
"filterList": "filterterminal,filterlogfile" |
|
107 |
} |
|
108 |
||
109 |
||
5 | 110 |
|
111 |
class ModelNode(object): |
|
112 |
""" Represents any node in a a tree of build information |
|
113 |
e.g. a tree of bld.infs, mmps and finally things like resource blocks and string table blocks. |
|
114 |
This is before they are produced into "build" specs. |
|
115 |
""" |
|
116 |
||
117 |
def __init__(self, id, parent = None): |
|
118 |
self.id = id |
|
119 |
self.type = type |
|
120 |
self.specs = [] |
|
121 |
self.deps = [] |
|
122 |
self.children = set() |
|
123 |
self.unfurled = False |
|
124 |
self.parent = parent |
|
125 |
||
126 |
# Allow one to make a set |
|
127 |
def __hash__(self): |
|
128 |
return hash(self.id) |
|
129 |
||
130 |
def __cmp__(self,other): |
|
131 |
return cmp(self.id, other) |
|
3 | 132 |
|
133 |
def __iter__(self): |
|
5 | 134 |
return iter(self.children) |
3 | 135 |
|
136 |
def __getitem__(self,x): |
|
137 |
if isinstance(x, slice): |
|
5 | 138 |
return self.children[x.start:x.stop] |
139 |
return self.children[x] |
|
3 | 140 |
|
141 |
def __setitem__(self,k, v): |
|
5 | 142 |
self.children[k] = v |
3 | 143 |
|
144 |
def __len__(self): |
|
5 | 145 |
return len(self.children) |
3 | 146 |
|
5 | 147 |
def add(self, item): |
148 |
return self.children.add(item) |
|
149 |
||
150 |
def isunfurled(self, c): |
|
151 |
return self.unfurled == False |
|
3 | 152 |
|
5 | 153 |
def unfurl(self, build): |
154 |
"""Find any children of this node by processing it, produces specs""" |
|
155 |
pass |
|
3 | 156 |
|
5 | 157 |
def unfurl_all(self, build): |
158 |
"""Unfurl self and all children - preparatory e.g for realisation""" |
|
159 |
if not self.unfurled: |
|
160 |
self.unfurl(build) |
|
3 | 161 |
|
5 | 162 |
self.realise_exports(build) # permit communication of dependencies between children |
3 | 163 |
|
5 | 164 |
for c in self.children: |
165 |
c.unfurl_all(build) |
|
166 |
||
3 | 167 |
|
5 | 168 |
def realise_exports(self, build): |
169 |
"""Do the things that are needed such that we can fully unfurl all |
|
170 |
sibling nodes. i.e. this step is here to "take care" of the dependencies |
|
171 |
between siblings. |
|
172 |
""" |
|
173 |
pass |
|
174 |
||
175 |
def realise_makefile(self, build, specs): |
|
176 |
makefilename_base = build.topMakefile |
|
177 |
if self.name is not None: |
|
3 | 178 |
makefile = generic_path.Path(str(makefilename_base) + "_" + raptor_utilities.sanitise(self.name)) |
179 |
else: |
|
180 |
makefile = generic_path.Path(str(makefilename_base)) |
|
181 |
||
182 |
# insert the start time into the Makefile name? |
|
183 |
makefile.path = makefile.path.replace("%TIME", build.timestring) |
|
184 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
185 |
build.InfoDiscovery(object_type = "layers", count = 1) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
186 |
build.InfoStartTime(object_type = "layer", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
187 |
key = str(makefile.path)) |
5 | 188 |
makefileset = build.maker.Write(makefile, specs, build.buildUnitsToBuild) |
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
189 |
build.InfoEndTime(object_type = "layer", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
190 |
key = str(makefile.path)) |
5 | 191 |
|
192 |
return makefileset |
|
193 |
||
194 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
195 |
|
5 | 196 |
def realise(self, build): |
197 |
"""Give the spec trees to the make engine and actually |
|
198 |
"build" the product represented by this model node""" |
|
199 |
# Must ensure that all children are unfurled at this point |
|
200 |
self.unfurl_all(build) |
|
201 |
||
202 |
sp = self.specs |
|
203 |
||
204 |
build.AssertBuildOK() |
|
205 |
||
206 |
m = self.realise_makefile(build, sp) |
|
207 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
208 |
build.InfoStartTime(object_type = "layer", task = "build", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
209 |
key = (str(m.directory) + "/" + str(m.filenamebase))) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
210 |
result = build.Make(m) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
211 |
build.InfoEndTime(object_type = "layer", task = "build", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
212 |
key = (str(m.directory) + "/" + str(m.filenamebase))) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
213 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
214 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
215 |
return result |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
216 |
|
5 | 217 |
|
3 | 218 |
|
5 | 219 |
class Project(ModelNode): |
220 |
"""A project or, in symbian-speak, an MMP |
|
221 |
""" |
|
222 |
def __init__(self, filename, parent = None): |
|
223 |
super(Project,self).__init__(filename, parent = parent) |
|
224 |
# Assume that components are specified in mmp files for now |
|
225 |
# One day that tyranny might end. |
|
226 |
self.mmp_name = str(generic_path.Path.Absolute(filename)) |
|
227 |
self.id = self.mmp_name |
|
228 |
self.unfurled = False |
|
229 |
||
230 |
def makefile(self, makefilename_base, engine, named = False): |
|
231 |
"""Makefiles for individual mmps not feasible at the moment""" |
|
232 |
pass # Cannot, currently, "unfurl an mmp" directly but do want |
|
233 |
# to be able to simulate the overall recursive unfurling of a build. |
|
234 |
||
235 |
class Component(ModelNode): |
|
236 |
"""A group of projects or, in symbian-speak, a bld.inf. |
|
237 |
""" |
|
238 |
def __init__(self, filename): |
|
239 |
super(Component,self).__init__(filename) |
|
240 |
# Assume that components are specified in bld.inf files for now |
|
241 |
# One day that tyranny might end. |
|
242 |
self.bldinf = None # Slot for a bldinf object if we spot one later |
|
243 |
self.bldinf_filename = generic_path.Path.Absolute(filename) |
|
244 |
||
245 |
self.id = str(self.bldinf_filename) |
|
246 |
self.exportspecs = [] |
|
247 |
self.depfiles = [] |
|
248 |
self.unfurled = False # We can parse this |
|
249 |
||
250 |
def AddMMP(self, filename): |
|
251 |
self.children.add(Project(filename)) |
|
3 | 252 |
|
253 |
||
5 | 254 |
class Layer(ModelNode): |
255 |
""" Some components that should be built togther |
|
256 |
e.g. a Layer in the system definition. |
|
257 |
""" |
|
258 |
def __init__(self, name, componentlist=[]): |
|
259 |
super(Layer,self).__init__(name) |
|
260 |
self.name = name |
|
261 |
||
262 |
for c in componentlist: |
|
263 |
self.children.add(Component(c)) |
|
264 |
||
265 |
def unfurl(self, build): |
|
266 |
"""Discover the children of this layer. This involves parsing the component MetaData (bld.infs, mmps). |
|
267 |
Takes a raptor object as a parameter (build), together with a list of Configurations. |
|
268 |
||
269 |
We currently have parsers that work on collections of components/bld.infs and that cannot |
|
270 |
parse at a "finer" level. So one can't 'unfurl' an mmp at the moment. |
|
271 |
||
272 |
Returns True if the object was successfully unfurled. |
|
273 |
""" |
|
274 |
||
275 |
# setup all our components |
|
276 |
for c in self.children: |
|
277 |
c.specs = [] |
|
278 |
||
279 |
self.configs = build.buildUnitsToBuild |
|
280 |
||
281 |
||
282 |
metaReader = None |
|
283 |
if len (self.children): |
|
284 |
try: |
|
285 |
# create a MetaReader that is aware of the list of |
|
286 |
# configurations that we are trying to build. |
|
287 |
metaReader = raptor_meta.MetaReader(build, build.buildUnitsToBuild) |
|
288 |
||
289 |
# convert the list of bld.inf files into a specification |
|
290 |
# hierarchy suitable for all the configurations we are using. |
|
291 |
self.specs = list(build.generic_specs) |
|
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
292 |
self.specs.extend(metaReader.ReadBldInfFiles(self.children, doexport = build.doExport, dobuild = not build.doExportOnly)) |
5 | 293 |
|
294 |
except raptor_meta.MetaDataError, e: |
|
295 |
build.Error(e.Text) |
|
296 |
||
297 |
self.unfurled = True |
|
298 |
||
299 |
||
300 |
def meta_realise(self, build): |
|
301 |
"""Generate specs that can be used to "take care of" finding out more |
|
302 |
about this metaunit - i.e. one doesn't want to parse it immediately |
|
303 |
but to create a makefile that will parse it. |
|
304 |
In this case it allows bld.infs to be parsed in parallel by make.""" |
|
305 |
||
3 | 306 |
# insert the start time into the Makefile name? |
307 |
||
5 | 308 |
buildconfig = build.GetConfig("build").GenerateBuildUnits(build.cache) |
309 |
self.configs = build.buildUnitsToBuild |
|
3 | 310 |
|
311 |
# Pass certain CLI flags through to the makefile-generating sbs calls |
|
312 |
cli_options = "" |
|
313 |
||
314 |
if build.debugOutput == True: |
|
315 |
cli_options += " -d" |
|
316 |
||
317 |
if build.ignoreOsDetection == True: |
|
318 |
cli_options += " -i" |
|
319 |
||
320 |
if build.keepGoing == True: |
|
321 |
cli_options += " -k" |
|
322 |
||
323 |
if build.quiet == True: |
|
324 |
cli_options += " -q" |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
325 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
326 |
if build.timing == True: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
327 |
cli_options += " --timing" |
3 | 328 |
|
329 |
||
5 | 330 |
nc = len(self.children) |
331 |
number_blocks = build.jobs |
|
3 | 332 |
block_size = (nc / number_blocks) + 1 |
333 |
component_blocks = [] |
|
334 |
spec_nodes = [] |
|
335 |
||
336 |
b = 0 |
|
5 | 337 |
childlist = list(self.children) |
3 | 338 |
while b < nc: |
5 | 339 |
component_blocks.append(childlist[b:b+block_size]) |
3 | 340 |
b += block_size |
341 |
||
5 | 342 |
while len(component_blocks[-1]) <= 0: |
3 | 343 |
component_blocks.pop() |
5 | 344 |
number_blocks -= 1 |
345 |
||
346 |
build.Info("Parallel Parsing: bld.infs split into %d blocks\n", number_blocks) |
|
347 |
# Cause the binding makefiles to have the toplevel makefile's |
|
348 |
# name. The bindee's have __pp appended. |
|
349 |
tm = build.topMakefile.Absolute() |
|
350 |
binding_makefiles = raptor_makefile.MakefileSet(str(tm.Dir()), build.maker.selectors, makefiles=None, filenamebase=str(tm.File())) |
|
351 |
build.topMakefile = generic_path.Path(str(build.topMakefile) + "_pp") |
|
352 |
||
3 | 353 |
loop_number = 0 |
354 |
for block in component_blocks: |
|
355 |
loop_number += 1 |
|
356 |
specNode = raptor_data.Specification("metadata_" + self.name) |
|
357 |
||
5 | 358 |
componentList = " ".join([str(c.bldinf_filename) for c in block]) |
359 |
||
360 |
||
361 |
configList = " ".join([c.name for c in self.configs if c.name != "build" ]) |
|
3 | 362 |
|
363 |
makefile_path = str(build.topMakefile) + "_" + str(loop_number) |
|
364 |
try: |
|
365 |
os.unlink(makefile_path) # until we have dependencies working properly |
|
366 |
except Exception,e: |
|
367 |
# print "couldn't unlink %s: %s" %(componentMakefileName, str(e)) |
|
368 |
pass |
|
369 |
||
370 |
# add some basic data in a component-wide variant |
|
371 |
var = raptor_data.Variant() |
|
372 |
var.AddOperation(raptor_data.Set("COMPONENT_PATHS", componentList)) |
|
373 |
var.AddOperation(raptor_data.Set("MAKEFILE_PATH", makefile_path)) |
|
374 |
var.AddOperation(raptor_data.Set("CONFIGS", configList)) |
|
375 |
var.AddOperation(raptor_data.Set("CLI_OPTIONS", cli_options)) |
|
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
376 |
|
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
377 |
|
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
378 |
# Allow the flm to skip exports. Note: this parameter |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
379 |
doexport_str = '1' |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
380 |
if not build.doExport: |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
381 |
doexport_str = '' |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
382 |
var.AddOperation(raptor_data.Set("DOEXPORT", doexport_str )) |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
383 |
|
3 | 384 |
# Pass on '-n' (if specified) to the makefile-generating sbs calls |
385 |
if build.noBuild: |
|
386 |
var.AddOperation(raptor_data.Set("NO_BUILD", "1")) |
|
387 |
specNode.AddVariant(var) |
|
388 |
||
389 |
try: |
|
390 |
interface = build.cache.FindNamedInterface("build.makefiles") |
|
391 |
specNode.SetInterface(interface) |
|
392 |
except KeyError: |
|
393 |
build.Error("Can't find flm interface 'build.makefiles' ") |
|
394 |
||
395 |
spec_nodes.append(specNode) |
|
5 | 396 |
binding_makefiles.addInclude(str(makefile_path)+"_all") |
397 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
398 |
build.InfoDiscovery(object_type = "layers", count = 1) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
399 |
build.InfoStartTime(object_type = "layer", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
400 |
key = str(build.topMakefile)) |
5 | 401 |
m = self.realise_makefile(build, spec_nodes) |
402 |
m.close() |
|
403 |
gen_result = build.Make(m) |
|
3 | 404 |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
405 |
build.InfoEndTime(object_type = "layer", task = "parse", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
406 |
key = str(build.topMakefile)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
407 |
build.InfoStartTime(object_type = "layer", task = "build", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
408 |
key = str(build.topMakefile)) |
5 | 409 |
build.Debug("Binding Makefile base name is %s ", binding_makefiles.filenamebase) |
410 |
binding_makefiles.close() |
|
411 |
b = build.Make(binding_makefiles) |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
412 |
build.InfoEndTime(object_type = "layer", task = "build", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
413 |
key = str(build.topMakefile)) |
5 | 414 |
return b |
3 | 415 |
|
416 |
||
5 | 417 |
|
418 |
||
419 |
class BuildCannotProgressException(Exception): |
|
3 | 420 |
pass |
421 |
||
422 |
# raptor module classes |
|
423 |
||
424 |
class Raptor(object): |
|
425 |
"""An instance of a running Raptor program. |
|
426 |
||
427 |
When operated from the command-line there is a single Raptor object |
|
428 |
created by the Main function. When operated by an IDE several Raptor |
|
429 |
objects may be created and operated at the same time.""" |
|
430 |
||
431 |
||
432 |
M_BUILD = 1 |
|
433 |
M_VERSION = 2 |
|
434 |
||
435 |
def __init__(self, home = None): |
|
436 |
||
437 |
self.DefaultSetUp(home) |
|
438 |
||
439 |
||
440 |
def DefaultSetUp(self, home = None): |
|
441 |
"revert to the default set-up state" |
|
442 |
self.errorCode = 0 |
|
443 |
self.skipAll = False |
|
444 |
self.summary = True |
|
445 |
self.out = sys.stdout # Just until filters get started. |
|
446 |
||
447 |
# Create a bootstrap output system. |
|
448 |
self.out = filter_list.FilterList() |
|
449 |
||
450 |
if home == None: |
|
451 |
try: |
|
452 |
home = os.environ[env] |
|
453 |
except KeyError: |
|
454 |
home = os.getcwd() |
|
455 |
||
456 |
# make sure the home directory exists |
|
457 |
self.home = generic_path.Path(home).Absolute() |
|
458 |
||
459 |
if not self.home.isDir(): |
|
460 |
self.Error("%s '%s' is not a directory", env, self.home) |
|
461 |
return |
|
462 |
||
463 |
# the set-up file location. |
|
464 |
# use the override "env2/xml2" if it exists |
|
465 |
# else use the primary "env/xml" if it exists |
|
466 |
# else keep the hard-coded defaults. |
|
467 |
self.raptorXML = self.home.Append(xml) |
|
468 |
||
469 |
if env2 in os.environ: |
|
470 |
sbs_init = generic_path.Join(os.environ[env2], xml2) |
|
471 |
if sbs_init.isFile(): |
|
472 |
self.raptorXML = sbs_init |
|
473 |
||
474 |
# things that can be overridden by the set-up file |
|
475 |
for key, value in defaults.items(): |
|
476 |
self.__dict__[key] = value |
|
477 |
||
478 |
# things to initialise |
|
479 |
self.args = [] |
|
480 |
||
5 | 481 |
self.layers = [] |
482 |
self.orderLayers = False |
|
3 | 483 |
self.commandlineComponents = [] |
484 |
||
485 |
self.systemModel = None |
|
486 |
self.systemDefinitionFile = None |
|
487 |
self.systemDefinitionRequestedLayers = [] |
|
488 |
self.systemDefinitionOrderLayers = False |
|
489 |
||
490 |
self.specGroups = {} |
|
491 |
||
492 |
self.configNames = [] |
|
493 |
self.configsToBuild = set() |
|
494 |
self.makeOptions = [] |
|
495 |
self.maker = None |
|
496 |
self.debugOutput = False |
|
497 |
self.doExportOnly = False |
|
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
498 |
self.doExport = True |
3 | 499 |
self.noBuild = False |
500 |
self.noDependInclude = False |
|
501 |
self.projects = set() |
|
502 |
||
503 |
self.cache = raptor_cache.Cache(self) |
|
504 |
self.override = {env: str(self.home)} |
|
505 |
self.targets = [] |
|
506 |
self.defaultTargets = [] |
|
507 |
||
508 |
self.doCheck = False |
|
509 |
self.doWhat = False |
|
510 |
self.doParallelParsing = False |
|
511 |
self.mission = Raptor.M_BUILD |
|
512 |
||
513 |
# what platform and filesystem are we running on? |
|
514 |
self.filesystem = raptor_utilities.getOSFileSystem() |
|
515 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
516 |
self.timing = False |
3 | 517 |
self.toolset = None |
518 |
||
519 |
self.starttime = time.time() |
|
520 |
self.timestring = time.strftime("%Y-%m-%d-%H-%M-%S") |
|
521 |
||
522 |
self.fatalErrorState = False |
|
523 |
||
524 |
def AddConfigList(self, configPathList): |
|
525 |
# this function converts cmd line option into a list |
|
526 |
# and prepends it to default config. |
|
527 |
self.configPath = generic_path.NormalisePathList(configPathList.split(os.pathsep)) + self.configPath |
|
528 |
return True |
|
529 |
||
530 |
def AddConfigName(self, name): |
|
5 | 531 |
if name == "build": |
532 |
traceback.print_stack((sys.stdout)) |
|
533 |
sys.exit(1) |
|
3 | 534 |
self.configNames.append(name) |
535 |
return True |
|
536 |
||
537 |
def RunQuietly(self, TrueOrFalse): |
|
538 |
self.quiet = TrueOrFalse |
|
539 |
return True |
|
540 |
||
541 |
def SetCheck(self, TrueOrFalse): |
|
542 |
self.doCheck = TrueOrFalse |
|
543 |
return True |
|
544 |
||
545 |
def SetWhat(self, TrueOrFalse): |
|
546 |
self.doWhat = TrueOrFalse |
|
547 |
return True |
|
548 |
||
549 |
def SetEnv(self, name, value): |
|
550 |
self.override[name] = value |
|
551 |
||
552 |
def AddTarget(self, target): |
|
553 |
if self.doCheck or self.doWhat: |
|
554 |
self.Warn("ignoring target %s because --what or --check is specified.\n", target) |
|
555 |
else: |
|
556 |
self.targets.append(target) |
|
557 |
||
558 |
def AddSourceTarget(self, filename): |
|
559 |
# source targets are sanitised and then added as if they were a "normal" makefile target |
|
560 |
# in addition they have a default, empty, top-level target assigned in order that they can |
|
561 |
# be presented to any generated makefile without error |
|
562 |
sourceTarget = generic_path.Path(filename).Absolute() |
|
563 |
sourceTarget = 'SOURCETARGET_' + raptor_utilities.sanitise(str(sourceTarget)) |
|
564 |
self.AddTarget(sourceTarget) |
|
565 |
self.defaultTargets.append(sourceTarget) |
|
566 |
return True |
|
567 |
||
568 |
def SetSysDefFile(self, filename): |
|
569 |
self.systemDefinitionFile = generic_path.Path(filename) |
|
570 |
return True |
|
571 |
||
572 |
def SetSysDefBase(self, path): |
|
573 |
self.systemDefinitionBase = generic_path.Path(path) |
|
574 |
return True |
|
575 |
||
576 |
def AddSysDefLayer(self, layer): |
|
577 |
self.systemDefinitionRequestedLayers.append(layer) |
|
578 |
return True |
|
579 |
||
580 |
def SetSysDefOrderLayers(self, TrueOrFalse): |
|
581 |
self.systemDefinitionOrderLayers = TrueOrFalse |
|
582 |
return True |
|
583 |
||
584 |
def AddBuildInfoFile(self, filename): |
|
585 |
bldinf = generic_path.Path(filename).Absolute() |
|
586 |
self.commandlineComponents.append(bldinf) |
|
587 |
return True |
|
588 |
||
589 |
def SetTopMakefile(self, filename): |
|
590 |
self.topMakefile = generic_path.Path(filename) |
|
591 |
return True |
|
592 |
||
593 |
def SetDebugOutput(self, TrueOrFalse): |
|
594 |
self.debugOutput = TrueOrFalse |
|
595 |
return True |
|
596 |
||
597 |
def SetExportOnly(self, TrueOrFalse): |
|
598 |
self.doExportOnly = TrueOrFalse |
|
21
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
599 |
if not self.doExport: |
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
600 |
self.Error("The --noexport and --export-only options are incompatible - won't to do anything useful") |
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
601 |
return False |
3 | 602 |
return True |
603 |
||
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
604 |
def SetNoExport(self, TrueOrFalse): |
14 | 605 |
self.doExport = not TrueOrFalse |
21
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
606 |
if self.doExportOnly: |
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
607 |
self.Error("The --noexport and --export-only options are incompatible - won't to do anything useful") |
a695dd5e4c37
Make --noexport and --export-only exclusive
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
608 |
return False |
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
609 |
return True |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
610 |
|
3 | 611 |
def SetNoBuild(self, TrueOrFalse): |
612 |
self.noBuild = TrueOrFalse |
|
613 |
return True |
|
614 |
||
615 |
def SetNoDependInclude(self, TrueOrFalse): |
|
616 |
self.noDependInclude = TrueOrFalse |
|
617 |
return True |
|
618 |
||
619 |
def SetKeepGoing(self, TrueOrFalse): |
|
620 |
self.keepGoing = TrueOrFalse |
|
621 |
return True |
|
622 |
||
623 |
def SetLogFileName(self, logfile): |
|
624 |
if logfile == "-": |
|
625 |
self.logFileName = None # stdout |
|
626 |
else: |
|
627 |
self.logFileName = generic_path.Path(logfile) |
|
628 |
return True |
|
629 |
||
630 |
def SetMakeEngine(self, makeEngine): |
|
631 |
self.makeEngine = makeEngine |
|
632 |
return True |
|
633 |
||
634 |
def AddMakeOption(self, makeOption): |
|
635 |
self.makeOptions.append(makeOption) |
|
636 |
return True |
|
637 |
||
638 |
def SetJobs(self, numberOfJobs): |
|
639 |
try: |
|
640 |
self.jobs = int(numberOfJobs) |
|
641 |
except ValueError: |
|
642 |
self.jobs = 0 |
|
643 |
||
644 |
if self.jobs < 1: |
|
645 |
self.Warn("The number of jobs (%s) must be a positive integer\n", numberOfJobs) |
|
646 |
self.jobs = 1 |
|
647 |
return False |
|
648 |
return True |
|
649 |
||
650 |
def SetTries(self, numberOfTries): |
|
651 |
try: |
|
652 |
self.tries = int(numberOfTries) |
|
653 |
except ValueError: |
|
654 |
self.tries = 0 |
|
655 |
||
656 |
if self.tries < 1: |
|
657 |
self.Warn("The number of tries (%s) must be a positive integer\n", numberOfTries) |
|
658 |
self.tries = 1 |
|
659 |
return False |
|
660 |
return True |
|
661 |
||
662 |
def SetToolCheck(self, type): |
|
663 |
type = type.lower() |
|
664 |
toolcheck_types= [ "forced", "on", "off" ] |
|
665 |
if type in toolcheck_types: |
|
666 |
self.toolcheck=type |
|
667 |
else: |
|
668 |
self.Warn("toolcheck option must be one of: %s" % toolcheck_types) |
|
669 |
return False |
|
670 |
||
671 |
return True |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
672 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
673 |
def SetTiming(self, TrueOrFalse): |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
674 |
self.timing = TrueOrFalse |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
675 |
return True |
3 | 676 |
|
677 |
def SetParallelParsing(self, type): |
|
678 |
type = type.lower() |
|
679 |
if type == "on": |
|
680 |
self.doParallelParsing = True |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
681 |
elif type == "slave": |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
682 |
self.isParallelParsingSlave = True |
3 | 683 |
elif type == "off": |
684 |
self.doParallelParsing = False |
|
685 |
else: |
|
686 |
self.Warn(" parallel parsing option must be either 'on' or 'off' (was %s)" % type) |
|
687 |
return False |
|
688 |
||
689 |
return True |
|
690 |
||
691 |
def AddProject(self, projectName): |
|
692 |
self.projects.add(projectName.lower()) |
|
693 |
return True |
|
694 |
||
695 |
def FilterList(self, value): |
|
696 |
self.filterList = value |
|
697 |
return True |
|
698 |
||
699 |
def IgnoreOsDetection(self, value): |
|
700 |
self.ignoreOsDetection = value |
|
701 |
return True |
|
702 |
||
703 |
def PrintVersion(self,dummy): |
|
704 |
global name |
|
5 | 705 |
print name, "version", raptor_version.fullversion() |
3 | 706 |
self.mission = Raptor.M_VERSION |
707 |
return False |
|
708 |
||
709 |
# worker methods |
|
710 |
||
711 |
def Introduction(self): |
|
712 |
"""Print a header of useful information about Raptor""" |
|
713 |
||
5 | 714 |
self.Info("%s: version %s\n", name, raptor_version.fullversion()) |
3 | 715 |
|
716 |
self.Info("%s %s", env, str(self.home)) |
|
717 |
self.Info("Set-up %s", str(self.raptorXML)) |
|
718 |
self.Info("Command-line-arguments %s", " ".join(self.args)) |
|
719 |
self.Info("Current working directory %s", os.getcwd()) |
|
720 |
||
721 |
# the inherited environment |
|
722 |
for e, value in os.environ.items(): |
|
5 | 723 |
self.Info("Environment %s=%s", e, value.replace("]]>", "]]>")) |
3 | 724 |
|
725 |
# and some general debug stuff |
|
726 |
self.Debug("Platform %s", "-".join(hostplatform)) |
|
727 |
self.Debug("Filesystem %s", self.filesystem) |
|
728 |
self.Debug("Python %d.%d.%d", *sys.version_info[:3]) |
|
729 |
self.Debug("Command-line-parser %s", self.CLI) |
|
730 |
||
731 |
for e,value in self.override.items(): |
|
732 |
self.Debug("Override %s = %s", e, value) |
|
733 |
||
734 |
for t in self.targets: |
|
735 |
self.Debug("Target %s", t) |
|
736 |
||
737 |
||
738 |
def ConfigFile(self): |
|
739 |
if not self.raptorXML.isFile(): |
|
740 |
return |
|
741 |
||
742 |
self.cache.Load(self.raptorXML) |
|
743 |
||
744 |
# find the 'defaults.raptor' variant and extract the values |
|
745 |
try: |
|
746 |
var = self.cache.FindNamedVariant("defaults.init") |
|
747 |
evaluator = self.GetEvaluator( None, raptor_data.BuildUnit(var.name,[var]) ) |
|
748 |
||
749 |
for key, value in defaults.items(): |
|
750 |
newValue = evaluator.Resolve(key) |
|
751 |
||
752 |
if newValue != None: |
|
753 |
# got a string for the value |
|
754 |
if type(value) == types.BooleanType: |
|
755 |
newValue = (newValue.lower() != "false") |
|
756 |
elif type(value) == types.IntType: |
|
757 |
newValue = int(newValue) |
|
758 |
elif isinstance(value, generic_path.Path): |
|
759 |
newValue = generic_path.Path(newValue) |
|
760 |
||
761 |
self.__dict__[key] = newValue |
|
762 |
||
763 |
except KeyError: |
|
764 |
# it is OK to not have this but useful to say it wasn't there |
|
765 |
self.Info("No 'defaults.init' configuration found in " + str(self.raptorXML)) |
|
766 |
||
767 |
||
768 |
def CommandLine(self, args): |
|
769 |
# remember the arguments for the log |
|
770 |
self.args = args |
|
771 |
||
772 |
# assuming self.CLI = "raptor_cli" |
|
773 |
more_to_do = raptor_cli.GetArgs(self, args) |
|
774 |
||
775 |
# resolve inter-argument dependencies. |
|
776 |
# --what or --check implies the WHAT target and FilterWhat Filter |
|
777 |
if self.doWhat or self.doCheck: |
|
778 |
self.targets = ["WHAT"] |
|
779 |
self.filterList = "filterwhat" |
|
780 |
||
781 |
else: |
|
782 |
# 1. CLEAN/CLEANEXPORT/REALLYCLEAN needs the FilterClean filter. |
|
783 |
# 2. Targets that clean should not be combined with other targets. |
|
784 |
||
785 |
targets = [x.lower() for x in self.targets] |
|
786 |
||
787 |
CL = "clean" |
|
788 |
CE = "cleanexport" |
|
789 |
RC = "reallyclean" |
|
790 |
||
791 |
is_clean = 0 |
|
792 |
is_suspicious_clean = 0 |
|
793 |
||
794 |
if CL in targets and CE in targets: |
|
795 |
is_clean = 1 |
|
796 |
if len(targets) > 2: |
|
797 |
is_suspicious_clean = 1 |
|
798 |
elif RC in targets or CL in targets or CE in targets: |
|
799 |
is_clean = 1 |
|
800 |
if len(targets) > 1: |
|
801 |
is_suspicious_clean = 1 |
|
802 |
||
803 |
if is_clean: |
|
804 |
self.filterList += ",filterclean" |
|
805 |
if is_suspicious_clean: |
|
806 |
self.Warn('CLEAN, CLEANEXPORT and a REALLYCLEAN should not be combined with other targets as the result is unpredictable.') |
|
807 |
||
808 |
if not more_to_do: |
|
809 |
self.skipAll = True # nothing else to do |
|
810 |
||
811 |
def ProcessConfig(self): |
|
812 |
# this function will perform additional processing of config |
|
813 |
||
814 |
# create list of generic paths |
|
815 |
self.configPath = generic_path.NormalisePathList(self.systemConfig.split(os.pathsep)) |
|
816 |
||
817 |
def LoadCache(self): |
|
818 |
def mkAbsolute(aGenericPath): |
|
819 |
""" internal function to make a generic_path.Path |
|
820 |
absolute if required""" |
|
821 |
if not aGenericPath.isAbsolute(): |
|
822 |
return self.home.Append(aGenericPath) |
|
823 |
else: |
|
824 |
return aGenericPath |
|
825 |
||
826 |
# make generic paths absolute (if required) |
|
827 |
self.configPath = map(mkAbsolute, self.configPath) |
|
828 |
self.cache.Load(self.configPath) |
|
829 |
||
830 |
if not self.systemFLM.isAbsolute(): |
|
831 |
self.systemFLM = self.home.Append(self.systemFLM) |
|
832 |
||
833 |
self.cache.Load(self.systemFLM) |
|
834 |
||
835 |
def GetConfig(self, configname): |
|
836 |
names = configname.split(".") |
|
837 |
||
838 |
cache = self.cache |
|
839 |
||
840 |
base = names[0] |
|
841 |
mods = names[1:] |
|
842 |
||
843 |
if base in cache.groups: |
|
844 |
x = cache.FindNamedGroup(base) |
|
845 |
elif base in cache.aliases: |
|
846 |
x = cache.FindNamedAlias(base) |
|
847 |
elif base in cache.variants: |
|
848 |
x = cache.FindNamedVariant(base) |
|
849 |
else: |
|
850 |
raise Exception("Unknown build configuration '%s'" % configname) |
|
851 |
||
852 |
x.ClearModifiers() |
|
853 |
||
854 |
||
855 |
try: |
|
856 |
for m in mods: x.AddModifier( cache.FindNamedVariant(m) ) |
|
857 |
except KeyError: |
|
858 |
raise Exception("Unknown build configuration '%s'" % configname) |
|
859 |
return x |
|
860 |
||
861 |
def GetBuildUnitsToBuild(self, configNames): |
|
862 |
"""Return a list of the configuration objects that correspond to the |
|
863 |
list of configuration names in the configNames parameter. |
|
864 |
||
865 |
raptor.GetBuildUnitsToBuild(["armv5", "winscw"]) |
|
866 |
>>> [ config1, config2, ... , configN ] |
|
867 |
""" |
|
868 |
||
869 |
if len(configNames) == 0: |
|
870 |
# use default config |
|
871 |
if len(self.defaultConfig) == 0: |
|
872 |
self.Warn("No default configuration name") |
|
873 |
else: |
|
874 |
configNames.append(self.defaultConfig) |
|
875 |
||
876 |
buildUnitsToBuild = set() |
|
877 |
||
878 |
||
879 |
for c in set(configNames): |
|
5 | 880 |
self.Debug("BuildUnit: %s", c) |
3 | 881 |
try: |
882 |
x = self.GetConfig(c) |
|
5 | 883 |
gb = x.GenerateBuildUnits(self.cache) |
884 |
buildUnitsToBuild.update( gb ) |
|
3 | 885 |
except Exception, e: |
886 |
self.FatalError(str(e)) |
|
887 |
||
888 |
for b in buildUnitsToBuild: |
|
889 |
self.Info("Buildable configuration '%s'", b.name) |
|
890 |
||
891 |
if len(buildUnitsToBuild) == 0: |
|
892 |
self.Error("No build configurations given") |
|
893 |
||
894 |
return buildUnitsToBuild |
|
895 |
||
896 |
def CheckToolset(self, evaluator, configname): |
|
897 |
"""Check the toolset for a particular config, allow other objects access |
|
898 |
to the toolset for this build (e.g. the raptor_make class).""" |
|
899 |
if self.toolset is None: |
|
900 |
if self.toolcheck == 'on': |
|
901 |
self.toolset = raptor_data.ToolSet(log=self) |
|
902 |
elif self.toolcheck == 'forced' : |
|
903 |
self.toolset = raptor_data.ToolSet(log=self, forced=True) |
|
904 |
else: |
|
905 |
return True |
|
906 |
||
907 |
return self.toolset.check(evaluator, configname) |
|
908 |
||
909 |
||
910 |
def CheckConfigs(self, configs): |
|
911 |
""" Tool checking for all the buildable configurations |
|
912 |
NB. We are allowed to use different tool versions for different |
|
913 |
configurations.""" |
|
914 |
||
915 |
tools_ok = True |
|
916 |
for b in configs: |
|
917 |
self.Debug("Tool check for %s", b.name) |
|
918 |
evaluator = self.GetEvaluator(None, b, gathertools=True) |
|
919 |
tools_ok = tools_ok and self.CheckToolset(evaluator, b.name) |
|
920 |
||
921 |
return tools_ok |
|
922 |
||
923 |
||
924 |
||
925 |
def GatherSysModelLayers(self, systemModel, systemDefinitionRequestedLayers): |
|
926 |
"""Return a list of lists of components to be built. |
|
927 |
||
928 |
components = GatherSysModelLayers(self, configurations) |
|
929 |
>>> set("abc/group/bld.inf","def/group/bld.inf, ....") |
|
930 |
""" |
|
931 |
layersToBuild = [] |
|
932 |
||
933 |
if systemModel: |
|
934 |
# We either process all available layers in the system model, or a subset of |
|
935 |
# layers specified on the command line. In both cases, the processing is the same, |
|
936 |
# and can be subject to ordering if explicitly requested. |
|
937 |
systemModel.DumpInfo() |
|
938 |
||
939 |
if systemDefinitionRequestedLayers: |
|
940 |
layersToProcess = systemDefinitionRequestedLayers |
|
941 |
else: |
|
942 |
layersToProcess = systemModel.GetLayerNames() |
|
943 |
||
944 |
for layer in layersToProcess: |
|
945 |
systemModel.DumpLayerInfo(layer) |
|
946 |
||
947 |
if systemModel.IsLayerBuildable(layer): |
|
5 | 948 |
layersToBuild.append(Layer(layer, |
3 | 949 |
systemModel.GetLayerComponents(layer))) |
950 |
||
951 |
return layersToBuild |
|
952 |
||
953 |
||
5 | 954 |
# Add bld.inf or system definition xml to command line layers (depending on preference) |
3 | 955 |
def FindSysDefIn(self, aDir = None): |
956 |
# Find a system definition file |
|
957 |
||
958 |
if aDir is None: |
|
959 |
dir = generic_path.CurrentDir() |
|
960 |
else: |
|
961 |
dir = generic_path.Path(aDir) |
|
962 |
||
963 |
sysDef = dir.Append(self.systemDefinition) |
|
964 |
if not sysDef.isFile(): |
|
965 |
return None |
|
966 |
||
967 |
return sysDef |
|
968 |
||
969 |
||
970 |
def FindComponentIn(self, aDir = None): |
|
971 |
# look for a bld.inf |
|
972 |
||
973 |
if aDir is None: |
|
974 |
dir = generic_path.CurrentDir() |
|
975 |
else: |
|
976 |
dir = generic_path.Path(aDir) |
|
977 |
||
978 |
bldInf = dir.Append(self.buildInformation) |
|
979 |
componentgroup = [] |
|
980 |
||
981 |
if bldInf.isFile(): |
|
982 |
return bldInf |
|
983 |
||
984 |
return None |
|
985 |
||
986 |
def GenerateGenericSpecs(self, configsToBuild): |
|
987 |
# if a Configuration has any config-wide interfaces |
|
988 |
# then add a Specification node to call each of them. |
|
989 |
configWide = {} |
|
990 |
genericSpecs = [] |
|
991 |
for c in configsToBuild: |
|
992 |
evaluator = self.GetEvaluator(None, c) |
|
993 |
iface = evaluator.Get("INTERFACE.config") |
|
994 |
if iface: |
|
995 |
if iface in configWide: |
|
996 |
# seen it already, so reuse the node |
|
997 |
filter = configWide[iface] |
|
998 |
filter.AddConfigCondition(c.name) |
|
999 |
else: |
|
1000 |
# create a new node |
|
5 | 1001 |
filter = raptor_data.Filter(name = "config_wide") |
3 | 1002 |
filter.AddConfigCondition(c.name) |
1003 |
for i in iface.split(): |
|
1004 |
spec = raptor_data.Specification(i) |
|
1005 |
spec.SetInterface(i) |
|
1006 |
filter.AddChildSpecification(spec) |
|
1007 |
# remember it, use it |
|
1008 |
configWide[iface] = filter |
|
1009 |
genericSpecs.append(filter) |
|
1010 |
||
1011 |
return genericSpecs |
|
1012 |
||
1013 |
||
1014 |
def GetEvaluator(self, specification, configuration, gathertools=False): |
|
1015 |
""" this will perform some caching later """ |
|
5 | 1016 |
return raptor_data.Evaluator(specification, configuration, gathertools=gathertools, cache = self.cache) |
3 | 1017 |
|
1018 |
||
5 | 1019 |
def Make(self, makefileset): |
1020 |
if not self.noBuild and makefileset is not None: |
|
1021 |
if self.maker.Make(makefileset): |
|
1022 |
self.Info("The make-engine exited successfully.") |
|
1023 |
return True |
|
1024 |
else: |
|
1025 |
self.Error("The make-engine exited with errors.") |
|
1026 |
return False |
|
1027 |
else: |
|
1028 |
self.Info("No build performed") |
|
3 | 1029 |
|
1030 |
||
1031 |
||
1032 |
def Report(self): |
|
1033 |
if self.quiet: |
|
1034 |
return |
|
1035 |
||
1036 |
self.endtime = time.time() |
|
1037 |
self.runtime = int(0.5 + self.endtime - self.starttime) |
|
1038 |
self.raptor_params.runtime = self.runtime |
|
1039 |
self.Info("Run time %s seconds" % self.runtime) |
|
1040 |
||
1041 |
def AssertBuildOK(self): |
|
5 | 1042 |
"""Raise a BuildCannotProgressException if no further processing is required |
3 | 1043 |
""" |
1044 |
if self.Skip(): |
|
5 | 1045 |
raise BuildCannotProgressException("") |
3 | 1046 |
|
1047 |
return True |
|
1048 |
||
1049 |
def Skip(self): |
|
1050 |
"""Indicate not to perform operation if: |
|
1051 |
fatalErrorState is set |
|
1052 |
an error code is set but we're not in keepgoing mode |
|
1053 |
""" |
|
1054 |
return self.fatalErrorState or ((self.errorCode != 0) and (not self.keepGoing)) |
|
1055 |
||
1056 |
||
1057 |
# log file open/close |
|
1058 |
||
1059 |
def OpenLog(self): |
|
1060 |
"""Open a log file for the various I/O methods to write to.""" |
|
1061 |
||
1062 |
try: |
|
1063 |
# Find all the raptor plugins and put them into a pluginbox. |
|
1064 |
if not self.systemPlugins.isAbsolute(): |
|
1065 |
self.systemPlugins = self.home.Append(self.systemPlugins) |
|
1066 |
||
1067 |
self.pbox = pluginbox.PluginBox(str(self.systemPlugins)) |
|
1068 |
||
1069 |
self.raptor_params = BuildStats(self) |
|
1070 |
||
1071 |
# Open the requested plugins using the pluginbox |
|
1072 |
self.out.open(self.raptor_params, self.filterList.split(','), self.pbox) |
|
1073 |
||
1074 |
# log header |
|
1075 |
self.out.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n") |
|
1076 |
||
1077 |
namespace = "http://symbian.com/xml/build/log" |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1078 |
progress_namespace = "http://symbian.com/xml/build/log/progress" |
3 | 1079 |
schema = "http://symbian.com/xml/build/log/1_0.xsd" |
1080 |
||
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1081 |
self.out.write("<buildlog sbs_version=\"%s\" xmlns=\"%s\" xmlns:progress=\"%s\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"%s %s\">\n" |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1082 |
% (raptor_version.fullversion(), namespace, progress_namespace, namespace, schema)) |
3 | 1083 |
self.logOpen = True |
1084 |
except Exception,e: |
|
1085 |
self.out = sys.stdout # make sure that we can actually get errors out. |
|
1086 |
self.logOpen = False |
|
9 | 1087 |
self.FatalError("Unable to open the output logs: %s" % str(e)) |
3 | 1088 |
|
1089 |
def CloseLog(self): |
|
1090 |
if self.logOpen: |
|
1091 |
self.out.summary() |
|
1092 |
self.out.write("</buildlog>\n") |
|
1093 |
||
1094 |
if not self.out.close(): |
|
1095 |
self.errorCode = 1 |
|
1096 |
||
1097 |
||
1098 |
def Cleanup(self): |
|
1099 |
# ensure that the toolset cache is flushed. |
|
1100 |
if self.toolset is not None: |
|
1101 |
self.toolset.write() |
|
1102 |
||
1103 |
# I/O methods |
|
1104 |
||
1105 |
@staticmethod |
|
1106 |
def attributeString(dictionary): |
|
1107 |
"turn a dictionary into a string of XML attributes" |
|
1108 |
atts = "" |
|
1109 |
for a,v in dictionary.items(): |
|
1110 |
atts += " " + a + "='" + v + "'" |
|
1111 |
return atts |
|
1112 |
||
1113 |
def Info(self, format, *extras, **attributes): |
|
1114 |
"""Send an information message to the configured channel |
|
1115 |
(XML control characters will be escaped) |
|
1116 |
""" |
|
1117 |
self.out.write("<info" + self.attributeString(attributes) + ">" + |
|
1118 |
escape(format % extras) + "</info>\n") |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1119 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1120 |
def InfoDiscovery(self, object_type, count): |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1121 |
if self.timing: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1122 |
try: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1123 |
self.out.write(raptor_timing.Timing.discovery_string(object_type = object_type, |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1124 |
count = count)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1125 |
except Exception, exception: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1126 |
Error(exception.Text, function = "InfoDiscoveryTime") |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1127 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1128 |
def InfoStartTime(self, object_type, task, key): |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1129 |
if self.timing: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1130 |
try: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1131 |
self.out.write(raptor_timing.Timing.start_string(object_type = object_type, |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1132 |
task = task, key = key)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1133 |
except Exception, exception: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1134 |
Error(exception.Text, function = "InfoStartTime") |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1135 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1136 |
def InfoEndTime(self, object_type, task, key): |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1137 |
if self.timing: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1138 |
try: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1139 |
self.out.write(raptor_timing.Timing.end_string(object_type = object_type, |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1140 |
task = task, key = key)) |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1141 |
except Exception, exception: |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
21
diff
changeset
|
1142 |
Error(exception.Text, function = "InfoEndTime") |
3 | 1143 |
|
1144 |
def Debug(self, format, *extras, **attributes): |
|
1145 |
"Send a debugging message to the configured channel" |
|
1146 |
||
1147 |
# the debug text is out of our control so wrap it in a CDATA |
|
1148 |
# in case it contains characters special to XML... like <> |
|
1149 |
if self.debugOutput: |
|
1150 |
self.out.write("<debug" + self.attributeString(attributes) + ">" + |
|
1151 |
"><![CDATA[\n" + (format % extras) + "\n]]></debug>\n") |
|
1152 |
||
1153 |
def Warn(self, format, *extras, **attributes): |
|
1154 |
"""Send a warning message to the configured channel |
|
1155 |
(XML control characters will be escaped) |
|
1156 |
""" |
|
1157 |
self.out.write("<warning" + self.attributeString(attributes) + ">" + |
|
1158 |
escape(format % extras) + "</warning>\n") |
|
1159 |
||
1160 |
def FatalError(self, format, *extras, **attributes): |
|
1161 |
"""Send an error message to the configured channel. This implies such a serious |
|
1162 |
error that the entire build must be shut down asap whilst still finishing off |
|
1163 |
correctly whatever housekeeping is possible e.g. producing error reports. |
|
1164 |
Remains quiet if the raptor object is already in a fatal state since there |
|
1165 |
further errors are probably triggered by the first. |
|
1166 |
""" |
|
1167 |
if not self.fatalErrorState: |
|
1168 |
self.out.write("<error" + self.attributeString(attributes) + ">" + |
|
1169 |
(format % extras) + "</error>\n") |
|
1170 |
self.errorCode = 1 |
|
1171 |
self.fatalErrorState = True |
|
1172 |
||
1173 |
def Error(self, format, *extras, **attributes): |
|
1174 |
"""Send an error message to the configured channel |
|
1175 |
(XML control characters will be escaped) |
|
1176 |
""" |
|
1177 |
self.out.write("<error" + self.attributeString(attributes) + ">" + |
|
1178 |
escape(format % extras) + "</error>\n") |
|
1179 |
self.errorCode = 1 |
|
1180 |
||
1181 |
||
1182 |
def PrintXML(self, format, *extras): |
|
1183 |
"Print to configured channel (no newline is added) (assumes valid xml)" |
|
1184 |
if format: |
|
1185 |
self.out.write(format % extras) |
|
1186 |
||
5 | 1187 |
def GetLayersFromCLI(self): |
1188 |
"""Returns the list of layers as specified by the |
|
3 | 1189 |
commandline interface to Raptor e.g. parameters |
1190 |
or the current directory""" |
|
5 | 1191 |
layers=[] |
3 | 1192 |
# Look for bld.infs or sysdefs in the current dir if none were specified |
1193 |
if self.systemDefinitionFile == None and len(self.commandlineComponents) == 0: |
|
1194 |
if not self.preferBuildInfoToSystemDefinition: |
|
1195 |
cwd = os.getcwd() |
|
1196 |
self.systemDefinitionFile = self.FindSysDefIn(cwd) |
|
1197 |
if self.systemDefinitionFile == None: |
|
1198 |
aComponent = self.FindComponentIn(cwd) |
|
1199 |
if aComponent: |
|
5 | 1200 |
layers.append(Layer('default',[aComponent])) |
3 | 1201 |
else: |
1202 |
aComponent = self.FindComponentIn(cwd) |
|
1203 |
if aComponent is None: |
|
1204 |
self.systemDefinitionFile = self.FindSysDefIn(cwd) |
|
1205 |
else: |
|
5 | 1206 |
layers.append(Layer('default',[aComponent])) |
3 | 1207 |
|
5 | 1208 |
if len(layers) <= 0 and self.systemDefinitionFile == None: |
3 | 1209 |
self.Warn("No default bld.inf or system definition file found in current directory (%s)", cwd) |
1210 |
||
1211 |
# If we now have a System Definition to parse then get the layers of components |
|
1212 |
if self.systemDefinitionFile != None: |
|
1213 |
systemModel = raptor_xml.SystemModel(self, self.systemDefinitionFile, self.systemDefinitionBase) |
|
5 | 1214 |
layers = self.GatherSysModelLayers(systemModel, self.systemDefinitionRequestedLayers) |
3 | 1215 |
|
1216 |
# Now get components specified on a commandline - build them after any |
|
1217 |
# layers in the system definition. |
|
1218 |
if len(self.commandlineComponents) > 0: |
|
5 | 1219 |
layers.append(Layer('commandline',self.commandlineComponents)) |
3 | 1220 |
|
1221 |
# If we aren't building components in order then flatten down |
|
1222 |
# the groups |
|
1223 |
if not self.systemDefinitionOrderLayers: |
|
1224 |
# Flatten the layers into one group of components if |
|
1225 |
# we are not required to build them in order. |
|
5 | 1226 |
newcg = Layer("all") |
1227 |
for cg in layers: |
|
1228 |
for c in cg: |
|
1229 |
newcg.add(c) |
|
1230 |
layers = [newcg] |
|
3 | 1231 |
|
5 | 1232 |
return layers |
3 | 1233 |
|
1234 |
def Build(self): |
|
1235 |
||
1236 |
if self.mission != Raptor.M_BUILD: # help or version requested instead. |
|
1237 |
return 0 |
|
1238 |
||
1239 |
# open the log file |
|
1240 |
self.OpenLog() |
|
1241 |
||
1242 |
||
1243 |
try: |
|
1244 |
# show the command and platform info |
|
1245 |
self.AssertBuildOK() |
|
1246 |
self.Introduction() |
|
1247 |
# establish an object cache |
|
1248 |
self.AssertBuildOK() |
|
1249 |
||
1250 |
self.LoadCache() |
|
1251 |
||
1252 |
# find out what configurations to build |
|
1253 |
self.AssertBuildOK() |
|
1254 |
buildUnitsToBuild = self.GetBuildUnitsToBuild(self.configNames) |
|
1255 |
||
5 | 1256 |
self.buildUnitsToBuild = buildUnitsToBuild |
1257 |
||
3 | 1258 |
# find out what components to build, and in what way |
5 | 1259 |
layers = [] |
3 | 1260 |
|
1261 |
self.AssertBuildOK() |
|
1262 |
if len(buildUnitsToBuild) >= 0: |
|
5 | 1263 |
layers = self.GetLayersFromCLI() |
3 | 1264 |
|
5 | 1265 |
componentCount = reduce(lambda x,y : x + y, [len(cg) for cg in layers]) |
3 | 1266 |
|
1267 |
if not componentCount > 0: |
|
5 | 1268 |
raise BuildCannotProgressException("No components to build.") |
3 | 1269 |
|
1270 |
# check the configurations (tools versions) |
|
1271 |
self.AssertBuildOK() |
|
1272 |
||
1273 |
if self.toolcheck != 'off': |
|
1274 |
self.CheckConfigs(buildUnitsToBuild) |
|
1275 |
else: |
|
1276 |
self.Info(" Not Checking Tool Versions") |
|
1277 |
||
1278 |
self.AssertBuildOK() |
|
1279 |
||
5 | 1280 |
# Setup a make engine. |
1281 |
if not self.maker: |
|
1282 |
self.maker = raptor_make.MakeEngine(self) |
|
1283 |
if self.maker == None: |
|
1284 |
self.Error("No make engine present") |
|
3 | 1285 |
|
5 | 1286 |
self.AssertBuildOK() |
1287 |
||
1288 |
# if self.doParallelParsing and not (len(layers) == 1 and len(layers[0]) == 1): |
|
3 | 1289 |
if self.doParallelParsing: |
1290 |
# Create a Makefile to parse components in parallel and build them |
|
5 | 1291 |
for l in layers: |
1292 |
l.meta_realise(self) |
|
3 | 1293 |
else: |
1294 |
# Parse components serially, creating one set of makefiles |
|
1295 |
# create non-component specs |
|
5 | 1296 |
self.generic_specs = self.GenerateGenericSpecs(buildUnitsToBuild) |
3 | 1297 |
|
1298 |
self.AssertBuildOK() |
|
5 | 1299 |
for l in layers: |
3 | 1300 |
# create specs for a specific group of components |
5 | 1301 |
l.realise(self) |
3 | 1302 |
|
5 | 1303 |
except BuildCannotProgressException,b: |
3 | 1304 |
if str(b) != "": |
1305 |
self.Info(str(b)) |
|
1306 |
||
1307 |
# final report |
|
1308 |
if not self.fatalErrorState: |
|
1309 |
self.Report() |
|
1310 |
||
1311 |
self.Cleanup() |
|
1312 |
||
1313 |
# close the log file |
|
1314 |
self.CloseLog() |
|
1315 |
||
1316 |
return self.errorCode |
|
1317 |
||
1318 |
@classmethod |
|
1319 |
def CreateCommandlineBuild(cls, argv): |
|
1320 |
""" Perform a 'typical' build. """ |
|
1321 |
# configure the framework |
|
1322 |
||
1323 |
build = Raptor() |
|
1324 |
build.AssertBuildOK() |
|
1325 |
build.ConfigFile() |
|
1326 |
build.ProcessConfig() |
|
1327 |
build.CommandLine(argv) |
|
1328 |
||
1329 |
return build |
|
1330 |
||
1331 |
||
1332 |
||
1333 |
# Class for passing constricted parameters to filters |
|
1334 |
class BuildStats(object): |
|
1335 |
||
1336 |
def __init__(self, raptor_instance): |
|
1337 |
self.logFileName = raptor_instance.logFileName |
|
1338 |
self.quiet = raptor_instance.quiet |
|
1339 |
self.doCheck = raptor_instance.doCheck |
|
1340 |
self.doWhat = raptor_instance.doWhat |
|
1341 |
self.platform = hostplatform |
|
1342 |
self.skipAll = raptor_instance.fatalErrorState |
|
1343 |
self.timestring = raptor_instance.timestring |
|
1344 |
self.targets = raptor_instance.targets |
|
1345 |
self.runtime = 0 |
|
1346 |
self.name = name |
|
1347 |
||
1348 |
||
1349 |
# raptor module functions |
|
1350 |
||
1351 |
def Main(argv): |
|
1352 |
"""The main entry point for Raptor. |
|
1353 |
||
1354 |
argv is a list of command-line parameters, |
|
1355 |
NOT including the name of the calling script. |
|
1356 |
||
1357 |
The return value is zero for success and non-zero for failure.""" |
|
1358 |
||
1359 |
DisplayBanner() |
|
1360 |
||
1361 |
# object which represents a build |
|
1362 |
b = Raptor.CreateCommandlineBuild(argv) |
|
1363 |
||
5 | 1364 |
return b.Build() |
3 | 1365 |
|
1366 |
||
1367 |
def DisplayBanner(): |
|
1368 |
"""Stuff that needs printing out for every command.""" |
|
1369 |
pass |
|
1370 |
||
1371 |
||
1372 |
||
5 | 1373 |
|
3 | 1374 |
# end of the raptor module |