Skip to content

Commit

Permalink
backends/ninja: cleanup dep handling a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Jul 1, 2024
1 parent 1e5ad87 commit 0549e02
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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']:
Expand Down

0 comments on commit 0549e02

Please sign in to comment.