diff options
author | John Ericson <git@JohnEricson.me> | 2018-12-12 00:19:03 -0500 |
---|---|---|
committer | John Ericson <git@JohnEricson.me> | 2019-02-02 13:59:14 -0500 |
commit | 19f81d3e33c70c9c902dabaad732e5d33bf05bd4 (patch) | |
tree | f86664395d7233bbba9e3c129c81c7056c6fa98b /mesonbuild/backend | |
parent | 6dbe33d949237411b1291c30f5383885befb3554 (diff) | |
download | meson-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/backend')
-rw-r--r-- | mesonbuild/backend/backends.py | 19 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 13 | ||||
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 26 |
3 files changed, 40 insertions, 18 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index a0326f3..ba5bd90 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -20,7 +20,7 @@ from .. import mesonlib from .. import mlog import json import subprocess -from ..mesonlib import MesonException, OrderedSet +from ..mesonlib import MachineChoice, MesonException, OrderedSet from ..mesonlib import classify_unity_sources from ..mesonlib import File from ..compilers import CompilerArgs, VisualStudioCCompiler @@ -185,9 +185,14 @@ class Backend: self.environment.coredata.base_options) def get_compiler_options_for_target(self, target): - return OptionOverrideProxy(target.option_overrides, - # no code depends on builtins for now - self.environment.coredata.compiler_options) + if self.environment.is_cross_build() and not target.is_cross: + for_machine = MachineChoice.BUILD + else: + for_machine = MachineChoice.HOST + + return OptionOverrideProxy( + target.option_overrides, + self.environment.coredata.compiler_options[for_machine]) def get_option_for_target(self, option_name, target): if option_name in target.option_overrides: @@ -574,10 +579,14 @@ class Backend: # Add compile args added using add_global_arguments() # These override per-project arguments commands += self.build.get_global_args(compiler, target.is_cross) + if self.environment.is_cross_build() and not target.is_cross: + for_machine = MachineChoice.BUILD + else: + for_machine = MachineChoice.HOST if not target.is_cross: # Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these # to override all the defaults, but not the per-target compile args. - commands += self.environment.coredata.get_external_args(compiler.get_language()) + commands += self.environment.coredata.get_external_args(for_machine, compiler.get_language()) # Always set -fPIC for shared libraries if isinstance(target, build.SharedLibrary): commands += compiler.get_pic_args() diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 9b215b2..87f9b38 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -31,7 +31,7 @@ from .. import dependencies from .. import compilers from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler from ..linkers import ArLinker -from ..mesonlib import File, MesonException, OrderedSet +from ..mesonlib import File, MachineChoice, MesonException, OrderedSet from ..mesonlib import get_compiler_for_source, has_path_sep from .backends import CleanTrees from ..build import InvalidArguments @@ -1460,7 +1460,7 @@ int dummy; or langname == 'cs': continue crstr = '' - cross_args = self.environment.properties.host.get_external_link_args(langname) + cross_args = self.environment.coredata.get_external_link_args(MachineChoice.HOST, langname) if is_cross: crstr = '_CROSS' rule = 'rule %s%s_LINKER\n' % (langname, crstr) @@ -2467,6 +2467,11 @@ rule FORTRAN_DEP_HACK%s if not isinstance(target, build.StaticLibrary): commands += self.get_link_whole_args(linker, target) + if self.environment.is_cross_build() and not target.is_cross: + for_machine = MachineChoice.BUILD + else: + for_machine = MachineChoice.HOST + if not isinstance(target, build.StaticLibrary): # Add link args added using add_project_link_arguments() commands += self.build.get_project_link_args(linker, target.subproject, target.is_cross) @@ -2476,7 +2481,7 @@ rule FORTRAN_DEP_HACK%s if not target.is_cross: # Link args added from the env: LDFLAGS. We want these to # override all the defaults but not the per-target link args. - commands += self.environment.coredata.get_external_link_args(linker.get_language()) + commands += self.environment.coredata.get_external_link_args(for_machine, linker.get_language()) # Now we will add libraries and library paths from various sources @@ -2522,7 +2527,7 @@ rule FORTRAN_DEP_HACK%s # to be after all internal and external libraries so that unresolved # symbols from those can be found here. This is needed when the # *_winlibs that we want to link to are static mingw64 libraries. - commands += linker.get_option_link_args(self.environment.coredata.compiler_options) + commands += linker.get_option_link_args(self.environment.coredata.compiler_options[for_machine]) dep_targets = [] dep_targets.extend(self.guess_external_link_dependencies(linker, target, commands, internal)) diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 783ae64..80204e4 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -25,7 +25,9 @@ from .. import dependencies from .. import mlog from .. import compilers from ..compilers import CompilerArgs -from ..mesonlib import MesonException, File, python_command, replace_if_different +from ..mesonlib import ( + MesonException, MachineChoice, File, python_command, replace_if_different +) from ..environment import Environment, build_filename def autodetect_vs_version(build): @@ -878,10 +880,14 @@ class Vs2010Backend(backends.Backend): file_inc_dirs = dict((lang, []) for lang in target.compilers) # The order in which these compile args are added must match # generate_single_compile() and generate_basic_compiler_args() + if self.environment.is_cross_build() and not target.is_cross: + for_machine = MachineChoice.BUILD + else: + for_machine = MachineChoice.HOST for l, comp in target.compilers.items(): if l in file_args: file_args[l] += compilers.get_base_compile_args(self.get_base_options_for_target(target), comp) - file_args[l] += comp.get_option_compile_args(self.environment.coredata.compiler_options) + file_args[l] += comp.get_option_compile_args(self.environment.coredata.compiler_options[for_machine]) # Add compile args added using add_project_arguments() for l, args in self.build.projects_args.get(target.subproject, {}).items(): @@ -893,9 +899,10 @@ class Vs2010Backend(backends.Backend): if l in file_args: file_args[l] += args if not target.is_cross: - # Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these - # to override all the defaults, but not the per-target compile args. - for key, opt in self.environment.coredata.compiler_options.items(): + # Compile args added from the env or cross file: CFLAGS/CXXFLAGS, + # etc. We want these to override all the defaults, but not the + # per-target compile args. + for key, opt in self.environment.coredata.compiler_options[for_machine].items(): l, suffix = key.split('_', 1) if suffix == 'args' and l in file_args: file_args[l] += opt.value @@ -1054,9 +1061,10 @@ class Vs2010Backend(backends.Backend): # These override per-project link arguments extra_link_args += self.build.get_global_link_args(compiler, target.is_cross) if not target.is_cross: - # Link args added from the env: LDFLAGS. We want these to - # override all the defaults but not the per-target link args. - extra_link_args += self.environment.coredata.get_external_link_args(compiler.get_language()) + # Link args added from the env: LDFLAGS, or the cross file. We + # want these to override all the defaults but not the + # per-target link args. + extra_link_args += self.environment.coredata.get_external_link_args(for_machine, compiler.get_language()) # Only non-static built targets need link args and link dependencies extra_link_args += target.link_args # External deps must be last because target link libraries may depend on them. @@ -1079,7 +1087,7 @@ class Vs2010Backend(backends.Backend): # to be after all internal and external libraries so that unresolved # symbols from those can be found here. This is needed when the # *_winlibs that we want to link to are static mingw64 libraries. - extra_link_args += compiler.get_option_link_args(self.environment.coredata.compiler_options) + extra_link_args += compiler.get_option_link_args(self.environment.coredata.compiler_options[for_machine]) (additional_libpaths, additional_links, extra_link_args) = self.split_link_args(extra_link_args.to_native()) # Add more libraries to be linked if needed |