From 0549e0260279c53d7c3cd9449c32a02b6f62979d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 1 Jul 2024 11:28:00 -0700 Subject: [PATCH] backends/ninja: cleanup dep handling a bit --- mesonbuild/backend/ninjabackend.py | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 1fba26a6139d..e81d66021d32 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3062,12 +3062,7 @@ def generate_single_compile(self, target: build.BuildTarget, self.add_full_deps(target, element, header_deps) for d in extra_deps: element.add_dep(d) - for d in order_deps: - if isinstance(d, File): - d = d.rel_to_builddir(self.build_to_src) - elif not self.has_dir_part(d): - d = os.path.join(self.get_target_private_dir(target), d) - element.add_orderdep(d) + self.add_order_deps(target, element, order_deps) element.add_dep(pch_dep) for i in self.get_fortran_orderdeps(target, compiler): element.add_orderdep(i) @@ -3120,6 +3115,17 @@ def add_dependency_scanner_entries_to_element(self, target: build.BuildTarget, c def get_dep_scan_file_for(self, target: build.BuildTarget) -> str: return os.path.join(self.get_target_private_dir(target), 'depscan.dd') + def _add_deps(self, target: build.BuildTarget, deps: T.Sequence[mesonlib.FileOrString], + to: T.Callable[[str], None]) -> None: + if isinstance(deps, str): + deps = [deps] + for d in deps: + if isinstance(d, File): + d = d.rel_to_builddir(self.build_to_src) + elif not self.has_dir_part(d): + d = os.path.join(self.get_target_private_dir(target), d) + to(d) + def add_full_deps(self, target: build.BuildTarget, ninja_element: NinjaBuildElement, deps: T.Sequence[mesonlib.FileOrString]) -> None: """Add multiple full dependencies. @@ -3128,14 +3134,17 @@ def add_full_deps(self, target: build.BuildTarget, ninja_element: NinjaBuildElem :param ninja_element: The Ninja build Element being modified :param deps: The dependencies being added """ - if isinstance(deps, str): - deps = [deps] - for d in deps: - if isinstance(d, File): - d = d.rel_to_builddir(self.build_to_src) - elif not self.has_dir_part(d): - d = os.path.join(self.get_target_private_dir(target), d) - ninja_element.add_dep(d) + self._add_deps(target, deps, ninja_element.add_dep) + + def add_order_deps(self, target: build.BuildTarget, ninja_element: NinjaBuildElement, + deps: T.Sequence[mesonlib.FileOrString]) -> None: + """Add multiple order-only dependencies. + + :param target: The Target which the sources come from + :param ninja_element: The Ninja build Element being modified + :param deps: The dependencies being added + """ + self._add_deps(target, deps, ninja_element.add_orderdep) def has_dir_part(self, fname: mesonlib.FileOrString) -> bool: # FIXME FIXME: The usage of this is a terrible and unreliable hack @@ -3202,7 +3211,7 @@ def generate_mwcc_pch_command(self, target, compiler, pch): dep = os.path.splitext(dst)[0] + '.' + compiler.get_depfile_suffix() return commands, dep, dst, [] # mwcc compilers do not create an object file during pch generation. - def generate_pch(self, target, header_deps=None): + def generate_pch(self, target: build.BuildTarget, header_deps: T.Optional[T.Sequence[mesonlib.FileOrString]] = None) -> T.List[str]: header_deps = header_deps if header_deps is not None else [] pch_objects = [] for lang in ['c', 'cpp']: