author | timothy.murphy@nokia.com |
Tue, 13 Apr 2010 13:30:12 +0100 | |
branch | fix |
changeset 482 | f3b5772862f7 |
parent 400 | 554cc189839f |
child 498 | 564986768b79 |
permissions | -rw-r--r-- |
3 | 1 |
# |
196 | 2 |
# Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | 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_data module |
|
16 |
# This module contains the classes that make up the Raptor Data Model. |
|
17 |
# |
|
18 |
||
19 |
import copy |
|
20 |
import generic_path |
|
21 |
import os |
|
22 |
import hashlib |
|
23 |
import raptor_utilities |
|
24 |
import re |
|
25 |
import types |
|
26 |
import sys |
|
27 |
import subprocess |
|
28 |
from tempfile import gettempdir |
|
29 |
from time import time, clock |
|
5 | 30 |
import traceback |
31 |
import raptor_cache |
|
3 | 32 |
|
33 |
||
5 | 34 |
class MissingInterfaceError(Exception): |
35 |
def __init__(self, s): |
|
36 |
Exception.__init__(self,s) |
|
3 | 37 |
|
38 |
# What host platforms we recognise |
|
39 |
# This allows us to tie some variants to one host platform and some to another |
|
40 |
class HostPlatform(object): |
|
41 |
""" List the host platforms on which we can build. Allow configuration |
|
42 |
files to specify different information based on that. |
|
43 |
""" |
|
44 |
hostplatforms = ["win32", "win64", "linux2"] |
|
45 |
hostplatform = sys.platform |
|
46 |
||
47 |
@classmethod |
|
48 |
def IsKnown(cls, platformpattern): |
|
49 |
"Does the parameter match the name of a known platform " |
|
50 |
hpnre = re.compile(platformpattern, re.I) |
|
51 |
for hp in cls.hostplatforms: |
|
52 |
if hpnre.match(hp): |
|
53 |
return True |
|
54 |
return False |
|
55 |
||
56 |
@classmethod |
|
57 |
def IsHost(cls, platformpattern): |
|
58 |
""" Does the parameter match the name of the |
|
59 |
platform that we're executing on? """ |
|
60 |
ppre = re.compile(platformpattern, re.I) |
|
61 |
if ppre.match(cls.hostplatform): |
|
62 |
return True |
|
63 |
return False |
|
64 |
||
65 |
||
66 |
# Make sure not to start up on an unsupported platform |
|
67 |
if not HostPlatform.IsKnown(HostPlatform.hostplatform): |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
68 |
raise Exception("raptor_data module loaded on an unrecognised platform '%s'. Expected one of %s" % (HostPlatform.hostplatform, str(HostPlatform.hostplatforms))) |
3 | 69 |
|
70 |
||
71 |
# raptor_data module classes |
|
72 |
||
73 |
class Model(object): |
|
74 |
"Base class for data-model objects" |
|
75 |
||
5 | 76 |
__slots__ = ('host', 'source', 'cacheID') |
77 |
||
3 | 78 |
def __init__(self): |
79 |
self.source = None # XML file |
|
80 |
self.host = None |
|
81 |
self.cacheID = "" # default set of cached objects |
|
5 | 82 |
# not using the cache parameter - there to make the |
83 |
# init for all Model objects "standard" |
|
3 | 84 |
|
85 |
||
86 |
def SetSourceFile(self, filename): |
|
87 |
self.source = filename |
|
88 |
||
89 |
||
90 |
def SetProperty(self, name, value): |
|
91 |
raise InvalidPropertyError() |
|
92 |
||
93 |
||
94 |
def AddChild(self, child): |
|
95 |
raise InvalidChildError() |
|
96 |
||
97 |
||
98 |
def Valid(self): |
|
99 |
return False |
|
100 |
||
101 |
def IsApplicable(self): |
|
102 |
"This variant may be caused to only apply when used on a particular host build platform" |
|
103 |
if self.host is None: |
|
104 |
return True |
|
105 |
||
106 |
if HostPlatform.IsHost(self.host): |
|
107 |
return True |
|
108 |
||
109 |
return False |
|
110 |
||
111 |
||
112 |
class InvalidPropertyError(Exception): |
|
113 |
pass |
|
114 |
||
115 |
class InvalidChildError(Exception): |
|
116 |
pass |
|
117 |
||
118 |
class BadReferenceError(Exception): |
|
119 |
pass |
|
120 |
||
121 |
||
122 |
class Reference(Model): |
|
123 |
"Base class for data-model reference objects" |
|
124 |
||
125 |
def __init__(self, ref = None): |
|
126 |
Model.__init__(self) |
|
127 |
self.ref = ref |
|
128 |
self.modifiers = [] |
|
129 |
||
130 |
def SetProperty(self, name, value): |
|
131 |
if name == "ref": |
|
132 |
self.ref = value |
|
133 |
elif name == "mod": |
|
134 |
self.modifiers = value.split(".") |
|
135 |
else: |
|
136 |
raise InvalidPropertyError() |
|
137 |
||
138 |
def Resolve(self): |
|
139 |
raise BadReferenceError() |
|
140 |
||
5 | 141 |
def GetModifiers(self, cache): |
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
142 |
mods = [] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
143 |
for m in self.modifiers: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
144 |
try: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
145 |
mods.append(cache.FindNamedVariant(m)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
146 |
except KeyError: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
147 |
raise BadReferenceError(m) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
148 |
return mods |
3 | 149 |
|
150 |
def Valid(self): |
|
151 |
return self.ref |
|
152 |
||
153 |
||
154 |
class VariantContainer(Model): |
|
155 |
||
156 |
def __init__(self): |
|
157 |
Model.__init__(self) # base class constructor |
|
158 |
self.variants = [] |
|
159 |
||
160 |
||
5 | 161 |
def __str__(self): |
162 |
return "\n".join([str(v) for v in self.variants]) |
|
3 | 163 |
|
164 |
||
165 |
def AddVariant(self, variant): |
|
166 |
if type(variant) is types.StringTypes: |
|
5 | 167 |
variant = VariantRef(ref = variant) |
3 | 168 |
|
169 |
||
170 |
# Only add the variant if it's not in the list |
|
171 |
# already |
|
172 |
if not variant in self.variants: |
|
173 |
self.variants.append(variant) |
|
174 |
||
5 | 175 |
def GetVariants(self, cache): |
3 | 176 |
# resolve any VariantRef objects into Variant objects |
5 | 177 |
missing_variants = [] |
3 | 178 |
for i,var in enumerate(self.variants): |
179 |
if isinstance(var, Reference): |
|
180 |
try: |
|
5 | 181 |
self.variants[i] = var.Resolve(cache=cache) |
3 | 182 |
|
183 |
except BadReferenceError: |
|
5 | 184 |
missing_variants.append(var.ref) |
185 |
||
186 |
if len(missing_variants) > 0: |
|
187 |
raise MissingVariantException("Missing variants '%s'", " ".join(missing_variants)) |
|
3 | 188 |
|
189 |
return self.variants |
|
190 |
||
191 |
||
192 |
class Interface(Model): |
|
193 |
||
194 |
def __init__(self, name = None): |
|
195 |
Model.__init__(self) # base class constructor |
|
196 |
self.name = name |
|
197 |
self.flm = None |
|
198 |
self.abstract = False |
|
199 |
self.extends = None |
|
200 |
self.params = [] |
|
201 |
self.paramgroups = [] |
|
202 |
||
5 | 203 |
def __str__(self): |
204 |
return "<interface name='%s'>" % self.name + "</interface>" |
|
3 | 205 |
|
5 | 206 |
def FindParent(self, cache): |
3 | 207 |
try: |
5 | 208 |
return cache.FindNamedInterface(self.extends, self.cacheID) |
3 | 209 |
except KeyError: |
210 |
raise BadReferenceError("Cannot extend interface because it cannot be found: "+str(self.extends)) |
|
211 |
||
5 | 212 |
def GetParams(self, cache): |
3 | 213 |
if self.extends != None: |
5 | 214 |
parent = self.FindParent(cache) |
3 | 215 |
|
216 |
# what parameter names do we have already? |
|
217 |
names = set([x.name for x in self.params]) |
|
218 |
||
219 |
# pick up ones we don't have that are in our parent |
|
220 |
pp = [] |
|
5 | 221 |
for p in parent.GetParams(cache): |
3 | 222 |
if not p.name in names: |
223 |
pp.append(p) |
|
224 |
||
225 |
# list parent parameters first then ours |
|
226 |
pp.extend(self.params) |
|
227 |
return pp |
|
228 |
||
229 |
return self.params |
|
230 |
||
5 | 231 |
def GetParamGroups(self, cache): |
3 | 232 |
if self.extends != None: |
5 | 233 |
parent = self.FindParent(cache) |
3 | 234 |
|
235 |
# what parameter names do we have already? |
|
236 |
patterns = set([x.pattern for x in self.paramgroups]) |
|
237 |
||
238 |
# pick up ones we don't have that are in our parent |
|
5 | 239 |
for g in parent.GetParamGroups(cache): |
3 | 240 |
if not g.pattern in patterns: |
241 |
self.paramgroups.append(g) |
|
242 |
||
243 |
return self.paramgroups |
|
244 |
||
245 |
||
5 | 246 |
def GetFLMIncludePath(self, cache): |
3 | 247 |
"absolute path to the FLM" |
248 |
||
249 |
if self.flm == None: |
|
250 |
if self.extends != None: |
|
5 | 251 |
parent = self.FindParent(cache) |
3 | 252 |
|
5 | 253 |
return parent.GetFLMIncludePath(cache) |
3 | 254 |
else: |
255 |
raise InvalidPropertyError() |
|
256 |
||
257 |
if not os.path.isabs(self.flm): |
|
258 |
self.flm = os.path.join(os.path.dirname(self.source), self.flm) |
|
259 |
||
260 |
return generic_path.Path(self.flm) |
|
261 |
||
262 |
||
263 |
def SetProperty(self, name, value): |
|
264 |
if name == "name": |
|
265 |
self.name = value |
|
266 |
elif name == "flm": |
|
267 |
self.flm = value |
|
268 |
elif name == "abstract": |
|
269 |
self.abstract = (value == "true") |
|
270 |
elif name == "extends": |
|
271 |
self.extends = value |
|
272 |
else: |
|
273 |
raise InvalidPropertyError() |
|
274 |
||
275 |
||
276 |
def AddChild(self, child): |
|
277 |
if isinstance(child, Parameter): |
|
278 |
self.AddParameter(child) |
|
279 |
elif isinstance(child, ParameterGroup): |
|
280 |
self.AddParameterGroup(child) |
|
281 |
else: |
|
282 |
raise InvalidChildError() |
|
283 |
||
284 |
||
285 |
def AddParameter(self, parameter): |
|
286 |
self.params.append(parameter) |
|
287 |
||
288 |
def AddParameterGroup(self, parametergroup): |
|
289 |
self.paramgroups.append(parametergroup) |
|
290 |
||
291 |
def Valid(self): |
|
292 |
return (self.name != None) |
|
293 |
||
294 |
||
295 |
class InterfaceRef(Reference): |
|
296 |
||
5 | 297 |
def __str__(self): |
298 |
return "<interfaceRef ref='%s'/>" % self.ref |
|
3 | 299 |
|
5 | 300 |
def Resolve(self, cache): |
3 | 301 |
try: |
5 | 302 |
return cache.FindNamedInterface(self.ref, self.cacheID) |
3 | 303 |
except KeyError: |
304 |
raise BadReferenceError() |
|
305 |
||
306 |
||
307 |
class Specification(VariantContainer): |
|
308 |
||
309 |
def __init__(self, name = "", type = ""): |
|
310 |
VariantContainer.__init__(self) # base class constructor |
|
311 |
self.name = name |
|
312 |
self.type = type |
|
313 |
self.interface = None |
|
314 |
self.childSpecs = [] |
|
315 |
self.parentSpec = None |
|
316 |
||
317 |
||
5 | 318 |
def __str__(self): |
319 |
s = "<spec name='%s'>" % str(self.name) |
|
320 |
s += VariantContainer.__str__(self) |
|
3 | 321 |
for c in self.childSpecs: |
5 | 322 |
s += str(c) + '\n' |
323 |
s += "</spec>" |
|
324 |
return s |
|
3 | 325 |
|
326 |
||
327 |
def SetProperty(self, name, value): |
|
328 |
if name == "name": |
|
329 |
self.name = value |
|
330 |
else: |
|
331 |
raise InvalidPropertyError() |
|
332 |
||
333 |
||
5 | 334 |
def Configure(self, config, cache): |
3 | 335 |
# configure all the children (some may be Filters or parents of) |
336 |
for spec in self.GetChildSpecs(): |
|
5 | 337 |
spec.Configure(config, cache = cache) |
3 | 338 |
|
339 |
||
340 |
def HasInterface(self): |
|
341 |
return self.interface != None |
|
342 |
||
343 |
||
344 |
def SetInterface(self, interface): |
|
345 |
if isinstance(interface, Interface) \ |
|
346 |
or isinstance(interface, InterfaceRef): |
|
347 |
self.interface = interface |
|
348 |
else: |
|
5 | 349 |
self.interface = InterfaceRef(ref = interface) |
3 | 350 |
|
351 |
||
5 | 352 |
def GetInterface(self, cache): |
3 | 353 |
"""return the Interface (fetching from the cache if it was a ref) |
354 |
may return None""" |
|
355 |
||
356 |
if self.interface == None \ |
|
357 |
or isinstance(self.interface, Interface): |
|
358 |
return self.interface |
|
359 |
||
360 |
if isinstance(self.interface, InterfaceRef): |
|
361 |
try: |
|
5 | 362 |
self.interface = self.interface.Resolve(cache=cache) |
3 | 363 |
return self.interface |
364 |
||
365 |
except BadReferenceError: |
|
5 | 366 |
raise MissingInterfaceError("Missing interface %s" % self.interface.ref) |
3 | 367 |
|
368 |
def AddChild(self, child): |
|
369 |
if isinstance(child, Specification): |
|
370 |
self.AddChildSpecification(child) |
|
371 |
elif isinstance(child, Interface) \ |
|
372 |
or isinstance(child, InterfaceRef): |
|
373 |
self.SetInterface(child) |
|
374 |
elif isinstance(child, Variant) \ |
|
375 |
or isinstance(child, VariantRef): |
|
376 |
self.AddVariant(child) |
|
377 |
else: |
|
378 |
raise InvalidChildError() |
|
379 |
||
380 |
||
381 |
def AddChildSpecification(self, child): |
|
382 |
child.SetParentSpec(self) |
|
383 |
self.childSpecs.append(child) |
|
384 |
||
385 |
||
386 |
def SetParentSpec(self, parent): |
|
387 |
self.parentSpec = parent |
|
388 |
||
389 |
||
390 |
def GetChildSpecs(self): |
|
391 |
return self.childSpecs |
|
392 |
||
393 |
||
394 |
def Valid(self): |
|
395 |
return True |
|
396 |
||
397 |
||
5 | 398 |
def GetAllVariantsRecursively(self, cache): |
3 | 399 |
"""Returns all variants contained in this node and in its ancestors. |
400 |
||
401 |
The returned value is a list, the structure of which is [variants-in-parent, |
|
402 |
variants-in-self]. |
|
403 |
||
404 |
Note that the function recurses through parent *Specifications*, not through |
|
405 |
the variants themselves. |
|
406 |
""" |
|
407 |
if self.parentSpec: |
|
5 | 408 |
variants = self.parentSpec.GetAllVariantsRecursively(cache = cache) |
3 | 409 |
else: |
410 |
variants = [] |
|
411 |
||
5 | 412 |
variants.extend( self.GetVariants(cache = cache) ) |
3 | 413 |
|
414 |
return variants |
|
415 |
||
416 |
||
417 |
class Filter(Specification): |
|
418 |
"""A Filter is two Specification nodes and a True/False switch. |
|
419 |
||
420 |
Filter extends Specification to have two nodes, only one of |
|
421 |
which can be active at any time. Which node is active is determined |
|
422 |
when the Configure method is called after setting up a Condition. |
|
423 |
||
424 |
If several Conditions are set, the test is an OR of all of them.""" |
|
425 |
||
426 |
def __init__(self, name = ""): |
|
5 | 427 |
Specification.__init__(self, name = name) # base class constructor |
428 |
self.Else = Specification(name = name) # same for Else part |
|
3 | 429 |
self.isTrue = True |
430 |
self.configNames = set() # |
|
431 |
self.variableNames = set() # TO DO: Condition class |
|
432 |
self.variableValues = {} # |
|
433 |
||
5 | 434 |
def __str__(self, prefix = ""): |
435 |
s = "<filter name='%s'>\n"% self.name |
|
436 |
s += "<if config='%s'>\n" % " | ".join(self.configNames) |
|
437 |
s += Specification.__str__(self) |
|
438 |
s += "</if>\n <else>\n" |
|
439 |
s += str(self.Else) |
|
440 |
s += " </else>\n</filter>\n" |
|
441 |
return s |
|
3 | 442 |
|
443 |
||
444 |
def SetConfigCondition(self, configName): |
|
445 |
self.configNames = set([configName]) |
|
446 |
||
447 |
def AddConfigCondition(self, configName): |
|
448 |
self.configNames.add(configName) |
|
449 |
||
450 |
||
451 |
def SetVariableCondition(self, variableName, variableValues): |
|
452 |
self.variableNames = set([variableName]) |
|
453 |
if type(variableValues) == types.ListType: |
|
454 |
self.variableValues[variableName] = set(variableValues) |
|
455 |
else: |
|
456 |
self.variableValues[variableName] = set([variableValues]) |
|
457 |
||
458 |
def AddVariableCondition(self, variableName, variableValues): |
|
459 |
self.variableNames.add(variableName) |
|
460 |
if type(variableValues) == types.ListType: |
|
461 |
self.variableValues[variableName] = set(variableValues) |
|
462 |
else: |
|
463 |
self.variableValues[variableName] = set([variableValues]) |
|
464 |
||
465 |
||
5 | 466 |
def Configure(self, buildUnit, cache): |
3 | 467 |
self.isTrue = False |
468 |
||
469 |
if buildUnit.name in self.configNames: |
|
470 |
self.isTrue = True |
|
471 |
elif self.variableNames: |
|
5 | 472 |
|
473 |
evaluator = Evaluator(self.parentSpec, buildUnit, cache=cache) |
|
3 | 474 |
|
475 |
for variableName in self.variableNames: |
|
476 |
variableValue = evaluator.Get(variableName) |
|
477 |
||
478 |
if variableValue in self.variableValues[variableName]: |
|
479 |
self.isTrue = True |
|
480 |
break |
|
481 |
||
482 |
# configure all the children too |
|
483 |
for spec in self.GetChildSpecs(): |
|
5 | 484 |
spec.Configure(buildUnit, cache=cache) |
3 | 485 |
|
486 |
||
487 |
def HasInterface(self): |
|
488 |
if self.isTrue: |
|
489 |
return Specification.HasInterface(self) |
|
490 |
else: |
|
491 |
return self.Else.HasInterface() |
|
492 |
||
493 |
||
5 | 494 |
def GetInterface(self, cache): |
3 | 495 |
if self.isTrue: |
5 | 496 |
return Specification.GetInterface(self, cache = cache) |
3 | 497 |
else: |
5 | 498 |
return self.Else.GetInterface(cache = cache) |
3 | 499 |
|
500 |
||
5 | 501 |
def GetVariants(self, cache): |
3 | 502 |
if self.isTrue: |
5 | 503 |
return Specification.GetVariants(self, cache = cache) |
3 | 504 |
else: |
5 | 505 |
return self.Else.GetVariants(cache = cache) |
3 | 506 |
|
507 |
||
508 |
def SetParentSpec(self, parent): |
|
509 |
# base class method |
|
510 |
Specification.SetParentSpec(self, parent) |
|
511 |
# same for Else part |
|
512 |
self.Else.SetParentSpec(parent) |
|
513 |
||
514 |
||
515 |
def GetChildSpecs(self): |
|
516 |
if self.isTrue: |
|
517 |
return Specification.GetChildSpecs(self) |
|
518 |
else: |
|
519 |
return self.Else.GetChildSpecs() |
|
520 |
||
521 |
||
522 |
class Parameter(Model): |
|
523 |
||
524 |
def __init__(self, name = None, default = None): |
|
525 |
Model.__init__(self) # base class constructor |
|
526 |
self.name = name |
|
527 |
self.default = default |
|
528 |
||
529 |
||
530 |
def SetProperty(self, name, value): |
|
531 |
if name == "name": |
|
532 |
self.name = value |
|
533 |
elif name == "default": |
|
534 |
self.default = value |
|
535 |
else: |
|
536 |
raise InvalidPropertyError() |
|
537 |
||
538 |
||
539 |
def Valid(self): |
|
540 |
return (self.name != None) |
|
541 |
||
542 |
class ParameterGroup(Model): |
|
543 |
"""A group of Parameters specified in an interface by a regexp""" |
|
544 |
def __init__(self, pattern = None, default = None): |
|
545 |
Model.__init__(self) # base class constructor |
|
546 |
self.pattern = pattern |
|
547 |
||
548 |
self.patternre = None |
|
549 |
if pattern: |
|
550 |
try: |
|
551 |
self.patternre = re.compile(pattern) |
|
552 |
except TypeError: |
|
553 |
pass |
|
554 |
self.default = default |
|
555 |
||
556 |
||
557 |
def SetProperty(self, pattern, value): |
|
558 |
if pattern == "pattern": |
|
559 |
self.pattern = value |
|
560 |
self.patternre = re.compile(value) |
|
561 |
elif pattern == "default": |
|
562 |
self.default = value |
|
563 |
else: |
|
564 |
raise InvalidPropertyError() |
|
565 |
||
566 |
||
567 |
def Valid(self): |
|
568 |
return (self.pattern != None and self.patternre != None) |
|
569 |
||
570 |
||
571 |
class Operation(Model): |
|
572 |
"Base class for variant operations" |
|
5 | 573 |
__slots__ = 'type' |
3 | 574 |
def __init__(self): |
575 |
Model.__init__(self) # base class constructor |
|
576 |
self.type = None |
|
577 |
||
578 |
def Apply(self, oldValue): |
|
579 |
pass |
|
580 |
||
581 |
||
582 |
class Append(Operation): |
|
5 | 583 |
__slots__ = ('name', 'value', 'separator') |
3 | 584 |
def __init__(self, name = None, value = None, separator = " "): |
585 |
Operation.__init__(self) # base class constructor |
|
586 |
self.name = name |
|
587 |
self.value = value |
|
588 |
self.separator = separator |
|
589 |
||
590 |
||
5 | 591 |
def __str__(self): |
3 | 592 |
attributes = "name='" + self.name + "' value='" + self.value + "' separator='" + self.separator + "'" |
5 | 593 |
return "<append %s/>" % attributes |
3 | 594 |
|
595 |
||
596 |
def Apply(self, oldValue): |
|
597 |
if len(oldValue) > 0: |
|
598 |
if len(self.value) > 0: |
|
599 |
return oldValue + self.separator + self.value |
|
600 |
else: |
|
601 |
return oldValue |
|
602 |
else: |
|
603 |
return self.value |
|
604 |
||
605 |
||
606 |
def SetProperty(self, name, value): |
|
607 |
if name == "name": |
|
608 |
self.name = value |
|
609 |
elif name == "value": |
|
610 |
self.value = value |
|
611 |
elif name == "separator": |
|
612 |
self.separator = value |
|
613 |
else: |
|
614 |
raise InvalidPropertyError() |
|
615 |
||
616 |
||
617 |
def Valid(self): |
|
618 |
return (self.name != None and self.value != None) |
|
619 |
||
620 |
||
621 |
class Prepend(Operation): |
|
5 | 622 |
__slots__ = ('name', 'value', 'separator') |
3 | 623 |
def __init__(self, name = None, value = None, separator = " "): |
624 |
Operation.__init__(self) # base class constructor |
|
625 |
self.name = name |
|
626 |
self.value = value |
|
627 |
self.separator = separator |
|
628 |
||
629 |
||
5 | 630 |
def __str__(self, prefix = ""): |
3 | 631 |
attributes = "name='" + self.name + "' value='" + self.value + "' separator='" + self.separator + "'" |
5 | 632 |
return "<prepend %s/>" % prefix |
3 | 633 |
|
634 |
||
635 |
def Apply(self, oldValue): |
|
636 |
if len(oldValue) > 0: |
|
637 |
if len(self.value) > 0: |
|
638 |
return self.value + self.separator + oldValue |
|
639 |
else: |
|
640 |
return oldValue |
|
641 |
else: |
|
642 |
return self.value |
|
643 |
||
644 |
||
645 |
def SetProperty(self, name, value): |
|
646 |
if name == "name": |
|
647 |
self.name = value |
|
648 |
elif name == "value": |
|
649 |
self.value = value |
|
650 |
elif name == "separator": |
|
651 |
self.separator = value |
|
652 |
else: |
|
653 |
raise InvalidPropertyError() |
|
654 |
||
655 |
||
656 |
def Valid(self): |
|
657 |
return (self.name != None and self.value != None) |
|
658 |
||
659 |
||
660 |
class Set(Operation): |
|
5 | 661 |
__slots__ = ('name', 'value', 'type', 'versionCommand', 'versionResult') |
3 | 662 |
"""implementation of <set> operation""" |
663 |
||
664 |
def __init__(self, name = None, value = "", type = ""): |
|
665 |
Operation.__init__(self) # base class constructor |
|
666 |
self.name = name |
|
667 |
self.value = value |
|
668 |
self.type = type |
|
669 |
self.versionCommand = "" |
|
670 |
self.versionResult = "" |
|
671 |
||
672 |
||
5 | 673 |
def __str__(self): |
3 | 674 |
attributes = "name='" + self.name + "' value='" + self.value + "' type='" + self.type + "'" |
675 |
if type == "tool": |
|
676 |
attributes += " versionCommand='" + self.versionCommand + "' versionResult='" + self.versionResult |
|
677 |
||
5 | 678 |
return "<set %s/>" % attributes |
3 | 679 |
|
680 |
||
681 |
def Apply(self, oldValue): |
|
682 |
return self.value |
|
683 |
||
684 |
||
685 |
def SetProperty(self, name, value): |
|
686 |
if name == "name": |
|
687 |
self.name = value |
|
688 |
elif name == "value": |
|
689 |
self.value = value |
|
690 |
elif name == "type": |
|
691 |
self.type = value |
|
692 |
elif name == "versionCommand": |
|
693 |
self.versionCommand = value |
|
694 |
elif name == "versionResult": |
|
695 |
self.versionResult = value |
|
696 |
elif name == "host": |
|
697 |
if HostPlatform.IsKnown(value): |
|
698 |
self.host = value |
|
699 |
else: |
|
700 |
raise InvalidPropertyError() |
|
701 |
||
702 |
||
703 |
def Valid(self): |
|
704 |
return (self.name != None and self.value != None) |
|
705 |
||
5 | 706 |
class BadToolValue(Exception): |
707 |
pass |
|
3 | 708 |
|
709 |
class Env(Set): |
|
710 |
"""implementation of <env> operator""" |
|
711 |
||
712 |
def __init__(self, name = None, default = None, type = ""): |
|
713 |
Set.__init__(self, name, "", type) # base class constructor |
|
714 |
self.default = default |
|
715 |
||
716 |
||
5 | 717 |
def __str__(self): |
3 | 718 |
attributes = "name='" + self.name + "' type='" + self.type + "'" |
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
719 |
if self.default != None: |
3 | 720 |
attributes += " default='" + self.default + "'" |
721 |
||
722 |
if type == "tool": |
|
723 |
attributes += " versionCommand='" + self.versionCommand + "' versionResult='" + self.versionResult + "'" |
|
724 |
||
5 | 725 |
return "<env %s/>" % attributes |
3 | 726 |
|
727 |
||
728 |
def Apply(self, oldValue): |
|
729 |
try: |
|
730 |
value = os.environ[self.name] |
|
60
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
731 |
|
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
732 |
if value: |
400
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
733 |
if self.type in ["path", "tool", "toolchainpath"]: |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
734 |
# if this value is some sort of path or tool then we need to make sure |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
735 |
# it is a proper absolute path in our preferred format. |
60
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
736 |
try: |
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
737 |
path = generic_path.Path(value) |
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
738 |
value = str(path.Absolute()) |
28ee654acf42
Deal with backslashes at the end of <env/> values
Jon Chatten <>
parents:
5
diff
changeset
|
739 |
except ValueError,e: |
400
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
740 |
raise BadToolValue("the environment variable %s is incorrect: %s" % (self.name, str(e))) |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
741 |
|
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
742 |
if self.type in ["tool", "toolchainpath"]: |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
743 |
# if we're dealing with tool-related values, then make sure that we can get "safe" |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
744 |
# versions if they contain spaces - if we can't, that's an error, as they won't |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
745 |
# survive full usage in the toolcheck or when used and/or referenced in FLMs |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
746 |
if ' ' in value: |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
747 |
path = generic_path.Path(value) |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
748 |
spaceSafeValue = path.GetSpaceSafePath() |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
749 |
|
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
750 |
if not spaceSafeValue: |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
751 |
raise BadToolValue("the environment variable %s is incorrect - it is a '%s' type but contains spaces that cannot be neutralised: %s" % (self.name, self.type, value)) |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
752 |
|
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
753 |
value = spaceSafeValue |
61
f520dfd22025
Correct backslash escaping to only operate on non-'path' and 'tool' types.
Jon Chatten
parents:
60
diff
changeset
|
754 |
elif value.endswith('\\'): |
400
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
755 |
# if this value ends in an un-escaped backslash, then it will be treated as a line continuation character |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
756 |
# in makefile parsing - un-escaped backslashes at the end of values are therefore escaped |
554cc189839f
Support for resolving, on Windows only, <env/> 'tool' and 'toolchain' type paths with spaces.
Jon Chatten
parents:
374
diff
changeset
|
757 |
count = len(value) - len(value.rstrip('\\')) # an odd number of backslashes means there's one to escape |
61
f520dfd22025
Correct backslash escaping to only operate on non-'path' and 'tool' types.
Jon Chatten
parents:
60
diff
changeset
|
758 |
if count % 2: |
f520dfd22025
Correct backslash escaping to only operate on non-'path' and 'tool' types.
Jon Chatten
parents:
60
diff
changeset
|
759 |
value += '\\' |
3 | 760 |
except KeyError: |
761 |
if self.default != None: |
|
762 |
value = self.default |
|
763 |
else: |
|
5 | 764 |
raise BadToolValue("%s is not set in the environment and has no default" % self.name) |
3 | 765 |
|
766 |
return value |
|
767 |
||
768 |
||
769 |
def SetProperty(self, name, value): |
|
770 |
if name == "default": |
|
771 |
self.default = value |
|
772 |
else: |
|
773 |
Set.SetProperty(self, name, value) |
|
774 |
||
775 |
||
776 |
def Valid(self): |
|
777 |
return (self.name != None) |
|
778 |
||
779 |
||
780 |
class BuildUnit(object): |
|
781 |
"Represents an individual buildable unit." |
|
782 |
||
783 |
def __init__(self, name, variants): |
|
784 |
self.name = name |
|
785 |
||
786 |
# A list of Variant objects. |
|
787 |
self.variants = variants |
|
788 |
||
789 |
# Cache for the variant operations implied by this BuildUnit. |
|
790 |
self.operations = [] |
|
791 |
self.variantKey = "" |
|
792 |
||
5 | 793 |
def GetOperations(self, cache): |
3 | 794 |
"""Return all operations related to this BuildUnit. |
795 |
||
796 |
The result is cached, and so will only be computed once per BuildUnit. |
|
797 |
""" |
|
798 |
key = '.'.join([x.name for x in self.variants]) |
|
799 |
if self.variantKey != key: |
|
800 |
self.variantKey = key |
|
801 |
for v in self.variants: |
|
5 | 802 |
self.operations.extend( v.GetAllOperationsRecursively(cache=cache) ) |
3 | 803 |
|
804 |
return self.operations |
|
805 |
||
806 |
class Config(object): |
|
807 |
"""Abstract type representing an argument to the '-c' option. |
|
808 |
||
809 |
The fundamental property of a Config is that it can generate one or more |
|
810 |
BuildUnits. |
|
811 |
""" |
|
812 |
||
813 |
def __init__(self): |
|
814 |
self.modifiers = [] |
|
815 |
||
816 |
def AddModifier(self, variant): |
|
817 |
self.modifiers.append(variant) |
|
818 |
||
819 |
def ClearModifiers(self): |
|
820 |
self.modifiers = [] |
|
821 |
||
5 | 822 |
def GenerateBuildUnits(self,cache): |
3 | 823 |
"""Returns a list of BuildUnits. |
824 |
||
825 |
This function must be overridden by derived classes. |
|
826 |
""" |
|
827 |
raise NotImplementedError() |
|
828 |
||
829 |
||
830 |
class Variant(Model, Config): |
|
831 |
||
5 | 832 |
__slots__ = ('cache','name','host','extends','ops','variantRefs','allOperations') |
833 |
||
3 | 834 |
def __init__(self, name = ""): |
835 |
Model.__init__(self) |
|
836 |
Config.__init__(self) |
|
837 |
self.name = name |
|
838 |
||
839 |
# Operations defined inside this variant. |
|
840 |
self.ops = [] |
|
841 |
||
842 |
# The name of our parent variant, if any. |
|
843 |
self.extends = "" |
|
844 |
||
845 |
# Any variant references used inside this variant. |
|
846 |
self.variantRefs = [] |
|
847 |
||
848 |
self.allOperations = [] |
|
849 |
||
850 |
def SetProperty(self, name, value): |
|
851 |
if name == "name": |
|
852 |
self.name = value |
|
853 |
elif name == "host": |
|
854 |
if HostPlatform.IsKnown(value): |
|
855 |
self.host = value |
|
856 |
elif name == "extends": |
|
857 |
self.extends = value |
|
858 |
else: |
|
859 |
raise InvalidPropertyError() |
|
860 |
||
861 |
def AddChild(self, child): |
|
862 |
if isinstance(child, Operation): |
|
863 |
self.ops.append(child) |
|
864 |
elif isinstance(child, VariantRef): |
|
865 |
self.variantRefs.append(child) |
|
866 |
else: |
|
867 |
raise InvalidChildError() |
|
868 |
||
869 |
def Valid(self): |
|
870 |
return self.name |
|
871 |
||
872 |
def AddOperation(self, op): |
|
873 |
self.ops.append(op) |
|
874 |
||
5 | 875 |
def GetAllOperationsRecursively(self, cache): |
3 | 876 |
"""Returns a list of all operations in this variant. |
877 |
||
878 |
The list elements are themselves lists; the overall structure of the |
|
879 |
returned value is: |
|
880 |
||
881 |
[ [ops-from-parent],[ops-from-varRefs], [ops-in-self] ] |
|
882 |
""" |
|
883 |
||
884 |
if not self.allOperations: |
|
885 |
if self.extends: |
|
5 | 886 |
parent = cache.FindNamedVariant(self.extends) |
887 |
self.allOperations.extend( parent.GetAllOperationsRecursively(cache = cache) ) |
|
3 | 888 |
for r in self.variantRefs: |
5 | 889 |
for v in [ r.Resolve(cache = cache) ] + r.GetModifiers(cache = cache): |
890 |
self.allOperations.extend( v.GetAllOperationsRecursively(cache = cache) ) |
|
3 | 891 |
self.allOperations.append(self.ops) |
892 |
||
893 |
return self.allOperations |
|
894 |
||
5 | 895 |
def GenerateBuildUnits(self,cache): |
3 | 896 |
|
897 |
name = self.name |
|
898 |
vars = [self] |
|
899 |
||
900 |
for m in self.modifiers: |
|
901 |
name = name + "." + m.name |
|
902 |
vars.append(m) |
|
5 | 903 |
return [ BuildUnit(name=name, variants=vars) ] |
3 | 904 |
|
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
905 |
def isDerivedFrom(self, progenitor, cache): |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
906 |
if self.name == progenitor: |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
907 |
return True |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
908 |
|
191
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
909 |
pname = self.extends |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
910 |
while pname is not None and pname is not '': |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
911 |
parent = cache.FindNamedVariant(pname) |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
912 |
if parent is None: |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
913 |
break |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
914 |
if parent.name == progenitor: |
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
915 |
return True |
191
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
916 |
pname = parent.extends |
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
917 |
|
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
918 |
return False |
191
3bfc260b6d61
fix: better error messages when an incorrect make engine is specified. Requires that all make engine variants should extend "make_engine".
timothy.murphy@nokia.com
parents:
61
diff
changeset
|
919 |
|
5 | 920 |
def __str__(self): |
921 |
s = "<var name='%s' extends='%s'>\n" % (self.name, self.extends) |
|
3 | 922 |
for op in self.ops: |
5 | 923 |
s += str(op) + '\n' |
924 |
s += "</var>" |
|
925 |
return s |
|
3 | 926 |
|
927 |
class VariantRef(Reference): |
|
928 |
||
929 |
def __init__(self, ref=None): |
|
5 | 930 |
Reference.__init__(self, ref = ref) |
3 | 931 |
|
5 | 932 |
def __str__(self): |
933 |
return "<varRef ref='%s'/>" % self.ref |
|
3 | 934 |
|
5 | 935 |
def Resolve(self, cache): |
3 | 936 |
try: |
5 | 937 |
return cache.FindNamedVariant(self.ref) |
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
938 |
except KeyError: |
3 | 939 |
raise BadReferenceError(self.ref) |
940 |
||
5 | 941 |
class MissingVariantException(Exception): |
942 |
pass |
|
3 | 943 |
|
944 |
class Alias(Model, Config): |
|
945 |
||
946 |
def __init__(self, name=""): |
|
947 |
Model.__init__(self) |
|
948 |
Config.__init__(self) |
|
949 |
self.name = name |
|
950 |
self.meaning = "" |
|
951 |
self.varRefs = [] |
|
952 |
self.variants = [] |
|
953 |
||
5 | 954 |
def __str__(self): |
955 |
return "<alias name='%s' meaning='%s'/>" % (self.name, self.meaning) |
|
3 | 956 |
|
957 |
def SetProperty(self, key, val): |
|
958 |
if key == "name": |
|
959 |
self.name = val |
|
960 |
elif key == "meaning": |
|
961 |
self.meaning = val |
|
962 |
||
963 |
for u in val.split("."): |
|
5 | 964 |
self.varRefs.append( VariantRef(ref = u) ) |
3 | 965 |
else: |
966 |
raise InvalidPropertyError() |
|
967 |
||
968 |
def Valid(self): |
|
969 |
return self.name and self.meaning |
|
970 |
||
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
971 |
def Resolve(self, cache): |
3 | 972 |
if not self.variants: |
5 | 973 |
missing_variants = [] |
3 | 974 |
for r in self.varRefs: |
975 |
try: |
|
5 | 976 |
self.variants.append( r.Resolve(cache=cache) ) |
3 | 977 |
except BadReferenceError: |
5 | 978 |
missing_variants.append(r.ref) |
979 |
||
980 |
if len(missing_variants) > 0: |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
981 |
raise MissingVariantException("Missing variants '%s'" % " ".join(missing_variants)) |
3 | 982 |
|
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
983 |
def GenerateBuildUnits(self, cache): |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
984 |
self.Resolve(cache) |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
985 |
|
3 | 986 |
name = self.name |
987 |
||
988 |
for v in self.modifiers: |
|
989 |
name = name + "." + v.name |
|
990 |
||
5 | 991 |
return [ BuildUnit(name=name, variants=self.variants + self.modifiers) ] |
3 | 992 |
|
192
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
993 |
def isDerivedFrom(self, progenitor, cache): |
76300483f6fd
fix: get make engine name validation working with aliases.
timothy.murphy@nokia.com
parents:
191
diff
changeset
|
994 |
self.Resolve(cache) |
204
a19456c07783
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
timothy.murphy@nokia.com
parents:
196
diff
changeset
|
995 |
for v in self.variants: |
a19456c07783
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
timothy.murphy@nokia.com
parents:
196
diff
changeset
|
996 |
if v.isDerivedFrom(progenitor,cache): |
a19456c07783
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
timothy.murphy@nokia.com
parents:
196
diff
changeset
|
997 |
return True |
a19456c07783
fix: failure of make engine test when a make engine alias contains a modifier. There can be more than one variant per alias via "." e.g. make.extrastuff where make and extrastuff are variants.
timothy.murphy@nokia.com
parents:
196
diff
changeset
|
998 |
return False |
3 | 999 |
|
1000 |
class AliasRef(Reference): |
|
1001 |
||
1002 |
def __init__(self, ref=None): |
|
1003 |
Reference.__init__(self, ref) |
|
1004 |
||
5 | 1005 |
def __str__(self): |
1006 |
return "<aliasRef ref='%s'/>" % self.ref |
|
3 | 1007 |
|
5 | 1008 |
def Resolve(self, cache): |
3 | 1009 |
try: |
5 | 1010 |
return cache.FindNamedAlias(self.ref) |
3 | 1011 |
except KeyError: |
1012 |
raise BadReferenceError(self.ref) |
|
1013 |
||
1014 |
||
1015 |
class Group(Model, Config): |
|
1016 |
def __init__(self, name=""): |
|
1017 |
Model.__init__(self) |
|
1018 |
Config.__init__(self) |
|
1019 |
self.name = name |
|
1020 |
self.childRefs = [] |
|
1021 |
||
1022 |
def SetProperty(self, key, val): |
|
1023 |
if key == "name": |
|
1024 |
self.name = val |
|
1025 |
else: |
|
1026 |
raise InvalidPropertyError() |
|
1027 |
||
1028 |
def AddChild(self, child): |
|
1029 |
if isinstance( child, (VariantRef,AliasRef,GroupRef) ): |
|
1030 |
self.childRefs.append(child) |
|
1031 |
else: |
|
1032 |
raise InvalidChildError() |
|
1033 |
||
1034 |
def Valid(self): |
|
1035 |
return self.name and self.childRefs |
|
1036 |
||
5 | 1037 |
def __str__(self): |
1038 |
s = "<group name='%s'>" % self.name |
|
3 | 1039 |
for r in self.childRefs: |
5 | 1040 |
s += str(r) |
1041 |
s += "</group>" |
|
1042 |
return s |
|
3 | 1043 |
|
5 | 1044 |
def GenerateBuildUnits(self, cache): |
3 | 1045 |
units = [] |
371
2db10eac415a
test data for bad groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
204
diff
changeset
|
1046 |
|
5 | 1047 |
missing_variants = [] |
3 | 1048 |
for r in self.childRefs: |
1049 |
try: |
|
5 | 1050 |
obj = r.Resolve(cache=cache) |
3 | 1051 |
except BadReferenceError: |
5 | 1052 |
missing_variants.append(r.ref) |
3 | 1053 |
else: |
1054 |
obj.ClearModifiers() |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1055 |
try: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1056 |
refMods = r.GetModifiers(cache) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1057 |
except BadReferenceError,e: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1058 |
missing_variants.append(str(e)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1059 |
else: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1060 |
for m in refMods + self.modifiers: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1061 |
obj.AddModifier(m) |
3 | 1062 |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1063 |
units.extend( obj.GenerateBuildUnits(cache) ) |
5 | 1064 |
|
1065 |
if len(missing_variants) > 0: |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1066 |
raise MissingVariantException("Missing variants '%s'" % " ".join(missing_variants)) |
3 | 1067 |
|
1068 |
return units |
|
1069 |
||
1070 |
||
1071 |
class GroupRef(Reference): |
|
1072 |
||
1073 |
def __init__(self, ref=None): |
|
1074 |
Reference.__init__(self, ref) |
|
1075 |
||
5 | 1076 |
def __str__(self): |
371
2db10eac415a
test data for bad groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
204
diff
changeset
|
1077 |
return "<groupRef ref='%s' mod='%s'/>" % (self.ref, ".".join(self.modifiers)) |
3 | 1078 |
|
5 | 1079 |
def Resolve(self, cache): |
3 | 1080 |
try: |
5 | 1081 |
return cache.FindNamedGroup(self.ref) |
3 | 1082 |
except KeyError: |
1083 |
raise BadReferenceError(self.ref) |
|
1084 |
||
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1085 |
def GetBuildUnits(configNames, cache, logger): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1086 |
"""expand a list of config strings like "arm.v5.urel" into a list |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1087 |
of BuildUnit objects that can be queried for settings. |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1088 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1089 |
The expansion tries to be tolerant of errors in the XML so that a |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1090 |
typo in one part of a group does not invalidate the whole group. |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1091 |
""" |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1092 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1093 |
# turn dot-separated name strings into Model objects (Group, Alias, Variant) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1094 |
models = [] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1095 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1096 |
for c in set(configNames): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1097 |
ok = True |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1098 |
names = c.split(".") |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1099 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1100 |
base = names[0] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1101 |
mods = names[1:] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1102 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1103 |
if base in cache.groups: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1104 |
x = cache.FindNamedGroup(base) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1105 |
elif base in cache.aliases: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1106 |
x = cache.FindNamedAlias(base) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1107 |
elif base in cache.variants: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1108 |
x = cache.FindNamedVariant(base) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1109 |
else: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1110 |
logger.Error("Unknown build configuration '%s'" % base) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1111 |
continue |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1112 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1113 |
x.ClearModifiers() |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1114 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1115 |
for m in mods: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1116 |
if m in cache.variants: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1117 |
x.AddModifier( cache.FindNamedVariant(m) ) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1118 |
else: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1119 |
logger.Error("Unknown build variant '%s'" % m) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1120 |
ok = False |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1121 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1122 |
if ok: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1123 |
models.append(copy.copy(x)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1124 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1125 |
# turn Model objects into BuildUnit objects |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1126 |
# |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1127 |
# all objects have a GenerateBuildUnits method but don't use |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1128 |
# that for Groups because it is not tolerant of errors (the |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1129 |
# first error raises an exception and the rest of the group is |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1130 |
# abandoned) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1131 |
units = [] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1132 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1133 |
while len(models) > 0: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1134 |
x = models.pop() |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1135 |
try: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1136 |
if isinstance(x, (Alias, Variant)): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1137 |
# these we just turn straight into BuildUnits |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1138 |
units.extend(x.GenerateBuildUnits(cache)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1139 |
elif isinstance(x, Group): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1140 |
# deal with each part of the group separately (later) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1141 |
for child in x.childRefs: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1142 |
modChild = copy.copy(child) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1143 |
modChild.modifiers = child.modifiers + [m.name for m in x.modifiers] |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1144 |
models.append(modChild) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1145 |
elif isinstance(x, Reference): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1146 |
# resolve references and their modifiers |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1147 |
try: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1148 |
obj = x.Resolve(cache) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1149 |
modObj = copy.copy(obj) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1150 |
modObj.modifiers = x.GetModifiers(cache) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1151 |
except BadReferenceError,e: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1152 |
logger.Error("Unknown reference '%s'" % str(e)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1153 |
else: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1154 |
models.append(modObj) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1155 |
except Exception, e: |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1156 |
logger.Error(str(e)) |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1157 |
|
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1158 |
return units |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1159 |
|
5 | 1160 |
class ToolErrorException(Exception): |
1161 |
def __init__(self, s): |
|
1162 |
Exception.__init__(self,s) |
|
1163 |
||
3 | 1164 |
class Tool(object): |
1165 |
"""Represents a tool that might be used by raptor e.g. a compiler""" |
|
1166 |
||
5 | 1167 |
# It's difficult and expensive to give each tool a log reference but a class one |
1168 |
# will facilitate debugging when that is needed without being a design flaw the |
|
1169 |
# rest of the time. |
|
1170 |
log = raptor_utilities.nulllog |
|
1171 |
||
3 | 1172 |
# For use in dealing with tools that return non-ascii version strings. |
1173 |
nonascii = "" |
|
1174 |
identity_chartable = chr(0) |
|
1175 |
for c in xrange(1,128): |
|
1176 |
identity_chartable += chr(c) |
|
1177 |
for c in xrange(128,256): |
|
1178 |
nonascii += chr(c) |
|
1179 |
identity_chartable += " " |
|
1180 |
||
5 | 1181 |
def __init__(self, name, command, versioncommand, versionresult, id=""): |
3 | 1182 |
self.name = name |
1183 |
self.command = command |
|
1184 |
self.versioncommand = versioncommand |
|
1185 |
self.versionresult = versionresult |
|
1186 |
self.id = id # what config this is from - used in debug messages |
|
1187 |
self.date = None |
|
1188 |
||
1189 |
||
1190 |
# Assume the tool is unavailable or the wrong |
|
1191 |
# version until someone proves that it's OK |
|
1192 |
self.valid = False |
|
1193 |
||
1194 |
||
1195 |
def expand(self, toolset): |
|
1196 |
self.versioncommand = toolset.ExpandAll(self.versioncommand) |
|
1197 |
self.versionresult = toolset.ExpandAll(self.versionresult) |
|
1198 |
self.command = toolset.ExpandAll(self.command) |
|
1199 |
self.key = hashlib.md5(self.versioncommand + self.versionresult).hexdigest() |
|
1200 |
||
1201 |
# We need the tool's date to find out if we should check it. |
|
1202 |
try: |
|
1203 |
if '/' in self.command: |
|
1204 |
testfile = os.path.abspath(self.command.strip("\"'")) |
|
1205 |
else: |
|
1206 |
# The tool isn't a relative or absolute path so the could be relying on the |
|
1207 |
# $PATH variable to make it available. We must find the tool if it's a simple |
|
1208 |
# executable file (e.g. "armcc" rather than "python myscript.py") then get it's date. |
|
1209 |
# We can use the date later to see if our cache is valid. |
|
1210 |
# If it really is not a simple command then we won't be able to get a date and |
|
1211 |
# we won't be able to tell if it is altered or updated - too bad! |
|
1212 |
testfile = generic_path.Where(self.command) |
|
5 | 1213 |
#self.log.Debug("toolcheck: tool '%s' was found on the path at '%s' ", self.command, testfile) |
3 | 1214 |
if testfile is None: |
1215 |
raise Exception("Can't be found in path") |
|
1216 |
||
1217 |
if not os.path.isfile(testfile): |
|
1218 |
raise Exception("tool %s appears to not be a file %s", self.command, testfile) |
|
1219 |
||
1220 |
testfile_stat = os.stat(testfile) |
|
1221 |
self.date = testfile_stat.st_mtime |
|
1222 |
except Exception,e: |
|
5 | 1223 |
# We really don't mind if the tool could not be dated - for any reason |
1224 |
Tool.log.Debug("toolcheck: '%s=%s' cannot be dated - this is ok, but the toolcheck won't be able to tell when a new version of the tool is installed. (%s)", self.name, self.command, str(e)) |
|
1225 |
pass |
|
3 | 1226 |
|
1227 |
||
5 | 1228 |
def check(self, shell, evaluator, log = raptor_utilities.nulllog): |
3 | 1229 |
|
1230 |
self.vre = re.compile(self.versionresult) |
|
1231 |
||
1232 |
try: |
|
1233 |
self.log.Debug("Pre toolcheck: '%s' for version '%s'", self.name, self.versionresult) |
|
1234 |
p = subprocess.Popen(args=[shell, "-c", self.versioncommand], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
|
5 | 1235 |
log.Debug("Checking tool '%s' for version '%s'", self.name, self.versionresult) |
3 | 1236 |
versionoutput,err = p.communicate() |
1237 |
except Exception,e: |
|
1238 |
versionoutput=None |
|
1239 |
||
1240 |
# Some tools return version strings with unicode characters! |
|
1241 |
# There is no good response other than a lot of decoding and encoding. |
|
1242 |
# Simpler to ignore it: |
|
1243 |
versionoutput_a = versionoutput.translate(Tool.identity_chartable,"") |
|
1244 |
||
1245 |
if versionoutput_a and self.vre.search(versionoutput_a) != None: |
|
5 | 1246 |
log.Debug("tool '%s' returned an acceptable version '%s'", self.name, versionoutput_a) |
3 | 1247 |
self.valid = True |
1248 |
else: |
|
1249 |
self.valid = False |
|
5 | 1250 |
raise ToolErrorException("tool '%s' from config '%s' did not return version '%s' as required.\nCommand '%s' returned:\n%s\nCheck your environment and configuration.\n" % (self.name, self.id, self.versionresult, self.versioncommand, versionoutput_a)) |
3 | 1251 |
|
1252 |
def envhash(irrelevant_vars): |
|
1253 |
"""Determine something unique about this environment to identify it. |
|
1254 |
must ignore variables that change without mattering to the caller |
|
1255 |
e.g. perhaps PATH matters but PWD and PPID don't""" |
|
1256 |
envid = hashlib.md5() |
|
1257 |
for k in os.environ: |
|
1258 |
if k not in irrelevant_vars: |
|
1259 |
envid.update(os.environ[k]) |
|
1260 |
return envid.hexdigest()[:16] |
|
1261 |
||
1262 |
||
1263 |
class ToolSet(object): |
|
1264 |
""" |
|
1265 |
This class manages a bunch of tools and keeps a cache of |
|
1266 |
all tools that it ever sees (across all configurations). |
|
1267 |
toolset.check() is called for each config but the cache is kept across calls to |
|
1268 |
catch the use of one tool in many configs. |
|
1269 |
write() is used to flush the cache to disc. |
|
1270 |
""" |
|
1271 |
# The raptor shell - this is not mutable. |
|
5 | 1272 |
if 'SBS_SHELL' in os.environ: |
1273 |
shell = os.environ['SBS_SHELL'] |
|
1274 |
else: |
|
1275 |
hostbinaries = os.path.join(os.environ['SBS_HOME'], |
|
1276 |
os.environ['HOSTPLATFORM_DIR']) |
|
3 | 1277 |
|
5 | 1278 |
if HostPlatform.IsHost('lin*'): |
1279 |
shell=os.path.join(hostbinaries, 'bin/bash') |
|
3 | 1280 |
else: |
5 | 1281 |
if 'SBS_CYGWIN' in os.environ: |
1282 |
shell=os.path.join(os.environ['SBS_CYGWIN'], 'bin\\bash.exe') |
|
1283 |
else: |
|
1284 |
shell=os.path.join(hostbinaries, 'cygwin\\bin\\bash.exe') |
|
3 | 1285 |
|
1286 |
||
1287 |
irrelevant_vars = ['PWD','OLDPWD','PID','PPID', 'SHLVL' ] |
|
1288 |
||
1289 |
||
1290 |
shell_version=".*GNU bash, version [34].*" |
|
1291 |
shell_re = re.compile(shell_version) |
|
1292 |
if 'SBS_BUILD_DIR' in os.environ: |
|
1293 |
cachefile_basename = str(generic_path.Join(os.environ['SBS_BUILD_DIR'],"toolcheck_cache_")) |
|
1294 |
elif 'EPOCROOT' in os.environ: |
|
1295 |
cachefile_basename = str(generic_path.Join(os.environ['EPOCROOT'],"epoc32/build/toolcheck_cache_")) |
|
1296 |
else: |
|
1297 |
cachefile_basename = None |
|
1298 |
||
1299 |
tool_env_id = envhash(irrelevant_vars) |
|
1300 |
filemarker = "sbs_toolcache_2.8.2" |
|
1301 |
||
1302 |
def __init__(self, log = raptor_utilities.nulllog, forced=False): |
|
1303 |
self.__toolcheckcache = {} |
|
1304 |
||
1305 |
self.valid = True |
|
1306 |
self.checked = False |
|
1307 |
self.shellok = False |
|
1308 |
self.configname="" |
|
1309 |
self.cache_loaded = False |
|
1310 |
self.forced = forced |
|
1311 |
||
1312 |
self.log=log |
|
1313 |
||
1314 |
# Read in the tool cache |
|
1315 |
# |
|
1316 |
# The cache format is a hash key which identifies the |
|
1317 |
# command and the version that we're checking for. Then |
|
1318 |
# there are name,value pairs that record, e.g. the date |
|
1319 |
# of the command file or the name of the variable that |
|
1320 |
# the config uses for the tool (GNUCP or MWCC or whatever) |
|
1321 |
||
1322 |
if ToolSet.cachefile_basename: |
|
1323 |
self.cachefilename = ToolSet.cachefile_basename+".tmp" |
|
1324 |
if not self.forced: |
|
1325 |
try: |
|
1326 |
f = open(self.cachefilename, "r+") |
|
1327 |
# if this tool cache was recorded in |
|
1328 |
# a different environment then ignore it. |
|
1329 |
marker = f.readline().rstrip("\r\n") |
|
1330 |
if marker == ToolSet.filemarker: |
|
1331 |
env_id_tmp = f.readline().rstrip("\r\n") |
|
1332 |
if env_id_tmp == ToolSet.tool_env_id: |
|
1333 |
try: |
|
1334 |
for l in f.readlines(): |
|
1335 |
toolhistory = l.rstrip(",\n\r").split(",") |
|
1336 |
ce = {} |
|
1337 |
for i in toolhistory[1:]: |
|
1338 |
(name,val) = i.split("=") |
|
1339 |
if name == "valid": |
|
1340 |
val = bool(val) |
|
1341 |
elif name == "age": |
|
1342 |
val = int(val) |
|
1343 |
elif name == "date": |
|
1344 |
if val != "None": |
|
1345 |
val = float(val) |
|
1346 |
else: |
|
1347 |
val= None |
|
1348 |
||
1349 |
ce[name] = val |
|
1350 |
self.__toolcheckcache[toolhistory[0]] = ce |
|
1351 |
log.Info("Loaded toolcheck cache: %s\n", self.cachefilename) |
|
1352 |
except Exception, e: |
|
1353 |
log.Info("Ignoring garbled toolcheck cache: %s (%s)\n", self.cachefilename, str(e)) |
|
1354 |
self.__toolcheckcache = {} |
|
1355 |
||
1356 |
else: |
|
1357 |
log.Info("Toolcheck cache %s ignored - environment changed\n", self.cachefilename) |
|
1358 |
else: |
|
1359 |
log.Info("Toolcheck cache not loaded = marker missing: %s %s\n", self.cachefilename, ToolSet.filemarker) |
|
1360 |
f.close() |
|
1361 |
except IOError, e: |
|
1362 |
log.Info("Failed to load toolcheck cache: %s\n", self.cachefilename) |
|
1363 |
else: |
|
1364 |
log.Debug("Toolcheck cachefile not created because EPOCROOT not set in environment.\n") |
|
1365 |
||
1366 |
def check_shell(self): |
|
1367 |
# The command shell is a critical tool because all the other tools run |
|
1368 |
# within it so we must check for it first. It has to be in the path. |
|
1369 |
# bash 4 is preferred, 3 is accepted |
|
1370 |
try: |
|
1371 |
p = subprocess.Popen(args=[ToolSet.shell, '--version'], bufsize=1024, shell = False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) |
|
1372 |
shellversion_out, errtxt = p.communicate() |
|
1373 |
if ToolSet.shell_re.search(shellversion_out) == None: |
|
1374 |
self.log.Error("A critical tool, '%s', did not return the required version '%s':\n%s\nPlease check that '%s' is in the path.", ToolSet.shell, ToolSet.shell_version, shellversion_out, ToolSet.shell) |
|
1375 |
self.valid = False |
|
1376 |
except Exception,e: |
|
1377 |
self.log.Error("A critical tool could not be found.\nPlease check that '%s' is in the path. (%s)", ToolSet.shell, str(e)) |
|
1378 |
self.valid = False |
|
1379 |
||
1380 |
return self.valid |
|
1381 |
||
1382 |
def check(self, evaluator, configname): |
|
1383 |
"""Check the toolset for a particular config""" |
|
1384 |
||
1385 |
self.checked = True # remember that we did check something |
|
1386 |
||
1387 |
if not self.shellok: |
|
1388 |
self.shellok = self.check_shell() |
|
1389 |
self.shellok = True |
|
1390 |
||
1391 |
self.valid = self.valid and self.shellok |
|
1392 |
||
1393 |
cache = self.__toolcheckcache |
|
1394 |
for tool in evaluator.tools: |
|
1395 |
if not self.forced: |
|
1396 |
try: |
|
1397 |
t = cache[tool.key] |
|
1398 |
||
1399 |
except KeyError,e: |
|
1400 |
pass |
|
1401 |
else: |
|
1402 |
# if the cache has an entry for the tool then see if the date on |
|
1403 |
# the tool has changed (assuming the tool is a simple executable file) |
|
1404 |
if t.has_key('date') and (tool.date is None or (tool.date - t['date'] > 0.1)) : |
|
1405 |
self.log.Debug("toolcheck forced: '%s' changed since the last check: %s < %s", tool.command, str(t['date']), str(tool.date)) |
|
1406 |
else: |
|
1407 |
t['age'] = 0 # we used it so it's obviously needed |
|
1408 |
self.valid = self.valid and t['valid'] |
|
1409 |
self.log.Debug("toolcheck saved on: '%s'", tool.name) |
|
1410 |
continue |
|
1411 |
||
1412 |
||
1413 |
self.log.Debug("toolcheck done: %s -key: %s" % (tool.name, tool.key)) |
|
1414 |
||
5 | 1415 |
try: |
1416 |
tool.check(ToolSet.shell, evaluator, log = self.log) |
|
1417 |
except ToolErrorException, e: |
|
3 | 1418 |
self.valid = False |
5 | 1419 |
self.log.Error("%s\n" % str(e)) |
3 | 1420 |
|
1421 |
# Tool failures are cached just like successes - don't want to repeat them |
|
1422 |
cache[tool.key] = { "name" : tool.name, "valid" : tool.valid, "age" : 0 , "date" : tool.date } |
|
1423 |
||
1424 |
||
1425 |
def write(self): |
|
1426 |
"""Writes the tool check cache to disc. |
|
1427 |
||
1428 |
toolset.write() |
|
1429 |
""" |
|
1430 |
cache = self.__toolcheckcache |
|
1431 |
||
1432 |
# Write out the cache. |
|
1433 |
if self.checked and ToolSet.cachefile_basename: |
|
1434 |
self.log.Debug("Saving toolcache: %s", self.cachefilename) |
|
1435 |
try: |
|
1436 |
f = open(self.cachefilename, "w+") |
|
1437 |
f.write(ToolSet.filemarker+"\n") |
|
1438 |
f.write(ToolSet.tool_env_id+"\n") |
|
1439 |
for k,ce in cache.iteritems(): |
|
1440 |
||
1441 |
# If a tool has not been used for an extraordinarily long time |
|
1442 |
# then forget it - to prevent the cache from clogging up with old tools. |
|
1443 |
# Only write entries for tools that were found to be ok - so that the |
|
1444 |
# next time the ones that weren't will be re-tested |
|
1445 |
||
1446 |
if ce['valid'] and ce['age'] < 100: |
|
1447 |
ce['age'] += 1 |
|
1448 |
f.write("%s," % k) |
|
1449 |
for n,v in ce.iteritems(): |
|
1450 |
f.write("%s=%s," % (n,str(v))) |
|
1451 |
f.write("\n") |
|
1452 |
f.close() |
|
1453 |
self.log.Info("Created/Updated toolcheck cache: %s\n", self.cachefilename) |
|
1454 |
except Exception, e: |
|
1455 |
self.log.Info("Could not write toolcheck cache: %s", str(e)) |
|
1456 |
return self.valid |
|
1457 |
||
5 | 1458 |
class UninitialisedVariableException(Exception): |
1459 |
pass |
|
3 | 1460 |
|
374
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1461 |
class RecursionException(Exception): |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1462 |
pass |
96629a6f26e4
fault tolerant XML groups
Richard Taylor <richard.i.taylor@nokia.com>
parents:
371
diff
changeset
|
1463 |
|
3 | 1464 |
class Evaluator(object): |
1465 |
"""Determine the values of variables under different Configurations. |
|
1466 |
Either of specification and buildUnit may be None.""" |
|
1467 |
||
1468 |
||
1469 |
refRegex = re.compile("\$\((.+?)\)") |
|
1470 |
||
5 | 1471 |
def __init__(self, specification, buildUnit, cache, gathertools = False): |
3 | 1472 |
self.dict = {} |
1473 |
self.tools = [] |
|
1474 |
self.gathertools = gathertools |
|
5 | 1475 |
self.cache = cache |
3 | 1476 |
|
1477 |
specName = "none" |
|
1478 |
configName = "none" |
|
1479 |
||
1480 |
# A list of lists of operations. |
|
1481 |
opsLists = [] |
|
1482 |
||
1483 |
if buildUnit: |
|
5 | 1484 |
ol = buildUnit.GetOperations(cache) |
1485 |
self.buildUnit = buildUnit |
|
1486 |
||
1487 |
opsLists.extend( ol ) |
|
3 | 1488 |
|
1489 |
if specification: |
|
5 | 1490 |
for v in specification.GetAllVariantsRecursively(cache): |
1491 |
opsLists.extend( v.GetAllOperationsRecursively(cache) ) |
|
3 | 1492 |
|
1493 |
tools = {} |
|
1494 |
||
5 | 1495 |
unfound_values = [] |
3 | 1496 |
for opsList in opsLists: |
1497 |
for op in opsList: |
|
1498 |
# applying an Operation to a non-existent variable |
|
1499 |
# is OK. We assume that it is just an empty string. |
|
1500 |
try: |
|
1501 |
oldValue = self.dict[op.name] |
|
1502 |
except KeyError: |
|
1503 |
oldValue = "" |
|
1504 |
||
5 | 1505 |
try: |
1506 |
newValue = op.Apply(oldValue) |
|
1507 |
except BadToolValue, e: |
|
1508 |
unfound_values.append(str(e)) |
|
1509 |
newValue = "NO_VALUE_FOR_" + op.name |
|
1510 |
||
3 | 1511 |
self.dict[op.name] = newValue |
1512 |
||
1513 |
if self.gathertools: |
|
1514 |
if op.type == "tool" and op.versionCommand and op.versionResult: |
|
5 | 1515 |
tools[op.name] = Tool(op.name, newValue, op.versionCommand, op.versionResult, configName) |
3 | 1516 |
|
5 | 1517 |
if len(unfound_values) > 0: |
1518 |
raise UninitialisedVariableException("\n".join(unfound_values)) |
|
3 | 1519 |
|
1520 |
if self.gathertools: |
|
1521 |
self.tools = tools.values() |
|
1522 |
else: |
|
1523 |
self.tools=[] |
|
1524 |
||
1525 |
# resolve inter-variable references in the dictionary |
|
1526 |
unresolved = True |
|
1527 |
||
1528 |
for k, v in self.dict.items(): |
|
1529 |
self.dict[k] = v.replace("$$","__RAPTOR_ESCAPED_DOLLAR__") |
|
1530 |
||
1531 |
while unresolved: |
|
1532 |
unresolved = False |
|
1533 |
for k, v in self.dict.items(): |
|
1534 |
if v.find('$(' + k + ')') != -1: |
|
5 | 1535 |
raise RecursionException("Recursion Detected in variable '%s' in configuration '%s' " % (k,configName)) |
3 | 1536 |
else: |
1537 |
expanded = self.ExpandAll(v, specName, configName) |
|
1538 |
||
1539 |
if expanded != v: # something changed? |
|
1540 |
self.dict[k] = expanded |
|
1541 |
unresolved = True # maybe more to do |
|
1542 |
||
1543 |
# unquote double-dollar references |
|
1544 |
for k, v in self.dict.items(): |
|
1545 |
self.dict[k] = v.replace("__RAPTOR_ESCAPED_DOLLAR__","$") |
|
1546 |
||
1547 |
for t in self.tools: |
|
1548 |
t.expand(self) |
|
1549 |
||
1550 |
||
1551 |
||
1552 |
def Get(self, name): |
|
1553 |
"""return the value of variable 'name' or None if not found.""" |
|
1554 |
||
1555 |
if name in self.dict: |
|
1556 |
return self.dict[name] |
|
1557 |
else: |
|
1558 |
return None |
|
1559 |
||
1560 |
||
1561 |
def Resolve(self, name): |
|
1562 |
"""same as Get except that env variables are expanded. |
|
1563 |
||
1564 |
raises BadReferenceError if the variable 'name' exists but a |
|
1565 |
contained environment variable does not exist.""" |
|
1566 |
return self.Get(name) # all variables are now expanded anyway |
|
1567 |
||
1568 |
||
1569 |
def ResolveMatching(self, pattern): |
|
1570 |
""" Return a dictionary of all variables that match the pattern """ |
|
1571 |
for k,v in self.dict.iteritems(): |
|
1572 |
if pattern.match(k): |
|
1573 |
yield (k,v) |
|
1574 |
||
1575 |
||
1576 |
def ExpandAll(self, value, spec = "none", config = "none"): |
|
1577 |
"""replace all $(SOMETHING) in the string value. |
|
1578 |
||
1579 |
returns the newly expanded string.""" |
|
1580 |
||
1581 |
refs = Evaluator.refRegex.findall(value) |
|
1582 |
||
5 | 1583 |
# store up all the unset variables before raising an exception |
1584 |
# to allow us to find them all |
|
1585 |
unset_variables = [] |
|
1586 |
||
3 | 1587 |
for r in set(refs): |
1588 |
expansion = None |
|
1589 |
||
5 | 1590 |
if r in self.dict: |
3 | 1591 |
expansion = self.dict[r] |
1592 |
else: |
|
1593 |
# no expansion for $(r) |
|
5 | 1594 |
unset_variables.append("Unset variable '%s' used in spec '%s' with config '%s'" % (r, spec, config)) |
3 | 1595 |
if expansion != None: |
1596 |
value = value.replace("$(" + r + ")", expansion) |
|
1597 |
||
5 | 1598 |
if len(unset_variables) > 0: # raise them all |
1599 |
raise UninitialisedVariableException(". ".join(unset_variables)) |
|
1600 |
||
3 | 1601 |
return value |
1602 |
||
1603 |
||
1604 |
# raptor_data module functions |
|
1605 |
||
1606 |
||
1607 |
# end of the raptor_data module |