diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-03-19 20:44:51 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2019-03-27 10:54:56 -0400 |
commit | f4da210f464446d92600456508439d2f926e6cea (patch) | |
tree | 453a9a73eebc21dc055e20fa3911c0093d265245 /mesonbuild/compilers/c.py | |
parent | b565eff084faeea8a8952ec2c1fe40483705aaef (diff) | |
download | meson-f4da210f464446d92600456508439d2f926e6cea.zip meson-f4da210f464446d92600456508439d2f926e6cea.tar.gz meson-f4da210f464446d92600456508439d2f926e6cea.tar.bz2 |
Sanity check with external args
Previously cross, but not native, external args were used. Then in
d451a4bd97f827bb492fd0c0e357cb20b6056ed9 the cross special cases were
removed, so external args are never used.
This commit switches that so they are always used. Sanity checking works
just the same as compiler checks like has header / has library.
Diffstat (limited to 'mesonbuild/compilers/c.py')
-rw-r--r-- | mesonbuild/compilers/c.py | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 2560c82..bcf8243 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -309,9 +309,9 @@ class CCompiler(Compiler): mlog.debug('Sanity testing ' + self.get_display_language() + ' compiler:', ' '.join(self.exelist)) mlog.debug('Is cross compiler: %s.' % str(self.is_cross)) - extra_flags = [] source_name = os.path.join(work_dir, sname) binname = sname.rsplit('.', 1)[0] + mode = 'link' if self.is_cross: binname += '_cross' if self.exe_wrapper is None: @@ -320,7 +320,9 @@ class CCompiler(Compiler): # on OSX the compiler binary is the same but you need # a ton of compiler flags to differentiate between # arm and x86_64. So just compile. - extra_flags += self.get_compile_only_args() + mode = 'compile' + extra_flags = self._get_basic_compiler_args(environment, mode) + # Is a valid executable output for all toolchains and platforms binname += '.exe' # Write binary check source @@ -392,6 +394,29 @@ class CCompiler(Compiler): return self.compiles(t.format(**fargs), env, extra_args=extra_args, dependencies=dependencies) + def _get_basic_compiler_args(self, env, mode): + args = [] + # Select a CRT if needed since we're linking + if mode == 'link': + args += self.get_linker_debug_crt_args() + if env.is_cross_build() and not self.is_cross: + for_machine = MachineChoice.BUILD + else: + for_machine = MachineChoice.HOST + if mode in {'compile', 'preprocess'}: + # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env + 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 + # argument checks. Thanks, Autotools. + cleaned_sys_args = self.remove_linkerlike_args(sys_args) + args += cleaned_sys_args + elif mode == 'link': + # Add LDFLAGS from the env + args += env.coredata.get_external_link_args(for_machine, self.language) + return args + def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'): if extra_args is None: extra_args = [] @@ -415,25 +440,9 @@ class CCompiler(Compiler): args += d.get_link_args() if d.need_threads(): args += self.thread_link_flags(env) - # Select a CRT if needed since we're linking - if mode == 'link': - args += self.get_linker_debug_crt_args() - if env.is_cross_build() and not self.is_cross: - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST - if mode in {'compile', 'preprocess'}: - # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env - 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 - # argument checks. Thanks, Autotools. - cleaned_sys_args = self.remove_linkerlike_args(sys_args) - args += cleaned_sys_args - elif mode == 'link': - # Add LDFLAGS from the env - args += env.coredata.get_external_link_args(for_machine, self.language) + + args += self._get_basic_compiler_args(env, mode) + args += self.get_compiler_check_args() # extra_args must override all other arguments, so we add them last args += extra_args |