aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-03-22 21:49:47 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-05-31 17:49:29 -0400
commitae0b40945b08482d04b594187f266c77878a32b5 (patch)
treec615a0bc0d25ae7b3afbf96e2ddc228aae3de150 /mesonbuild/interpreter
parent38c00feb9d2004c05491f52d6ec40f2ed8467b4e (diff)
downloadmeson-ae0b40945b08482d04b594187f266c77878a32b5.zip
meson-ae0b40945b08482d04b594187f266c77878a32b5.tar.gz
meson-ae0b40945b08482d04b594187f266c77878a32b5.tar.bz2
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.
Diffstat (limited to 'mesonbuild/interpreter')
-rw-r--r--mesonbuild/interpreter/interpreter.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 53e819b..1876f21 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/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()