aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorJohn Ericson <git@JohnEricson.me>2018-12-12 00:19:03 -0500
committerJohn Ericson <git@JohnEricson.me>2019-02-02 13:59:14 -0500
commit19f81d3e33c70c9c902dabaad732e5d33bf05bd4 (patch)
treef86664395d7233bbba9e3c129c81c7056c6fa98b /mesonbuild/compilers
parent6dbe33d949237411b1291c30f5383885befb3554 (diff)
downloadmeson-19f81d3e33c70c9c902dabaad732e5d33bf05bd4.zip
meson-19f81d3e33c70c9c902dabaad732e5d33bf05bd4.tar.gz
meson-19f81d3e33c70c9c902dabaad732e5d33bf05bd4.tar.bz2
Never access environment.properties downstream
Instead use coredata.compiler_options.<machine>. This brings the cross and native code paths closer together, since both now use that. Command line options are interpreted just as before, for backwards compatibility. This does introduce some funny conditionals. In the future, I'd like to change the interpretation of command line options so - The logic is cross-agnostic, i.e. there are no conditions affected by `is_cross_build()`. - Compiler args for both the build and host machines can always be controlled by the command line. - Compiler args for both machines can always be controlled separately.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py22
-rw-r--r--mesonbuild/compilers/compilers.py15
-rw-r--r--mesonbuild/compilers/d.py13
3 files changed, 34 insertions, 16 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index a591183..b47be7d 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -25,9 +25,9 @@ from .. import mlog
from .. import coredata
from . import compilers
from ..mesonlib import (
- EnvironmentException, MesonException, version_compare, Popen_safe, listify,
- for_windows, for_darwin, for_cygwin, for_haiku, for_openbsd,
- darwin_get_object_archs
+ EnvironmentException, MachineChoice, MesonException, Popen_safe, listify,
+ version_compare, for_windows, for_darwin, for_cygwin, for_haiku,
+ for_openbsd, darwin_get_object_archs
)
from .c_function_attributes import C_FUNC_ATTRIBUTES
@@ -427,12 +427,16 @@ class CCompiler(Compiler):
# Read c_args/cpp_args/etc from the cross-info file (if needed)
args += self.get_cross_extra_flags(env, link=(mode == 'link'))
if not self.is_cross:
+ if env.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
if mode == 'preprocess':
# Add CPPFLAGS from the env.
- args += env.coredata.get_external_preprocess_args(self.language)
+ args += env.coredata.get_external_preprocess_args(for_machine, self.language)
elif mode == 'compile':
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
- sys_args = env.coredata.get_external_args(self.language)
+ sys_args = env.coredata.get_external_args(for_machine, self.language)
# Apparently it is a thing to inject linker flags both
# via CFLAGS _and_ LDFLAGS, even though the former are
# also used during linking. These flags can break
@@ -441,7 +445,7 @@ class CCompiler(Compiler):
args += cleaned_sys_args
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.get_external_link_args(self.language)
+ args += env.coredata.get_external_link_args(for_machine, self.language)
args += self.get_compiler_check_args()
# extra_args must override all other arguments, so we add them last
args += extra_args
@@ -1081,7 +1085,11 @@ class CCompiler(Compiler):
commands = self.get_exelist() + ['-v', '-E', '-']
commands += self.get_always_args()
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
- commands += env.coredata.get_external_args(self.language)
+ if env.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ commands += env.coredata.get_external_args(for_machine, self.language)
mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')
os_env = os.environ.copy()
os_env['LC_ALL'] = 'C'
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 317d91a..9a101bf 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -21,8 +21,8 @@ from .. import coredata
from .. import mlog
from .. import mesonlib
from ..mesonlib import (
- EnvironmentException, MesonException, OrderedSet, version_compare,
- Popen_safe
+ EnvironmentException, MachineChoice, MesonException, OrderedSet,
+ version_compare, Popen_safe
)
"""This file contains the data files of all compilers Meson knows
@@ -1011,7 +1011,11 @@ class Compiler:
opts = {} # build afresh every time
# Take default values from env variables.
- compile_args, link_args = self.get_args_from_envvars()
+ if not self.is_cross:
+ compile_args, link_args = self.get_args_from_envvars()
+ else:
+ compile_args = []
+ link_args = []
description = 'Extra arguments passed to the {}'.format(self.get_display_language())
opts.update({
self.language + '_args': coredata.UserArrayOption(
@@ -1083,10 +1087,9 @@ class Compiler:
def get_cross_extra_flags(self, environment, link):
extra_flags = []
if self.is_cross and environment:
- props = environment.properties.host
- extra_flags += props.get_external_args(self.language)
+ extra_flags += environment.coredata.get_external_args(MachineChoice.HOST, self.language)
if link:
- extra_flags += props.get_external_link_args(self.language)
+ extra_flags += environment.coredata.get_external_link_args(MachineChoice.HOST, self.language)
return extra_flags
def _get_compile_output(self, dirname, mode):
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 3065ac7..1390694 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -14,7 +14,9 @@
import os.path, subprocess
-from ..mesonlib import EnvironmentException, version_compare, is_windows, is_osx
+from ..mesonlib import (
+ EnvironmentException, MachineChoice, version_compare, is_windows, is_osx
+)
from .compilers import (
CompilerType,
@@ -306,12 +308,17 @@ class DCompiler(Compiler):
# Add link flags needed to find dependencies
args += d.get_link_args()
+ if env.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+
if mode == 'compile':
# Add DFLAGS from the env
- args += env.coredata.get_external_args(self.language)
+ args += env.coredata.get_external_args(for_machine, self.language)
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.get_external_link_args(self.language)
+ args += env.coredata.get_external_link_args(for_machine, self.language)
# extra_args must override all other arguments, so we add them last
args += extra_args
return args