diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-08-20 11:29:56 -0700 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-08-26 12:23:03 -0400 |
| commit | 75e5ca58374fc7d070a6e34822046391cc5a24e5 (patch) | |
| tree | 65f5160a745549c86aa204bc7c5d8fe75481ebf4 | |
| parent | 08a46bb6c5aabb7fccafe95afd7b10a75e9f3e07 (diff) | |
| download | meson-75e5ca58374fc7d070a6e34822046391cc5a24e5.tar.gz | |
cmake/interpreter: Remove None from values we promise wont have None
We've documented these lists as being `List[Path]`, but then we have the
potential to insert a None into them via the `rel_path()` function,
which can return `None` in some cases. Currently we fix some (but not
all) of these later, but we should actually remove them from the list
before we assign, so that it's actually a `List[Path]` at all times.
While we're here I've simplified the logic a bit.
Closes: #13551
| -rw-r--r-- | mesonbuild/cmake/interpreter.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index b427132f6..a0fcb6972 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -8,6 +8,7 @@ from __future__ import annotations from functools import lru_cache from os import environ from pathlib import Path +import itertools import re import typing as T @@ -416,11 +417,14 @@ class ConverterTarget: return x.relative_to(root_src_dir) return x + def non_optional(inputs: T.Iterable[T.Optional[Path]]) -> T.List[Path]: + return [p for p in inputs if p is not None] + build_dir_rel = self.build_dir.relative_to(Path(self.env.get_build_dir()) / subdir) - self.generated_raw = [rel_path(x, False, True) for x in self.generated_raw] - self.includes = list(OrderedSet([rel_path(x, True, False) for x in OrderedSet(self.includes)] + [build_dir_rel])) - self.sys_includes = list(OrderedSet([rel_path(x, True, False) for x in OrderedSet(self.sys_includes)])) - self.sources = [rel_path(x, False, False) for x in self.sources] + self.generated_raw = non_optional(rel_path(x, False, True) for x in self.generated_raw) + self.includes = non_optional(itertools.chain((rel_path(x, True, False) for x in OrderedSet(self.includes)), [build_dir_rel])) + self.sys_includes = non_optional(rel_path(x, True, False) for x in OrderedSet(self.sys_includes)) + self.sources = non_optional(rel_path(x, False, False) for x in self.sources) # Resolve custom targets for gen_file in self.generated_raw: @@ -430,14 +434,9 @@ class ConverterTarget: ref = ctgt.get_ref(gen_file) assert isinstance(ref, CustomTargetReference) and ref.valid() self.generated_ctgt += [ref] - elif gen_file is not None: + else: self.generated += [gen_file] - # Remove delete entries - self.includes = [x for x in self.includes if x is not None] - self.sys_includes = [x for x in self.sys_includes if x is not None] - self.sources = [x for x in self.sources if x is not None] - # Make sure '.' is always in the include directories if Path('.') not in self.includes: self.includes += [Path('.')] |
