'\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.TP
-.RI env.AppendUnique( key = val ", [...])"
+.RI env.AppendUnique( key = val ", [...], delete_existing=0)"
Appends the specified keyword arguments
to the end of construction variables in the environment.
If the Environment does not have
construction variable will
.I not
be added again to the list.
+However, if delete_existing is 1,
+existing matching values are removed first, so
+existing values in the arg list move to the end of the list.
Example:
'\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.TP
-.RI env.PrependUnique( key = val ", [...])"
+.RI env.PrependUnique( key = val ", delete_existing=0, [...])"
Appends the specified keyword arguments
to the beginning of construction variables in the environment.
If the Environment does not have
construction variable will
.I not
be added again to the list.
+However, if delete_existing is 1,
+existing matching values are removed first, so
+existing values in the arg list move to the front of the list.
Example:
self._dict[envname][name] = nv
- def AppendUnique(self, **kw):
+ def AppendUnique(self, delete_existing=0, **kw):
"""Append values to existing construction variables
in an Environment, if they're not already there.
+ If delete_existing is 1, removes existing values first, so
+ values move to end.
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
dk = self._dict[key]
if not SCons.Util.is_List(dk):
dk = [dk]
- val = filter(lambda x, dk=dk: x not in dk, val)
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
+ else:
+ val = filter(lambda x, dk=dk: x not in dk, val)
self._dict[key] = dk + val
else:
dk = self._dict[key]
if SCons.Util.is_List(dk):
# By elimination, val is not a list. Since dk is a
# list, wrap val in a list first.
- if not val in dk:
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
self._dict[key] = dk + [val]
+ else:
+ if not val in dk:
+ self._dict[key] = dk + [val]
else:
- self._dict[key] = self._dict[key] + val
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
+ self._dict[key] = dk + val
self.scanner_map_delete(kw)
def Clone(self, tools=[], toolpath=None, parse_flags = None, **kw):
self._dict[envname][name] = nv
- def PrependUnique(self, **kw):
- """Append values to existing construction variables
+ def PrependUnique(self, delete_existing=0, **kw):
+ """Prepend values to existing construction variables
in an Environment, if they're not already there.
+ If delete_existing is 1, removes existing values first, so
+ values move to front.
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
dk = self._dict[key]
if not SCons.Util.is_List(dk):
dk = [dk]
- val = filter(lambda x, dk=dk: x not in dk, val)
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
+ else:
+ val = filter(lambda x, dk=dk: x not in dk, val)
self._dict[key] = val + dk
else:
dk = self._dict[key]
if SCons.Util.is_List(dk):
# By elimination, val is not a list. Since dk is a
# list, wrap val in a list first.
- if not val in dk:
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
self._dict[key] = [val] + dk
+ else:
+ if not val in dk:
+ self._dict[key] = [val] + dk
else:
+ if delete_existing:
+ dk = filter(lambda x, val=val: x not in val, dk)
self._dict[key] = val + dk
self.scanner_map_delete(kw)
BBB4 = ['b4'],
BBB5 = ['b5'],
CCC1 = '',
- CCC2 = '')
+ CCC2 = '',
+ DDD1 = ['a', 'b', 'c'])
env.AppendUnique(AAA1 = 'a1',
AAA2 = ['a2'],
AAA3 = ['a3', 'b', 'c', 'a3'],
BBB4 = 'b4.new',
BBB5 = ['b5.new'],
CCC1 = 'c1',
- CCC2 = ['c2'])
+ CCC2 = ['c2'],
+ DDD1 = 'b')
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
assert env['BBB5'] == ['b5', 'b5.new'], env['BBB5']
assert env['CCC1'] == 'c1', env['CCC1']
assert env['CCC2'] == ['c2'], env['CCC2']
+ assert env['DDD1'] == ['a', 'b', 'c'], env['DDD1']
+ env.AppendUnique(DDD1 = 'b', delete_existing=1)
+ assert env['DDD1'] == ['a', 'c', 'b'], env['DDD1'] # b moves to end
+ env.AppendUnique(DDD1 = ['a','b'], delete_existing=1)
+ assert env['DDD1'] == ['c', 'a', 'b'], env['DDD1'] # a & b move to end
+
env['CLVar'] = CLVar([])
env.AppendUnique(CLVar = 'bar')
result = env['CLVar']
BBB4 = ['b4'],
BBB5 = ['b5'],
CCC1 = '',
- CCC2 = '')
+ CCC2 = '',
+ DDD1 = ['a', 'b', 'c'])
env.PrependUnique(AAA1 = 'a1',
AAA2 = ['a2'],
AAA3 = ['a3', 'b', 'c', 'a3'],
BBB4 = 'b4.new',
BBB5 = ['b5.new'],
CCC1 = 'c1',
- CCC2 = ['c2'])
+ CCC2 = ['c2'],
+ DDD1 = 'b')
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
assert env['AAA3'] == ['b', 'c', 'a3'], env['AAA3']
assert env['BBB5'] == ['b5.new', 'b5'], env['BBB5']
assert env['CCC1'] == 'c1', env['CCC1']
assert env['CCC2'] == ['c2'], env['CCC2']
+ assert env['DDD1'] == ['a', 'b', 'c'], env['DDD1']
+
+ env.PrependUnique(DDD1 = 'b', delete_existing=1)
+ assert env['DDD1'] == ['b', 'a', 'c'], env['DDD1'] # b moves to front
+ env.PrependUnique(DDD1 = ['a','c'], delete_existing=1)
+ assert env['DDD1'] == ['a', 'c', 'b'], env['DDD1'] # a & c move to front
+
env['CLVar'] = CLVar([])
env.PrependUnique(CLVar = 'bar')