aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-03-19 20:44:51 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2019-03-27 10:54:56 -0400
commitf4da210f464446d92600456508439d2f926e6cea (patch)
tree453a9a73eebc21dc055e20fa3911c0093d265245
parentb565eff084faeea8a8952ec2c1fe40483705aaef (diff)
downloadmeson-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.
-rw-r--r--mesonbuild/compilers/c.py51
-rw-r--r--mesonbuild/compilers/fortran.py15
-rw-r--r--mesonbuild/compilers/objc.py10
-rw-r--r--mesonbuild/compilers/objcpp.py13
-rw-r--r--mesonbuild/compilers/swift.py16
-rw-r--r--mesonbuild/compilers/vala.py21
6 files changed, 94 insertions, 32 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
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index a16f2b5..5afbb3d 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -31,7 +31,9 @@ from .compilers import (
PGICompiler
)
-from mesonbuild.mesonlib import EnvironmentException, is_osx, LibType
+from mesonbuild.mesonlib import (
+ EnvironmentException, MachineChoice, is_osx, LibType
+)
class FortranCompiler(Compiler):
@@ -79,7 +81,13 @@ class FortranCompiler(Compiler):
binary_name = os.path.join(work_dir, 'sanitycheckf')
with open(source_name, 'w') as ofile:
ofile.write('print *, "Fortran compilation is working."; end')
- pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
+ if environment.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait()
if pc.returncode != 0:
raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
@@ -223,6 +231,9 @@ class FortranCompiler(Compiler):
def gen_import_library_args(self, implibname):
return CCompiler.gen_import_library_args(self, implibname)
+ def _get_basic_compiler_args(self, env, mode):
+ return CCompiler._get_basic_compiler_args(self, env, mode)
+
def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'):
return CCompiler._get_compiler_check_args(self, env, extra_args, dependencies, mode='compile')
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 8dfd0a2..c4a7019 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -14,7 +14,7 @@
import os.path, subprocess
-from ..mesonlib import EnvironmentException
+from ..mesonlib import EnvironmentException, MachineChoice
from .c import CCompiler
from .compilers import ClangCompiler, GnuCompiler
@@ -31,9 +31,15 @@ class ObjCCompiler(CCompiler):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
binary_name = os.path.join(work_dir, 'sanitycheckobjc')
- extra_flags = []
+ if environment.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ extra_flags = environment.coredata.get_external_args(for_machine, self.language)
if self.is_cross:
extra_flags += self.get_compile_only_args()
+ else:
+ extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\n'
'int main(int argc, char **argv) { return 0; }\n')
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index e66d730..4c23d0a 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -14,7 +14,7 @@
import os.path, subprocess
-from ..mesonlib import EnvironmentException
+from ..mesonlib import EnvironmentException, MachineChoice
from .cpp import CPPCompiler
from .compilers import ClangCompiler, GnuCompiler
@@ -31,11 +31,20 @@ class ObjCPPCompiler(CPPCompiler):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm')
binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
+ if environment.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ if self.is_cross:
+ extra_flags += self.get_compile_only_args()
+ else:
+ extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\n'
'class MyClass;'
'int main(int argc, char **argv) { return 0; }\n')
- pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
+ pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait()
if pc.returncode != 0:
raise EnvironmentException('ObjC++ compiler %s can not compile programs.' % self.name_string())
diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py
index 94e6736..17705ac 100644
--- a/mesonbuild/compilers/swift.py
+++ b/mesonbuild/compilers/swift.py
@@ -14,7 +14,7 @@
import subprocess, os.path
-from ..mesonlib import EnvironmentException
+from ..mesonlib import EnvironmentException, MachineChoice
from .compilers import Compiler, swift_buildtype_args, clike_debug_args
@@ -102,13 +102,25 @@ class SwiftCompiler(Compiler):
src = 'swifttest.swift'
source_name = os.path.join(work_dir, src)
output_name = os.path.join(work_dir, 'swifttest')
+ if environment.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ if self.is_cross:
+ extra_flags += self.get_compile_only_args()
+ else:
+ extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('''print("Swift compilation is working.")
''')
- pc = subprocess.Popen(self.exelist + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
+ pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait()
if pc.returncode != 0:
raise EnvironmentException('Swift compiler %s can not compile programs.' % self.name_string())
+ if self.is_cross:
+ # Can't check if the binaries run so we have to assume they do
+ return
if subprocess.call(output_name) != 0:
raise EnvironmentException('Executables created by Swift compiler %s are not runnable.' % self.name_string())
diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py
index b463f0d..98b8b42 100644
--- a/mesonbuild/compilers/vala.py
+++ b/mesonbuild/compilers/vala.py
@@ -15,7 +15,7 @@
import os.path
from .. import mlog
-from ..mesonlib import EnvironmentException, version_compare
+from ..mesonlib import EnvironmentException, MachineChoice, version_compare
from .compilers import Compiler
@@ -87,7 +87,16 @@ class ValaCompiler(Compiler):
def sanity_check(self, work_dir, environment):
code = 'class MesonSanityCheck : Object { }'
- with self.compile(code, [], 'compile') as p:
+ if environment.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ if self.is_cross:
+ extra_flags += self.get_compile_only_args()
+ else:
+ extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ with self.compile(code, extra_flags, 'compile') as p:
if p.returncode != 0:
msg = 'Vala compiler {!r} can not compile programs' \
''.format(self.name_string())
@@ -105,8 +114,14 @@ class ValaCompiler(Compiler):
# no extra dirs are specified.
if not extra_dirs:
code = 'class MesonFindLibrary : Object { }'
+ if env.is_cross_build() and not self.is_cross:
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ args = env.coredata.get_external_args(for_machine, self.language)
vapi_args = ['--pkg', libname]
- with self.compile(code, vapi_args, 'compile') as p:
+ args += vapi_args
+ with self.compile(code, args, 'compile') as p:
if p.returncode == 0:
return vapi_args
# Not found? Try to find the vapi file itself.