diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-11 17:12:20 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-06-11 18:56:54 -0400 |
commit | 82d0d1755d5c88e0415a3deb4102d4cdcf0d7435 (patch) | |
tree | c1c0727c82cec0f59639bcd1590fb08f9af8f78c | |
parent | f2f42318ed047ebf25cfb53c24faf6c15539fff6 (diff) | |
download | meson-82d0d1755d5c88e0415a3deb4102d4cdcf0d7435.zip meson-82d0d1755d5c88e0415a3deb4102d4cdcf0d7435.tar.gz meson-82d0d1755d5c88e0415a3deb4102d4cdcf0d7435.tar.bz2 |
ninja backend: fix cleandead deleting files that meson implicitly creates
Specifically, when those files can be created by a build rule with one
version of meson.build, and created as e.g. a shared_library alias
symlink in another version of meson.build, the cleandead command will
delete important files just because they don't happen to be created by
ninja itself.
Work around this by making a dummy rule that exists solely to insert the
files into the build graph to trick ninja into not deleting them.
Closes #11861
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5aeaa48..08f2b9d 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -488,6 +488,7 @@ class NinjaBackend(backends.Backend): self.introspection_data = {} self.created_llvm_ir_rule = PerMachine(False, False) self.rust_crates: T.Dict[str, RustCrate] = {} + self.implicit_meson_outs = [] def create_phony_target(self, all_outputs, dummy_outfile, rulename, phony_infilename, implicit_outs=None): ''' @@ -3439,17 +3440,20 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) def generate_shlib_aliases(self, target, outdir): for alias, to, tag in target.get_aliases(): - aliasfile = os.path.join(self.environment.get_build_dir(), outdir, alias) + aliasfile = os.path.join(outdir, alias) + abs_aliasfile = os.path.join(self.environment.get_build_dir(), outdir, alias) try: - os.remove(aliasfile) + os.remove(abs_aliasfile) except Exception: pass try: - os.symlink(to, aliasfile) + os.symlink(to, abs_aliasfile) except NotImplementedError: mlog.debug("Library versioning disabled because symlinks are not supported.") except OSError: mlog.debug("Library versioning disabled because we do not have symlink creation privileges.") + else: + self.implicit_meson_outs.append(aliasfile) def generate_custom_target_clean(self, trees: T.List[str]) -> str: e = self.create_phony_target(self.all_outputs, 'clean-ctlist', 'CUSTOM_COMMAND', 'PHONY') @@ -3611,6 +3615,12 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) elem.add_item('pool', 'console') self.add_build(elem) + # If these files used to be explicitly created, they need to appear on the build graph somehow, + # otherwise cleandead deletes them. See https://github.com/ninja-build/ninja/issues/2299 + if self.implicit_meson_outs: + elem = NinjaBuildElement(self.all_outputs, 'meson-implicit-outs', 'phony', self.implicit_meson_outs) + self.add_build(elem) + elem = NinjaBuildElement(self.all_outputs, 'reconfigure', 'REGENERATE_BUILD', 'PHONY') elem.add_item('pool', 'console') self.add_build(elem) |