diff options
32 files changed, 1228 insertions, 535 deletions
diff --git a/.appveyor.yml b/.appveyor.yml index d5e0fbf..38ebe56 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,8 +10,6 @@ branches: - master install: - - ps: (new-object net.webclient).DownloadFile('https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi', 'python-3.4.4.msi') - - ps: msiexec /i python-3.4.4.msi /quiet /qn /norestart - ps: (new-object net.webclient).DownloadFile('https://dl.dropboxusercontent.com/u/37517477/ninja.exe', 'c:\python34\ninja.exe') - cmd: copy c:\python34\python.exe c:\python34\python3.exe - '"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x86' @@ -20,4 +18,8 @@ build_script: - cmd: echo No build step. test_script: - - cmd: PATH c:\python34;%PATH% && python3 run_tests.py --backend=ninja + - cmd: PATH c:\python34;%PATH%; && python3 run_tests.py --backend=ninja + +on_finish: + - appveyor PushArtifact meson-test-run.txt -DeploymentName "Text test logs" + - appveyor PushArtifact meson-test-run.xml -DeploymentName "XML test logs" @@ -27,6 +27,17 @@ pip will download the package automatically). The exact command to type to install with pip can very between systems, be sure to use the Python 3 version of pip. +#### Creating a standalone script + +Meson can be run as a [Python zip +app](https://docs.python.org/3/library/zipapp.html). To generate the +executable run the following command: + + python3 -m zipapp -p '/usr/bin/env python3' -m meson:main -o meson <source checkout> + +Note that the source checkout may not be `meson` because it would +clash with the generated binary name. + ####Running Meson requires that you have a source directory and a build directory diff --git a/authors.txt b/authors.txt index fbac571..f0c2006 100644 --- a/authors.txt +++ b/authors.txt @@ -45,3 +45,4 @@ Elliott Sales de Andrade Patrick Griffis Iain Lane Daniel Brendle +Franz Zapata @@ -17,8 +17,18 @@ from mesonbuild import mesonmain import sys, os -thisfile = __file__ -if not os.path.isabs(thisfile): - thisfile = os.path.normpath(os.path.join(os.getcwd(), thisfile)) +def main(): + thisfile = __file__ + if not os.path.isabs(thisfile): + thisfile = os.path.normpath(os.path.join(os.getcwd(), thisfile)) + if __package__ == '': + thisfile = os.path.dirname(thisfile) + + # The first argument *must* be an absolute path because + # the user may have launched the program from a dir + # that is not in path. + sys.exit(mesonmain.run(thisfile, sys.argv[1:])) + +if __name__ == '__main__': + main() -sys.exit(mesonmain.run(thisfile, sys.argv[1:])) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index efddf7b..d5af056 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -237,27 +237,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: @@ -629,3 +608,24 @@ class Backend(): for s in self.build.postconf_scripts: cmd = s['exe'].get_command() + s['args'] subprocess.check_call(cmd, env=child_env) + + # Subprojects of subprojects may cause the same dep args to be used + # multiple times. Remove duplicates here. Note that we can't dedup + # libraries based on name alone, because "-lfoo -lbar -lfoo" is + # a completely valid (though pathological) sequence and removing the + # latter may fail. Usually only applies to static libs, though. + def dedup_arguments(self, commands): + includes = {} + final_commands = [] + previous = '-fsuch_arguments=woof' + for c in commands: + if c.startswith(('-I', '-L', '/LIBPATH')): + if c in includes: + continue + includes[c] = True + if previous == c: + continue + previous = c + final_commands.append(c) + return final_commands + diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 930d37f..6b6b4ea 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -239,19 +239,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) self.process_target_dependencies(target, outfile) self.generate_custom_generator_rules(target, outfile) @@ -737,8 +736,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 = '' @@ -788,8 +786,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', []) @@ -842,14 +839,14 @@ int dummy; outfile.write('\n') def split_vala_sources(self, sources): - src = [] + other_src = [] vapi_src = [] for s in sources: if s.endswith('.vapi'): vapi_src.append(s) else: - src.append(s) - return (src, vapi_src) + other_src.append(s) + return (other_src, vapi_src) def determine_dep_vapis(self, target): result = [] @@ -864,17 +861,13 @@ 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'] - (src, vapi_src) = self.split_vala_sources(target.get_sources()) + valac = target.compilers['vala'] + (other_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 = [] - vala_input_files = [] - for s in src: - if s.endswith('.vala'): - vala_input_files.append(s.rel_to_builddir(self.build_to_src)) - if len(src) == 0: + if len(other_src) == 0: raise InvalidArguments('Vala library has no Vala source files.') namebase = target.name base_h = namebase + '.h' @@ -885,8 +878,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): @@ -894,9 +887,23 @@ int dummy; args += ['-H', hname] args += ['--library=' + target.name] args += ['--vapi=' + os.path.join('..', base_vapi)] - for src in vala_input_files: - namebase = os.path.splitext(os.path.split(src)[1])[0] + '.c' - full_c = os.path.join(self.get_target_private_dir(target), namebase) + vala_src = [] + for s in other_src: + if not s.endswith('.vala'): + continue + vala_file = s.rel_to_builddir(self.build_to_src) + vala_src.append(vala_file) + # Figure out where the Vala compiler will write the compiled C file + dirname, basename = os.path.split(vala_file) + # If the Vala file is in a subdir of the build dir (in our case + # because it was generated/built by something else), the subdir path + # components will be preserved in the output path. But if the Vala + # file is outside the build directory, the path components will be + # stripped and just the basename will be used. + c_file = os.path.splitext(basename)[0] + '.c' + if s.is_built: + c_file = os.path.join(dirname, c_file) + full_c = os.path.join(self.get_target_private_dir(target), c_file) generated_c_files.append(full_c) outputs.append(full_c) if self.environment.coredata.get_builtin_option('werror'): @@ -922,14 +929,14 @@ int dummy; args += dependency_vapis element = NinjaBuildElement(self.all_outputs, outputs, valac.get_language() + '_COMPILER', - vala_input_files + vapi_src) + vala_src + vapi_src) element.add_item('ARGS', args) element.add_dep(extra_dep_files) element.write(outfile) 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): @@ -1020,7 +1027,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 = [] @@ -1693,6 +1700,7 @@ rule FORTRAN_DEP_HACK element.add_orderdep(d) element.add_orderdep(pch_dep) element.add_orderdep(extra_orderdeps) + commands = self.dedup_arguments(commands) for i in self.get_fortran_orderdeps(target, compiler): element.add_orderdep(i) element.add_item('DEPFILE', dep_file) @@ -1855,7 +1863,7 @@ rule FORTRAN_DEP_HACK custom_target_libraries = self.get_custom_target_provided_libraries(target) commands += extra_args commands += custom_target_libraries - commands = linker.unix_link_flags_to_native(commands) + commands = linker.unix_link_flags_to_native(self.dedup_arguments(commands)) dep_targets = [self.get_dependency_filename(t) for t in dependencies] dep_targets += [os.path.join(self.environment.source_dir, target.subdir, t) for t in target.link_depends] 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 8772803..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'] @@ -588,15 +622,15 @@ class CCompiler(Compiler): code = 'int main(int argc, char **argv) { int class=0; return class; }\n' return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code) - def has_header(self, hname, env, extra_args=None): + def has_header(self, hname, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] templ = '''#include<%s> int someSymbolHereJustForFun; ''' - return self.compiles(templ % hname, env, extra_args) + return self.compiles(templ % hname, env, extra_args, dependencies) - def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None): + def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] templ = '''{2} @@ -604,7 +638,7 @@ int someSymbolHereJustForFun; int main () {{ {1}; }}''' # Pass -O0 to ensure that the symbol isn't optimized away args = extra_args + self.get_no_optimization_args() - return self.compiles(templ.format(hname, symbol, prefix), env, args) + return self.compiles(templ.format(hname, symbol, prefix), env, args, dependencies) def compile(self, code, srcname, extra_args=None): if extra_args is None: @@ -624,18 +658,23 @@ int main () {{ {1}; }}''' os.remove(srcname) return p - def compiles(self, code, env, extra_args=None): + def compiles(self, code, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] if isinstance(extra_args, str): extra_args = [extra_args] + if dependencies is None: + dependencies = [] + elif not isinstance(dependencies, list): + dependencies = [dependencies] suflen = len(self.default_suffix) (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) os.close(fd) with open(srcname, 'w') as ofile: ofile.write(code) + cargs = [a for d in dependencies for a in d.get_compile_args()] # Convert flags to the native type of the selected compiler - args = self.unix_link_flags_to_native(extra_args) + args = self.unix_link_flags_to_native(cargs + extra_args) # Read c_args/cpp_args/etc from the cross-info file (if needed) args += self.get_cross_extra_flags(env, compile=True, link=False) # We only want to compile; not link @@ -652,19 +691,25 @@ int main () {{ {1}; }}''' pass return p.returncode == 0 - def links(self, code, env, extra_args=None): + def links(self, code, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] elif isinstance(extra_args, str): extra_args = [extra_args] + if dependencies is None: + dependencies = [] + elif not isinstance(dependencies, list): + dependencies = [dependencies] (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) os.close(fd) (fd, dstname) = tempfile.mkstemp() os.close(fd) with open(srcname, 'w') as ofile: ofile.write(code) + cargs = [a for d in dependencies for a in d.get_compile_args()] + link_args = [a for d in dependencies for a in d.get_link_args()] # Convert flags to the native type of the selected compiler - args = self.unix_link_flags_to_native(extra_args) + args = self.unix_link_flags_to_native(cargs + link_args + extra_args) # Select a CRT if needed since we're linking args += self.get_linker_debug_crt_args() # Read c_args/c_link_args/cpp_args/cpp_link_args/etc from the cross-info file (if needed) @@ -678,17 +723,23 @@ int main () {{ {1}; }}''' pass return p.returncode == 0 - def run(self, code, env, extra_args=None): + def run(self, code, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] + if dependencies is None: + dependencies = [] + elif not isinstance(dependencies, list): + dependencies = [dependencies] if self.is_cross and self.exe_wrapper is None: raise CrossNoRunException('Can not run test applications in this cross environment.') (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) os.close(fd) with open(srcname, 'w') as ofile: ofile.write(code) + cargs = [a for d in dependencies for a in d.get_compile_args()] + link_args = [a for d in dependencies for a in d.get_link_args()] # Convert flags to the native type of the selected compiler - args = self.unix_link_flags_to_native(extra_args) + args = self.unix_link_flags_to_native(cargs + link_args + extra_args) # Select a CRT if needed since we're linking args += self.get_linker_debug_crt_args() # Read c_link_args/cpp_link_args/etc from the cross-info file @@ -737,7 +788,7 @@ int main () {{ {1}; }}''' pass return RunResult(True, pe.returncode, so, se) - def cross_sizeof(self, element, prefix, env, extra_args=None): + def cross_sizeof(self, element, prefix, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] element_exists_templ = '''#include <stdio.h> @@ -751,11 +802,11 @@ int main(int argc, char **argv) {{ int temparray[%d-sizeof(%s)]; ''' args = extra_args + self.get_no_optimization_args() - if not self.compiles(element_exists_templ.format(prefix, element), env, args): + if not self.compiles(element_exists_templ.format(prefix, element), env, args, dependencies): return -1 for i in range(1, 1024): code = templ % (prefix, i, element) - if self.compiles(code, env, args): + if self.compiles(code, env, args, dependencies): if self.id == 'msvc': # MSVC refuses to construct an array of zero size, so # the test only succeeds when i is sizeof(element) + 1 @@ -763,11 +814,11 @@ int temparray[%d-sizeof(%s)]; return i raise EnvironmentException('Cross checking sizeof overflowed.') - def sizeof(self, element, prefix, env, extra_args=None): + def sizeof(self, element, prefix, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] if self.is_cross: - return self.cross_sizeof(element, prefix, env, extra_args) + return self.cross_sizeof(element, prefix, env, extra_args, dependencies) templ = '''#include<stdio.h> %s @@ -776,14 +827,14 @@ int main(int argc, char **argv) { return 0; }; ''' - res = self.run(templ % (prefix, element), env, extra_args) + res = self.run(templ % (prefix, element), env, extra_args, dependencies) if not res.compiled: return -1 if res.returncode != 0: raise EnvironmentException('Could not run sizeof test binary.') return int(res.stdout) - def cross_alignment(self, typename, env, extra_args=None): + def cross_alignment(self, typename, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] type_exists_templ = '''#include <stdio.h> @@ -800,11 +851,11 @@ struct tmp { int testarray[%d-offsetof(struct tmp, target)]; ''' args = extra_args + self.get_no_optimization_args() - if not self.compiles(type_exists_templ.format(typename), env, args): + if not self.compiles(type_exists_templ.format(typename), env, args, dependencies): return -1 for i in range(1, 1024): code = templ % (typename, i) - if self.compiles(code, env, args): + if self.compiles(code, env, args, dependencies): if self.id == 'msvc': # MSVC refuses to construct an array of zero size, so # the test only succeeds when i is sizeof(element) + 1 @@ -812,11 +863,11 @@ int testarray[%d-offsetof(struct tmp, target)]; return i raise EnvironmentException('Cross checking offsetof overflowed.') - def alignment(self, typename, env, extra_args=None): + def alignment(self, typename, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] if self.is_cross: - return self.cross_alignment(typename, env, extra_args) + return self.cross_alignment(typename, env, extra_args, dependencies) templ = '''#include<stdio.h> #include<stddef.h> @@ -830,7 +881,7 @@ int main(int argc, char **argv) { return 0; } ''' - res = self.run(templ % typename, env, extra_args) + res = self.run(templ % typename, env, extra_args, dependencies) if not res.compiled: raise EnvironmentException('Could not compile alignment test.') if res.returncode != 0: @@ -840,7 +891,7 @@ int main(int argc, char **argv) { raise EnvironmentException('Could not determine alignment of %s. Sorry. You might want to file a bug.' % typename) return align - def has_function(self, funcname, prefix, env, extra_args=None): + def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None): """ First, this function looks for the symbol in the default libraries provided by the compiler (stdlib + a few others usually). If that @@ -897,7 +948,7 @@ int main(int argc, char **argv) { if isinstance(val, bool): return val raise EnvironmentException('Cross variable {0} is not a boolean.'.format(varname)) - if self.links(templ.format(prefix, funcname), env, extra_args): + if self.links(templ.format(prefix, funcname), env, extra_args, dependencies): return True # Add -O0 to ensure that the symbol isn't optimized away by the compiler args = extra_args + self.get_no_optimization_args() @@ -906,15 +957,15 @@ int main(int argc, char **argv) { # still detect the function. We still want to fail if __stub_foo or # _stub_foo are defined, of course. header_templ = '#include <limits.h>\n{0}\n' + stubs_fail + '\nint main() {{ {1}; }}' - if self.links(header_templ.format(prefix, funcname), env, args): + if self.links(header_templ.format(prefix, funcname), env, args, dependencies): return True # Some functions like alloca() are defined as compiler built-ins which # are inlined by the compiler, so test for that instead. Built-ins are # special functions that ignore all includes and defines, so we just # directly try to link via main(). - return self.links('int main() {{ {0}; }}'.format('__builtin_' + funcname), env, args) + return self.links('int main() {{ {0}; }}'.format('__builtin_' + funcname), env, args, dependencies) - def has_members(self, typename, membernames, prefix, env, extra_args=None): + def has_members(self, typename, membernames, prefix, env, extra_args=None, dependencies=None): if extra_args is None: extra_args = [] templ = '''{0} @@ -928,15 +979,15 @@ void bar() {{ for m in membernames: members += 'foo.{};\n'.format(m) code = templ.format(prefix, typename, 'foo', members) - return self.compiles(code, env, extra_args) + return self.compiles(code, env, extra_args, dependencies) - def has_type(self, typename, prefix, env, extra_args): + def has_type(self, typename, prefix, env, extra_args, dependencies=None): templ = '''%s void bar() { sizeof(%s); }; ''' - return self.compiles(templ % (prefix, typename), env, extra_args) + return self.compiles(templ % (prefix, typename), env, extra_args, dependencies) def find_library(self, libname, env, extra_dirs): # First try if we can just add the library as -l. @@ -976,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' @@ -992,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 @@ -1026,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 @@ -1061,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' @@ -1085,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[:] @@ -1124,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 [] @@ -1170,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' @@ -1188,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[:] @@ -1232,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 [] @@ -1279,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): @@ -1291,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) @@ -1313,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'] @@ -1324,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 @@ -1334,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') @@ -1357,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] @@ -1368,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[:] @@ -1386,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'] @@ -1455,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): @@ -1486,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[:] @@ -1901,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.', @@ -1957,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: @@ -1979,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. @@ -2003,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'], @@ -2038,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']} @@ -2076,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']} @@ -2125,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']} @@ -2147,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): @@ -2177,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) @@ -2202,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. @@ -2291,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] @@ -2325,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'] @@ -2381,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 @@ -2406,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 @@ -2425,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 @@ -2445,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 @@ -2467,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 4a76c94..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() @@ -666,6 +667,25 @@ class CompilerHolder(InterpreterObject): args += mesonlib.stringlistify(kwargs.get('args', [])) return args + def determine_dependencies(self, kwargs, allowed_dep_types=None): + deps = kwargs.get('dependencies', None) + if allowed_dep_types is None: + allowed_dep_types = (dependencies.Dependency, dependencies.ExternalLibrary) + if deps is not None: + if not isinstance(deps, list): + deps = [deps] + final_deps = [] + for d in deps: + try: + d = d.held_object + except Exception: + pass + if not isinstance(d, allowed_dep_types): + raise InterpreterException('Dependencies must be external deps') + final_deps.append(d) + deps = final_deps + return deps + def alignment_method(self, args, kwargs): if len(args) != 1: raise InterpreterException('Alignment method takes exactly one positional argument.') @@ -685,7 +705,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(testname, str): raise InterpreterException('Testname argument must be a string.') extra_args = self.determine_args(kwargs) - result = self.compiler.run(code, self.environment, extra_args) + deps = self.determine_dependencies(kwargs) + result = self.compiler.run(code, self.environment, extra_args, deps) if len(testname) > 0: if not result.compiled: h = mlog.red('DID NOT COMPILE') @@ -715,8 +736,9 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of has_member must be a string.') extra_args = self.determine_args(kwargs) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) had = self.compiler.has_members(typename, [membername], prefix, - self.environment, extra_args) + self.environment, extra_args, deps) if had: hadtxt = mlog.green('YES') else: @@ -733,8 +755,9 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of has_members must be a string.') extra_args = self.determine_args(kwargs) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) had = self.compiler.has_members(typename, membernames, prefix, - self.environment, extra_args) + self.environment, extra_args, deps) if had: hadtxt = mlog.green('YES') else: @@ -753,7 +776,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of has_function must be a string.') extra_args = self.determine_args(kwargs) - had = self.compiler.has_function(funcname, prefix, self.environment, extra_args) + deps = self.determine_dependencies(kwargs) + had = self.compiler.has_function(funcname, prefix, self.environment, extra_args, deps) if had: hadtxt = mlog.green('YES') else: @@ -770,7 +794,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of has_type must be a string.') extra_args = self.determine_args(kwargs) - had = self.compiler.has_type(typename, prefix, self.environment, extra_args) + deps = self.determine_dependencies(kwargs) + had = self.compiler.has_type(typename, prefix, self.environment, extra_args, deps) if had: hadtxt = mlog.green('YES') else: @@ -787,7 +812,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of sizeof must be a string.') extra_args = self.determine_args(kwargs) - esize = self.compiler.sizeof(element, prefix, self.environment, extra_args) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) + esize = self.compiler.sizeof(element, prefix, self.environment, extra_args, deps) mlog.log('Checking for size of "%s": %d' % (element, esize)) return esize @@ -800,7 +826,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(testname, str): raise InterpreterException('Testname argument must be a string.') extra_args = self.determine_args(kwargs) - result = self.compiler.compiles(code, self.environment, extra_args) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) + result = self.compiler.compiles(code, self.environment, extra_args, deps) if len(testname) > 0: if result: h = mlog.green('YES') @@ -818,7 +845,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(testname, str): raise InterpreterException('Testname argument must be a string.') extra_args = self.determine_args(kwargs) - result = self.compiler.links(code, self.environment, extra_args) + deps = self.determine_dependencies(kwargs) + result = self.compiler.links(code, self.environment, extra_args, deps) if len(testname) > 0: if result: h = mlog.green('YES') @@ -833,7 +861,8 @@ class CompilerHolder(InterpreterObject): check_stringlist(args) string = args[0] extra_args = self.determine_args(kwargs) - haz = self.compiler.has_header(string, self.environment, extra_args) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) + haz = self.compiler.has_header(string, self.environment, extra_args, deps) if haz: h = mlog.green('YES') else: @@ -851,7 +880,8 @@ class CompilerHolder(InterpreterObject): if not isinstance(prefix, str): raise InterpreterException('Prefix argument of has_function must be a string.') extra_args = self.determine_args(kwargs) - haz = self.compiler.has_header_symbol(hname, symbol, prefix, self.environment, extra_args) + deps = self.determine_dependencies(kwargs, allowed_dep_types=(dependencies.Dependency,)) + haz = self.compiler.has_header_symbol(hname, symbol, prefix, self.environment, extra_args, deps) if haz: h = mlog.green('YES') else: @@ -860,6 +890,7 @@ class CompilerHolder(InterpreterObject): return haz def find_library_method(self, args, kwargs): + # TODO add dependencies support? if len(args) != 1: raise InterpreterException('find_library method takes one argument.') libname = args[0] @@ -1069,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 @@ -1096,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'] @@ -1111,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 @@ -1166,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: @@ -1214,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(): @@ -1232,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): @@ -1244,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: @@ -1565,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: @@ -1589,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: @@ -1599,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): @@ -1619,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): @@ -1697,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') diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index d8c8f10..11abf88 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -16,7 +16,7 @@ functionality such as gobject-introspection and gresources.''' from .. import build -import os, sys +import os import subprocess from ..mesonlib import MesonException from .. import dependencies @@ -94,16 +94,17 @@ class GnomeModule: return stdout.split('\n')[:-1] - def get_link_args(self, state, lib, depends): + def get_link_args(self, state, lib, depends=None): link_command = ['-l%s' % lib.name] if isinstance(lib, build.SharedLibrary): link_command += ['-L%s' % os.path.join(state.environment.get_build_dir(), lib.subdir)] - depends.append(lib) + if depends: + depends.append(lib) return link_command - def get_include_args(self, state, include_dirs): + def get_include_args(self, state, include_dirs, prefix='-I'): if not include_dirs: return [] @@ -113,14 +114,81 @@ class GnomeModule: dirs = incdirs.held_object else: dirs = incdirs - for incdir in dirs.get_incdirs(): - if os.path.isabs(incdir): - dirs_str += ['-I%s' % os.path.join(incdir)] - else: - dirs_str += ['-I%s' % os.path.join(state.environment.get_source_dir(), - dirs.curdir, incdir)] + + if isinstance(dirs, str): + dirs_str += ['%s%s' % (prefix, dirs)] + continue + + # Should be build.IncludeDirs object. + basedir = dirs.get_curdir() + for d in dirs.get_incdirs(): + expdir = os.path.join(basedir, d) + srctreedir = os.path.join(state.environment.get_source_dir(), expdir) + buildtreedir = os.path.join(state.environment.get_build_dir(), expdir) + dirs_str += ['%s%s' % (prefix, buildtreedir), + '%s%s' % (prefix, srctreedir)] + for d in dirs.get_extra_build_dirs(): + dirs_str += ['%s%s' % (prefix, d)] + return dirs_str + def get_dependencies_flags(self, deps, state, depends=None): + cflags = set() + ldflags = set() + gi_includes = set() + if not isinstance(deps, list): + deps = [deps] + + for dep in deps: + if hasattr(dep, 'held_object'): + dep = dep.held_object + if isinstance(dep, dependencies.InternalDependency): + cflags.update(self.get_include_args( state, dep.include_directories)) + for lib in dep.libraries: + ldflags.update(self.get_link_args(state, lib.held_object, depends)) + libdepflags = self.get_dependencies_flags(lib.held_object.get_external_deps(), state, depends) + cflags.update(libdepflags[0]) + ldflags.update(libdepflags[1]) + gi_includes.update(libdepflags[2]) + extdepflags = self.get_dependencies_flags(dep.ext_deps, state, depends) + cflags.update(extdepflags[0]) + ldflags.update(extdepflags[1]) + gi_includes.update(extdepflags[2]) + for source in dep.sources: + if isinstance(source.held_object, GirTarget): + gi_includes.update([os.path.join(state.environment.get_build_dir(), + source.held_object.get_subdir())]) + # This should be any dependency other than an internal one. + elif isinstance(dep, dependencies.Dependency): + cflags.update(dep.get_compile_args()) + for lib in dep.get_link_args(): + if (os.path.isabs(lib) and + # For PkgConfigDependency only: + getattr(dep, 'is_libtool', False)): + ldflags.update(["-L%s" % os.path.dirname(lib)]) + libname = os.path.basename(lib) + if libname.startswith("lib"): + libname = libname[3:] + libname = libname.split(".so")[0] + lib = "-l%s" % libname + # Hack to avoid passing some compiler options in + if lib.startswith("-W"): + continue + ldflags.update([lib]) + + if isinstance(dep, dependencies.PkgConfigDependency): + girdir = dep.get_variable("girdir") + if girdir: + gi_includes.update([girdir]) + elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): + for incd in dep.get_include_dirs(): + cflags.update(incd.get_incdirs()) + else: + mlog.log('dependency %s not handled to build gir files' % dep) + continue + + return cflags, ldflags, gi_includes + def generate_gir(self, state, args, kwargs): if len(args) != 1: raise MesonException('Gir takes one argument') @@ -143,6 +211,7 @@ class GnomeModule: libsources = kwargs.pop('sources') girfile = '%s-%s.gir' % (ns, nsversion) depends = [girtarget] + gir_inc_dirs = [] scan_command = ['g-ir-scanner', '@INPUT@'] scan_command += pkgargs @@ -151,7 +220,7 @@ class GnomeModule: extra_args = mesonlib.stringlistify(kwargs.pop('extra_args', [])) scan_command += extra_args - scan_command += self.get_include_args(state, girtarget.include_dirs) + scan_command += self.get_include_args(state, girtarget.get_include_dirs()) if 'link_with' in kwargs: link_with = kwargs.pop('link_with') @@ -162,12 +231,25 @@ class GnomeModule: if 'includes' in kwargs: includes = kwargs.pop('includes') - if isinstance(includes, str): - scan_command += ['--include=%s' % includes] - elif isinstance(includes, list): - scan_command += ['--include=%s' % inc for inc in includes] - else: - raise MesonException('Gir includes must be str or list') + if not isinstance(includes, list): + includes = [includes] + for inc in includes: + if hasattr(inc, 'held_object'): + inc = inc.held_object + if isinstance(inc, str): + scan_command += ['--include=%s' % (inc, )] + elif isinstance(inc, GirTarget): + gir_inc_dirs += [ + os.path.join(state.environment.get_build_dir(), + inc.get_subdir()), + ] + scan_command += [ + "--include=%s" % (inc.get_basename()[:-4], ), + ] + depends += [inc] + else: + raise MesonException( + 'Gir includes must be str, GirTarget, or list of them') if state.global_args.get('c'): scan_command += ['--cflags-begin'] scan_command += state.global_args['c'] @@ -191,54 +273,27 @@ class GnomeModule: else: raise MesonException('Gir export packages must be str or list') - deps = None - if 'dependencies' in kwargs: - deps = kwargs.pop('dependencies') - if not isinstance (deps, list): - deps = [deps] - for dep in deps: - if isinstance(dep.held_object, dependencies.InternalDependency): - scan_command += self.get_include_args(state, dep.held_object.include_directories) - for lib in dep.held_object.libraries: - scan_command += self.get_link_args(state, lib.held_object, depends) - for source in dep.held_object.sources: - if isinstance(source.held_object, GirTarget): - scan_command += ["--add-include-path=%s" % - os.path.join(state.environment.get_build_dir(), - source.held_object.get_subdir())] - elif isinstance(dep.held_object, dependencies.PkgConfigDependency): - for lib in dep.held_object.libs: - if os.path.isabs(lib) and dep.held_object.is_libtool: - scan_command += ["-L%s" % os.path.dirname(lib)] - libname = os.path.basename(lib) - if libname.startswith("lib"): - libname = libname[3:] - libname = libname.split(".so")[0] - lib = "-l%s" % libname - # Hack to avoid passing some compiler options in - if lib.startswith("-W"): - continue - scan_command += [lib] - - girdir = dep.held_object.get_variable ("girdir") - if girdir: - scan_command += ["--add-include-path=%s" % girdir] - else: - mlog.log('dependency %s not handled to build gir files' % dep) - continue + deps = kwargs.pop('dependencies', []) + if not isinstance(deps, list): + deps = [deps] + deps = (girtarget.get_all_link_deps() + girtarget.get_external_deps() + + deps) + cflags, ldflags, gi_includes = self.get_dependencies_flags(deps, state, depends) + scan_command += list(cflags) + list(ldflags) + for i in gi_includes: + scan_command += ['--add-include-path=%s' % i] + + inc_dirs = kwargs.pop('include_directories', []) + if not isinstance(inc_dirs, list): + inc_dirs = [inc_dirs] + for incd in inc_dirs: + if not isinstance(incd.held_object, (str, build.IncludeDirs)): + raise MesonException( + 'Gir include dirs should be include_directories().') + scan_command += self.get_include_args(state, inc_dirs) + scan_command += self.get_include_args(state, gir_inc_dirs + inc_dirs, + prefix='--add-include-path=') - inc_dirs = None - if kwargs.get('include_directories'): - inc_dirs = kwargs.pop('include_directories') - - if not isinstance(inc_dirs, list): - inc_dirs = [inc_dirs] - - for ind in inc_dirs: - if isinstance(ind.held_object, build.IncludeDirs): - scan_command += ['--add-include-path=%s' % inc for inc in ind.held_object.get_incdirs()] - else: - raise MesonException('Gir include dirs should be include_directories()') if isinstance(girtarget, build.Executable): scan_command += ['--program', girtarget] elif isinstance(girtarget, build.SharedLibrary): @@ -257,22 +312,24 @@ class GnomeModule: typelib_output = '%s-%s.typelib' % (ns, nsversion) typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@'] - if inc_dirs: - for incd in inc_dirs: - typelib_cmd += ['--includedir=%s' % inc for inc in - incd.held_object.get_incdirs()] - if deps: - for dep in deps: - if isinstance(dep.held_object, dependencies.InternalDependency): - for source in dep.held_object.sources: - if isinstance(source.held_object, GirTarget): - typelib_cmd += ["--includedir=%s" % - os.path.join(state.environment.get_build_dir(), - source.held_object.get_subdir())] - elif isinstance(dep.held_object, dependencies.PkgConfigDependency): - girdir = dep.held_object.get_variable ("girdir") - if girdir: - typelib_cmd += ["--includedir=%s" % girdir] + typelib_cmd += self.get_include_args(state, gir_inc_dirs, + prefix='--includedir=') + for dep in deps: + if hasattr(dep, 'held_object'): + dep = dep.held_object + if isinstance(dep, dependencies.InternalDependency): + for source in dep.sources: + if isinstance(source.held_object, GirTarget): + typelib_cmd += [ + "--includedir=%s" % ( + os.path.join(state.environment.get_build_dir(), + source.held_object.get_subdir()), + ) + ] + elif isinstance(dep, dependencies.PkgConfigDependency): + girdir = dep.get_variable("girdir") + if girdir: + typelib_cmd += ["--includedir=%s" % (girdir, )] kwargs['output'] = typelib_output kwargs['command'] = typelib_cmd @@ -335,12 +392,40 @@ class GnomeModule: '--modulename=' + modulename] args += self.unpack_args('--htmlargs=', 'html_args', kwargs) args += self.unpack_args('--scanargs=', 'scan_args', kwargs) + args += self.unpack_args('--scanobjsargs=', 'scanobjs_args', kwargs) + args += self.unpack_args('--gobjects-types-file=', 'gobject_typesfile', kwargs, state) args += self.unpack_args('--fixxrefargs=', 'fixxref_args', kwargs) + args += self.unpack_args('--html-assets=', 'html_assets', kwargs, state) + args += self.unpack_args('--content-files=', 'content_files', kwargs, state) + args += self.unpack_args('--installdir=', 'install_dir', kwargs, state) + args += self.get_build_args(kwargs, state) res = [build.RunTarget(targetname, command[0], command[1:] + args, [], state.subdir)] if kwargs.get('install', True): res.append(build.InstallScript(command + args)) return res + def get_build_args(self, kwargs, state): + args = [] + cflags, ldflags, gi_includes = self.get_dependencies_flags(kwargs.get('dependencies', []), state) + inc_dirs = kwargs.get('include_directories', []) + if not isinstance(inc_dirs, list): + inc_dirs = [inc_dirs] + for incd in inc_dirs: + if not isinstance(incd.held_object, (str, build.IncludeDirs)): + raise MesonException( + 'Gir include dirs should be include_directories().') + cflags.update(self.get_include_args(state, inc_dirs)) + if cflags: + args += ['--cflags=%s' % ' '.join(cflags)] + if ldflags: + args += ['--ldflags=%s' % ' '.join(ldflags)] + compiler = state.environment.coredata.compilers.get('c') + if compiler: + args += ['--cc=%s' % ' '.join(compiler.get_exelist())] + args += ['--ld=%s' % ' '.join(compiler.get_linker_exelist())] + + return args + def gtkdoc_html_dir(self, state, args, kwarga): if len(args) != 1: raise MesonException('Must have exactly one argument.') @@ -350,18 +435,24 @@ class GnomeModule: return os.path.join('share/gtkdoc/html', modulename) - def unpack_args(self, arg, kwarg_name, kwargs): - try: - new_args = kwargs[kwarg_name] - if not isinstance(new_args, list): - new_args = [new_args] - for i in new_args: - if not isinstance(i, str): - raise MesonException('html_args values must be strings.') - except KeyError: - return[] - if len(new_args) > 0: - return [arg + '@@'.join(new_args)] + def unpack_args(self, arg, kwarg_name, kwargs, expend_file_state=None): + if kwarg_name not in kwargs: + return [] + + new_args = kwargs[kwarg_name] + if not isinstance(new_args, list): + new_args = [new_args] + args = [] + for i in new_args: + if expend_file_state and isinstance(i, mesonlib.File): + i = os.path.join(expend_file_state.environment.get_build_dir(), i.subdir, i.fname) + elif not isinstance(i, str): + raise MesonException(kwarg_name + ' values must be strings.') + args.append(i) + + if args: + return [arg + '@@'.join(args)] + return [] def gdbus_codegen(self, state, args, kwargs): diff --git a/mesonbuild/scripts/gtkdochelper.py b/mesonbuild/scripts/gtkdochelper.py index 0c87717..e87a379 100644 --- a/mesonbuild/scripts/gtkdochelper.py +++ b/mesonbuild/scripts/gtkdochelper.py @@ -30,7 +30,16 @@ parser.add_argument('--mainfile', dest='mainfile') parser.add_argument('--modulename', dest='modulename') parser.add_argument('--htmlargs', dest='htmlargs', default='') parser.add_argument('--scanargs', dest='scanargs', default='') +parser.add_argument('--scanobjsargs', dest='scanobjsargs', default='') +parser.add_argument('--gobjects-types-file', dest='gobject_typesfile', default='') parser.add_argument('--fixxrefargs', dest='fixxrefargs', default='') +parser.add_argument('--ld', dest='ld', default='') +parser.add_argument('--cc', dest='cc', default='') +parser.add_argument('--ldflags', dest='ldflags', default='') +parser.add_argument('--cflags', dest='cflags', default='') +parser.add_argument('--content-files', dest='content_files', default='') +parser.add_argument('--html-assets', dest='html_assets', default='') +parser.add_argument('--installdir', dest='install_dir') def gtkdoc_run_check(cmd, cwd): p = subprocess.Popen(cmd, cwd=cwd, @@ -45,15 +54,49 @@ def gtkdoc_run_check(cmd, cwd): raise MesonException('\n'.join(err_msg)) def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir, - main_file, module, html_args, scan_args, fixxref_args): + main_file, module, html_args, scan_args, fixxref_args, + gobject_typesfile, scanobjs_args, ld, cc, ldflags, cflags, + html_assets, content_files): + print("Building documentation for %s" % module) + abs_src = os.path.join(source_root, src_subdir) + doc_src = os.path.join(source_root, doc_subdir) abs_out = os.path.join(build_root, doc_subdir) htmldir = os.path.join(abs_out, 'html') + + content_files += [main_file] + sections = os.path.join(doc_src, module + "-sections.txt") + if os.path.exists(sections): + content_files.append(sections) + + # Copy files to build directory + for f in content_files: + f_abs = os.path.join(doc_src, f) + shutil.copyfile(f_abs, os.path.join( + abs_out, os.path.basename(f_abs))) + + shutil.rmtree(htmldir, ignore_errors=True) + try: + os.mkdir(htmldir) + except Exception: + pass + + for f in html_assets: + f_abs = os.path.join(doc_src, f) + shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs))) + scan_cmd = ['gtkdoc-scan', '--module=' + module, '--source-dir=' + abs_src] + scan_args gtkdoc_run_check(scan_cmd, abs_out) + if gobject_typesfile: + scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + [gobject_typesfile, + '--module=' + module, '--cflags=' + cflags, '--ldflags=' + ldflags] + + gtkdoc_run_check(scanobjs_cmd, abs_out) + + # Make docbook files if main_file.endswith('sgml'): modeflag = '--sgml-mode' @@ -62,21 +105,16 @@ def build_gtkdoc(source_root, build_root, doc_subdir, src_subdir, mkdb_cmd = ['gtkdoc-mkdb', '--module=' + module, '--output-format=xml', + '--expand-content-files=', modeflag, '--source-dir=' + abs_src] - main_abs = os.path.join(source_root, doc_subdir, main_file) if len(main_file) > 0: # Yes, this is the flag even if the file is in xml. mkdb_cmd.append('--main-sgml-file=' + main_file) gtkdoc_run_check(mkdb_cmd, abs_out) # Make HTML documentation - shutil.rmtree(htmldir, ignore_errors=True) - try: - os.mkdir(htmldir) - except Exception: - pass - mkhtml_cmd = ['gtkdoc-mkhtml', + mkhtml_cmd = ['gtkdoc-mkhtml', '--path=' + abs_src, module, ] + html_args @@ -109,28 +147,42 @@ def run(args): scanargs = options.scanargs.split('@@') else: scanargs = [] + if len(options.scanobjsargs) > 0: + scanobjsargs = options.scanobjsargs.split('@@') + else: + scanobjsargs = [] if len(options.fixxrefargs) > 0: fixxrefargs = options.fixxrefargs.split('@@') else: fixxrefargs = [] - build_gtkdoc(options.sourcedir, - options.builddir, - options.subdir, - options.headerdir, - options.mainfile, - options.modulename, - htmlargs, - scanargs, - fixxrefargs) + build_gtkdoc( + options.sourcedir, + options.builddir, + options.subdir, + options.headerdir, + options.mainfile, + options.modulename, + htmlargs, + scanargs, + fixxrefargs, + options.gobject_typesfile, + scanobjsargs, + options.ld, + options.cc, + options.ldflags, + options.cflags, + options.html_assets.split('@@') if options.html_assets else [], + options.content_files.split('@@') if options.content_files else []) if 'MESON_INSTALL_PREFIX' in os.environ: + install_dir = options.install_dir if options.install_dir else options.modulename destdir = os.environ.get('DESTDIR', '') installdir = destdir_join(destdir, os.environ['MESON_INSTALL_PREFIX']) install_gtkdoc(options.builddir, options.subdir, installdir, 'share/gtk-doc/html', - options.modulename) + install_dir) return 0 if __name__ == '__main__': diff --git a/test cases/common/117 custom target capture/meson.build b/test cases/common/117 custom target capture/meson.build index 6c19752..fa59d51 100644 --- a/test cases/common/117 custom target capture/meson.build +++ b/test cases/common/117 custom target capture/meson.build @@ -7,10 +7,10 @@ python = find_program('python3') comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py') mytarget = custom_target('bindat', -output : 'data.dat', -input : 'data_source.txt', -capture : true, -command : [python, comp, '@INPUT@'], -install : true, -install_dir : 'subdir' + output : 'data.dat', + input : 'data_source.txt', + capture : true, + command : [python, comp, '@INPUT@'], + install : true, + install_dir : 'subdir' ) diff --git a/test cases/common/94 default options/meson.build b/test cases/common/94 default options/meson.build index 6299106..a718bcc 100644 --- a/test cases/common/94 default options/meson.build +++ b/test cases/common/94 default options/meson.build @@ -2,6 +2,7 @@ project('default options', 'cpp', 'c', default_options : [ 'buildtype=debugoptimized', 'cpp_std=c++03', 'cpp_eh=none', + 'warning_level=3', ]) cpp = meson.get_compiler('cpp') @@ -9,11 +10,16 @@ cpp = meson.get_compiler('cpp') assert(get_option('buildtype') == 'debugoptimized', 'Build type default value wrong.') if cpp.get_id() == 'msvc' - assert(get_option('cpp_eh') == 'none', 'MSVC eh value wrong.') + cpp_eh = get_option('cpp_eh') + assert(cpp_eh == 'none', 'MSVC eh value is "' + cpp_eh + '" instead of "none"') else - assert(get_option('cpp_std') == 'c++03', 'C++ std value wrong.') + cpp_std = get_option('cpp_std') + assert(cpp_std == 'c++03', 'C++ std value is "' + cpp_std + '" instead of c++03.') endif +w_level = get_option('warning_level') +assert(w_level == '3', 'warning level "' + w_level + '" instead of "3"') + # FIXME. Since we no longer accept invalid options to c_std etc, # there is no simple way to test this. Gcc does not seem to expose # the C std used in a preprocessor token so we can't check for it. diff --git a/test cases/frameworks/12 multiple gir/gir/meson-subsample.c b/test cases/frameworks/12 multiple gir/gir/meson-subsample.c new file mode 100644 index 0000000..2d58a10 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson-subsample.c @@ -0,0 +1,124 @@ +#include "meson-subsample.h" + +struct _MesonSubSample +{ + MesonSample parent_instance; + + gchar *msg; +}; + +G_DEFINE_TYPE (MesonSubSample, meson_sub_sample, MESON_TYPE_SAMPLE) + +enum { + PROP_0, + PROP_MSG, + LAST_PROP +}; + +static GParamSpec *gParamSpecs [LAST_PROP]; + +/** + * meson_sub_sample_new: + * @msg: The message to set. + * + * Allocates a new #MesonSubSample. + * + * Returns: (transfer full): a #MesonSubSample. + */ +MesonSubSample * +meson_sub_sample_new (const gchar *msg) +{ + g_return_val_if_fail (msg != NULL, NULL); + + return g_object_new (MESON_TYPE_SUB_SAMPLE, + "message", msg, + NULL); +} + +static void +meson_sub_sample_finalize (GObject *object) +{ + MesonSubSample *self = (MesonSubSample *)object; + + g_clear_pointer (&self->msg, g_free); + + G_OBJECT_CLASS (meson_sub_sample_parent_class)->finalize (object); +} + +static void +meson_sub_sample_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MesonSubSample *self = MESON_SUB_SAMPLE (object); + + switch (prop_id) + { + case PROP_MSG: + g_value_set_string (value, self->msg); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sub_sample_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MesonSubSample *self = MESON_SUB_SAMPLE (object); + + switch (prop_id) + { + case PROP_MSG: + self->msg = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sub_sample_class_init (MesonSubSampleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = meson_sub_sample_finalize; + object_class->get_property = meson_sub_sample_get_property; + object_class->set_property = meson_sub_sample_set_property; + + gParamSpecs [PROP_MSG] = + g_param_spec_string ("message", + "Message", + "The message to print.", + NULL, + (G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs); +} + +static void +meson_sub_sample_init (MesonSubSample *self) +{ +} + +/** + * meson_sub_sample_print_message: + * @self: a #MesonSubSample. + * + * Prints the message. + * + * Returns: Nothing. + */ +void +meson_sub_sample_print_message (MesonSubSample *self) +{ + g_return_if_fail (MESON_IS_SUB_SAMPLE (self)); + + g_print ("Message: %s\n", self->msg); +} diff --git a/test cases/frameworks/12 multiple gir/gir/meson-subsample.h b/test cases/frameworks/12 multiple gir/gir/meson-subsample.h new file mode 100644 index 0000000..9d34a08 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson-subsample.h @@ -0,0 +1,17 @@ +#ifndef MESON_SUB_SAMPLE_H +#define MESON_SUB_SAMPLE_H + +#include <glib-object.h> +#include <meson-sample.h> + +G_BEGIN_DECLS + +#define MESON_TYPE_SUB_SAMPLE (meson_sub_sample_get_type()) + +G_DECLARE_FINAL_TYPE (MesonSubSample, meson_sub_sample, MESON, SUB_SAMPLE, MesonSample) + +MesonSubSample *meson_sub_sample_new (const gchar *msg); + +G_END_DECLS + +#endif /* MESON_SUB_SAMPLE_H */ diff --git a/test cases/frameworks/12 multiple gir/gir/meson.build b/test cases/frameworks/12 multiple gir/gir/meson.build new file mode 100644 index 0000000..6001a09 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson.build @@ -0,0 +1,30 @@ +libsources = ['meson-subsample.c', 'meson-subsample.h'] + +girsubproject = shared_library( + 'girsubproject', + sources : libsources, + dependencies : [gobj, girlib_dep], + install : true +) + +girexe = executable( + 'girprog', + sources : 'prog.c', + dependencies : [gobj, girlib_dep], + link_with : girsubproject +) + +gnome.generate_gir( + girsubproject, + sources : libsources, + nsversion : '1.0', + namespace : 'MesonSub', + symbol_prefix : 'meson_sub_', + identifier_prefix : 'MesonSub', + includes : ['GObject-2.0', meson_gir], + install : true +) + +message('TEST: ' + girsubproject.outdir()) + +test('gobject introspection/subproject/c', girexe) diff --git a/test cases/frameworks/12 multiple gir/gir/prog.c b/test cases/frameworks/12 multiple gir/gir/prog.c new file mode 100644 index 0000000..f25c9d8 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/prog.c @@ -0,0 +1,12 @@ +#include "meson-subsample.h" + +gint +main (gint argc, + gchar *argv[]) +{ + MesonSample * i = (MesonSample*) meson_sub_sample_new ("Hello, sub/meson/c!"); + meson_sample_print_message (i); + g_object_unref (i); + + return 0; +} diff --git a/test cases/frameworks/12 multiple gir/installed_files.txt b/test cases/frameworks/12 multiple gir/installed_files.txt new file mode 100644 index 0000000..9fb51bf --- /dev/null +++ b/test cases/frameworks/12 multiple gir/installed_files.txt @@ -0,0 +1,6 @@ +usr/lib/girepository-1.0/Meson-1.0.typelib +usr/lib/girepository-1.0/MesonSub-1.0.typelib +usr/lib/libgirlib.so +usr/lib/libgirsubproject.so +usr/share/gir-1.0/Meson-1.0.gir +usr/share/gir-1.0/MesonSub-1.0.gir diff --git a/test cases/frameworks/12 multiple gir/meson.build b/test cases/frameworks/12 multiple gir/meson.build new file mode 100644 index 0000000..794abc5 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/meson.build @@ -0,0 +1,7 @@ +project('multiple-gobject-introspection', 'c') + +gnome = import('gnome') +gobj = dependency('gobject-2.0') + +subdir('mesongir') +subdir('gir') diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c new file mode 100644 index 0000000..2ed9cdf --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c @@ -0,0 +1,126 @@ +#include "meson-sample.h" + +typedef struct _MesonSamplePrivate +{ + gchar *msg; +} MesonSamplePrivate; + + +G_DEFINE_TYPE_WITH_PRIVATE (MesonSample, meson_sample, G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_MSG, + LAST_PROP +}; + +static GParamSpec *gParamSpecs [LAST_PROP]; + +/** + * meson_sample_new: + * @msg: The message to set. + * + * Allocates a new #MesonSample. + * + * Returns: (transfer full): a #MesonSample. + */ +MesonSample * +meson_sample_new (const gchar *msg) +{ + g_return_val_if_fail (msg != NULL, NULL); + + return g_object_new (MESON_TYPE_SAMPLE, + "message", msg, + NULL); +} + +static void +meson_sample_finalize (GObject *object) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + g_clear_pointer (&priv->msg, g_free); + + G_OBJECT_CLASS (meson_sample_parent_class)->finalize (object); +} + +static void +meson_sample_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + switch (prop_id) + { + case PROP_MSG: + g_value_set_string (value, priv->msg); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sample_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + switch (prop_id) + { + case PROP_MSG: + priv->msg = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sample_class_init (MesonSampleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = meson_sample_finalize; + object_class->get_property = meson_sample_get_property; + object_class->set_property = meson_sample_set_property; + + gParamSpecs [PROP_MSG] = + g_param_spec_string ("message", + "Message", + "The message to print.", + NULL, + (G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs); +} + +static void +meson_sample_init (MesonSample *self) +{ +} + +/** + * meson_sample_print_message: + * @self: a #MesonSample. + * + * Prints the message. + * + */ +void +meson_sample_print_message (MesonSample *self) +{ + MesonSamplePrivate *priv; + + g_return_if_fail (MESON_IS_SAMPLE (self)); + + priv = meson_sample_get_instance_private (self); + + g_print ("Message: %s\n", priv->msg); +} diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in new file mode 100644 index 0000000..d0ab29e --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in @@ -0,0 +1,22 @@ +#ifndef MESON_SAMPLE_H +#define MESON_SAMPLE_H + +#include <@HEADER@> + +G_BEGIN_DECLS + +#define MESON_TYPE_SAMPLE (meson_sample_get_type()) + +G_DECLARE_DERIVABLE_TYPE (MesonSample, meson_sample, MESON, SAMPLE, GObject) + +struct _MesonSampleClass { + GObjectClass parent_class; +}; + + +MesonSample *meson_sample_new (const gchar *msg); +void meson_sample_print_message (MesonSample *self); + +G_END_DECLS + +#endif /* MESON_SAMPLE_H */ diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson.build b/test cases/frameworks/12 multiple gir/mesongir/meson.build new file mode 100644 index 0000000..4775fea --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson.build @@ -0,0 +1,37 @@ +conf = configuration_data() +conf.set('HEADER', 'glib-object.h') + +meson_sample_header = configure_file( + input : 'meson-sample.h.in', + output : 'meson-sample.h', + configuration : conf) + +libsources = ['meson-sample.c', meson_sample_header] + +girlib = shared_library( + 'girlib', + sources : libsources, + dependencies : gobj, + install : true +) + +girtarget = gnome.generate_gir( + girlib, + sources : libsources, + nsversion : '1.0', + namespace : 'Meson', + symbol_prefix : 'meson_', + identifier_prefix : 'Meson', + includes : ['GObject-2.0'], + install : true +) +meson_gir = girtarget[0] +meson_typelib = girtarget[1] + +girlib_inc = include_directories('.') +girlib_dep = declare_dependency(link_with : girlib, + include_directories : [girlib_inc], + dependencies : [gobj], + # Everything that uses libgst needs this built to compile + sources : girtarget, +) diff --git a/test cases/linuxlike/9 compiler checks with dependencies/meson.build b/test cases/linuxlike/9 compiler checks with dependencies/meson.build new file mode 100644 index 0000000..2aa9015 --- /dev/null +++ b/test cases/linuxlike/9 compiler checks with dependencies/meson.build @@ -0,0 +1,31 @@ +project('compiler checks with dependencies', 'c') + +cc = meson.get_compiler('c') + +glib = dependency ('glib-2.0') +if glib.found() + assert (cc.has_header('glib.h', dependencies : glib), 'glib.h not found') + assert (cc.has_type('gint32', prefix : '#include <glib.h>', dependencies : glib), 'gint32 not found') + assert (cc.has_function('g_print', dependencies : glib), 'g_print not found') + assert (cc.has_member('GError', 'message', prefix : '#include <glib.h>', dependencies : glib), 'GError::message not found') + assert (cc.has_header_symbol('glib.h', 'gint32', dependencies : glib), 'gint32 symbol not found') + linkcode = '''#include <glib.h> +int main (int argc, char *argv[]) { + GError *error = g_error_new_literal (0, 0, NULL); + return error == NULL; +} + ''' + assert (cc.links(linkcode, dependencies : glib, name : 'Test link against glib'), 'Linking test against glib failed') +endif + +zlib = cc.find_library ('z') +if zlib.found() + linkcode = '''#include<zlib.h> +int main(int argc, char *argv[]) { + void *ptr = (void*)(deflate); + return ptr == 0; +} +''' + assert (cc.has_function('deflate', prefix : '#include<zlib.h>', dependencies : zlib, name : 'Test for function in zlib'), 'has_function test failed.') + assert (cc.links(linkcode, dependencies : zlib, name : 'Test link against zlib'), 'Linking test failed against zlib.') +endif diff --git a/test cases/vala/8 generated source/installed_files.txt b/test cases/vala/8 generated source/installed_files.txt new file mode 100644 index 0000000..a4c37f6 --- /dev/null +++ b/test cases/vala/8 generated source/installed_files.txt @@ -0,0 +1 @@ +usr/bin/generatedtest diff --git a/test cases/vala/8 generated source/meson.build b/test cases/vala/8 generated source/meson.build new file mode 100644 index 0000000..7271821 --- /dev/null +++ b/test cases/vala/8 generated source/meson.build @@ -0,0 +1,7 @@ +project('mytest', 'vala', 'c') + +cd = configuration_data() +cd.set('x', 'y') + +subdir('src') +subdir('tools') diff --git a/test cases/vala/8 generated source/src/config.vala.in b/test cases/vala/8 generated source/src/config.vala.in new file mode 100644 index 0000000..a5196fd --- /dev/null +++ b/test cases/vala/8 generated source/src/config.vala.in @@ -0,0 +1,3 @@ +namespace Config { + public static const string x = "@x@"; +} diff --git a/test cases/vala/8 generated source/src/meson.build b/test cases/vala/8 generated source/src/meson.build new file mode 100644 index 0000000..9096c67 --- /dev/null +++ b/test cases/vala/8 generated source/src/meson.build @@ -0,0 +1,5 @@ +config = configure_file(input: 'config.vala.in', + output: 'config.vala', + configuration: cd) + +src = files('test.vala') diff --git a/test cases/vala/8 generated source/src/test.vala b/test cases/vala/8 generated source/src/test.vala new file mode 100644 index 0000000..98d6821 --- /dev/null +++ b/test cases/vala/8 generated source/src/test.vala @@ -0,0 +1,3 @@ +void main() { + print (Config.x); +} diff --git a/test cases/vala/8 generated source/tools/meson.build b/test cases/vala/8 generated source/tools/meson.build new file mode 100644 index 0000000..834ec1a --- /dev/null +++ b/test cases/vala/8 generated source/tools/meson.build @@ -0,0 +1,3 @@ +executable('generatedtest', [src, config], + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) |