Skip to content

Commit

Permalink
environment: make sure multiple-name program lookup is always equal
Browse files Browse the repository at this point in the history
We support this in a machine file:

```
[binaries]
pkgconfig = 'pkg-config'
pkg-config = 'pkg-config'
```

and you can use either one, because internally we look up both. But this
plays awkwardly with setting $PKG_CONFIG, since we don't know which one
you set in the machine file and the *other* one will be initialized from
the environment instead.

We can't solve this by changing the order of lookup, because we need to
know that we checked for machine file entries before falling back to the
environment. Instead, make one compatible machine file entry propagate
to the other possibilities before we finish populating the binary table
with environment variables.
  • Loading branch information
eli-schwartz committed Aug 1, 2023
1 parent 7c95561 commit f5ecafc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ def __init__(self, source_dir: T.Optional[str], build_dir: T.Optional[str], opti
# Command line options override those from cross/native files
self.options.update(options.cmd_line_options)

# Normalize inconsistent legacy binary names before falling back to env.
self._match_remapped_names()
# Take default value from env if not set in cross/native files or command line.
self._set_default_options_from_env()
self._set_default_binaries_from_env()
Expand Down Expand Up @@ -734,6 +736,21 @@ def _set_default_options_from_env(self) -> None:
if k not in self.options:
self.options[k] = v

def _match_remapped_names(self) -> None:
"""Some binaries can appear in a machine file under multiple names."""

bins = [('pkg-config', 'pkgconfig')]
for binset, for_machine in itertools.product(bins, MachineChoice):
canonical: T.Optional[T.List[str]] = None
for name in binset:
hit = self.lookup_binary_entry(for_machine, name)
if hit is not None:
canonical = hit
break
if canonical:
for name in binset:
self.binaries[for_machine].binaries.setdefault(name, canonical)

def _set_default_binaries_from_env(self) -> None:
"""Set default binaries from the environment.
Expand Down

0 comments on commit f5ecafc

Please sign in to comment.