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