Skip to content

Commit

Permalink
backend/ninja: Fix bug in NinjaRule.length_estimate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dcbaker committed Apr 23, 2024
1 parent 01fc021 commit 5708a8b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,13 @@ def length_estimate(self, infiles: str, outfiles: str,
# 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])
Expand Down

0 comments on commit 5708a8b

Please sign in to comment.