Skip to content

Commit cf0fecf

Browse files
committed
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
1 parent fb5a0b4 commit cf0fecf

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎mesonbuild/backend/ninjabackend.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ def length_estimate(self, infiles: str, outfiles: str,
278278
# determine variables
279279
# this order of actions only approximates ninja's scoping rules, as
280280
# documented at: https://ninja-build.org/manual.html#ref_scope
281-
ninja_vars: T.Dict[str, T.Union[T.List[str], T.Optional[str]]] = {}
282-
for e in elems:
283-
name, value = e
284-
ninja_vars[name] = value
285-
ninja_vars['deps'] = self.deps
286-
ninja_vars['depfile'] = self.depfile
287-
ninja_vars['in'] = infiles
288-
ninja_vars['out'] = outfiles
281+
ninja_vars = dict(elems)
282+
if self.deps is not None:
283+
ninja_vars['deps'] = [self.deps]
284+
if self.depfile is not None:
285+
ninja_vars['depfile'] = [self.depfile]
286+
ninja_vars['in'] = [infiles]
287+
ninja_vars['out'] = [outfiles]
289288

290289
# expand variables in command
291290
command = ' '.join([self._quoter(x) for x in self.command + self.args])

0 commit comments

Comments
 (0)