diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2024-04-18 14:20:07 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2024-04-24 20:40:34 -0700 |
commit | cf0fecfcef77235257546a43811559aa08b6c5de (patch) | |
tree | bfd6af76793cb5e5bf9ce0f0075303ebcd778251 | |
parent | fb5a0b4b61651e8ec5adb656a2957a792ae5d2d7 (diff) | |
download | meson-cf0fecfcef77235257546a43811559aa08b6c5de.zip meson-cf0fecfcef77235257546a43811559aa08b6c5de.tar.gz meson-cf0fecfcef77235257546a43811559aa08b6c5de.tar.bz2 |
backend/ninja: Fix bug in NinjaRule.length_estimate
The code would create a dictionary that was of type `str : list[str] |
str | None`. Then would later try to call `len(' '.join(dict[key]))`.
This would result in two different bugs:
1. If the value is `None` it would except, since None isn't iterable
and cannot be converted to a string
2. If the value was a string, then it would double the length of the
actual string and return that, by adding a space between each
character
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 885a97e..32a36a9 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -278,14 +278,13 @@ class NinjaRule: # determine variables # this order of actions only approximates ninja's scoping rules, as # documented at: https://ninja-build.org/manual.html#ref_scope - ninja_vars: T.Dict[str, T.Union[T.List[str], T.Optional[str]]] = {} - for e in elems: - name, value = e - ninja_vars[name] = value - ninja_vars['deps'] = self.deps - ninja_vars['depfile'] = self.depfile - ninja_vars['in'] = infiles - ninja_vars['out'] = outfiles + ninja_vars = dict(elems) + if self.deps is not None: + ninja_vars['deps'] = [self.deps] + if self.depfile is not None: + ninja_vars['depfile'] = [self.depfile] + ninja_vars['in'] = [infiles] + ninja_vars['out'] = [outfiles] # expand variables in command command = ' '.join([self._quoter(x) for x in self.command + self.args]) |