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
pull/13603/head
Dylan Baker 3 months ago committed by Eli Schwartz
parent 08a46bb6c5
commit 75e5ca5837
  1. 19
      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('.')]

Loading…
Cancel
Save