Skip to content

Commit cdfa46c

Browse files
author
Bogdan Marinescu
committed
Fixes to the new targets code
It is now possible to remove a macro using "_remove" for both macros without vale (MACRO) and macros with value (MACRO=VALUE) simply by specifying the macro name.
1 parent 96b03b9 commit cdfa46c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tools/targets.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,24 @@ def __getattr_helper(self, attrname):
140140
v.extend(data[attrname + "_add"])
141141
# Do we have anything to remove ?
142142
if data.has_key(attrname + "_remove"):
143-
[v.remove(e) for e in data[attrname + "_remove"]]
143+
# Macros can be defined either without a value (MACRO) or with a value (MACRO=10).
144+
# When removing, we specify only the name of the macro, without the value. So we need
145+
# to create a mapping between the macro name and its value. This will work for
146+
# extra_labels and other type of arrays as well, since they fall into the "macros
147+
# without a value" category (simple definitions without a value).
148+
name_def_map = {}
149+
for crtv in v:
150+
if crtv.find('=') != -1:
151+
temp = crtv.split('=')
152+
if len(temp) != 2:
153+
raise ValueError("Invalid macro definition '%s'" % crtv)
154+
name_def_map[temp[0]] = crtv
155+
else:
156+
name_def_map[crtv] = crtv
157+
for e in data[attrname + "_remove"]:
158+
if not e in name_def_map:
159+
raise ValueError("Unable to remove '%s' in '%s.%s' since it doesn't exist" % (e, self.name, attrname))
160+
v.remove(name_def_map[e])
144161
return v
145162
# Look for the attribute in the class and its parents, as defined by the resolution order
146163
v = None
@@ -191,7 +208,7 @@ def init_hooks(self, hook, toolchain_name):
191208
# A hook was found. The hook's name is in the format "classname.functionname"
192209
temp = hook_data["function"].split(".")
193210
if len(temp) != 2:
194-
raise HookException("Invalid format for hook '%s' in target '%s' (must be 'class_name.function_name')" % (hook_data["function"], self.name))
211+
raise HookError("Invalid format for hook '%s' in target '%s' (must be 'class_name.function_name')" % (hook_data["function"], self.name))
195212
class_name, function_name = temp[0], temp[1]
196213
# "class_name" must refer to a class in this file, so check if the class exists
197214
mdata = self.get_module_data()

0 commit comments

Comments
 (0)