aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/backend/backends.py21
-rw-r--r--mesonbuild/backend/ninjabackend.py31
-rw-r--r--mesonbuild/build.py101
-rw-r--r--mesonbuild/compilers.py308
-rw-r--r--mesonbuild/dependencies.py24
-rw-r--r--mesonbuild/environment.py185
-rw-r--r--mesonbuild/interpreter.py46
-rw-r--r--mesonbuild/mesonlib.py3
8 files changed, 363 insertions, 356 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 5681f7c..bdbfee1 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -238,27 +238,6 @@ class Backend():
self.write_benchmark_file(datafile)
return (test_data, benchmark_data)
- def has_source_suffix(self, target, suffix):
- for s in target.get_sources():
- if s.endswith(suffix):
- return True
- return False
-
- def has_vala(self, target):
- return self.has_source_suffix(target, '.vala')
-
- def has_rust(self, target):
- return self.has_source_suffix(target, '.rs')
-
- def has_cs(self, target):
- return self.has_source_suffix(target, '.cs')
-
- def has_swift(self, target):
- return self.has_source_suffix(target, '.swift')
-
- def has_d(self, target):
- return self.has_source_suffix(target, '.d')
-
def determine_linker(self, target, src):
if isinstance(target, build.StaticLibrary):
if self.build.static_cross_linker is not None:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 41f96f1..a84de0e 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -233,19 +233,18 @@ int dummy;
if isinstance(target, build.Jar):
self.generate_jar_target(target, outfile)
return
- if 'rust' in self.environment.coredata.compilers.keys() and self.has_rust(target):
+ if 'rust' in target.compilers:
self.generate_rust_target(target, outfile)
return
- if 'cs' in self.environment.coredata.compilers.keys() and self.has_cs(target):
+ if 'cs' in target.compilers:
self.generate_cs_target(target, outfile)
return
- if 'vala' in self.environment.coredata.compilers.keys() and self.has_vala(target):
- vc = self.environment.coredata.compilers['vala']
- vala_output_files = self.generate_vala_compile(vc, target, outfile)
- gen_src_deps += vala_output_files
- if 'swift' in self.environment.coredata.compilers.keys() and self.has_swift(target):
+ if 'swift' in target.compilers:
self.generate_swift_target(target, outfile)
return
+ if 'vala' in target.compilers:
+ vala_output_files = self.generate_vala_compile(target, outfile)
+ gen_src_deps += vala_output_files
self.scan_fortran_module_outputs(target)
# The following deals with C/C++ compilation.
(gen_src, gen_other_deps) = self.process_dep_gens(outfile, target)
@@ -718,8 +717,7 @@ int dummy;
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
class_list = []
- compiler = self.get_compiler_for_source(src_list[0], False)
- assert(compiler.get_language() == 'java')
+ compiler = target.compilers['java']
c = 'c'
m = ''
e = ''
@@ -769,8 +767,7 @@ int dummy;
fname = target.get_filename()
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
- compiler = self.get_compiler_for_source(src_list[0], False)
- assert(compiler.get_language() == 'cs')
+ compiler = target.compilers['cs']
rel_srcs = [s.rel_to_builddir(self.build_to_src) for s in src_list]
deps = []
commands = target.extra_args.get('cs', [])
@@ -845,9 +842,9 @@ int dummy;
break
return result
- def generate_vala_compile(self, compiler, target, outfile):
+ def generate_vala_compile(self, target, outfile):
"""Vala is compiled into C. Set up all necessary build steps here."""
- valac = self.environment.coredata.compilers['vala']
+ valac = target.compilers['vala']
(src, vapi_src) = self.split_vala_sources(target.get_sources())
vapi_src = [x.rel_to_builddir(self.build_to_src) for x in vapi_src]
extra_dep_files = []
@@ -866,8 +863,8 @@ int dummy;
generated_c_files = []
outputs = [vapiname]
args = []
- args += self.build.get_global_args(compiler)
- args += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype'))
+ args += self.build.get_global_args(valac)
+ args += valac.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype'))
args += ['-d', self.get_target_private_dir(target)]
args += ['-C']#, '-o', cname]
if not isinstance(target, build.Executable):
@@ -910,7 +907,7 @@ int dummy;
return generated_c_files
def generate_rust_target(self, target, outfile):
- rustc = self.environment.coredata.compilers['rust']
+ rustc = target.compilers['rust']
relsrc = []
for i in target.get_sources():
if not rustc.can_compile(i):
@@ -1001,7 +998,7 @@ int dummy;
def generate_swift_target(self, target, outfile):
module_name = self.target_swift_modulename(target)
- swiftc = self.environment.coredata.compilers['swift']
+ swiftc = target.compilers['swift']
abssrc = []
abs_headers = []
header_imports = []
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index dce0236..1ef183b 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -51,36 +51,16 @@ known_shlib_kwargs.update({'version' : True,
'name_suffix' : True,
'vs_module_defs' : True})
-def sources_are_suffix(sources, suffix):
- for source in sources:
- if source.endswith('.' + suffix):
- return True
- return False
-
-def compiler_is_msvc(sources, is_cross, env):
+def compilers_are_msvc(compilers):
"""
- Since each target does not currently have the compiler information attached
- to it, we must do this detection manually here.
-
- This detection is purposely incomplete and will cause bugs if other code is
- extended and this piece of code is forgotten.
+ Check if all the listed compilers are MSVC. Used by Executable,
+ StaticLibrary, and SharedLibrary for deciding when to use MSVC-specific
+ file naming.
"""
- compiler = None
- if sources_are_suffix(sources, 'c'):
- try:
- compiler = env.detect_c_compiler(is_cross)
- except MesonException:
+ for compiler in compilers.values():
+ if compiler.get_id() != 'msvc':
return False
- elif sources_are_suffix(sources, 'cxx') or \
- sources_are_suffix(sources, 'cpp') or \
- sources_are_suffix(sources, 'cc'):
- try:
- compiler = env.detect_cpp_compiler(is_cross)
- except MesonException:
- return False
- if compiler and compiler.get_id() == 'msvc':
- return True
- return False
+ return True
class InvalidArguments(MesonException):
@@ -234,7 +214,9 @@ class BuildTarget():
self.subdir = subdir
self.subproject = subproject # Can not be calculated from subdir as subproject dirname can be changed per project.
self.is_cross = is_cross
+ self.environment = environment
self.sources = []
+ self.compilers = {}
self.objects = []
self.external_deps = []
self.include_dirs = []
@@ -256,6 +238,7 @@ class BuildTarget():
len(self.generated) == 0 and \
len(self.objects) == 0:
raise InvalidArguments('Build target %s has no sources.' % name)
+ self.process_compilers()
self.validate_sources()
def __repr__(self):
@@ -320,16 +303,52 @@ class BuildTarget():
msg = 'Bad source of type {!r} in target {!r}.'.format(type(s).__name__, self.name)
raise InvalidArguments(msg)
+ @staticmethod
+ def can_compile_remove_sources(compiler, sources):
+ removed = False
+ for s in sources[:]:
+ if compiler.can_compile(s):
+ sources.remove(s)
+ removed = True
+ return removed
+
+ def process_compilers(self):
+ if len(self.sources) == 0:
+ return
+ sources = list(self.sources)
+ if self.is_cross:
+ compilers = self.environment.coredata.cross_compilers
+ else:
+ compilers = self.environment.coredata.compilers
+ for lang, compiler in compilers.items():
+ if self.can_compile_remove_sources(compiler, sources):
+ self.compilers[lang] = compiler
+
def validate_sources(self):
- if len(self.sources) > 0:
+ if len(self.sources) == 0:
+ return
+ for lang in ('cs', 'java'):
+ if lang in self.compilers:
+ check_sources = list(self.sources)
+ compiler = self.compilers[lang]
+ if not self.can_compile_remove_sources(compiler, check_sources):
+ m = 'No {} sources found in target {!r}'.format(lang, self.name)
+ raise InvalidArguments(m)
+ if check_sources:
+ m = '{0} targets can only contain {0} files:\n'.format(lang.capitalize())
+ m += '\n'.join([repr(c) for c in check_sources])
+ raise InvalidArguments(m)
+ # CSharp and Java targets can't contain any other file types
+ assert(len(self.compilers) == 1)
+ return
+ if 'rust' in self.compilers:
firstname = self.sources[0]
if isinstance(firstname, File):
firstname = firstname.fname
first = os.path.split(firstname)[1]
(base, suffix) = os.path.splitext(first)
- if suffix == '.rs':
- if self.name != base:
- raise InvalidArguments('In Rust targets, the first source file must be named projectname.rs.')
+ if suffix != '.rs' or self.name != base:
+ raise InvalidArguments('In Rust targets, the first source file must be named projectname.rs.')
def get_original_kwargs(self):
return self.kwargs
@@ -768,7 +787,7 @@ class Executable(BuildTarget):
self.prefix = ''
if not hasattr(self, 'suffix'):
# Executable for Windows or C#/Mono
- if for_windows(is_cross, environment) or sources_are_suffix(self.sources, 'cs'):
+ if for_windows(is_cross, environment) or 'cs' in self.compilers:
self.suffix = 'exe'
else:
self.suffix = ''
@@ -777,8 +796,7 @@ class Executable(BuildTarget):
self.filename += '.' + self.suffix
# See determine_debug_filenames() in build.SharedLibrary
buildtype = environment.coredata.get_builtin_option('buildtype')
- if compiler_is_msvc(self.sources, is_cross, environment) and \
- buildtype.startswith('debug'):
+ if compilers_are_msvc(self.compilers) and buildtype.startswith('debug'):
self.debug_filename = self.prefix + self.name + '.pdb'
def type_suffix(self):
@@ -787,7 +805,7 @@ class Executable(BuildTarget):
class StaticLibrary(BuildTarget):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs)
- if sources_are_suffix(self.sources, 'cs'):
+ if 'cs' in self.compilers:
raise InvalidArguments('Static libraries not supported for C#.')
# By default a static library is named libfoo.a even on Windows because
# MSVC does not have a consistent convention for what static libraries
@@ -800,15 +818,14 @@ class StaticLibrary(BuildTarget):
self.prefix = 'lib'
if not hasattr(self, 'suffix'):
# Rust static library crates have .rlib suffix
- if sources_are_suffix(self.sources, 'rs'):
+ if 'rust' in self.compilers:
self.suffix = 'rlib'
else:
self.suffix = 'a'
self.filename = self.prefix + self.name + '.' + self.suffix
# See determine_debug_filenames() in build.SharedLibrary
buildtype = environment.coredata.get_builtin_option('buildtype')
- if compiler_is_msvc(self.sources, is_cross, environment) and \
- buildtype.startswith('debug'):
+ if compilers_are_msvc(self.compilers) and buildtype.startswith('debug'):
self.debug_filename = self.prefix + self.name + '.pdb'
def type_suffix(self):
@@ -864,12 +881,12 @@ class SharedLibrary(BuildTarget):
if self.prefix != None and self.suffix != None:
pass
# C# and Mono
- elif sources_are_suffix(self.sources, 'cs'):
+ elif 'cs' in self.compilers:
prefix = ''
suffix = 'dll'
self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
# Rust
- elif sources_are_suffix(self.sources, 'rs'):
+ elif 'rust' in self.compilers:
# Currently, we always build --crate-type=rlib
prefix = 'lib'
suffix = 'rlib'
@@ -881,7 +898,7 @@ class SharedLibrary(BuildTarget):
suffix = 'dll'
self.vs_import_filename = '{0}.lib'.format(self.name)
self.gcc_import_filename = 'lib{0}.dll.a'.format(self.name)
- if compiler_is_msvc(self.sources, is_cross, env):
+ if compilers_are_msvc(self.compilers):
# Shared library is of the form foo.dll
prefix = ''
# Import library is called foo.lib
@@ -928,7 +945,7 @@ class SharedLibrary(BuildTarget):
determine_filenames() above.
"""
buildtype = env.coredata.get_builtin_option('buildtype')
- if compiler_is_msvc(self.sources, is_cross, env) and buildtype.startswith('debug'):
+ if compilers_are_msvc(self.compilers) and buildtype.startswith('debug'):
# Currently we only implement separate debug symbol files for MSVC
# since the toolchain does it for us. Other toolchains embed the
# debugging symbols in the file itself by default.
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index c5b932c..0310e01 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -23,12 +23,27 @@ from . import coredata
about. To support a new compiler, add its information below.
Also add corresponding autodetection code in environment.py."""
-header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di']
-cpp_suffixes = ['cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'ipp', 'hxx', 'c++']
-c_suffixes = ['c']
-clike_suffixes = c_suffixes + cpp_suffixes
-obj_suffixes = ['o', 'obj', 'res']
-lib_suffixes = ['a', 'lib', 'dll', 'dylib', 'so']
+header_suffixes = ('h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di')
+obj_suffixes = ('o', 'obj', 'res')
+lib_suffixes = ('a', 'lib', 'dll', 'dylib', 'so')
+# Mapping of language to suffixes of files that should always be in that language
+# This means we can't include .h headers here since they could be C, C++, ObjC, etc.
+lang_suffixes = {
+ 'c': ('c',),
+ 'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx'),
+ 'fortran': ('f', 'f90', 'f95'),
+ 'd': ('d', 'di'),
+ 'objc': ('m',),
+ 'objcpp': ('mm',),
+ 'rust': ('rs',),
+ 'vala': ('vala', 'vapi'),
+ 'cs': ('cs',),
+ 'swift': ('swift',),
+ 'java': ('java',),
+}
+cpp_suffixes = lang_suffixes['cpp'] + ('h',)
+c_suffixes = lang_suffixes['c'] + ('h',)
+clike_suffixes = lang_suffixes['c'] + lang_suffixes['cpp'] + ('h',)
def is_header(fname):
if hasattr(fname, 'fname'):
@@ -300,9 +315,38 @@ class Compiler():
self.exelist = exelist
else:
raise TypeError('Unknown argument to Compiler')
+ # In case it's been overriden by a child class already
+ if not hasattr(self, 'file_suffixes'):
+ self.file_suffixes = lang_suffixes[self.language]
+ if not hasattr(self, 'can_compile_suffixes'):
+ self.can_compile_suffixes = set(self.file_suffixes)
+ self.default_suffix = self.file_suffixes[0]
self.version = version
self.base_options = []
+ def can_compile(self, src):
+ if hasattr(src, 'fname'):
+ src = src.fname
+ suffix = os.path.splitext(src)[1].lower()
+ if suffix and suffix[1:] in self.can_compile_suffixes:
+ return True
+ return False
+
+ def get_id(self):
+ return self.id
+
+ def get_language(self):
+ return self.language
+
+ def get_exelist(self):
+ return self.exelist[:]
+
+ def get_define(self, *args, **kwargs):
+ raise EnvironmentException('%s does not support get_define.' % self.id)
+
+ def has_define(self, *args, **kwargs):
+ raise EnvironmentException('%s does not support has_define.' % self.id)
+
def get_always_args(self):
return []
@@ -391,11 +435,13 @@ class Compiler():
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ # If a child ObjC or CPP class has already set it, don't set it ourselves
+ if not hasattr(self, 'language'):
+ self.language = 'c'
super().__init__(exelist, version)
- self.language = 'c'
- self.default_suffix = 'c'
self.id = 'unknown'
self.is_cross = is_cross
+ self.can_compile_suffixes.add('h')
if isinstance(exe_wrapper, str):
self.exe_wrapper = [exe_wrapper]
else:
@@ -434,9 +480,6 @@ class CCompiler(Compiler):
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
return build_unix_rpath_args(build_dir, rpath_paths, install_rpath)
- def get_id(self):
- return self.id
-
def get_dependency_gen_args(self, outtarget, outfile):
return ['-MMD', '-MQ', outtarget, '-MF', outfile]
@@ -446,9 +489,6 @@ class CCompiler(Compiler):
def get_depfile_suffix(self):
return 'd'
- def get_language(self):
- return self.language
-
def get_default_suffix(self):
return self.default_suffix
@@ -502,12 +542,6 @@ class CCompiler(Compiler):
return libstr.split(':')
return []
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix == 'c' or suffix == 'h':
- return True
- return False
-
def get_pic_args(self):
return ['-fPIC']
@@ -993,15 +1027,10 @@ void bar() {
class CPPCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
+ # If a child ObjCPP class has already set it, don't set it ourselves
+ if not hasattr(self, 'language'):
+ self.language = 'cpp'
CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
- self.language = 'cpp'
- self.default_suffix = 'cpp'
-
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix in cpp_suffixes:
- return True
- return False
def sanity_check(self, work_dir, environment):
code = 'class breakCCompiler;int main(int argc, char **argv) { return 0; }\n'
@@ -1009,15 +1038,8 @@ class CPPCompiler(CCompiler):
class ObjCCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.language = 'objc'
- self.default_suffix = 'm'
-
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix == 'm' or suffix == 'h':
- return True
- return False
+ CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
def sanity_check(self, work_dir, environment):
# TODO try to use sanity_check_impl instead of duplicated code
@@ -1043,15 +1065,8 @@ class ObjCCompiler(CCompiler):
class ObjCPPCompiler(CPPCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.language = 'objcpp'
- self.default_suffix = 'mm'
-
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix == 'mm' or suffix == 'h':
- return True
- return False
+ CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
def sanity_check(self, work_dir, environment):
# TODO try to use sanity_check_impl instead of duplicated code
@@ -1078,9 +1093,8 @@ class ObjCPPCompiler(CPPCompiler):
class MonoCompiler(Compiler):
def __init__(self, exelist, version):
- super().__init__(exelist, version)
self.language = 'cs'
- self.default_suffix = 'cs'
+ super().__init__(exelist, version)
self.id = 'mono'
self.monorunner = 'mono'
@@ -1102,21 +1116,12 @@ class MonoCompiler(Compiler):
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
return []
- def get_id(self):
- return self.id
-
def get_dependency_gen_args(self, outtarget, outfile):
return []
- def get_language(self):
- return self.language
-
def get_default_suffix(self):
return self.default_suffix
- def get_exelist(self):
- return self.exelist[:]
-
def get_linker_exelist(self):
return self.exelist[:]
@@ -1141,12 +1146,6 @@ class MonoCompiler(Compiler):
def get_std_shared_lib_link_args(self):
return []
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix == 'cs':
- return True
- return False
-
def get_pic_args(self):
return []
@@ -1187,9 +1186,8 @@ class MonoCompiler(Compiler):
class JavaCompiler(Compiler):
def __init__(self, exelist, version):
- super().__init__(exelist, version)
self.language = 'java'
- self.default_suffix = 'java'
+ super().__init__(exelist, version)
self.id = 'unknown'
self.javarunner = 'java'
@@ -1205,21 +1203,12 @@ class JavaCompiler(Compiler):
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
return []
- def get_id(self):
- return self.id
-
def get_dependency_gen_args(self, outtarget, outfile):
return []
- def get_language(self):
- return self.language
-
def get_default_suffix(self):
return self.default_suffix
- def get_exelist(self):
- return self.exelist[:]
-
def get_linker_exelist(self):
return self.exelist[:]
@@ -1249,12 +1238,6 @@ class JavaCompiler(Compiler):
def get_std_shared_lib_link_args(self):
return []
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix == 'java':
- return True
- return False
-
def get_pic_args(self):
return []
@@ -1296,10 +1279,10 @@ class JavaCompiler(Compiler):
class ValaCompiler(Compiler):
def __init__(self, exelist, version):
+ self.language = 'vala'
super().__init__(exelist, version)
self.version = version
- self.id = 'unknown'
- self.language = 'vala'
+ self.id = 'valac'
self.is_cross = False
def name_string(self):
@@ -1308,15 +1291,9 @@ class ValaCompiler(Compiler):
def needs_static_linker(self):
return False # Because compiles into C.
- def get_exelist(self):
- return self.exelist[:]
-
def get_werror_args(self):
return ['--fatal-warnings']
- def get_language(self):
- return self.language
-
def sanity_check(self, work_dir, environment):
src = 'valatest.vala'
source_name = os.path.join(work_dir, src)
@@ -1330,10 +1307,6 @@ class ValaCompiler(Compiler):
if pc.returncode != 0:
raise EnvironmentException('Vala compiler %s can not compile programs.' % self.name_string())
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- return suffix in ('vala', 'vapi')
-
def get_buildtype_args(self, buildtype):
if buildtype == 'debug' or buildtype == 'debugoptimized' or buildtype == 'minsize':
return ['--debug']
@@ -1341,9 +1314,9 @@ class ValaCompiler(Compiler):
class RustCompiler(Compiler):
def __init__(self, exelist, version):
- super().__init__(exelist, version)
- self.id = 'unknown'
self.language = 'rust'
+ super().__init__(exelist, version)
+ self.id = 'rustc'
def needs_static_linker(self):
return False
@@ -1351,15 +1324,6 @@ class RustCompiler(Compiler):
def name_string(self):
return ' '.join(self.exelist)
- def get_exelist(self):
- return self.exelist[:]
-
- def get_id(self):
- return self.id
-
- def get_language(self):
- return self.language
-
def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanity.rs')
output_name = os.path.join(work_dir, 'rusttest')
@@ -1374,9 +1338,6 @@ class RustCompiler(Compiler):
if subprocess.call(output_name) != 0:
raise EnvironmentException('Executables created by Rust compiler %s are not runnable.' % self.name_string())
- def can_compile(self, fname):
- return fname.endswith('.rs')
-
def get_dependency_gen_args(self, outfile):
return ['--dep-info', outfile]
@@ -1385,15 +1346,12 @@ class RustCompiler(Compiler):
class SwiftCompiler(Compiler):
def __init__(self, exelist, version):
+ self.language = 'swift'
super().__init__(exelist, version)
self.version = version
self.id = 'llvm'
- self.language = 'swift'
self.is_cross = False
- def get_id(self):
- return self.id
-
def get_linker_exelist(self):
return self.exelist[:]
@@ -1403,15 +1361,9 @@ class SwiftCompiler(Compiler):
def needs_static_linker(self):
return True
- def get_exelist(self):
- return self.exelist[:]
-
def get_werror_args(self):
return ['--fatal-warnings']
- def get_language(self):
- return self.language
-
def get_dependency_gen_args(self, outtarget, outfile):
return ['-emit-dependencies']
@@ -1472,15 +1424,11 @@ class SwiftCompiler(Compiler):
if subprocess.call(output_name) != 0:
raise EnvironmentException('Executables created by Swift compiler %s are not runnable.' % self.name_string())
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- return suffix in ('swift')
-
class DCompiler(Compiler):
def __init__(self, exelist, version, is_cross):
+ self.language = 'd'
super().__init__(exelist, version)
self.id = 'unknown'
- self.language = 'd'
self.is_cross = is_cross
def sanity_check(self, work_dir, environment):
@@ -1503,19 +1451,6 @@ class DCompiler(Compiler):
def name_string(self):
return ' '.join(self.exelist)
- def get_exelist(self):
- return self.exelist
-
- def get_id(self):
- return self.id
-
- def get_language(self):
- return self.language
-
- def can_compile(self, fname):
- suffix = fname.split('.')[-1]
- return suffix in ('d', 'di')
-
def get_linker_exelist(self):
return self.exelist[:]
@@ -1918,17 +1853,11 @@ class VisualStudioCCompiler(CCompiler):
class VisualStudioCPPCompiler(VisualStudioCCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap):
- VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.language = 'cpp'
+ VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.default_suffix = 'cpp'
self.base_options = ['b_pch'] # FIXME add lto, pgo and the like
- def can_compile(self, filename):
- suffix = filename.split('.')[-1]
- if suffix in cpp_suffixes:
- return True
- return False
-
def get_options(self):
return {'cpp_eh' : coredata.UserComboOption('cpp_eh',
'C++ exception handling type.',
@@ -1974,9 +1903,10 @@ def get_gcc_soname_args(gcc_type, shlib_name, path, soversion):
class GnuCompiler:
# Functionality that is common to all GNU family compilers.
- def __init__(self, gcc_type):
+ def __init__(self, gcc_type, defines):
self.id = 'gcc'
self.gcc_type = gcc_type
+ self.defines = defines or {}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_colorout', 'b_ndebug']
if self.gcc_type != GCC_OSX:
@@ -1996,6 +1926,13 @@ class GnuCompiler:
args[args.index('-Wpedantic')] = '-pedantic'
return args
+ def has_define(self, define):
+ return define in self.defines
+
+ def get_define(self, define):
+ if define in self.defines:
+ return defines[define]
+
def get_pic_args(self):
if self.gcc_type == GCC_MINGW:
return [] # On Window gcc defaults to fpic being always on.
@@ -2020,16 +1957,15 @@ class GnuCompiler:
return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
class GnuCCompiler(GnuCompiler, CCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
+ def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
- GnuCompiler.__init__(self, gcc_type)
+ GnuCompiler.__init__(self, gcc_type, defines)
+ # Gcc can do asm, too.
+ self.can_compile_suffixes.add('s')
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
- def can_compile(self, filename):
- return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Gcc can do asm, too.
-
def get_options(self):
opts = {'c_std' : coredata.UserComboOption('c_std', 'C language standard to use',
['none', 'c89', 'c99', 'c11', 'gnu89', 'gnu99', 'gnu11'],
@@ -2055,9 +1991,9 @@ class GnuCCompiler(GnuCompiler, CCompiler):
class GnuCPPCompiler(GnuCompiler, CPPCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap):
+ def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap, defines):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
- GnuCompiler.__init__(self, gcc_type)
+ GnuCompiler.__init__(self, gcc_type, defines)
self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
@@ -2093,22 +2029,22 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
class GnuObjCCompiler(GnuCompiler,ObjCCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ def __init__(self, exelist, version, is_cross, exe_wrapper=None, defines=None):
ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
# Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
# if this breaks your use case.
- GnuCompiler.__init__(self, GCC_STANDARD)
+ GnuCompiler.__init__(self, GCC_STANDARD, defines)
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None):
- ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ def __init__(self, exelist, version, is_cross, exe_wrapper=None, defines=None):
+ ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
# Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
# if this breaks your use case.
- GnuCompiler.__init__(self, GCC_STANDARD)
+ GnuCompiler.__init__(self, GCC_STANDARD, defines)
self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
@@ -2142,6 +2078,8 @@ class ClangCCompiler(ClangCompiler, CCompiler):
def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
ClangCompiler.__init__(self, clang_type)
+ # Clang can do asm, too.
+ self.can_compile_suffixes.add('s')
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
@@ -2164,9 +2102,6 @@ class ClangCCompiler(ClangCompiler, CCompiler):
def has_argument(self, arg, env):
return super().has_argument(['-Werror=unknown-warning-option', arg], env)
- def can_compile(self, filename):
- return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too.
-
class ClangCPPCompiler(ClangCompiler, CPPCompiler):
def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
@@ -2194,9 +2129,6 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
def has_argument(self, arg, env):
return super().has_argument(['-Werror=unknown-warning-option', arg], env)
- def can_compile(self, filename):
- return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Clang can do asm, too.
-
class ClangObjCCompiler(GnuObjCCompiler):
def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
super().__init__(exelist, version, is_cross, exe_wrapper)
@@ -2219,26 +2151,17 @@ class ClangObjCPPCompiler(GnuObjCPPCompiler):
class FortranCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ self.language = 'fortran'
super().__init__(exelist, version)
self.is_cross = is_cross
self.exe_wrapper = exe_wrapper
- self.language = 'fortran'
# Not really correct but I don't have Fortran compilers to test with. Sorry.
self.gcc_type = GCC_STANDARD
self.id = "IMPLEMENTATION CLASSES MUST SET THIS"
- def get_id(self):
- return self.id
-
def name_string(self):
return ' '.join(self.exelist)
- def get_exelist(self):
- return self.exelist[:]
-
- def get_language(self):
- return self.language
-
def get_pic_args(self):
if self.gcc_type == GCC_MINGW:
return [] # On Windows gcc defaults to fpic being always on.
@@ -2308,14 +2231,6 @@ end program prog
def get_linker_output_args(self, outputname):
return ['-o', outputname]
- def can_compile(self, src):
- if hasattr(src, 'fname'):
- src = src.fname
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f95' or suffix == '.f90':
- return True
- return False
-
def get_include_args(self, path, is_system):
return ['-I' + path]
@@ -2342,11 +2257,19 @@ end program prog
class GnuFortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
+ def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
super().__init__(exelist, version, is_cross, exe_wrapper=None)
self.gcc_type = gcc_type
+ self.defines = defines or {}
self.id = 'gcc'
+ def has_define(self, define):
+ return define in self.defines
+
+ def get_define(self, define):
+ if define in self.defines:
+ return defines[define]
+
def get_always_args(self):
return ['-pipe']
@@ -2398,18 +2321,13 @@ class IntelFortranCompiler(FortranCompiler):
std_warn_args = ['-warn', 'all']
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ self.file_suffixes = ('f', 'f90')
super().__init__(exelist, version, is_cross, exe_wrapper=None)
self.id = 'intel'
def get_module_outdir_args(self, path):
return ['-module', path]
- def can_compile(self, src):
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f90':
- return True
- return False
-
def get_warn_args(self, level):
return IntelFortranCompiler.std_warn_args
@@ -2423,12 +2341,6 @@ class PathScaleFortranCompiler(FortranCompiler):
def get_module_outdir_args(self, path):
return ['-module', path]
- def can_compile(self, src):
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
- return True
- return False
-
def get_std_warn_args(self, level):
return PathScaleFortranCompiler.std_warn_args
@@ -2442,12 +2354,6 @@ class PGIFortranCompiler(FortranCompiler):
def get_module_outdir_args(self, path):
return ['-module', path]
- def can_compile(self, src):
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
- return True
- return False
-
def get_warn_args(self, level):
return PGIFortranCompiler.std_warn_args
@@ -2462,12 +2368,6 @@ class Open64FortranCompiler(FortranCompiler):
def get_module_outdir_args(self, path):
return ['-module', path]
- def can_compile(self, src):
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
- return True
- return False
-
def get_warn_args(self, level):
return Open64FortranCompiler.std_warn_args
@@ -2484,12 +2384,6 @@ class NAGFortranCompiler(FortranCompiler):
def get_always_args(self):
return []
- def can_compile(self, src):
- suffix = os.path.splitext(src)[1].lower()
- if suffix == '.f' or suffix == '.f90' or suffix == '.f95':
- return True
- return False
-
def get_warn_args(self, level):
return NAGFortranCompiler.std_warn_args
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py
index 106273c..1b9e6f4 100644
--- a/mesonbuild/dependencies.py
+++ b/mesonbuild/dependencies.py
@@ -25,6 +25,7 @@ import sysconfig
from . mesonlib import MesonException
from . import mlog
from . import mesonlib
+from .environment import detect_cpu_family
class DependencyException(MesonException):
def __init__(self, *args, **kwargs):
@@ -474,7 +475,12 @@ class BoostDependency(Dependency):
def __init__(self, environment, kwargs):
Dependency.__init__(self)
self.name = 'boost'
+ self.environment = environment
self.libdir = ''
+ if 'native' in kwargs and environment.is_cross_build():
+ want_cross = not kwargs['native']
+ else:
+ want_cross = environment.is_cross_build()
try:
self.boost_root = os.environ['BOOST_ROOT']
if not os.path.isabs(self.boost_root):
@@ -482,6 +488,8 @@ class BoostDependency(Dependency):
except KeyError:
self.boost_root = None
if self.boost_root is None:
+ if want_cross:
+ raise DependencyException('BOOST_ROOT is needed while cross-compiling')
if mesonlib.is_windows():
self.boost_root = self.detect_win_root()
self.incdir = self.boost_root
@@ -575,11 +583,21 @@ class BoostDependency(Dependency):
return self.detect_lib_modules_nix()
def detect_lib_modules_win(self):
- if mesonlib.is_32bit():
+ arch = detect_cpu_family(self.environment.coredata.compilers)
+ # Guess the libdir
+ if arch == 'x86':
gl = 'lib32*'
- else:
+ elif arch == 'x86_64':
gl = 'lib64*'
- libdir = glob.glob(os.path.join(self.boost_root, gl))
+ else:
+ # Does anyone do Boost cross-compiling to other archs on Windows?
+ gl = None
+ # See if the libdir is valid
+ if gl:
+ libdir = glob.glob(os.path.join(self.boost_root, gl))
+ else:
+ libdir = []
+ # Can't find libdir, bail
if len(libdir) == 0:
return
libdir = libdir[0]
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 341e5e8..e411687 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -57,26 +57,89 @@ def detect_ninja():
if p.returncode == 0 and mesonlib.version_compare(version, ">=1.6"):
return n
-def detect_cpu_family():
+def detect_native_windows_arch():
+ """
+ The architecture of Windows itself: x86 or amd64
+ """
+ # These env variables are always available. See:
+ # https://msdn.microsoft.com/en-us/library/aa384274(VS.85).aspx
+ # https://blogs.msdn.microsoft.com/david.wang/2006/03/27/howto-detect-process-bitness/
+ arch = os.environ.get('PROCESSOR_ARCHITEW6432', '').lower()
+ if not arch:
+ try:
+ # If this doesn't exist, something is messing with the environment
+ arch = os.environ['PROCESSOR_ARCHITECTURE'].lower()
+ except KeyError:
+ raise InterpreterException('Unable to detect native OS architecture')
+ return arch
+
+def detect_windows_arch(compilers):
+ """
+ Detecting the 'native' architecture of Windows is not a trivial task. We
+ cannot trust that the architecture that Python is built for is the 'native'
+ one because you can run 32-bit apps on 64-bit Windows using WOW64 and
+ people sometimes install 32-bit Python on 64-bit Windows.
+
+ We also can't rely on the architecture of the OS itself, since it's
+ perfectly normal to compile and run 32-bit applications on Windows as if
+ they were native applications. It's a terrible experience to require the
+ user to supply a cross-info file to compile 32-bit applications on 64-bit
+ Windows. Thankfully, the only way to compile things with Visual Studio on
+ Windows is by entering the 'msvc toolchain' environment, which can be
+ easily detected.
+
+ In the end, the sanest method is as follows:
+ 1. Check if we're in an MSVC toolchain environment, and if so, return the
+ MSVC toolchain architecture as our 'native' architecture.
+ 2. If not, check environment variables that are set by Windows and WOW64 to
+ find out the architecture that Windows is built for, and use that as our
+ 'native' architecture.
+ """
+ os_arch = detect_native_windows_arch()
+ if os_arch != 'amd64':
+ return os_arch
+ # If we're on 64-bit Windows, 32-bit apps can be compiled without
+ # cross-compilation. So if we're doing that, just set the native arch as
+ # 32-bit and pretend like we're running under WOW64. Else, return the
+ # actual Windows architecture that we deduced above.
+ for compiler in compilers.values():
+ # Check if we're using and inside an MSVC toolchain environment
+ if compiler.id == 'msvc' and 'VCINSTALLDIR' in os.environ:
+ # 'Platform' is only set when the target arch is not 'x86'.
+ # It's 'x64' when targetting x86_64 and 'arm' when targetting ARM.
+ platform = os.environ.get('Platform', 'x86').lower()
+ if platform == 'x86':
+ return platform
+ if compiler.id == 'gcc' and compiler.has_define('__i386__'):
+ return 'x86'
+ return os_arch
+
+def detect_cpu_family(compilers):
"""
Python is inconsistent in its platform module.
It returns different values for the same cpu.
For x86 it might return 'x86', 'i686' or somesuch.
Do some canonicalization.
"""
- trial = platform.machine().lower()
+ if mesonlib.is_windows():
+ trial = detect_windows_arch(compilers)
+ else:
+ trial = platform.machine().lower()
if trial.startswith('i') and trial.endswith('86'):
return 'x86'
if trial.startswith('arm'):
return 'arm'
- if trial == 'amd64':
+ if trial in ('amd64', 'x64'):
return 'x86_64'
# Add fixes here as bugs are reported.
return trial
-def detect_cpu():
- trial = platform.machine().lower()
- if trial == 'amd64':
+def detect_cpu(compilers):
+ if mesonlib.is_windows():
+ trial = detect_windows_arch(compilers)
+ else:
+ trial = platform.machine().lower()
+ if trial in ('amd64', 'x64'):
return 'x86_64'
# Add fixes here as bugs are reported.
return trial
@@ -225,6 +288,45 @@ class Environment():
if type(oldval) != type(value):
self.coredata.user_options[name] = value
+ @staticmethod
+ def get_gnu_compiler_defines(compiler):
+ """
+ Detect GNU compiler platform type (Apple, MinGW, Unix)
+ """
+ # Arguments to output compiler pre-processor defines to stdout
+ # gcc, g++, and gfortran all support these arguments
+ args = compiler + ['-E', '-dM', '-']
+ p = subprocess.Popen(args, universal_newlines=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = p.communicate('')[0]
+ if p.returncode != 0:
+ raise EnvironmentException('Unable to detect GNU compiler type:\n' + output)
+ # Parse several lines of the type:
+ # `#define ___SOME_DEF some_value`
+ # and extract `___SOME_DEF`
+ defines = {}
+ for line in output.split('\n'):
+ if not line:
+ continue
+ d, *rest = line.split(' ', 2)
+ if d != '#define':
+ continue
+ if len(rest) == 1:
+ defines[rest] = True
+ if len(rest) == 2:
+ defines[rest[0]] = rest[1]
+ return defines
+
+ @staticmethod
+ def get_gnu_compiler_type(defines):
+ # Detect GCC type (Apple, MinGW, Cygwin, Unix)
+ if '__APPLE__' in defines:
+ return GCC_OSX
+ elif '__MINGW32__' in defines or '__MINGW64__' in defines:
+ return GCC_MINGW
+ # We ignore Cygwin for now, and treat it as a standard GCC
+ return GCC_STANDARD
+
def detect_c_compiler(self, want_cross):
evar = 'CC'
if self.is_cross_build() and want_cross:
@@ -266,16 +368,13 @@ class Environment():
version = vmatch.group(0)
else:
version = 'unknown version'
- if 'apple' in out and 'Free Software Foundation' in out:
- return GnuCCompiler(ccache + [compiler], version, GCC_OSX, is_cross, exe_wrap)
- if (out.startswith('cc') or 'gcc' in out.lower()) and \
- 'Free Software Foundation' in out:
- lowerout = out.lower()
- if 'mingw' in lowerout or 'msys' in lowerout or 'mingw' in compiler.lower():
- gtype = GCC_MINGW
- else:
- gtype = GCC_STANDARD
- return GnuCCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap)
+ if 'Free Software Foundation' in out:
+ defines = self.get_gnu_compiler_defines([compiler])
+ if not defines:
+ popen_exceptions[compiler] = 'no pre-processor defines'
+ continue
+ gtype = self.get_gnu_compiler_type(defines)
+ return GnuCCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap, defines)
if 'clang' in out:
if 'Apple' in out:
cltype = CLANG_OSX
@@ -331,13 +430,12 @@ class Environment():
version = vmatch.group(0)
if 'GNU Fortran' in out:
- if mesonlib.is_osx():
- gcctype = GCC_OSX
- elif mesonlib.is_windows():
- gcctype = GCC_MINGW
- else:
- gcctype = GCC_STANDARD
- return GnuFortranCompiler([compiler], version, gcctype, is_cross, exe_wrap)
+ defines = self.get_gnu_compiler_defines([compiler])
+ if not defines:
+ popen_exceptions[compiler] = 'no pre-processor defines'
+ continue
+ gtype = self.get_gnu_compiler_type(defines)
+ return GnuFortranCompiler([compiler], version, gtype, is_cross, exe_wrap, defines)
if 'G95' in out:
return G95FortranCompiler([compiler], version, is_cross, exe_wrap)
@@ -419,16 +517,13 @@ class Environment():
version = vmatch.group(0)
else:
version = 'unknown version'
- if 'apple' in out and 'Free Software Foundation' in out:
- return GnuCPPCompiler(ccache + [compiler], version, GCC_OSX, is_cross, exe_wrap)
- if (out.startswith('c++ ') or 'g++' in out or 'GCC' in out) and \
- 'Free Software Foundation' in out:
- lowerout = out.lower()
- if 'mingw' in lowerout or 'msys' in lowerout or 'mingw' in compiler.lower():
- gtype = GCC_MINGW
- else:
- gtype = GCC_STANDARD
- return GnuCPPCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap)
+ if 'Free Software Foundation' in out:
+ defines = self.get_gnu_compiler_defines([compiler])
+ if not defines:
+ popen_exceptions[compiler] = 'no pre-processor defines'
+ continue
+ gtype = self.get_gnu_compiler_type(defines)
+ return GnuCPPCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap, defines)
if 'clang' in out:
if 'Apple' in out:
cltype = CLANG_OSX
@@ -469,13 +564,11 @@ class Environment():
version = vmatch.group(0)
else:
version = 'unknown version'
- if (out.startswith('cc ') or 'gcc' in out) and \
- 'Free Software Foundation' in out:
- return GnuObjCCompiler(exelist, version, is_cross, exe_wrap)
+ if 'Free Software Foundation' in out:
+ defines = self.get_gnu_compiler_defines(exelist)
+ return GnuObjCCompiler(exelist, version, is_cross, exe_wrap, defines)
if out.startswith('Apple LLVM'):
return ClangObjCCompiler(exelist, version, CLANG_OSX, is_cross, exe_wrap)
- if 'apple' in out and 'Free Software Foundation' in out:
- return GnuObjCCompiler(exelist, version, is_cross, exe_wrap)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_objcpp_compiler(self, want_cross):
@@ -502,13 +595,11 @@ class Environment():
version = vmatch.group(0)
else:
version = 'unknown version'
- if (out.startswith('c++ ') or out.startswith('g++')) and \
- 'Free Software Foundation' in out:
- return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap)
+ if 'Free Software Foundation' in out:
+ defines = self.get_gnu_compiler_defines(exelist)
+ return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap, defines)
if out.startswith('Apple LLVM'):
return ClangObjCPPCompiler(exelist, version, CLANG_OSX, is_cross, exe_wrap)
- if 'apple' in out and 'Free Software Foundation' in out:
- return GnuObjCPPCompiler(exelist, version, is_cross, exe_wrap)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_java_compiler(self):
@@ -846,10 +937,12 @@ class CrossBuildInfo():
return 'host_machine' in self.config
def need_exe_wrapper(self):
- if self.has_host() and detect_cpu_family() == 'x86_64' and \
+ # Can almost always run 32-bit binaries on 64-bit natively if the host
+ # and build systems are the same. We don't pass any compilers to
+ # detect_cpu_family() here because we always want to know the OS
+ # architecture, not what the compiler environment tells us.
+ if self.has_host() and detect_cpu_family({}) == 'x86_64' and \
self.config['host_machine']['cpu_family'] == 'x86' and \
self.config['host_machine']['system'] == detect_system():
- # Can almost always run 32-bit binaries on 64-bit natively if the
- # host and build systems are the same
return False
return True
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 385e07a..cc85e77 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -375,7 +375,8 @@ class GeneratedListHolder(InterpreterObject):
self.held_object.add_file(a)
class BuildMachine(InterpreterObject):
- def __init__(self):
+ def __init__(self, compilers):
+ self.compilers = compilers
InterpreterObject.__init__(self)
self.methods.update({'system' : self.system_method,
'cpu_family' : self.cpu_family_method,
@@ -384,10 +385,10 @@ class BuildMachine(InterpreterObject):
})
def cpu_family_method(self, args, kwargs):
- return environment.detect_cpu_family()
+ return environment.detect_cpu_family(self.compilers)
def cpu_method(self, args, kwargs):
- return environment.detect_cpu()
+ return environment.detect_cpu(self.compilers)
def system_method(self, args, kwargs):
return environment.detect_system()
@@ -1099,6 +1100,8 @@ class Interpreter():
def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects'):
self.build = build
+ self.environment = build.environment
+ self.coredata = self.environment.get_coredata()
self.backend = backend
self.subproject = subproject
self.subdir = subdir
@@ -1126,7 +1129,8 @@ class Interpreter():
self.sanity_check_ast()
self.variables = {}
self.builtin = {}
- self.builtin['build_machine'] = BuildMachine()
+ self.parse_project()
+ self.builtin['build_machine'] = BuildMachine(self.coredata.compilers)
if not self.build.environment.is_cross_build():
self.builtin['host_machine'] = self.builtin['build_machine']
self.builtin['target_machine'] = self.builtin['build_machine']
@@ -1141,10 +1145,8 @@ class Interpreter():
else:
self.builtin['target_machine'] = self.builtin['host_machine']
self.builtin['meson'] = MesonMain(build, self)
- self.environment = build.environment
self.build_func_dict()
self.build_def_files = [os.path.join(self.subdir, environment.build_filename)]
- self.coredata = self.environment.get_coredata()
self.generators = []
self.visited_subdirs = {}
self.global_args_frozen = False
@@ -1196,6 +1198,15 @@ class Interpreter():
'environment' : self.func_environment,
}
+ def parse_project(self):
+ """
+ Parses project() and initializes languages, compilers etc. Do this
+ early because we need this before we parse the rest of the AST.
+ """
+ project = self.ast.lines[0]
+ args, kwargs = self.reduce_arguments(project.args)
+ self.func_project(project, args, kwargs)
+
def module_method_callback(self, invalues):
unwrap_single = False
if invalues is None:
@@ -1244,6 +1255,10 @@ class Interpreter():
first = self.ast.lines[0]
if not isinstance(first, mparser.FunctionNode) or first.func_name != 'project':
raise InvalidCode('First statement must be a call to project')
+ args = self.reduce_arguments(first.args)[0]
+ if len(args) < 2:
+ raise InvalidArguments('Not enough arguments to project(). Needs at least the project name and one language')
+
def check_cross_stdlibs(self):
if self.build.environment.is_cross_build():
@@ -1262,10 +1277,12 @@ class Interpreter():
pass
def run(self):
- self.evaluate_codeblock(self.ast)
+ # Evaluate everything after the first line, which is project() because
+ # we already parsed that in self.parse_project()
+ self.evaluate_codeblock(self.ast, start=1)
mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets))))
- def evaluate_codeblock(self, node):
+ def evaluate_codeblock(self, node, start=0):
if node is None:
return
if not isinstance(node, mparser.CodeBlockNode):
@@ -1274,7 +1291,7 @@ class Interpreter():
e.colno = node.colno
raise e
statements = node.lines
- i = 0
+ i = start
while i < len(statements):
cur = statements[i]
try:
@@ -1595,9 +1612,6 @@ class Interpreter():
@stringArgs
def func_project(self, node, args, kwargs):
- if len(args) < 2:
- raise InvalidArguments('Not enough arguments to project(). Needs at least the project name and one language')
-
if not self.is_subproject():
self.build.project_name = args[0]
if self.environment.first_invocation and 'default_options' in kwargs:
@@ -1619,7 +1633,7 @@ class Interpreter():
raise InterpreterException('Meson version is %s but project requires %s.' % (cv, pv))
self.build.projects[self.subproject] = args[0]
mlog.log('Project name: ', mlog.bold(args[0]), sep='')
- self.add_languages(node, args[1:], True)
+ self.add_languages(args[1:], True)
langs = self.coredata.compilers.keys()
if 'vala' in langs:
if not 'c' in langs:
@@ -1629,7 +1643,7 @@ class Interpreter():
@stringArgs
def func_add_languages(self, node, args, kwargs):
- return self.add_languages(node, args, kwargs.get('required', True))
+ return self.add_languages(args, kwargs.get('required', True))
@noKwargs
def func_message(self, node, args, kwargs):
@@ -1649,8 +1663,6 @@ class Interpreter():
raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.')
mlog.log(mlog.bold('Message:'), argstr)
- return
-
@noKwargs
def func_error(self, node, args, kwargs):
@@ -1727,7 +1739,7 @@ class Interpreter():
self.coredata.compiler_options = new_options
return (comp, cross_comp)
- def add_languages(self, node, args, required):
+ def add_languages(self, args, required):
success = True
need_cross_compiler = self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler()
for lang in args:
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 7294a54..abb5641 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -91,9 +91,6 @@ def is_windows():
platname = platform.system().lower()
return platname == 'windows' or 'mingw' in platname
-def is_32bit():
- return not(sys.maxsize > 2**32)
-
def is_debianlike():
return os.path.isfile('/etc/debian_version')