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
pull/10167/head
Eli Schwartz 3 years ago
parent dd2f1c4c57
commit 38c00feb9d
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 4
      mesonbuild/backend/ninjabackend.py
  2. 7
      mesonbuild/interpreter/interpreter.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)

@ -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.")

Loading…
Cancel
Save