[libc++] Raise an exception if a Lit feature resolves to an invalid name

This allows reporting issues early when creating feature names.
This commit is contained in:
Louis Dionne 2020-06-15 12:19:32 -04:00
parent d1505233c8
commit 58610eb368
2 changed files with 12 additions and 0 deletions

View File

@ -194,6 +194,16 @@ class TestFeature(SetupConfigs):
feature.enableIn(self.config)
self.assertIn('name', self.config.available_features)
def test_name_is_not_a_string_1(self):
feature = dsl.Feature(name=None)
assert feature.isSupported(self.config)
self.assertRaises(ValueError, lambda: feature.enableIn(self.config))
def test_name_is_not_a_string_2(self):
feature = dsl.Feature(name=lambda cfg: None)
assert feature.isSupported(self.config)
self.assertRaises(ValueError, lambda: feature.enableIn(self.config))
def test_adding_compile_flag(self):
feature = dsl.Feature(name='name', compileFlag='-foo')
origLinkFlags = copy.deepcopy(self.getSubstitution('%{link_flags}'))

View File

@ -220,6 +220,8 @@ class Feature(object):
config.substitutions = addTo(config.substitutions, '%{link_flags}', linkFlag)
name = self._name(config) if callable(self._name) else self._name
if not isinstance(name, str):
raise ValueError("Feature did not resolve to a name that's a string, got {}".format(name))
config.available_features.add(name)