Skip to content

Commit e3ab0ee

Browse files
committed
[build-presets] Support expansion of preset option names
This allows me to selectively enable build features (such as building lldb, building swiftpm reconfiguring etc.) locally from a single preset.
1 parent 237338b commit e3ab0ee

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

utils/build_swift/build_swift/presets.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,23 @@ def _get_preset(self, name):
361361
def _interpolate_preset_vars(self, preset, vars):
362362
interpolated_options = []
363363
for (name, value) in preset.options:
364-
try:
365-
value = _interpolate_string(value, vars)
366-
except KeyError as e:
367-
raise InterpolationError(
368-
preset.name, name, value, e.args[0])
364+
# If the option is a key-value pair, e.g.
365+
# install-destdir=%(install_dir)s
366+
# interpolate the value. If it is a raw option, e.g.
367+
# %(some_flag)s
368+
# is a raw option without a value, expand the name.
369+
if value:
370+
try:
371+
value = _interpolate_string(value, vars)
372+
except KeyError as e:
373+
raise InterpolationError(
374+
preset.name, name, value, e.args[0])
375+
else:
376+
try:
377+
name = _interpolate_string(name, vars)
378+
except KeyError as e:
379+
raise InterpolationError(
380+
preset.name, name, name, e.args[0])
369381

370382
interpolated_options.append((name, value))
371383

utils/build_swift/tests/build_swift/test_presets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
ios
114114
"""
115115

116+
EXPAND_OPTION_NAME = """
117+
[preset: test]
118+
119+
%(my_option)s
120+
"""
121+
116122

117123
# -----------------------------------------------------------------------------
118124

@@ -281,3 +287,12 @@ def test_preset_names(self):
281287

282288
self.assertEqual(set(parser.preset_names),
283289
set(['foo', 'bar', 'baz']))
290+
291+
def test_expand_option_name(self):
292+
parser = PresetParser()
293+
parser.read_string(EXPAND_OPTION_NAME)
294+
295+
preset = parser.get_preset('test', vars={'my_option': 'macos'})
296+
self.assertEqual(preset.options, [
297+
('macos', None),
298+
])

0 commit comments

Comments
 (0)