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 |
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): |
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): |
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 |