Macro %define updates an existing macro.

Analysis of the current script shows a number of updates are happening
and this should be the default.
This commit is contained in:
Chris Johns
2013-03-08 13:58:48 +11:00
parent 79f80fd979
commit 50da39a33a
2 changed files with 33 additions and 14 deletions

View File

@@ -546,6 +546,10 @@ the output of this command becauses of its size.
$ ../source-builder/sb-defaults $ ../source-builder/sb-defaults
------------------------------------------------------------- -------------------------------------------------------------
A nested build set is given a separate copy of the defaults. Changes in one
change set are not seen in other build sets. That same happens with
configuration files unless inline includes are used.
Build Set Files Build Set Files
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
@@ -1092,8 +1096,8 @@ Source Builder. This can also be used as `%{error: message}`.
%define %define
^^^^^^^ ^^^^^^^
The +%define+ macro defines a new macro. If the macro being defined already The +%define+ macro defines a new macro or updates an existing one. If no value
exists a warning is raised. If you value is given it is assumed to be 1. is given it is assumed to be 1.
------------------------------------------------------------- -------------------------------------------------------------
%define foo bar %define foo bar

View File

@@ -200,6 +200,7 @@ class file:
self.opts = opts self.opts = opts
if self.opts.trace(): if self.opts.trace():
print 'config: %s' % (name) print 'config: %s' % (name)
self.disable_macro_reassign = False
self.configpath = [] self.configpath = []
self.wss = re.compile(r'\s+') self.wss = re.compile(r'\s+')
self.tags = re.compile(r':+') self.tags = re.compile(r':+')
@@ -370,7 +371,15 @@ class file:
expanded = True expanded = True
mn = None mn = None
elif m.startswith('%{echo'): elif m.startswith('%{echo'):
mn = None if not m.endswith('}'):
self._warning("malformed conditional macro '%s'" % (m))
mn = None
else:
e = self._expand(m[6:-1].strip())
self._output('%s' % (self._name_line_msg(e)))
s = ''
expanded = True
mn = None
elif m.startswith('%{defined'): elif m.startswith('%{defined'):
n = self._label(m[9:-1].strip()) n = self._label(m[9:-1].strip())
if n in self.defines: if n in self.defines:
@@ -432,15 +441,20 @@ class file:
self._warning('invalid macro definition') self._warning('invalid macro definition')
else: else:
d = self._label(ls[1]) d = self._label(ls[1])
if (d not in self.defines) or \ if self.disable_macro_reassign:
(d in self.defines and len(self.defines[d]) == 0): if (d not in self.defines) or \
(d in self.defines and len(self.defines[d]) == 0):
if len(ls) == 2:
self.defines[d] = '1'
else:
self.defines[d] = ls[2].strip()
else:
self._warning("macro '%s' already defined" % (d))
else:
if len(ls) == 2: if len(ls) == 2:
self.defines[d] = '1' self.defines[d] = '1'
else: else:
self.defines[d] = ls[2].strip() self.defines[d] = ls[2].strip()
else:
if self.opts.warn_all():
self._warning("macro '%s' already defined" % (d))
def _undefine(self, config, ls): def _undefine(self, config, ls):
if len(ls) <= 1: if len(ls) <= 1:
@@ -448,8 +462,9 @@ class file:
else: else:
mn = self._label(ls[1]) mn = self._label(ls[1])
if mn in self.defines: if mn in self.defines:
self._error("macro '%s' not defined" % (mn)) del self.defines[mn]
del self.defines[mn] else:
self._warning("macro '%s' not defined" % (mn))
def _ifs(self, config, ls, label, iftrue, isvalid): def _ifs(self, config, ls, label, iftrue, isvalid):
text = [] text = []
@@ -793,7 +808,7 @@ class file:
elif r[0] == 'control': elif r[0] == 'control':
if r[1] == '%end': if r[1] == '%end':
break break
self._warning("unexpected '" + r[1] + "'") self._warning("unexpected '%s'" % (r[1]))
elif r[0] == 'directive': elif r[0] == 'directive':
new_data = [] new_data = []
if r[1] == '%description': if r[1] == '%description':
@@ -840,11 +855,11 @@ class file:
# defines or can be accessed via macros. # defines or can be accessed via macros.
self._define(None, ('', info, info_data)) self._define(None, ('', info, info_data))
else: else:
self._warning("invalid format: '" + info_data[:-1] + "'") self._warning("invalid format: '%s'" % (info_data[:-1]))
else: else:
data.append(l) data.append(l)
else: else:
self._error("invalid parse state: '" + r[0] + "'") self._error("%d: invalid parse state: '%s" % (self.lc, r[0]))
if dir is not None: if dir is not None:
self._directive_extend(dir, data) self._directive_extend(dir, data)
except: except:
@@ -866,7 +881,7 @@ class file:
if n in self.defines: if n in self.defines:
d = self.defines[n] d = self.defines[n]
else: else:
raise error.general('macro "' + name + '" not found') raise error.general('%d: macro "%s" not found' % (self.lc, name))
return self._expand(d) return self._expand(d)
def set_define(self, name, value): def set_define(self, name, value):