compiler: Use cross tools args in sanity check.

pull/590/head
Martin Hostettler 9 years ago
parent 5384a203f3
commit 4979b4c84f
  1. 68
      mesonbuild/compilers.py
  2. 4
      mesonbuild/interpreter.py

@ -296,6 +296,18 @@ class Compiler():
def has_argument(self, arg): def has_argument(self, arg):
raise EnvironmentException('Language {} does not support has_arg.'.format(self.language)) raise EnvironmentException('Language {} does not support has_arg.'.format(self.language))
def get_cross_extra_flags(self, environment, *, compile, link):
extra_flags = []
if self.is_cross:
if 'properties' in environment.cross_info.config:
lang_args_key = self.language + '_args'
if compile:
extra_flags += environment.cross_info.config['properties'].get(lang_args_key, [])
lang_link_args_key = self.language + '_link_args'
if link:
extra_flags += environment.cross_info.config['properties'].get(lang_link_args_key, [])
return extra_flags
class CCompiler(Compiler): class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None): def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version) super().__init__(exelist, version)
@ -423,7 +435,7 @@ class CCompiler(Compiler):
def get_linker_search_args(self, dirname): def get_linker_search_args(self, dirname):
return ['-L'+dirname] return ['-L'+dirname]
def sanity_check_impl(self, work_dir, sname, code): def sanity_check_impl(self, work_dir, environment, sname, code):
mlog.debug('Sanity testing ' + self.language + ' compiler:', ' '.join(self.exelist)) mlog.debug('Sanity testing ' + self.language + ' compiler:', ' '.join(self.exelist))
mlog.debug('Is cross compiler: %s.' % str(self.is_cross)) mlog.debug('Is cross compiler: %s.' % str(self.is_cross))
@ -438,7 +450,10 @@ class CCompiler(Compiler):
# on OSX the compiler binary is the same but you need # on OSX the compiler binary is the same but you need
# a ton of compiler flags to differentiate between # a ton of compiler flags to differentiate between
# arm and x86_64. So just compile. # arm and x86_64. So just compile.
extra_flags += self.get_cross_extra_flags(environment, compile=True, link=False)
extra_flags = self.get_compile_only_args() extra_flags = self.get_compile_only_args()
else:
extra_flags += self.get_cross_extra_flags(environment, compile=True, link=True)
# Is a valid executable output for all toolchains and platforms # Is a valid executable output for all toolchains and platforms
binname += '.exe' binname += '.exe'
# Write binary check source # Write binary check source
@ -474,9 +489,9 @@ class CCompiler(Compiler):
if pe.returncode != 0: if pe.returncode != 0:
raise EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string())) raise EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string()))
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
code = 'int main(int argc, char **argv) { int class=0; return class; }\n' code = 'int main(int argc, char **argv) { int class=0; return class; }\n'
return self.sanity_check_impl(work_dir, 'sanitycheckc.c', code) return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code)
def has_header(self, hname, extra_args=[]): def has_header(self, hname, extra_args=[]):
templ = '''#include<%s> templ = '''#include<%s>
@ -839,9 +854,9 @@ class CPPCompiler(CCompiler):
return True return True
return False return False
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
code = 'class breakCCompiler;int main(int argc, char **argv) { return 0; }\n' code = 'class breakCCompiler;int main(int argc, char **argv) { return 0; }\n'
return self.sanity_check_impl(work_dir, 'sanitycheckcpp.cc', code) return self.sanity_check_impl(work_dir, environment, 'sanitycheckcpp.cc', code)
class ObjCCompiler(CCompiler): class ObjCCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap): def __init__(self, exelist, version, is_cross, exe_wrap):
@ -855,16 +870,23 @@ class ObjCCompiler(CCompiler):
return True return True
return False return False
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjc.m') source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
binary_name = os.path.join(work_dir, 'sanitycheckobjc') binary_name = os.path.join(work_dir, 'sanitycheckobjc')
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False)
if self.is_cross:
extra_flags = self.get_compile_only_args()
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n') ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n')
ofile.close() ofile.close()
pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('ObjC 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
pe = subprocess.Popen(binary_name) pe = subprocess.Popen(binary_name)
pe.wait() pe.wait()
if pe.returncode != 0: if pe.returncode != 0:
@ -882,16 +904,23 @@ class ObjCPPCompiler(CPPCompiler):
return True return True
return False return False
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm') source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm')
binary_name = os.path.join(work_dir, 'sanitycheckobjcpp') binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True)
if self.is_cross:
extra_flags = self.get_compile_only_args()
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
ofile.write('#import<stdio.h>\nclass MyClass;int main(int argc, char **argv) { return 0; }\n') ofile.write('#import<stdio.h>\nclass MyClass;int main(int argc, char **argv) { return 0; }\n')
ofile.close() ofile.close()
pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('ObjC++ compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('ObjC++ 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
pe = subprocess.Popen(binary_name) pe = subprocess.Popen(binary_name)
pe.wait() pe.wait()
if pe.returncode != 0: if pe.returncode != 0:
@ -980,7 +1009,7 @@ class MonoCompiler(Compiler):
def get_pch_name(self, header_name): def get_pch_name(self, header_name):
return '' return ''
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
src = 'sanity.cs' src = 'sanity.cs'
obj = 'sanity.exe' obj = 'sanity.exe'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
@ -1092,7 +1121,7 @@ class JavaCompiler(Compiler):
def get_buildtype_args(self, buildtype): def get_buildtype_args(self, buildtype):
return java_buildtype_args[buildtype] return java_buildtype_args[buildtype]
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
src = 'SanityCheck.java' src = 'SanityCheck.java'
obj = 'SanityCheck' obj = 'SanityCheck'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
@ -1140,7 +1169,7 @@ class ValaCompiler(Compiler):
def get_language(self): def get_language(self):
return self.language return self.language
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
src = 'valatest.vala' src = 'valatest.vala'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
@ -1148,7 +1177,8 @@ class ValaCompiler(Compiler):
} }
''') ''')
ofile.close() ofile.close()
pc = subprocess.Popen(self.exelist + ['-C', '-c', src], cwd=work_dir) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False)
pc = subprocess.Popen(self.exelist + extra_flags + ['-C', '-c', src], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('Vala compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('Vala compiler %s can not compile programs.' % self.name_string())
@ -1183,7 +1213,7 @@ class RustCompiler(Compiler):
def get_language(self): def get_language(self):
return self.language return self.language
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanity.rs') source_name = os.path.join(work_dir, 'sanity.rs')
output_name = os.path.join(work_dir, 'rusttest') output_name = os.path.join(work_dir, 'rusttest')
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
@ -1281,7 +1311,7 @@ class SwiftCompiler(Compiler):
def get_compile_only_args(self): def get_compile_only_args(self):
return ['-c'] return ['-c']
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
src = 'swifttest.swift' src = 'swifttest.swift'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
output_name = os.path.join(work_dir, 'swifttest') output_name = os.path.join(work_dir, 'swifttest')
@ -1289,7 +1319,8 @@ class SwiftCompiler(Compiler):
ofile.write('''1 + 2 ofile.write('''1 + 2
''') ''')
ofile.close() ofile.close()
pc = subprocess.Popen(self.exelist + ['-emit-executable', '-o', output_name, src], cwd=work_dir) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True)
pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('Swift compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('Swift compiler %s can not compile programs.' % self.name_string())
@ -1825,7 +1856,7 @@ class FortranCompiler(Compiler):
def needs_static_linker(self): def needs_static_linker(self):
return True return True
def sanity_check(self, work_dir): def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanitycheckf.f90') source_name = os.path.join(work_dir, 'sanitycheckf.f90')
binary_name = os.path.join(work_dir, 'sanitycheckf') binary_name = os.path.join(work_dir, 'sanitycheckf')
ofile = open(source_name, 'w') ofile = open(source_name, 'w')
@ -1834,7 +1865,8 @@ class FortranCompiler(Compiler):
end program prog end program prog
''') ''')
ofile.close() ofile.close()
pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name]) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True)
pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string()) raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())

@ -1557,10 +1557,10 @@ class Interpreter():
# cross_comp = self.environment.detect_fortran_compiler(True) # cross_comp = self.environment.detect_fortran_compiler(True)
else: else:
raise InvalidCode('Tried to use unknown language "%s".' % lang) raise InvalidCode('Tried to use unknown language "%s".' % lang)
comp.sanity_check(self.environment.get_scratch_dir()) comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
self.coredata.compilers[lang] = comp self.coredata.compilers[lang] = comp
if cross_comp is not None: if cross_comp is not None:
cross_comp.sanity_check(self.environment.get_scratch_dir()) cross_comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
self.coredata.cross_compilers[lang] = cross_comp self.coredata.cross_compilers[lang] = cross_comp
new_options = comp.get_options() new_options = comp.get_options()
optprefix = lang + '_' optprefix = lang + '_'

Loading…
Cancel
Save