branch | fix |
changeset 386 | 8c80a05c93b7 |
parent 374 | 96629a6f26e4 |
child 400 | 554cc189839f |
385:cc1110af33a3 | 386:8c80a05c93b7 |
---|---|
63 return False |
63 return False |
64 |
64 |
65 |
65 |
66 # Make sure not to start up on an unsupported platform |
66 # Make sure not to start up on an unsupported platform |
67 if not HostPlatform.IsKnown(HostPlatform.hostplatform): |
67 if not HostPlatform.IsKnown(HostPlatform.hostplatform): |
68 raise Exception("raptor_data module loaded on an unrecognised platform '%s'. Expected one of %s" % (hostplatform, str(hostplatforms))) |
68 raise Exception("raptor_data module loaded on an unrecognised platform '%s'. Expected one of %s" % (HostPlatform.hostplatform, str(HostPlatform.hostplatforms))) |
69 |
69 |
70 |
70 |
71 # raptor_data module classes |
71 # raptor_data module classes |
72 |
72 |
73 class Model(object): |
73 class Model(object): |
137 |
137 |
138 def Resolve(self): |
138 def Resolve(self): |
139 raise BadReferenceError() |
139 raise BadReferenceError() |
140 |
140 |
141 def GetModifiers(self, cache): |
141 def GetModifiers(self, cache): |
142 return [ cache.FindNamedVariant(m) for m in self.modifiers ] |
142 mods = [] |
143 for m in self.modifiers: |
|
144 try: |
|
145 mods.append(cache.FindNamedVariant(m)) |
|
146 except KeyError: |
|
147 raise BadReferenceError(m) |
|
148 return mods |
|
143 |
149 |
144 def Valid(self): |
150 def Valid(self): |
145 return self.ref |
151 return self.ref |
146 |
152 |
147 |
153 |
708 self.default = default |
714 self.default = default |
709 |
715 |
710 |
716 |
711 def __str__(self): |
717 def __str__(self): |
712 attributes = "name='" + self.name + "' type='" + self.type + "'" |
718 attributes = "name='" + self.name + "' type='" + self.type + "'" |
713 if default != None: |
719 if self.default != None: |
714 attributes += " default='" + self.default + "'" |
720 attributes += " default='" + self.default + "'" |
715 |
721 |
716 if type == "tool": |
722 if type == "tool": |
717 attributes += " versionCommand='" + self.versionCommand + "' versionResult='" + self.versionResult + "'" |
723 attributes += " versionCommand='" + self.versionCommand + "' versionResult='" + self.versionResult + "'" |
718 |
724 |
904 for op in self.ops: |
910 for op in self.ops: |
905 s += str(op) + '\n' |
911 s += str(op) + '\n' |
906 s += "</var>" |
912 s += "</var>" |
907 return s |
913 return s |
908 |
914 |
909 import traceback |
|
910 class VariantRef(Reference): |
915 class VariantRef(Reference): |
911 |
916 |
912 def __init__(self, ref=None): |
917 def __init__(self, ref=None): |
913 Reference.__init__(self, ref = ref) |
918 Reference.__init__(self, ref = ref) |
914 |
919 |
916 return "<varRef ref='%s'/>" % self.ref |
921 return "<varRef ref='%s'/>" % self.ref |
917 |
922 |
918 def Resolve(self, cache): |
923 def Resolve(self, cache): |
919 try: |
924 try: |
920 return cache.FindNamedVariant(self.ref) |
925 return cache.FindNamedVariant(self.ref) |
921 except KeyError, e: |
926 except KeyError: |
922 raise BadReferenceError(self.ref) |
927 raise BadReferenceError(self.ref) |
923 |
928 |
924 class MissingVariantException(Exception): |
929 class MissingVariantException(Exception): |
925 pass |
930 pass |
926 |
931 |
959 self.variants.append( r.Resolve(cache=cache) ) |
964 self.variants.append( r.Resolve(cache=cache) ) |
960 except BadReferenceError: |
965 except BadReferenceError: |
961 missing_variants.append(r.ref) |
966 missing_variants.append(r.ref) |
962 |
967 |
963 if len(missing_variants) > 0: |
968 if len(missing_variants) > 0: |
964 raise MissingVariantException("Missing variants '%s'", " ".join(missing_variants)) |
969 raise MissingVariantException("Missing variants '%s'" % " ".join(missing_variants)) |
965 |
970 |
966 def GenerateBuildUnits(self, cache): |
971 def GenerateBuildUnits(self, cache): |
967 self.Resolve(cache) |
972 self.Resolve(cache) |
968 |
973 |
969 name = self.name |
974 name = self.name |
1024 s += "</group>" |
1029 s += "</group>" |
1025 return s |
1030 return s |
1026 |
1031 |
1027 def GenerateBuildUnits(self, cache): |
1032 def GenerateBuildUnits(self, cache): |
1028 units = [] |
1033 units = [] |
1029 |
1034 |
1030 missing_variants = [] |
1035 missing_variants = [] |
1031 for r in self.childRefs: |
1036 for r in self.childRefs: |
1032 refMods = r.GetModifiers(cache) |
|
1033 |
|
1034 try: |
1037 try: |
1035 obj = r.Resolve(cache=cache) |
1038 obj = r.Resolve(cache=cache) |
1036 except BadReferenceError: |
1039 except BadReferenceError: |
1037 missing_variants.append(r.ref) |
1040 missing_variants.append(r.ref) |
1038 else: |
1041 else: |
1039 obj.ClearModifiers() |
1042 obj.ClearModifiers() |
1040 |
1043 try: |
1041 for m in refMods + self.modifiers: |
1044 refMods = r.GetModifiers(cache) |
1042 obj.AddModifier(m) |
1045 except BadReferenceError,e: |
1043 |
1046 missing_variants.append(str(e)) |
1044 units.extend( obj.GenerateBuildUnits(cache) ) |
1047 else: |
1048 for m in refMods + self.modifiers: |
|
1049 obj.AddModifier(m) |
|
1050 |
|
1051 units.extend( obj.GenerateBuildUnits(cache) ) |
|
1045 |
1052 |
1046 if len(missing_variants) > 0: |
1053 if len(missing_variants) > 0: |
1047 raise MissingVariantException("Missing variants '%s'", " ".join(missing_variants)) |
1054 raise MissingVariantException("Missing variants '%s'" % " ".join(missing_variants)) |
1048 |
1055 |
1049 return units |
1056 return units |
1050 |
1057 |
1051 |
1058 |
1052 class GroupRef(Reference): |
1059 class GroupRef(Reference): |
1053 |
1060 |
1054 def __init__(self, ref=None): |
1061 def __init__(self, ref=None): |
1055 Reference.__init__(self, ref) |
1062 Reference.__init__(self, ref) |
1056 |
1063 |
1057 def __str__(self): |
1064 def __str__(self): |
1058 return "<%s /><groupRef ref='%s' mod='%s'/>" % (prefix, self.ref, ".".join(self.modifiers)) |
1065 return "<groupRef ref='%s' mod='%s'/>" % (self.ref, ".".join(self.modifiers)) |
1059 |
1066 |
1060 def Resolve(self, cache): |
1067 def Resolve(self, cache): |
1061 try: |
1068 try: |
1062 return cache.FindNamedGroup(self.ref) |
1069 return cache.FindNamedGroup(self.ref) |
1063 except KeyError: |
1070 except KeyError: |
1064 raise BadReferenceError(self.ref) |
1071 raise BadReferenceError(self.ref) |
1065 |
1072 |
1073 def GetBuildUnits(configNames, cache, logger): |
|
1074 """expand a list of config strings like "arm.v5.urel" into a list |
|
1075 of BuildUnit objects that can be queried for settings. |
|
1076 |
|
1077 The expansion tries to be tolerant of errors in the XML so that a |
|
1078 typo in one part of a group does not invalidate the whole group. |
|
1079 """ |
|
1080 |
|
1081 # turn dot-separated name strings into Model objects (Group, Alias, Variant) |
|
1082 models = [] |
|
1083 |
|
1084 for c in set(configNames): |
|
1085 ok = True |
|
1086 names = c.split(".") |
|
1087 |
|
1088 base = names[0] |
|
1089 mods = names[1:] |
|
1090 |
|
1091 if base in cache.groups: |
|
1092 x = cache.FindNamedGroup(base) |
|
1093 elif base in cache.aliases: |
|
1094 x = cache.FindNamedAlias(base) |
|
1095 elif base in cache.variants: |
|
1096 x = cache.FindNamedVariant(base) |
|
1097 else: |
|
1098 logger.Error("Unknown build configuration '%s'" % base) |
|
1099 continue |
|
1100 |
|
1101 x.ClearModifiers() |
|
1102 |
|
1103 for m in mods: |
|
1104 if m in cache.variants: |
|
1105 x.AddModifier( cache.FindNamedVariant(m) ) |
|
1106 else: |
|
1107 logger.Error("Unknown build variant '%s'" % m) |
|
1108 ok = False |
|
1109 |
|
1110 if ok: |
|
1111 models.append(copy.copy(x)) |
|
1112 |
|
1113 # turn Model objects into BuildUnit objects |
|
1114 # |
|
1115 # all objects have a GenerateBuildUnits method but don't use |
|
1116 # that for Groups because it is not tolerant of errors (the |
|
1117 # first error raises an exception and the rest of the group is |
|
1118 # abandoned) |
|
1119 units = [] |
|
1120 |
|
1121 while len(models) > 0: |
|
1122 x = models.pop() |
|
1123 try: |
|
1124 if isinstance(x, (Alias, Variant)): |
|
1125 # these we just turn straight into BuildUnits |
|
1126 units.extend(x.GenerateBuildUnits(cache)) |
|
1127 elif isinstance(x, Group): |
|
1128 # deal with each part of the group separately (later) |
|
1129 for child in x.childRefs: |
|
1130 modChild = copy.copy(child) |
|
1131 modChild.modifiers = child.modifiers + [m.name for m in x.modifiers] |
|
1132 models.append(modChild) |
|
1133 elif isinstance(x, Reference): |
|
1134 # resolve references and their modifiers |
|
1135 try: |
|
1136 obj = x.Resolve(cache) |
|
1137 modObj = copy.copy(obj) |
|
1138 modObj.modifiers = x.GetModifiers(cache) |
|
1139 except BadReferenceError,e: |
|
1140 logger.Error("Unknown reference '%s'" % str(e)) |
|
1141 else: |
|
1142 models.append(modObj) |
|
1143 except Exception, e: |
|
1144 logger.Error(str(e)) |
|
1145 |
|
1146 return units |
|
1147 |
|
1066 class ToolErrorException(Exception): |
1148 class ToolErrorException(Exception): |
1067 def __init__(self, s): |
1149 def __init__(self, s): |
1068 Exception.__init__(self,s) |
1150 Exception.__init__(self,s) |
1069 |
1151 |
1070 class Tool(object): |
1152 class Tool(object): |
1362 return self.valid |
1444 return self.valid |
1363 |
1445 |
1364 class UninitialisedVariableException(Exception): |
1446 class UninitialisedVariableException(Exception): |
1365 pass |
1447 pass |
1366 |
1448 |
1449 class RecursionException(Exception): |
|
1450 pass |
|
1451 |
|
1367 class Evaluator(object): |
1452 class Evaluator(object): |
1368 """Determine the values of variables under different Configurations. |
1453 """Determine the values of variables under different Configurations. |
1369 Either of specification and buildUnit may be None.""" |
1454 Either of specification and buildUnit may be None.""" |
1370 |
1455 |
1371 |
1456 |
1434 while unresolved: |
1519 while unresolved: |
1435 unresolved = False |
1520 unresolved = False |
1436 for k, v in self.dict.items(): |
1521 for k, v in self.dict.items(): |
1437 if v.find('$(' + k + ')') != -1: |
1522 if v.find('$(' + k + ')') != -1: |
1438 raise RecursionException("Recursion Detected in variable '%s' in configuration '%s' " % (k,configName)) |
1523 raise RecursionException("Recursion Detected in variable '%s' in configuration '%s' " % (k,configName)) |
1439 expanded = "RECURSIVE_INVALID_STRING" |
|
1440 else: |
1524 else: |
1441 expanded = self.ExpandAll(v, specName, configName) |
1525 expanded = self.ExpandAll(v, specName, configName) |
1442 |
1526 |
1443 if expanded != v: # something changed? |
1527 if expanded != v: # something changed? |
1444 self.dict[k] = expanded |
1528 self.dict[k] = expanded |