make sure no custom_target outputs are named "all" or "meson-internal__*"

Or any other reserved names. We check in add_target that the primary
name of any build target isn't on the forbidden list, but custom_target
allows names that are distinct from the output filenames, so we need to
check those too.

We would eventually still error out all the way at the end, with:

```
ERROR: Multiple producers for Ninja target "all". Please rename your targets.
```

But, if we can check that early and provide the underlying reason
(reserved name) alongside actually useful debugging info (a line
number), then why not?

Refactor the check into a small helper function in the process.
pull/10167/head
Eli Schwartz 3 years ago
parent 38c00feb9d
commit ae0b40945b
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 24
      mesonbuild/interpreter/interpreter.py

@ -1924,6 +1924,8 @@ class Interpreter(InterpreterBase, HoldableObject):
f'(there are {len(kwargs["install_tag"])} install_tags, '
f'and {len(kwargs["output"])} outputs)')
for t in kwargs['output']:
self.validate_forbidden_targets(t)
self._validate_custom_target_outputs(len(inputs) > 1, kwargs['output'], "custom_target")
tg = build.CustomTarget(
@ -2914,6 +2916,18 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey
'string or File-type object')
return results
@staticmethod
def validate_forbidden_targets(name: str) -> None:
if name.startswith('meson-internal__'):
raise InvalidArguments("Target names starting with 'meson-internal__' are reserved "
"for Meson's internal use. Please rename.")
if name.startswith('meson-') and '.' not in name:
raise InvalidArguments("Target names starting with 'meson-' and without a file extension "
"are reserved for Meson's internal use. Please rename.")
if name in coredata.FORBIDDEN_TARGET_NAMES:
raise InvalidArguments(f"Target name '{name}' is reserved for Meson's "
"internal use. Please rename.")
def add_target(self, name, tobj):
if name == '':
raise InterpreterException('Target name must not be empty.')
@ -2927,15 +2941,7 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey
To define a target that builds in that directory you must define it
in the meson.build file in that directory.
'''))
if name.startswith('meson-internal__'):
raise InvalidArguments("Target names starting with 'meson-internal__' are reserved "
"for Meson's internal use. Please rename.")
if name.startswith('meson-') and '.' not in name:
raise InvalidArguments("Target names starting with 'meson-' and without a file extension "
"are reserved for Meson's internal use. Please rename.")
if name in coredata.FORBIDDEN_TARGET_NAMES:
raise InvalidArguments(f"Target name '{name}' is reserved for Meson's "
"internal use. Please rename.")
self.validate_forbidden_targets(name)
# To permit an executable and a shared library to have the
# same name, such as "foo.exe" and "libfoo.a".
idname = tobj.get_id()

Loading…
Cancel
Save