aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manual tests/6 hg wrap/meson.build (renamed from manual tests/10 hg wrap/meson.build)0
-rw-r--r--manual tests/6 hg wrap/prog.c (renamed from manual tests/10 hg wrap/prog.c)0
-rw-r--r--manual tests/6 hg wrap/subprojects/samplesubproject.wrap (renamed from manual tests/10 hg wrap/subprojects/samplesubproject.wrap)0
-rw-r--r--mesonbuild/backend/backends.py5
-rw-r--r--mesonbuild/backend/ninjabackend.py67
-rw-r--r--mesonbuild/build.py14
-rw-r--r--mesonbuild/compilers.py38
-rw-r--r--mesonbuild/coredata.py2
-rw-r--r--mesonbuild/environment.py6
-rw-r--r--mesonbuild/interpreter.py76
-rw-r--r--mesonbuild/mesonlib.py9
-rw-r--r--mesonbuild/mesonmain.py6
-rw-r--r--mesonbuild/modules/gnome.py17
-rw-r--r--mesonbuild/modules/pkgconfig.py2
-rwxr-xr-xmesonbuild/scripts/meson_benchmark.py99
-rwxr-xr-xmesonbuild/scripts/meson_test.py290
-rwxr-xr-xmesontest.py375
-rwxr-xr-xrun_project_tests.py6
-rwxr-xr-xrun_unittests.py14
-rw-r--r--test cases/common/12 data/fileobject_datafile.dat1
-rw-r--r--test cases/common/12 data/installed_files.txt1
-rw-r--r--test cases/common/12 data/meson.build1
-rw-r--r--test cases/common/31 find program/meson.build2
-rw-r--r--test cases/common/9 header install/installed_files.txt1
-rw-r--r--test cases/common/9 header install/meson.build5
-rw-r--r--test cases/common/9 header install/sub/fileheader.h3
-rw-r--r--test cases/common/9 header install/sub/meson.build2
-rw-r--r--test cases/frameworks/7 gnome/resources/meson.build2
-rw-r--r--test cases/java/3 args/com/mesonbuild/Simple.java7
-rw-r--r--test cases/java/3 args/meson.build9
30 files changed, 521 insertions, 539 deletions
diff --git a/manual tests/10 hg wrap/meson.build b/manual tests/6 hg wrap/meson.build
index c7ac004..c7ac004 100644
--- a/manual tests/10 hg wrap/meson.build
+++ b/manual tests/6 hg wrap/meson.build
diff --git a/manual tests/10 hg wrap/prog.c b/manual tests/6 hg wrap/prog.c
index df38000..df38000 100644
--- a/manual tests/10 hg wrap/prog.c
+++ b/manual tests/6 hg wrap/prog.c
diff --git a/manual tests/10 hg wrap/subprojects/samplesubproject.wrap b/manual tests/6 hg wrap/subprojects/samplesubproject.wrap
index 6d3b3f2..6d3b3f2 100644
--- a/manual tests/10 hg wrap/subprojects/samplesubproject.wrap
+++ b/manual tests/6 hg wrap/subprojects/samplesubproject.wrap
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index b82227f..c37ae2a 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -50,7 +50,7 @@ class ExecutableSerialisation():
class TestSerialisation:
def __init__(self, name, suite, fname, is_cross, exe_wrapper, is_parallel, cmd_args, env,
- should_fail, valgrind_args, timeout, workdir, extra_paths):
+ should_fail, timeout, workdir, extra_paths):
self.name = name
self.suite = suite
self.fname = fname
@@ -60,7 +60,6 @@ class TestSerialisation:
self.cmd_args = cmd_args
self.env = env
self.should_fail = should_fail
- self.valgrind_args = valgrind_args
self.timeout = timeout
self.workdir = workdir
self.extra_paths = extra_paths
@@ -443,7 +442,7 @@ class Backend():
a = os.path.join(self.environment.get_build_dir(), a.rel_to_builddir(self.build_to_src))
cmd_args.append(a)
ts = TestSerialisation(t.get_name(), t.suite, fname, is_cross, exe_wrapper,
- t.is_parallel, cmd_args, t.env, t.should_fail, t.valgrind_args,
+ t.is_parallel, cmd_args, t.env, t.should_fail,
t.timeout, t.workdir, extra_paths)
arr.append(ts)
pickle.dump(arr, datafile)
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index fa4d5cf..659a53d 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -142,7 +142,6 @@ class NinjaBackend(backends.Backend):
self.ninja_filename = 'build.ninja'
self.fortran_deps = {}
self.all_outputs = {}
- self.valgrind = environment.find_valgrind()
def detect_vs_dep_prefix(self, tempfilename):
'''VS writes its dependency in a locale dependent format.
@@ -657,12 +656,15 @@ int dummy;
incroot = self.environment.get_includedir()
headers = self.build.get_headers()
+ srcdir = self.environment.get_source_dir()
+ builddir = self.environment.get_build_dir()
for h in headers:
outdir = h.get_custom_install_dir()
if outdir is None:
outdir = os.path.join(incroot, h.get_install_subdir())
for f in h.get_sources():
- abspath = os.path.join(self.environment.get_source_dir(), h.get_source_subdir(), f)
+ assert(isinstance(f, File))
+ abspath = f.absolute_path(srcdir, builddir)
i = [abspath, outdir]
d.headers.append(i)
@@ -682,18 +684,16 @@ int dummy;
def generate_data_install(self, d):
data = self.build.get_data()
+ srcdir = self.environment.get_source_dir()
+ builddir = self.environment.get_build_dir()
for de in data:
assert(isinstance(de, build.Data))
subdir = de.install_dir
for f in de.sources:
- plain_f = os.path.split(f)[1]
- if de.in_sourcetree:
- srcprefix = self.environment.get_source_dir()
- else:
- srcprefix = self.environment.get_build_dir()
- srcabs = os.path.join(srcprefix, de.source_subdir, f)
+ assert(isinstance(f, mesonlib.File))
+ plain_f = os.path.split(f.fname)[1]
dstabs = os.path.join(subdir, plain_f)
- i = [srcabs, dstabs]
+ i = [f.absolute_path(srcdir, builddir), dstabs]
d.data.append(i)
def generate_subdir_install(self, d):
@@ -710,56 +710,25 @@ int dummy;
dst_dir = os.path.join(self.environment.get_prefix(), sd.install_dir)
d.install_subdirs.append([src_dir, inst_dir, dst_dir])
- def write_test_suite_targets(self, cmd, outfile):
- suites = {}
- for t in self.build.get_tests():
- for s in t.suite:
- suites[s] = True
- suites = list(suites.keys())
- suites.sort()
- for s in suites:
- if s == '':
- visible_name = 'for top level tests'
- else:
- visible_name = s
- elem = NinjaBuildElement(self.all_outputs, 'test:' + s, 'CUSTOM_COMMAND', ['all', 'PHONY'])
- elem.add_item('COMMAND', cmd + ['--suite=' + s])
- elem.add_item('DESC', 'Running test suite %s.' % visible_name)
- elem.add_item('pool', 'console')
- elem.write(outfile)
-
- if self.valgrind:
- velem = NinjaBuildElement(self.all_outputs, 'test-valgrind:' + s, 'CUSTOM_COMMAND', ['all', 'PHONY'])
- velem.add_item('COMMAND', cmd + ['--wrapper=' + self.valgrind, '--suite=' + s])
- velem.add_item('DESC', 'Running test suite %s under Valgrind.' % visible_name)
- velem.add_item('pool', 'console')
- velem.write(outfile)
-
def generate_tests(self, outfile):
- (test_data, benchmark_data) = self.serialise_tests()
- script_root = self.environment.get_script_dir()
- cmd = [ sys.executable, self.environment.get_build_command(), '--internal', 'test' ]
+ self.serialise_tests()
+ meson_exe = self.environment.get_build_command()
+ (base, ext) = os.path.splitext(meson_exe)
+ test_exe = base + 'test' + ext
+ cmd = [sys.executable, test_exe]
if not self.environment.coredata.get_builtin_option('stdsplit'):
cmd += ['--no-stdsplit']
if self.environment.coredata.get_builtin_option('errorlogs'):
cmd += ['--print-errorlogs']
- cmd += [ test_data ]
elem = NinjaBuildElement(self.all_outputs, 'test', 'CUSTOM_COMMAND', ['all', 'PHONY'])
elem.add_item('COMMAND', cmd)
elem.add_item('DESC', 'Running all tests.')
elem.add_item('pool', 'console')
elem.write(outfile)
- self.write_test_suite_targets(cmd, outfile)
-
- if self.valgrind:
- velem = NinjaBuildElement(self.all_outputs, 'test-valgrind', 'CUSTOM_COMMAND', ['all', 'PHONY'])
- velem.add_item('COMMAND', cmd + ['--wrapper=' + self.valgrind])
- velem.add_item('DESC', 'Running test suite under Valgrind.')
- velem.add_item('pool', 'console')
- velem.write(outfile)
# And then benchmarks.
- cmd = [sys.executable, self.environment.get_build_command(), '--internal', 'benchmark', benchmark_data]
+ cmd = [sys.executable, test_exe, '--benchmark','--logbase',
+ 'benchmarklog', '--num-processes=1']
elem = NinjaBuildElement(self.all_outputs, 'benchmark', 'CUSTOM_COMMAND', ['all', 'PHONY'])
elem.add_item('COMMAND', cmd)
elem.add_item('DESC', 'Running benchmark suite.')
@@ -806,7 +775,6 @@ int dummy;
def generate_jar_target(self, target, outfile):
fname = target.get_filename()
- subdir = target.get_subdir()
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
class_list = []
@@ -891,6 +859,9 @@ int dummy;
def generate_single_java_compile(self, src, target, compiler, outfile):
args = []
args += compiler.get_buildtype_args(self.environment.coredata.get_builtin_option('buildtype'))
+ args += self.build.get_global_args(compiler)
+ args += self.build.get_project_args(compiler, target.subproject)
+ args += target.get_java_args()
args += compiler.get_output_args(self.get_target_private_dir(target))
for i in target.include_dirs:
for idir in i.get_incdirs():
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 42cdc57..98f05c2 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -28,6 +28,7 @@ known_basic_kwargs = {'install' : True,
'cs_args' : True,
'vala_args' : True,
'd_args' : True,
+ 'java_args' : True,
'link_args' : True,
'link_depends': True,
'link_with' : True,
@@ -1342,7 +1343,7 @@ class Jar(BuildTarget):
if not s.endswith('.java'):
raise InvalidArguments('Jar source %s is not a java file.' % s)
self.filename = self.name + '.jar'
- incdirs = kwargs.get('include_directories', [])
+ self.java_args = kwargs.get('java_args', [])
def get_main_class(self):
return self.main_class
@@ -1350,6 +1351,9 @@ class Jar(BuildTarget):
def type_suffix(self):
return "@jar"
+ def get_java_args(self):
+ return self.java_args
+
class ConfigureFile():
def __init__(self, subdir, sourcename, targetname, configuration_data):
@@ -1393,11 +1397,13 @@ class ConfigurationData():
# A bit poorly named, but this represents plain data files to copy
# during install.
class Data():
- def __init__(self, in_sourcetree, source_subdir, sources, install_dir):
- self.in_sourcetree = in_sourcetree
- self.source_subdir = source_subdir
+ def __init__(self, sources, install_dir):
self.sources = sources
self.install_dir = install_dir
+ if not isinstance(self.sources, list):
+ self.sources = [self.sources]
+ for s in self.sources:
+ assert(isinstance(s, File))
class InstallScript:
def __init__(self, cmd_arr):
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index fef4c1d..8f8851f 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -927,9 +927,11 @@ int main(int argc, char **argv) {
"""
# Add the 'prefix', aka defines, includes, etc that the user provides
head = '#include <limits.h>\n{0}\n'
- # We don't know what the function takes or returns, so try to use it as
- # a function pointer
- main = '\nint main() {{ void *a = (void*) &{1}; }}'
+ # We don't know what the function takes or returns, so return it as an int.
+ # Just taking the address or comparing it to void is not enough because
+ # compilers are smart enough to optimize it away. The resulting binary
+ # is not run so we don't care what the return value is.
+ main = '\nint main() {{ void *a = (void*) &{1}; long b = (long) a; return (int) b; }}'
return head, main
def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):
@@ -1844,11 +1846,7 @@ class VisualStudioCCompiler(CCompiler):
}
def get_option_link_args(self, options):
- # FIXME: See GnuCCompiler.get_option_link_args
- if 'c_winlibs' in options:
- return options['c_winlibs'].value[:]
- else:
- return msvc_winlibs[:]
+ return options['c_winlibs'].value[:]
def unix_link_flags_to_native(self, args):
result = []
@@ -1953,11 +1951,7 @@ class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
return args
def get_option_link_args(self, options):
- # FIXME: See GnuCCompiler.get_option_link_args
- if 'cpp_winlibs' in options:
- return options['cpp_winlibs'].value[:]
- else:
- return msvc_winlibs[:]
+ return options['cpp_winlibs'].value[:]
GCC_STANDARD = 0
GCC_OSX = 1
@@ -2069,17 +2063,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
def get_option_link_args(self, options):
if self.gcc_type == GCC_MINGW:
- # FIXME: This check is needed because we currently pass
- # cross-compiler options to the native compiler too and when
- # cross-compiling from Windows to Linux, `options` will contain
- # Linux-specific options which doesn't include `c_winlibs`. The
- # proper fix is to allow cross-info files to specify compiler
- # options and to maintain both cross and native compiler options in
- # coredata: https://github.com/mesonbuild/meson/issues/1029
- if 'c_winlibs' in options:
- return options['c_winlibs'].value[:]
- else:
- return gnu_winlibs[:]
+ return options['c_winlibs'].value[:]
return []
class GnuCPPCompiler(GnuCompiler, CPPCompiler):
@@ -2117,11 +2101,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
def get_option_link_args(self, options):
if self.gcc_type == GCC_MINGW:
- # FIXME: See GnuCCompiler.get_option_link_args
- if 'cpp_winlibs' in options:
- return options['cpp_winlibs'].value[:]
- else:
- return gnu_winlibs[:]
+ return options['cpp_winlibs'].value[:]
return []
def get_compiler_check_args(self):
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 0894f9a..29ea1bf 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -241,8 +241,6 @@ forbidden_target_names = {'clean': None,
'all': None,
'test': None,
'test:': None,
- 'test-valgrind': None,
- 'test-valgrind:': None,
'benchmark': None,
'install': None,
'build.ninja': None,
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 405685c..cc62010 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -39,12 +39,6 @@ def find_coverage_tools():
genhtml_exe = None
return (gcovr_exe, lcov_exe, genhtml_exe)
-def find_valgrind():
- valgrind_exe = 'valgrind'
- if not mesonlib.exe_exists([valgrind_exe, '--version']):
- valgrind_exe = None
- return valgrind_exe
-
def detect_ninja():
for n in ['ninja', 'ninja-build']:
try:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 6becdb6..ef99511 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -457,10 +457,9 @@ class IncludeDirsHolder(InterpreterObject):
class Headers(InterpreterObject):
- def __init__(self, src_subdir, sources, kwargs):
+ def __init__(self, sources, kwargs):
InterpreterObject.__init__(self)
self.sources = sources
- self.source_subdir = src_subdir
self.install_subdir = kwargs.get('subdir', '')
self.custom_install_dir = kwargs.get('install_dir', None)
if self.custom_install_dir is not None:
@@ -473,9 +472,6 @@ class Headers(InterpreterObject):
def get_install_subdir(self):
return self.install_subdir
- def get_source_subdir(self):
- return self.source_subdir
-
def get_sources(self):
return self.sources
@@ -483,15 +479,11 @@ class Headers(InterpreterObject):
return self.custom_install_dir
class DataHolder(InterpreterObject):
- def __init__(self, in_sourcetree, source_subdir, sources, kwargs):
+ def __init__(self, sources, install_dir):
super().__init__()
- kwsource = mesonlib.stringlistify(kwargs.get('sources', []))
- sources += kwsource
- check_stringlist(sources)
- install_dir = kwargs.get('install_dir', None)
if not isinstance(install_dir, str):
raise InterpreterException('Custom_install_dir must be a string.')
- self.held_object = build.Data(in_sourcetree, source_subdir, sources, install_dir)
+ self.held_object = build.Data(sources, install_dir)
def get_source_subdir(self):
return self.held_object.source_subdir
@@ -614,7 +606,7 @@ class RunTargetHolder(InterpreterObject):
self.held_object = build.RunTarget(name, command, args, dependencies, subdir)
class Test(InterpreterObject):
- def __init__(self, name, suite, exe, is_parallel, cmd_args, env, should_fail, valgrind_args, timeout, workdir):
+ def __init__(self, name, suite, exe, is_parallel, cmd_args, env, should_fail, timeout, workdir):
InterpreterObject.__init__(self)
self.name = name
self.suite = suite
@@ -623,7 +615,6 @@ class Test(InterpreterObject):
self.cmd_args = cmd_args
self.env = env
self.should_fail = should_fail
- self.valgrind_args = valgrind_args
self.timeout = timeout
self.workdir = workdir
@@ -1771,12 +1762,12 @@ class Interpreter():
raise InvalidCode('Tried to use unknown language "%s".' % lang)
comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
self.coredata.compilers[lang] = comp
+ # Native compiler always exist so always add its options.
+ new_options = comp.get_options()
if cross_comp is not None:
cross_comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
self.coredata.cross_compilers[lang] = cross_comp
- new_options = cross_comp.get_options()
- else:
- new_options = comp.get_options()
+ new_options.update(cross_comp.get_options())
optprefix = lang + '_'
for i in new_options:
if not i.startswith(optprefix):
@@ -1834,18 +1825,22 @@ class Interpreter():
break
self.coredata.base_options[optname] = oobj
+ @stringArgs
def func_find_program(self, node, args, kwargs):
- self.validate_arguments(args, 1, [str])
+ if len(args) == 0:
+ raise InterpreterException('No program name specified.')
required = kwargs.get('required', True)
if not isinstance(required, bool):
raise InvalidArguments('"required" argument must be a boolean.')
- exename = args[0]
# Search for scripts relative to current subdir.
# Do not cache found programs because find_program('foobar')
# might give different results when run from different source dirs.
search_dir = os.path.join(self.environment.get_source_dir(), self.subdir)
- extprog = dependencies.ExternalProgram(exename, search_dir=search_dir)
- progobj = ExternalProgramHolder(extprog)
+ for exename in args:
+ extprog = dependencies.ExternalProgram(exename, search_dir=search_dir)
+ progobj = ExternalProgramHolder(extprog)
+ if progobj.found():
+ return progobj
if required and not progobj.found():
raise InvalidArguments('Program "%s" not found.' % exename)
return progobj
@@ -2128,12 +2123,8 @@ requirements use the version keyword argument instead.''')
if ' ' in k:
raise InterpreterException('Env var key must not have spaces in it.')
env[k] = val
- valgrind_args = kwargs.get('valgrind_args', [])
- if not isinstance(valgrind_args, list):
- valgrind_args = [valgrind_args]
- for a in valgrind_args:
- if not isinstance(a, str):
- raise InterpreterException('Valgrind_arg not a string.')
+ if not isinstance(envlist, list):
+ envlist = [envlist]
should_fail = kwargs.get('should_fail', False)
if not isinstance(should_fail, bool):
raise InterpreterException('Keyword argument should_fail must be a boolean.')
@@ -2156,7 +2147,7 @@ requirements use the version keyword argument instead.''')
s = '.' + s
newsuite.append(self.subproject.replace(' ', '_').replace('.', '_') + s)
suite = newsuite
- t = Test(args[0], suite, args[1].held_object, par, cmd_args, env, should_fail, valgrind_args, timeout, workdir)
+ t = Test(args[0], suite, args[1].held_object, par, cmd_args, env, should_fail, timeout, workdir)
if is_base_test:
self.build.tests.append(t)
mlog.debug('Adding test "', mlog.bold(args[0]), '".', sep='')
@@ -2164,9 +2155,9 @@ requirements use the version keyword argument instead.''')
self.build.benchmarks.append(t)
mlog.debug('Adding benchmark "', mlog.bold(args[0]), '".', sep='')
- @stringArgs
def func_install_headers(self, node, args, kwargs):
- h = Headers(self.subdir, args, kwargs)
+ source_files = self.source_strings_to_files(args)
+ h = Headers(source_files, kwargs)
self.build.headers.append(h)
return h
@@ -2208,9 +2199,19 @@ requirements use the version keyword argument instead.''')
self.evaluate_codeblock(codeblock)
self.subdir = prev_subdir
- @stringArgs
def func_install_data(self, node, args, kwargs):
- data = DataHolder(True, self.subdir, args, kwargs)
+ kwsource = mesonlib.stringlistify(kwargs.get('sources', []))
+ raw_sources = args + kwsource
+ sources = []
+ source_strings = []
+ for s in raw_sources:
+ if isinstance(s, mesonlib.File):
+ sources.append(s)
+ else:
+ source_strings.append(s)
+ sources += self.source_strings_to_files(source_strings)
+ install_dir = kwargs.get('install_dir', None)
+ data = DataHolder(sources, install_dir)
self.build.data.append(data.held_object)
return data
@@ -2240,11 +2241,12 @@ requirements use the version keyword argument instead.''')
raise InterpreterException('Output must be a string.')
if os.path.split(output)[0] != '':
raise InterpreterException('Output file name must not contain a subdirectory.')
+ (ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output))
+ ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname)
if 'configuration' in kwargs:
conf = kwargs['configuration']
if not isinstance(conf, ConfigurationDataHolder):
raise InterpreterException('Argument "configuration" is not of type configuration_data')
- ofile_abs = os.path.join(self.environment.build_dir, self.subdir, output)
if inputfile is not None:
# Normalize the path of the conffile to avoid duplicates
# This is especially important to convert '/' to '\' on Windows
@@ -2266,8 +2268,10 @@ requirements use the version keyword argument instead.''')
(res.stdout, res.stderr))
else:
raise InterpreterException('Configure_file must have either "configuration" or "command".')
- if isinstance(kwargs.get('install_dir', None), str):
- self.build.data.append(DataHolder(False, self.subdir, [output], kwargs).held_object)
+ idir = kwargs.get('install_dir', None)
+ if isinstance(idir, str):
+ cfile = mesonlib.File.from_built_file(ofile_path, ofile_fname)
+ self.build.data.append(DataHolder([cfile], idir).held_object)
return mesonlib.File.from_built_file(self.subdir, output)
@stringArgs
@@ -2369,10 +2373,6 @@ requirements use the version keyword argument instead.''')
@stringArgs
@noKwargs
def func_join_paths(self, node, args, kwargs):
- if isinstance(args, str):
- st = (args,)
- else:
- st = tuple(args)
return os.path.join(*args).replace('\\', '/')
def flatten(self, args):
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 943a23e..b92be5f 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -58,6 +58,12 @@ class File:
else:
return os.path.join(build_to_src, self.subdir, self.fname)
+ def absolute_path(self, srcdir, builddir):
+ if self.is_built:
+ return os.path.join(builddir, self.subdir, self.fname)
+ else:
+ return os.path.join(srcdir, self.subdir, self.fname)
+
def endswith(self, ending):
return self.fname.endswith(ending)
@@ -70,6 +76,9 @@ class File:
def __hash__(self):
return hash((self.fname, self.subdir, self.is_built))
+ def relative_name(self):
+ return os.path.join(self.subdir, self.fname)
+
def get_compiler_for_source(compilers, src):
for comp in compilers:
if comp.can_compile(src):
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 88826f8..57c814c 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -192,12 +192,6 @@ def run_script_command(args):
if cmdname == 'exe':
import mesonbuild.scripts.meson_exe as abc
cmdfunc = abc.run
- elif cmdname == 'test':
- import mesonbuild.scripts.meson_test as abc
- cmdfunc = abc.run
- elif cmdname == 'benchmark':
- import mesonbuild.scripts.meson_benchmark as abc
- cmdfunc = abc.run
elif cmdname == 'install':
import mesonbuild.scripts.meson_install as abc
cmdfunc = abc.run
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 777fda8..7c4fb1d 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -31,7 +31,7 @@ from .. import interpreter
#
# https://github.com/ninja-build/ninja/issues/1184
# https://bugzilla.gnome.org/show_bug.cgi?id=774368
-gresource_dep_needed_version = '>9.99.99'
+gresource_dep_needed_version = '>= 2.52.0'
native_glib_version = None
girwarning_printed = False
@@ -715,7 +715,7 @@ can not be used with the current version of glib-compiled-resources, due to
known_kwargs = ['comments', 'eprod', 'fhead', 'fprod', 'ftail',
'identifier_prefix', 'symbol_prefix', 'template',
'vhead', 'vprod', 'vtail']
- known_custom_target_kwargs = ['install', 'install_dir', 'build_always',
+ known_custom_target_kwargs = ['install_dir', 'build_always',
'depends', 'depend_files']
c_template = h_template = None
install_header = False
@@ -724,8 +724,16 @@ can not be used with the current version of glib-compiled-resources, due to
sources = [value] + sources
elif arg == 'c_template':
c_template = value
+ if 'template' in kwargs:
+ raise MesonException('Mkenums does not accept both '
+ 'c_template and template keyword '
+ 'arguments at the same time.')
elif arg == 'h_template':
h_template = value
+ if 'template' in kwargs:
+ raise MesonException('Mkenums does not accept both '
+ 'h_template and template keyword '
+ 'arguments at the same time.')
elif arg == 'install_header':
install_header = value
elif arg in known_kwargs:
@@ -913,13 +921,13 @@ can not be used with the current version of glib-compiled-resources, due to
vapi_args = ret + self._vapi_args_to_command('--pkg=', 'packages', kwargs, accept_vapi=True)
return vapi_args, vapi_depends, vapi_packages, vapi_includes
- def _generate_deps(self, state, library, packages, indir):
+ def _generate_deps(self, state, library, packages, install_dir):
outdir = state.environment.scratch_dir
fname = os.path.join(outdir, library + '.deps')
with open(fname, 'w') as ofile:
for package in packages:
ofile.write(package + '\n')
- return build.Data(False, outdir, [fname], indir)
+ return build.Data(mesonlib.File(True, outdir, fname), install_dir)
def _get_vapi_link_with(self, target):
link_with = []
@@ -985,6 +993,7 @@ can not be used with the current version of glib-compiled-resources, due to
# We shouldn't need this locally but we install it
deps_target = self._generate_deps(state, library, vapi_packages, install_dir)
+ # XXX WRONG, state objects must not be modified! Fix this!
state.data.append(deps_target)
vapi_target = VapiTarget(vapi_output, state.subdir, custom_kwargs)
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index 3ecb40d..9f50b0e 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -138,7 +138,7 @@ class PkgConfigModule:
self.generate_pkgconfig_file(state, libs, subdirs, name, description, url,
version, pcfile, pub_reqs, priv_reqs,
conflicts, priv_libs)
- return build.Data(False, state.environment.get_scratch_dir(), [pcfile], pkgroot)
+ return build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
def initialize():
return PkgConfigModule()
diff --git a/mesonbuild/scripts/meson_benchmark.py b/mesonbuild/scripts/meson_benchmark.py
deleted file mode 100755
index 6d138b0..0000000
--- a/mesonbuild/scripts/meson_benchmark.py
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2015 The Meson development team
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import subprocess, sys, os, argparse
-import pickle, statistics, json
-from . import meson_test
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--wd', default=None, dest='wd',
- help='directory to cd into before running')
-parser.add_argument('args', nargs='+')
-
-def print_stats(numlen, num_tests, name, res, i, duration, stdev):
- startpad = ' '*(numlen - len('%d' % (i+1)))
- num = '%s%d/%d' % (startpad, i+1, num_tests)
- padding1 = ' '*(38-len(name))
- padding2 = ' '*(8-len(res))
- result_str = '%s %s %s%s%s%5.5f s +- %5.5f s' % \
- (num, name, padding1, res, padding2, duration, stdev)
- print(result_str)
-# write_json_log(jsonlogfile, name, result)
-
-def print_json_log(jsonlogfile, rawruns, test_name, i):
- jsonobj = {'name' : test_name}
- runs = []
- for r in rawruns:
- runobj = {'duration': r.duration,
- 'stdout': r.stdo,
- 'returncode' : r.returncode,
- 'duration' : r.duration}
- if r.stde:
- runobj['stderr'] = r.stde
- runs.append(runobj)
- jsonobj['runs'] = runs
- jsonlogfile.write(json.dumps(jsonobj) + '\n')
- jsonlogfile.flush()
-
-def run_benchmarks(options, datafile):
- failed_tests = 0
- logfile_base = 'meson-logs/benchmarklog'
- jsonlogfilename = logfile_base+ '.json'
- with open(datafile, 'rb') as f:
- tests = pickle.load(f)
- num_tests = len(tests)
- if num_tests == 0:
- print('No benchmarks defined.')
- return 0
- iteration_count = 5
- wrap = [] # Benchmarks on cross builds are pointless so don't support them.
- with open(jsonlogfilename, 'w') as jsonlogfile:
- for i, test in enumerate(tests):
- runs = []
- durations = []
- failed = False
- for _ in range(iteration_count):
- res = meson_test.run_single_test(wrap, test)
- runs.append(res)
- durations.append(res.duration)
- if res.returncode != 0:
- failed = True
- mean = statistics.mean(durations)
- stddev = statistics.stdev(durations)
- if failed:
- resultstr = 'FAIL'
- failed_tests += 1
- else:
- resultstr = 'OK'
- print_stats(3, num_tests, test.name, resultstr, i, mean, stddev)
- print_json_log(jsonlogfile, runs, test.name, i)
- print('\nFull log written to meson-logs/benchmarklog.json.')
- return failed_tests
-
-def run(args):
- global failed_tests
- options = parser.parse_args(args)
- if len(options.args) != 1:
- print('Benchmark runner for Meson. Do not run on your own, mmm\'kay?')
- print('%s [data file]' % sys.argv[0])
- if options.wd is not None:
- os.chdir(options.wd)
- datafile = options.args[0]
- returncode = run_benchmarks(options, datafile)
- return returncode
-
-if __name__ == '__main__':
- sys.exit(run(sys.argv[1:]))
diff --git a/mesonbuild/scripts/meson_test.py b/mesonbuild/scripts/meson_test.py
deleted file mode 100755
index 8034815..0000000
--- a/mesonbuild/scripts/meson_test.py
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2013-2016 The Meson development team
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import mesonbuild
-from .. import build
-import sys, os, subprocess, time, datetime, pickle, multiprocessing, json
-import concurrent.futures as conc
-import argparse
-import platform
-import signal
-
-def is_windows():
- platname = platform.system().lower()
- return platname == 'windows' or 'mingw' in platname
-
-collected_logs = []
-error_count = 0
-options = None
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--wrapper', default=None, dest='wrapper',
- help='wrapper to run tests with (e.g. valgrind)')
-parser.add_argument('--wd', default=None, dest='wd',
- help='directory to cd into before running')
-parser.add_argument('--suite', default=None, dest='suite',
- help='Only run tests belonging to this suite.')
-parser.add_argument('--no-stdsplit', default=True, dest='split', action='store_false',
- help='Do not split stderr and stdout in test logs.')
-parser.add_argument('--print-errorlogs', default=False, action='store_true',
- help="Whether to print faling tests' logs.")
-parser.add_argument('args', nargs='+')
-
-
-class TestRun():
- def __init__(self, res, returncode, should_fail, duration, stdo, stde, cmd,
- env):
- self.res = res
- self.returncode = returncode
- self.duration = duration
- self.stdo = stdo
- self.stde = stde
- self.cmd = cmd
- self.env = env
- self.should_fail = should_fail
-
- def get_log(self):
- res = '--- command ---\n'
- if self.cmd is None:
- res += 'NONE\n'
- else:
- res += "\n%s %s\n" %(' '.join(
- ["%s='%s'" % (k, v) for k, v in self.env.items()]),
- ' ' .join(self.cmd))
- if self.stdo:
- res += '--- stdout ---\n'
- res += self.stdo
- if self.stde:
- if res[-1:] != '\n':
- res += '\n'
- res += '--- stderr ---\n'
- res += self.stde
- if res[-1:] != '\n':
- res += '\n'
- res += '-------\n\n'
- return res
-
-def decode(stream):
- try:
- return stream.decode('utf-8')
- except UnicodeDecodeError:
- return stream.decode('iso-8859-1', errors='ignore')
-
-def write_json_log(jsonlogfile, test_name, result):
- jresult = {'name' : test_name,
- 'stdout' : result.stdo,
- 'result' : result.res,
- 'duration' : result.duration,
- 'returncode' : result.returncode,
- 'command' : result.cmd,
- 'env' : result.env}
- if result.stde:
- jresult['stderr'] = result.stde
- jsonlogfile.write(json.dumps(jresult) + '\n')
-
-def run_with_mono(fname):
- if fname.endswith('.exe') and not is_windows():
- return True
- return False
-
-def run_single_test(wrap, test):
- global options
- if test.fname[0].endswith('.jar'):
- cmd = ['java', '-jar'] + test.fname
- elif not test.is_cross and run_with_mono(test.fname[0]):
- cmd = ['mono'] + test.fname
- else:
- if test.is_cross:
- if test.exe_runner is None:
- # Can not run test on cross compiled executable
- # because there is no execute wrapper.
- cmd = None
- else:
- cmd = [test.exe_runner] + test.fname
- else:
- cmd = test.fname
- if cmd is None:
- res = 'SKIP'
- duration = 0.0
- stdo = 'Not run because can not execute cross compiled binaries.'
- stde = None
- returncode = -1
- else:
- if len(wrap) > 0 and 'valgrind' in wrap[0]:
- cmd = wrap + test.valgrind_args + cmd + test.cmd_args
- else:
- cmd = wrap + cmd + test.cmd_args
- starttime = time.time()
- child_env = os.environ.copy()
- if isinstance(test.env, build.EnvironmentVariables):
- test.env = test.env.get_env(child_env)
-
- child_env.update(test.env)
- if len(test.extra_paths) > 0:
- child_env['PATH'] = (child_env['PATH'] +
- os.pathsep.join([''] + test.extra_paths))
- if is_windows():
- setsid = None
- else:
- setsid = os.setsid
- p = subprocess.Popen(cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE if options and options.split else subprocess.STDOUT,
- env=child_env,
- cwd=test.workdir,
- preexec_fn=setsid)
- timed_out = False
- try:
- (stdo, stde) = p.communicate(timeout=test.timeout)
- except subprocess.TimeoutExpired:
- timed_out = True
- # Python does not provide multiplatform support for
- # killing a process and all its children so we need
- # to roll our own.
- if is_windows():
- subprocess.call(['taskkill', '/F', '/T', '/PID', str(p.pid)])
- else:
- os.killpg(os.getpgid(p.pid), signal.SIGKILL)
- (stdo, stde) = p.communicate()
- endtime = time.time()
- duration = endtime - starttime
- stdo = decode(stdo)
- if stde:
- stde = decode(stde)
- if timed_out:
- res = 'TIMEOUT'
- elif (not test.should_fail and p.returncode == 0) or \
- (test.should_fail and p.returncode != 0):
- res = 'OK'
- else:
- res = 'FAIL'
- returncode = p.returncode
- return TestRun(res, returncode, test.should_fail, duration, stdo, stde, cmd, test.env)
-
-def print_stats(numlen, tests, name, result, i, logfile, jsonlogfile):
- global collected_logs, error_count, options
- startpad = ' '*(numlen - len('%d' % (i+1)))
- num = '%s%d/%d' % (startpad, i+1, len(tests))
- padding1 = ' '*(38-len(name))
- padding2 = ' '*(8-len(result.res))
- result_str = '%s %s %s%s%s%5.2f s' % \
- (num, name, padding1, result.res, padding2, result.duration)
- print(result_str)
- result_str += "\n\n" + result.get_log()
- if (result.returncode != 0) != result.should_fail:
- error_count += 1
- if options.print_errorlogs:
- collected_logs.append(result_str)
- logfile.write(result_str)
- write_json_log(jsonlogfile, name, result)
-
-def drain_futures(futures):
- for i in futures:
- (result, numlen, tests, name, i, logfile, jsonlogfile) = i
- print_stats(numlen, tests, name, result.result(), i, logfile, jsonlogfile)
-
-def filter_tests(suite, tests):
- if suite is None:
- return tests
- return [x for x in tests if suite in x.suite]
-
-def run_tests(datafilename):
- global options
- logfile_base = 'meson-logs/testlog'
- if options.wrapper is None:
- wrap = []
- logfilename = logfile_base + '.txt'
- jsonlogfilename = logfile_base+ '.json'
- else:
- wrap = [options.wrapper]
- logfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.txt'
- jsonlogfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.json'
- with open(datafilename, 'rb') as f:
- tests = pickle.load(f)
- if len(tests) == 0:
- print('No tests defined.')
- return
- numlen = len('%d' % len(tests))
- varname = 'MESON_TESTTHREADS'
- if varname in os.environ:
- try:
- num_workers = int(os.environ[varname])
- except ValueError:
- print('Invalid value in %s, using 1 thread.' % varname)
- num_workers = 1
- else:
- num_workers = multiprocessing.cpu_count()
- executor = conc.ThreadPoolExecutor(max_workers=num_workers)
- futures = []
- filtered_tests = filter_tests(options.suite, tests)
-
- with open(jsonlogfilename, 'w') as jsonlogfile, \
- open(logfilename, 'w') as logfile:
- logfile.write('Log of Meson test suite run on %s.\n\n' %
- datetime.datetime.now().isoformat())
- for i, test in enumerate(filtered_tests):
- if test.suite[0] == '':
- visible_name = test.name
- else:
- if options.suite is not None:
- visible_name = options.suite + ' / ' + test.name
- else:
- visible_name = test.suite[0] + ' / ' + test.name
-
- if not test.is_parallel:
- drain_futures(futures)
- futures = []
- res = run_single_test(wrap, test)
- print_stats(numlen, filtered_tests, visible_name, res, i,
- logfile, jsonlogfile)
- else:
- f = executor.submit(run_single_test, wrap, test)
- futures.append((f, numlen, filtered_tests, visible_name, i,
- logfile, jsonlogfile))
- drain_futures(futures)
- return logfilename
-
-def run(args):
- global collected_logs, error_count, options
- collected_logs = [] # To avoid state leaks when invoked multiple times (running tests in-process)
- error_count = 0
- options = parser.parse_args(args)
- if len(options.args) != 1:
- print('Test runner for Meson. Do not run on your own, mmm\'kay?')
- print('%s [data file]' % sys.argv[0])
- if options.wd is not None:
- os.chdir(options.wd)
- datafile = options.args[0]
- logfilename = run_tests(datafile)
- if len(collected_logs) > 0:
- if len(collected_logs) > 10:
- print('\nThe output from 10 first failed tests:\n')
- else:
- print('\nThe output from the failed tests:\n')
- for log in collected_logs[:10]:
- lines = log.splitlines()
- if len(lines) > 100:
- print(lines[0])
- print('--- Listing only the last 100 lines from a long log. ---')
- lines = lines[-99:]
- for line in lines:
- print(line)
- if logfilename:
- print('Full log written to %s.' % logfilename)
- return error_count
-
-if __name__ == '__main__':
- sys.exit(run(sys.argv[1:]))
diff --git a/mesontest.py b/mesontest.py
new file mode 100755
index 0000000..04f72df
--- /dev/null
+++ b/mesontest.py
@@ -0,0 +1,375 @@
+#!/usr/bin/env python3
+
+# Copyright 2016 The Meson development team
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A tool to run tests in many different ways.
+
+import subprocess, sys, os, argparse
+import pickle
+import mesonbuild
+from mesonbuild import build
+from mesonbuild import environment
+
+import time, datetime, pickle, multiprocessing, json
+import concurrent.futures as conc
+import platform
+import signal
+
+def is_windows():
+ platname = platform.system().lower()
+ return platname == 'windows' or 'mingw' in platname
+
+def determine_worker_count():
+ varname = 'MESON_TESTTHREADS'
+ if varname in os.environ:
+ try:
+ num_workers = int(os.environ[varname])
+ except ValueError:
+ print('Invalid value in %s, using 1 thread.' % varname)
+ num_workers = 1
+ else:
+ try:
+ # Fails in some weird environments such as Debian
+ # reproducible build.
+ num_workers = multiprocessing.cpu_count()
+ except Exception:
+ num_workers = 1
+ return num_workers
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--repeat', default=1, dest='repeat', type=int,
+ help='Number of times to run the tests.')
+parser.add_argument('--gdb', default=False, dest='gdb', action='store_true',
+ help='Run test under gdb.')
+parser.add_argument('--list', default=False, dest='list', action='store_true',
+ help='List available tests.')
+parser.add_argument('--wrapper', default=None, dest='wrapper',
+ help='wrapper to run tests with (e.g. Valgrind)')
+parser.add_argument('--wd', default=None, dest='wd',
+ help='directory to cd into before running')
+parser.add_argument('--suite', default=None, dest='suite',
+ help='Only run tests belonging to the given suite.')
+parser.add_argument('--no-stdsplit', default=True, dest='split', action='store_false',
+ help='Do not split stderr and stdout in test logs.')
+parser.add_argument('--print-errorlogs', default=False, action='store_true',
+ help="Whether to print faling tests' logs.")
+parser.add_argument('--benchmark', default=False, action='store_true',
+ help="Run benchmarks instead of tests.")
+parser.add_argument('--logbase', default='testlog',
+ help="Base name for log file.")
+parser.add_argument('--num-processes', default=determine_worker_count(), type=int,
+ help='How many parallel processes to use.')
+parser.add_argument('args', nargs='*')
+
+class TestRun():
+ def __init__(self, res, returncode, should_fail, duration, stdo, stde, cmd,
+ env):
+ self.res = res
+ self.returncode = returncode
+ self.duration = duration
+ self.stdo = stdo
+ self.stde = stde
+ self.cmd = cmd
+ self.env = env
+ self.should_fail = should_fail
+
+ def get_log(self):
+ res = '--- command ---\n'
+ if self.cmd is None:
+ res += 'NONE\n'
+ else:
+ res += "\n%s %s\n" %(' '.join(
+ ["%s='%s'" % (k, v) for k, v in self.env.items()]),
+ ' ' .join(self.cmd))
+ if self.stdo:
+ res += '--- stdout ---\n'
+ res += self.stdo
+ if self.stde:
+ if res[-1:] != '\n':
+ res += '\n'
+ res += '--- stderr ---\n'
+ res += self.stde
+ if res[-1:] != '\n':
+ res += '\n'
+ res += '-------\n\n'
+ return res
+
+def decode(stream):
+ try:
+ return stream.decode('utf-8')
+ except UnicodeDecodeError:
+ return stream.decode('iso-8859-1', errors='ignore')
+
+def write_json_log(jsonlogfile, test_name, result):
+ jresult = {'name' : test_name,
+ 'stdout' : result.stdo,
+ 'result' : result.res,
+ 'duration' : result.duration,
+ 'returncode' : result.returncode,
+ 'command' : result.cmd,
+ 'env' : result.env}
+ if result.stde:
+ jresult['stderr'] = result.stde
+ jsonlogfile.write(json.dumps(jresult) + '\n')
+
+def run_with_mono(fname):
+ if fname.endswith('.exe') and not is_windows():
+ return True
+ return False
+
+class TestHarness:
+ def __init__(self, options):
+ self.options = options
+ self.collected_logs = []
+ self.error_count = 0
+ self.is_run = False
+ if self.options.benchmark:
+ self.datafile = 'meson-private/meson_benchmark_setup.dat'
+ else:
+ self.datafile = 'meson-private/meson_test_setup.dat'
+
+ def run_single_test(self, wrap, test):
+ if test.fname[0].endswith('.jar'):
+ cmd = ['java', '-jar'] + test.fname
+ elif not test.is_cross and run_with_mono(test.fname[0]):
+ cmd = ['mono'] + test.fname
+ else:
+ if test.is_cross:
+ if test.exe_runner is None:
+ # Can not run test on cross compiled executable
+ # because there is no execute wrapper.
+ cmd = None
+ else:
+ cmd = [test.exe_runner] + test.fname
+ else:
+ cmd = test.fname
+ if cmd is None:
+ res = 'SKIP'
+ duration = 0.0
+ stdo = 'Not run because can not execute cross compiled binaries.'
+ stde = None
+ returncode = -1
+ else:
+ cmd = wrap + cmd + test.cmd_args
+ starttime = time.time()
+ child_env = os.environ.copy()
+ if isinstance(test.env, build.EnvironmentVariables):
+ test.env = test.env.get_env(child_env)
+
+ child_env.update(test.env)
+ if len(test.extra_paths) > 0:
+ child_env['PATH'] = child_env['PATH'] + ';'.join([''] + test.extra_paths)
+ if is_windows():
+ setsid = None
+ else:
+ setsid = os.setsid
+ p = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE if self.options and self.options.split else subprocess.STDOUT,
+ env=child_env,
+ cwd=test.workdir,
+ preexec_fn=setsid)
+ timed_out = False
+ try:
+ (stdo, stde) = p.communicate(timeout=test.timeout)
+ except subprocess.TimeoutExpired:
+ timed_out = True
+ # Python does not provide multiplatform support for
+ # killing a process and all its children so we need
+ # to roll our own.
+ if is_windows():
+ subprocess.call(['taskkill', '/F', '/T', '/PID', str(p.pid)])
+ else:
+ os.killpg(os.getpgid(p.pid), signal.SIGKILL)
+ (stdo, stde) = p.communicate()
+ endtime = time.time()
+ duration = endtime - starttime
+ stdo = decode(stdo)
+ if stde:
+ stde = decode(stde)
+ if timed_out:
+ res = 'TIMEOUT'
+ elif (not test.should_fail and p.returncode == 0) or \
+ (test.should_fail and p.returncode != 0):
+ res = 'OK'
+ else:
+ res = 'FAIL'
+ returncode = p.returncode
+ return TestRun(res, returncode, test.should_fail, duration, stdo, stde, cmd, test.env)
+
+ def print_stats(self, numlen, tests, name, result, i, logfile, jsonlogfile):
+ startpad = ' '*(numlen - len('%d' % (i+1)))
+ num = '%s%d/%d' % (startpad, i+1, len(tests))
+ padding1 = ' '*(38-len(name))
+ padding2 = ' '*(8-len(result.res))
+ result_str = '%s %s %s%s%s%5.2f s' % \
+ (num, name, padding1, result.res, padding2, result.duration)
+ print(result_str)
+ result_str += "\n\n" + result.get_log()
+ if (result.returncode != 0) != result.should_fail:
+ self.error_count += 1
+ if self.options.print_errorlogs:
+ self.collected_logs.append(result_str)
+ logfile.write(result_str)
+ write_json_log(jsonlogfile, name, result)
+
+ def doit(self):
+ if self.is_run:
+ raise RuntimeError('Test harness object can only be used once.')
+ if not os.path.isfile(self.datafile):
+ print('Test data file. Probably this means that you did not run this in the build directory.')
+ return 1
+ self.is_run = True
+ logfilename = self.run_tests(self.datafile, self.options.logbase)
+ if len(self.collected_logs) > 0:
+ if len(self.collected_logs) > 10:
+ print('\nThe output from 10 first failed tests:\n')
+ else:
+ print('\nThe output from the failed tests:\n')
+ for log in self.collected_logs[:10]:
+ lines = log.splitlines()
+ if len(lines) > 100:
+ print(lines[0])
+ print('--- Listing only the last 100 lines from a long log. ---')
+ lines = lines[-99:]
+ for line in lines:
+ print(line)
+ print('Full log written to %s.' % logfilename)
+ return self.error_count
+
+ def run_tests(self, datafilename, log_base):
+ logfile_base = os.path.join('meson-logs', log_base)
+ if self.options.wrapper is None:
+ wrap = []
+ logfilename = logfile_base + '.txt'
+ jsonlogfilename = logfile_base+ '.json'
+ else:
+ wrap = self.options.wrapper.split()
+ namebase = wrap[0]
+ logfilename = logfile_base + '-' + namebase.replace(' ', '_') + '.txt'
+ jsonlogfilename = logfile_base + '-' + namebase.replace(' ', '_') + '.json'
+ with open(datafilename, 'rb') as f:
+ tests = pickle.load(f)
+ if len(tests) == 0:
+ print('No tests defined.')
+ return
+ numlen = len('%d' % len(tests))
+ executor = conc.ThreadPoolExecutor(max_workers=self.options.num_processes)
+ futures = []
+ filtered_tests = filter_tests(self.options.suite, tests)
+
+ with open(jsonlogfilename, 'w') as jsonlogfile, \
+ open(logfilename, 'w') as logfile:
+ logfile.write('Log of Meson test suite run on %s.\n\n' %
+ datetime.datetime.now().isoformat())
+ for i, test in enumerate(filtered_tests):
+ if test.suite[0] == '':
+ visible_name = test.name
+ else:
+ if self.options.suite is not None:
+ visible_name = self.options.suite + ' / ' + test.name
+ else:
+ visible_name = test.suite[0] + ' / ' + test.name
+
+ if not test.is_parallel:
+ self.drain_futures(futures)
+ futures = []
+ res = self.run_single_test(wrap, test)
+ self.print_stats(numlen, filtered_tests, visible_name, res, i,
+ logfile, jsonlogfile)
+ else:
+ f = executor.submit(self.run_single_test, wrap, test)
+ futures.append((f, numlen, filtered_tests, visible_name, i,
+ logfile, jsonlogfile))
+ self.drain_futures(futures)
+ return logfilename
+
+
+ def drain_futures(self, futures):
+ for i in futures:
+ (result, numlen, tests, name, i, logfile, jsonlogfile) = i
+ self.print_stats(numlen, tests, name, result.result(), i, logfile, jsonlogfile)
+
+ def run_special(self):
+ 'Tests run by the user, usually something like "under gdb 1000 times".'
+ if self.is_run:
+ raise RuntimeError('Can not use run_special after a full run.')
+ if self.options.wrapper is not None:
+ wrap = self.options.wrapper.split(' ')
+ else:
+ wrap = []
+ if self.options.gdb and len(wrap) > 0:
+ print('Can not specify both a wrapper and gdb.')
+ return 1
+ if os.path.isfile('build.ninja'):
+ subprocess.check_call([environment.detect_ninja(), 'all'])
+ tests = pickle.load(open(self.datafile, 'rb'))
+ if self.options.list:
+ for i in tests:
+ print(i.name)
+ return 0
+ for t in tests:
+ if t.name in self.options.args:
+ for i in range(self.options.repeat):
+ print('Running: %s %d/%d' % (t.name, i+1, self.options.repeat))
+ if self.options.gdb:
+ gdbrun(t)
+ else:
+ res = self.run_single_test(wrap, t)
+ if (res.returncode == 0 and res.should_fail) or \
+ (res.returncode != 0 and not res.should_fail):
+ print('Test failed:\n\n-- stdout --\n')
+ print(res.stdo)
+ print('\n-- stderr --\n')
+ print(res.stde)
+ return 1
+ return 0
+
+def filter_tests(suite, tests):
+ if suite is None:
+ return tests
+ return [x for x in tests if suite in x.suite]
+
+def gdbrun(test):
+ child_env = os.environ.copy()
+ child_env.update(test.env)
+ # On success will exit cleanly. On failure gdb will ask user
+ # if they really want to exit.
+ exe = test.fname
+ args = test.cmd_args
+ if len(args) > 0:
+ argset = ['-ex', 'set args ' + ' '.join(args)]
+ else:
+ argset = []
+ cmd = ['gdb', '--quiet'] + argset + ['-ex', 'run', '-ex', 'quit'] + exe
+ # FIXME a ton of stuff. run_single_test grabs stdout & co,
+ # which we do not want to do when running under gdb.
+ p = subprocess.Popen(cmd,
+ env=child_env,
+ cwd=test.workdir,
+ )
+ p.communicate()
+
+def run(args):
+ options = parser.parse_args(args)
+ if options.benchmark:
+ options.num_processes = 1
+ th = TestHarness(options)
+ if len(options.args) == 0:
+ return th.doit()
+ return th.run_special()
+
+if __name__ == '__main__':
+ sys.exit(run(sys.argv[1:]))
diff --git a/run_project_tests.py b/run_project_tests.py
index 15d656b..dcc6006 100755
--- a/run_project_tests.py
+++ b/run_project_tests.py
@@ -19,12 +19,12 @@ import os, subprocess, shutil, sys, signal
from io import StringIO
from ast import literal_eval
import sys, tempfile
+import mesontest
from mesonbuild import environment
from mesonbuild import mesonlib
from mesonbuild import mlog
from mesonbuild import mesonmain
from mesonbuild.mesonlib import stringlistify
-from mesonbuild.scripts import meson_test, meson_benchmark
import argparse
import xml.etree.ElementTree as ET
import time
@@ -211,8 +211,8 @@ def run_test_inprocess(testdir):
old_cwd = os.getcwd()
os.chdir(testdir)
try:
- returncode_test = meson_test.run(['meson-private/meson_test_setup.dat'])
- returncode_benchmark = meson_benchmark.run(['meson-private/meson_benchmark_setup.dat'])
+ returncode_test = mesontest.run([])
+ returncode_benchmark = mesontest.run(['--benchmark', '--logbase', 'benchmarklog'])
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
diff --git a/run_unittests.py b/run_unittests.py
index fff0c35..39e93c9 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -190,9 +190,16 @@ class LinuxlikeTests(unittest.TestCase):
self.run_target('check_exists')
def test_qt5dependency_qmake_detection(self):
- # Can't be sure that `qmake` is Qt5, so just try qmake-qt5.
+ # Verify that qmake is for Qt5
if not shutil.which('qmake-qt5'):
- raise unittest.SkipTest('qt5 not found')
+ if not shutil.which('qmake'):
+ raise unittest.SkipTest('QMake not found')
+ # For some inexplicable reason qmake --version gives different
+ # results when run from the command line vs invoked by Python.
+ # Check for both cases in case this behaviour changes in the future.
+ output = subprocess.getoutput(['qmake', '--version'])
+ if 'Qt version 5' not in output and 'qt5' not in output:
+ raise unittest.SkipTest('Qmake found, but it is not for Qt 5.')
# Disable pkg-config codepath and force searching with qmake/qmake-qt5
os.environ['PKG_CONFIG_LIBDIR'] = self.builddir
os.environ['PKG_CONFIG_PATH'] = self.builddir
@@ -200,8 +207,9 @@ class LinuxlikeTests(unittest.TestCase):
self.init(testdir)
# Confirm that the dependency was found with qmake
msg = 'Qt5 native `qmake-qt5` dependency (modules: Core) found: YES\n'
+ msg2 = 'Qt5 native `qmake` dependency (modules: Core) found: YES\n'
mesonlog = self.get_meson_log()
- self.assertTrue(msg in mesonlog)
+ self.assertTrue(msg in mesonlog or msg2 in mesonlog)
if __name__ == '__main__':
unittest.main()
diff --git a/test cases/common/12 data/fileobject_datafile.dat b/test cases/common/12 data/fileobject_datafile.dat
new file mode 100644
index 0000000..872aa5a
--- /dev/null
+++ b/test cases/common/12 data/fileobject_datafile.dat
@@ -0,0 +1 @@
+This is a data file that is installed via a File object.
diff --git a/test cases/common/12 data/installed_files.txt b/test cases/common/12 data/installed_files.txt
index 3d4b12c..8651e3a 100644
--- a/test cases/common/12 data/installed_files.txt
+++ b/test cases/common/12 data/installed_files.txt
@@ -1,4 +1,5 @@
usr/share/progname/datafile.dat
+usr/share/progname/fileobject_datafile.dat
usr/share/progname/vanishing.dat
usr/share/progname/vanishing2.dat
etc/etcfile.dat
diff --git a/test cases/common/12 data/meson.build b/test cases/common/12 data/meson.build
index 80f3835..7494abc 100644
--- a/test cases/common/12 data/meson.build
+++ b/test cases/common/12 data/meson.build
@@ -1,6 +1,7 @@
project('data install test', 'c')
install_data(sources : 'datafile.dat', install_dir : 'share/progname')
install_data(sources : 'etcfile.dat', install_dir : '/etc')
+install_data(files('fileobject_datafile.dat'), install_dir : 'share/progname')
subdir('vanishing')
diff --git a/test cases/common/31 find program/meson.build b/test cases/common/31 find program/meson.build
index ae71703..ba5386d 100644
--- a/test cases/common/31 find program/meson.build
+++ b/test cases/common/31 find program/meson.build
@@ -9,7 +9,7 @@ if build_machine.system() == 'windows'
# the program can be found.
cp = find_program('xcopy')
else
- cp = find_program('cp')
+ cp = find_program('donotfindme', 'cp')
gen = generator(cp, \
output : '@BASENAME@.c', \
arguments : ['@INPUT@', '@OUTPUT@'])
diff --git a/test cases/common/9 header install/installed_files.txt b/test cases/common/9 header install/installed_files.txt
index b9e91a2..8af6c1f 100644
--- a/test cases/common/9 header install/installed_files.txt
+++ b/test cases/common/9 header install/installed_files.txt
@@ -1,3 +1,4 @@
usr/include/rootdir.h
usr/include/subdir/subdir.h
usr/include/vanished.h
+usr/include/fileheader.h
diff --git a/test cases/common/9 header install/meson.build b/test cases/common/9 header install/meson.build
index 8c8ca73..7f3ce51 100644
--- a/test cases/common/9 header install/meson.build
+++ b/test cases/common/9 header install/meson.build
@@ -2,7 +2,10 @@ project('header install', 'c')
as_array = ['subdir.h']
+subdir('vanishing_subdir')
+subdir('sub')
+
h1 = install_headers('rootdir.h')
h2 = install_headers(as_array, subdir : 'subdir')
+h3 = install_headers(subheader)
-subdir('vanishing_subdir')
diff --git a/test cases/common/9 header install/sub/fileheader.h b/test cases/common/9 header install/sub/fileheader.h
new file mode 100644
index 0000000..28e5c8d
--- /dev/null
+++ b/test cases/common/9 header install/sub/fileheader.h
@@ -0,0 +1,3 @@
+#pragma once
+
+#define LIFE "Is life! Na naa, naa-na na."
diff --git a/test cases/common/9 header install/sub/meson.build b/test cases/common/9 header install/sub/meson.build
new file mode 100644
index 0000000..1ee0d1d
--- /dev/null
+++ b/test cases/common/9 header install/sub/meson.build
@@ -0,0 +1,2 @@
+subheader = files('fileheader.h')
+
diff --git a/test cases/frameworks/7 gnome/resources/meson.build b/test cases/frameworks/7 gnome/resources/meson.build
index f8c3d58..f17e469 100644
--- a/test cases/frameworks/7 gnome/resources/meson.build
+++ b/test cases/frameworks/7 gnome/resources/meson.build
@@ -11,7 +11,7 @@ simple_res_exe = executable('simple-resources-test',
dependencies: gio)
test('simple resource test', simple_res_exe)
-if glib.version() >= '9.99.9'
+if glib.version() >= '2.52.0'
# This test cannot pass if GLib version is older than 9.99.9.
# Meson will raise an error if the user tries to use the 'dependencies'
# argument and the version of GLib is too old for generated resource
diff --git a/test cases/java/3 args/com/mesonbuild/Simple.java b/test cases/java/3 args/com/mesonbuild/Simple.java
new file mode 100644
index 0000000..325a49a
--- /dev/null
+++ b/test cases/java/3 args/com/mesonbuild/Simple.java
@@ -0,0 +1,7 @@
+package com.mesonbuild;
+
+class Simple {
+ public static void main(String [] args) {
+ System.out.println("Java is working.\n");
+ }
+}
diff --git a/test cases/java/3 args/meson.build b/test cases/java/3 args/meson.build
new file mode 100644
index 0000000..7a73cf8
--- /dev/null
+++ b/test cases/java/3 args/meson.build
@@ -0,0 +1,9 @@
+project('simplejava', 'java')
+
+add_project_arguments('-target', '1.6', language : 'java')
+
+javaprog = jar('myprog', 'com/mesonbuild/Simple.java',
+ main_class : 'com.mesonbuild.Simple',
+ java_args : ['-source', '1.6'])
+test('mytest', javaprog)
+