Skip to content

Commit

Permalink
cmake/interpreter: Remove None from values we promise wont have None
Browse files Browse the repository at this point in the history
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. We need to actually remove them
from the list before we assign, so that it's actually a `List[Path]`.
While we're here I've simplified the logic a bit.

Closes: mesonbuild#13551
  • Loading branch information
dcbaker committed Aug 20, 2024
1 parent 28bff92 commit 5c7dc55
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mesonbuild/cmake/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import lru_cache
from os import environ
from pathlib import Path
import itertools
import re
import typing as T

Expand Down Expand Up @@ -416,11 +417,14 @@ def rel_path(x: Path, is_header: bool, is_generated: bool) -> T.Optional[Path]:
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:
Expand Down

0 comments on commit 5c7dc55

Please sign in to comment.