diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-11-15 20:41:31 -0500 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2022-12-05 12:33:17 -0800 |
commit | 9e8a3b9cbd5b90cc6384020ac5799ea054912f55 (patch) | |
tree | 9bc6c3c906683d50e1d149a18d2b9e5b18010e75 | |
parent | ce120ff164e67eb526ecfe70bf87bbb94050bc52 (diff) | |
download | meson-9e8a3b9cbd5b90cc6384020ac5799ea054912f55.zip meson-9e8a3b9cbd5b90cc6384020ac5799ea054912f55.tar.gz meson-9e8a3b9cbd5b90cc6384020ac5799ea054912f55.tar.bz2 |
when generating optional utility targets in ninja, skip existing aliases too
When auto-generating e.g. a `clang-format` target, we first check to see
if the user has already defined one, and if so we don't bother creating
our own. We check for two things:
- if a ninja target already exists, skip
- if a run_target was defined, skip
The second check is *obviously* a duplicate of the first check. But the
first check never actually worked, because all_outputs was only
generated *after* generating all utility rules and actually writing out
the build.ninja file. The check itself compares against nothing, and
always evaluates to false no matter what.
Fix this by reordering the target creation logic so we track outputs
immediately, but only error about them later. Now, we no longer need to
special-case run_target at all, so we can drop that whole logic from
build.py and interpreter.py, and simplify the tracked state.
Fixes defining an `alias_target()` for a utility, which tried to
auto-generate another rule and errored out. Also fixes doing the same
thing with a `custom_target()` although I cannot imagine why anyone
would want to produce an output file named `clang-format` (unless clang
itself decided to migrate to Meson, which would be cool but feels
unlikely).
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 13 | ||||
-rw-r--r-- | mesonbuild/build.py | 1 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 3 | ||||
-rw-r--r-- | test cases/common/51 run target/.clang-format | 1 | ||||
-rw-r--r-- | test cases/common/51 run target/.clang-tidy | 0 | ||||
-rw-r--r-- | test cases/common/51 run target/meson.build | 9 |
6 files changed, 14 insertions, 13 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 339867d..c583024 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -314,6 +314,7 @@ class NinjaBuildElement: self.orderdeps = OrderedSet() self.elems = [] self.all_outputs = all_outputs + self.output_errors = '' def add_dep(self, dep): if isinstance(dep, list): @@ -362,7 +363,8 @@ class NinjaBuildElement: self.rule.refcount += 1 def write(self, outfile): - self.check_outputs() + if self.output_errors: + raise MesonException(self.output_errors) ins = ' '.join([ninja_quote(i, True) for i in self.infilenames]) outs = ' '.join([ninja_quote(i, True) for i in self.outfilenames]) implicit_outs = ' '.join([ninja_quote(i, True) for i in self.implicit_outfilenames]) @@ -421,7 +423,7 @@ class NinjaBuildElement: def check_outputs(self): for n in self.outfilenames: if n in self.all_outputs: - raise MesonException(f'Multiple producers for Ninja target "{n}". Please rename your targets.') + self.output_errors = f'Multiple producers for Ninja target "{n}". Please rename your targets.' self.all_outputs[n] = True @dataclass @@ -1283,6 +1285,7 @@ class NinjaBackend(backends.Backend): self.ruledict[rule.name] = rule def add_build(self, build): + build.check_outputs() self.build_elements.append(build) if build.rulename != 'phony': @@ -3331,7 +3334,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) def generate_scanbuild(self): if not environment.detect_scanbuild(): return - if ('', 'scan-build') in self.build.run_target_names: + if 'scan-build' in self.all_outputs: return cmd = self.environment.get_build_command() + \ ['--internal', 'scanbuild', self.environment.source_dir, self.environment.build_dir] + \ @@ -3352,8 +3355,6 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) return if target_name in self.all_outputs: return - if ('', target_name) in self.build.run_target_names: - return cmd = self.environment.get_build_command() + \ ['--internal', 'clang' + name, self.environment.source_dir, self.environment.build_dir] + \ extra_args @@ -3378,8 +3379,6 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) import shutil if not shutil.which(tool): return - if ('', target_name) in self.build.run_target_names: - return if target_name in self.all_outputs: return cmd = self.environment.get_build_command() + \ diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0ef5122..2fd5626 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -236,7 +236,6 @@ class Build: self.environment = environment self.projects = {} self.targets: 'T.OrderedDict[str, T.Union[CustomTarget, BuildTarget]]' = OrderedDict() - self.run_target_names: T.Set[T.Tuple[str, str]] = set() self.global_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {}) self.global_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachine({}, {}) self.projects_args: PerMachine[T.Dict[str, T.Dict[str, T.List[str]]]] = PerMachine({}, {}) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 552f51c..59cb6e0 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1990,9 +1990,6 @@ class Interpreter(InterpreterBase, HoldableObject): tg = build.RunTarget(name, all_args, kwargs['depends'], self.subdir, self.subproject, self.environment, kwargs['env']) self.add_target(name, tg) - full_name = (self.subproject, name) - assert full_name not in self.build.run_target_names - self.build.run_target_names.add(full_name) return tg @FeatureNew('alias_target', '0.52.0') diff --git a/test cases/common/51 run target/.clang-format b/test cases/common/51 run target/.clang-format new file mode 100644 index 0000000..9b3aa8b --- /dev/null +++ b/test cases/common/51 run target/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: LLVM diff --git a/test cases/common/51 run target/.clang-tidy b/test cases/common/51 run target/.clang-tidy new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/51 run target/.clang-tidy diff --git a/test cases/common/51 run target/meson.build b/test cases/common/51 run target/meson.build index 85d30f0..dbb6732 100644 --- a/test cases/common/51 run target/meson.build +++ b/test cases/common/51 run target/meson.build @@ -78,8 +78,13 @@ custom_target('configure_script_ct', run_target('ctags', command : converter) -run_target('clang-format', - command : converter) +clangf = run_target('clang-format', + command : [converter, files('.clang-format'), meson.current_build_dir() / 'clang-format']) +custom_target('clang-tidy', + input: '.clang-tidy', + output: 'clang-tidy', + command : [converter, '@INPUT@', '@OUTPUT@']) +alias_target('clang-format-check', clangf) # Check we can pass env to the program. Also check some string substitutions # that were added in 0.57.0 but not documented. This is documented behaviour |