From ae0b40945b08482d04b594187f266c77878a32b5 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 22 Mar 2022 21:49:47 -0400 Subject: 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. --- mesonbuild/interpreter/interpreter.py | 24 +++++++++++++++--------- 1 file 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() -- cgit v1.1