From 38c00feb9d2004c05491f52d6ec40f2ed8467b4e Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 26 May 2022 22:49:50 -0400 Subject: relax target name restrictions to cater to internal use We don't want to allow targets that conflict with: - our aliased meson-* targets for phony commands - any meson-*/ directories we create for internal purposes We do want to allow targets such as: - our own meson-*.X manpages There are a couple routes we could take. Using a better restriction, such as `meson-internal__*`, is trivially done for our aliased targets, but changing directory names is... awkward. We probably cannot do this, and doing the former but not the latter is not very useful. We could also carefully allow patterns we know we won't use, such as file extensions, but which the manpages need, which works for our directories and for many aliased targets, but run_target() is user-specified and can be anything. Use a hybrid approach to cover both use cases. We will now allow target names that fulfill *all* the following criteria: - it begins with "meson-" - it doesn't continue with "internal__" - it has a file extension --- mesonbuild/backend/ninjabackend.py | 4 ++-- mesonbuild/interpreter/interpreter.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index c6f82e3e1..5c77dc29f 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -442,10 +442,10 @@ class NinjaBackend(backends.Backend): 'benchmark', etc, and also for RunTargets. https://github.com/mesonbuild/meson/issues/1644 ''' - if dummy_outfile.startswith('meson-'): + if dummy_outfile.startswith('meson-internal__'): raise AssertionError(f'Invalid usage of create_phony_target with {dummy_outfile!r}') - to_name = f'meson-{dummy_outfile}' + to_name = f'meson-internal__{dummy_outfile}' elem = NinjaBuildElement(all_outputs, dummy_outfile, 'phony', to_name) self.add_build(elem) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index af83c0e54..53e819b8c 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2927,9 +2927,12 @@ 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-'): - raise InvalidArguments("Target names starting with 'meson-' are reserved " + 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.") -- cgit v1.2.3