From 6dbe33d949237411b1291c30f5383885befb3554 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 19 Dec 2018 01:22:39 -0500 Subject: C# and Java compilers should have `is_cross = False` All compilers should define this attribute. Probably should change base class to require this. --- mesonbuild/compilers/cs.py | 1 + mesonbuild/compilers/java.py | 1 + 2 files changed, 2 insertions(+) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index cbfcd9c..cd67da0 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -32,6 +32,7 @@ class CsCompiler(Compiler): self.language = 'cs' super().__init__(exelist, version) self.id = id + self.is_cross = False self.runner = runner def get_display_language(self): diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index 03ee382..5d7f865 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -23,6 +23,7 @@ class JavaCompiler(Compiler): self.language = 'java' super().__init__(exelist, version) self.id = 'unknown' + self.is_cross = False self.javarunner = 'java' def get_soname_args(self, *args): -- cgit v1.1 From 19f81d3e33c70c9c902dabaad732e5d33bf05bd4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 12 Dec 2018 00:19:03 -0500 Subject: Never access environment.properties downstream Instead use coredata.compiler_options.. 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. --- mesonbuild/compilers/c.py | 22 +++++++++++++++------- mesonbuild/compilers/compilers.py | 15 +++++++++------ mesonbuild/compilers/d.py | 13 ++++++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) (limited to 'mesonbuild/compilers') 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 -- cgit v1.1