Naturally use env vars a bit more to match Autoconf

PR #6363 made it so our interpretation of env vars no longer clashed
with Autoconf's: if both Meson and Autoconf would read and env var, both
would do the same things with the value they read.

However, there were still cases that autoconf would read an env var when
meson wouldn't:

 - Autoconf would use `CC` in cross builds too

 - Autoconf would use `CC_FOR_BUILD` in native builds too.

There's no reason Meson can't also do this--if native cross files
overwrite rather than replace env vars, cross files can also overwrite
rather than replace env vars.

Because variables like `CC` are so ubiquitous, and because ignoring them
in cross builds just makes those builds liable to break (and things more
complicated in general), we bring Meson's behavior in line with
Autoconf's.
pull/6798/merge
John Ericson 5 years ago committed by Jussi Pakkanen
parent 3a4388e51d
commit 097dfc085e
  1. 15
      docs/markdown/howtox.md
  2. 10
      docs/markdown/snippets/env_vars_and_cross.md
  3. 4
      mesonbuild/envconfig.py
  4. 5
      run_unittests.py

@ -12,15 +12,16 @@ When first running Meson, set it in an environment variable.
$ CC=mycc meson <options>
```
Note that environment variables like `CC` only works in native builds. The `CC`
refers to the compiler for the host platform, that is the compiler used to
compile programs that run on the machine we will eventually install the project
on. The compiler used to build things that run on the machine we do the
building can be specified with `CC_FOR_BUILD`. You can use it in cross builds.
Note that environment variables like `CC` only refer to the host platform in
cross builds. That is, the `CC` refers compiler used to compile programs that
run on the machine we will eventually install the project on. The compiler used
to build things that run on the machine we do the building can be specified
with `CC_FOR_BUILD`. You can always used `CC_FOR_BUILD`, but for native builds
it is less well known because Meson (and Autotools) will default `CC_FOR_BUILD`
with `CC`.
Note that environment variables are never the idiomatic way to do anything with
Meson, however. It is better to use the native and cross files. And the tools
for the host platform in cross builds can only be specified with a cross file.
Meson, however. It is better to use the native and cross files.
There is a table of all environment variables supported [Here](Reference-tables.md#compiler-and-linker-selection-variables)

@ -2,11 +2,11 @@
Previously in Meson, variables like `CC` effected both the host and build
platforms for native builds, but the just the build platform for cross builds.
Now `CC_FOR_BUILD` is used for the build platform in cross builds.
Now `CC` always effects the host platform, and `CC_FOR_BUILD` always affects
the build platform, with `CC` also effecting the build platform for native
builds only when `CC_FOR_BUILD` is not defined.
This old behavior is inconsistent with the way Autotools works, which
undermines the purpose of distro-integration that is the only reason
environment variables are supported at all in Meson. The new behavior is not
quite the same, but doesn't conflict: meson doesn't always repond to an
environment when Autoconf would, but when it does it interprets it as Autotools
would.
environment variables are supported at all in Meson. The new behavior is
consistent.

@ -119,9 +119,9 @@ def get_env_var_pair(for_machine: MachineChoice,
# compiling we fall back on the unprefixed host version. This
# allows native builds to never need to worry about the 'BUILD_*'
# ones.
([var_name + '_FOR_BUILD'] if is_cross else [var_name]),
[var_name + '_FOR_BUILD'] + ([] if is_cross else [var_name]),
# Always just the unprefixed host verions
([] if is_cross else [var_name]),
[var_name],
)[for_machine]
for var in candidates:
value = os.environ.get(var)

@ -6338,11 +6338,10 @@ c = ['{0}']
testdir = os.path.join(self.unit_test_dir, '61 identity cross')
env = {
'CC_FOR_BUILD': '"' + os.path.join(testdir, 'build_wrapper.py') + '"',
'CC': '"' + os.path.join(testdir, 'host_wrapper.py') + '"',
}
crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile.write('''[binaries]
c = ['{0}']
'''.format(os.path.join(testdir, 'host_wrapper.py')))
crossfile.write('')
crossfile.flush()
self.meson_cross_file = crossfile.name
# TODO should someday be explicit about build platform only here

Loading…
Cancel
Save