aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/build.py50
-rw-r--r--mesonbuild/coredata.py1
-rw-r--r--mesonbuild/dependencies.py20
-rw-r--r--mesonbuild/environment.py21
-rw-r--r--mesonbuild/interpreter.py23
-rwxr-xr-xmesontest.py9
-rw-r--r--test cases/common/56 custom target/meson.build4
-rwxr-xr-xtest cases/common/56 custom target/my_compiler.py15
-rw-r--r--test cases/failing/42 abs subdir/bob/meson.build2
-rw-r--r--test cases/failing/42 abs subdir/meson.build6
-rw-r--r--test cases/failing/42 abspath to srcdir/meson.build3
-rw-r--r--test cases/linuxlike/5 dependency versions/meson.build2
12 files changed, 118 insertions, 38 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 5466431..5f2de3b 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1298,6 +1298,29 @@ class CustomTarget(Target):
deps.append(c)
return deps
+ def flatten_command(self, cmd):
+ if not isinstance(cmd, list):
+ cmd = [cmd]
+ final_cmd = []
+ for c in cmd:
+ if hasattr(c, 'held_object'):
+ c = c.held_object
+ if isinstance(c, (str, File)):
+ final_cmd.append(c)
+ elif isinstance(c, dependencies.ExternalProgram):
+ if not c.found():
+ m = 'Tried to use not-found external program {!r} in "command"'
+ raise InvalidArguments(m.format(c.name))
+ final_cmd += c.get_command()
+ elif isinstance(c, (BuildTarget, CustomTarget)):
+ self.dependencies.append(c)
+ final_cmd.append(c)
+ elif isinstance(c, list):
+ final_cmd += self.flatten_command(c)
+ else:
+ raise InvalidArguments('Argument {!r} in "command" is invalid'.format(c))
+ return final_cmd
+
def process_kwargs(self, kwargs):
super().process_kwargs(kwargs)
self.sources = kwargs.get('input', [])
@@ -1325,32 +1348,7 @@ class CustomTarget(Target):
if os.path.split(depfile)[1] != depfile:
raise InvalidArguments('Depfile must be a plain filename without a subdirectory.')
self.depfile = depfile
- cmd = kwargs['command']
- if not(isinstance(cmd, list)):
- cmd = [cmd]
- final_cmd = []
- for i, c in enumerate(cmd):
- if hasattr(c, 'held_object'):
- c = c.held_object
- if isinstance(c, (str, File)):
- final_cmd.append(c)
- elif isinstance(c, dependencies.ExternalProgram):
- if not c.found():
- raise InvalidArguments('Tried to use not found external program {!r} in a build rule.'.format(c.name))
- final_cmd += c.get_command()
- elif isinstance(c, (BuildTarget, CustomTarget)):
- self.dependencies.append(c)
- final_cmd.append(c)
- elif isinstance(c, list):
- # Hackety hack, only supports one level of flattening. Should really
- # work to arbtrary depth.
- for s in c:
- if not isinstance(s, str):
- raise InvalidArguments('Array as argument %d contains a non-string.' % i)
- final_cmd.append(s)
- else:
- raise InvalidArguments('Argument %s in "command" is invalid.' % i)
- self.command = final_cmd
+ self.command = self.flatten_command(kwargs['command'])
if self.capture:
for c in self.command:
if isinstance(c, str) and '@OUTPUT@' in c:
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index d39f161..0e6685c 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -304,7 +304,6 @@ forbidden_target_names = {'clean': None,
'PHONY': None,
'all': None,
'test': None,
- 'test:': None,
'benchmark': None,
'install': None,
'uninstall': None,
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py
index c894b0e..9525ffa 100644
--- a/mesonbuild/dependencies.py
+++ b/mesonbuild/dependencies.py
@@ -1,4 +1,4 @@
-# Copyright 2013-2015 The Meson development team
+# Copyright 2013-2017 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.
@@ -589,6 +589,9 @@ class BoostDependency(Dependency):
mlog.log('Dependency Boost (%s) found:' % module_str, mlog.green('YES'), info)
else:
mlog.log("Dependency Boost (%s) found:" % module_str, mlog.red('NO'))
+ if 'cpp' not in self.environment.coredata.compilers:
+ raise DependencyException('Tried to use Boost but a C++ compiler is not defined.')
+ self.cpp_compiler = self.environment.coredata.compilers['cpp']
def detect_win_root(self):
globtext = 'c:\\local\\boost_*'
@@ -721,8 +724,19 @@ class BoostDependency(Dependency):
args.append('-L' + os.path.join(self.boost_root, 'lib'))
for module in self.requested_modules:
module = BoostDependency.name2lib.get(module, module)
- if module in self.lib_modules or module in self.lib_modules_mt:
- linkcmd = '-lboost_' + module
+ libname = 'boost_' + module
+ # The compiler's library detector is the most reliable so use that first.
+ default_detect = self.cpp_compiler.find_library(libname, self.environment, [])
+ if default_detect is not None:
+ if module == 'unit_testing_framework':
+ emon_args = self.cpp_compiler.find_library('boost_test_exec_monitor')
+ else:
+ emon_args = None
+ args += default_detect
+ if emon_args is not None:
+ args += emon_args
+ elif module in self.lib_modules or module in self.lib_modules_mt:
+ linkcmd = '-l' + libname
args.append(linkcmd)
# FIXME a hack, but Boost's testing framework has a lot of
# different options and it's hard to determine what to do
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index a7d1750..13b38d5 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -122,6 +122,18 @@ def detect_cpu_family(compilers):
if trial.startswith('arm'):
return 'arm'
if trial in ('amd64', 'x64'):
+ trial = 'x86_64'
+ if trial == 'x86_64':
+ # On Linux (and maybe others) there can be any mixture of 32/64 bit
+ # code in the kernel, Python, system etc. The only reliable way
+ # to know is to check the compiler defines.
+ for c in compilers.values():
+ try:
+ if c.has_define('__i386__'):
+ return 'x86'
+ except mesonlib.MesonException:
+ # Ignore compilers that do not support has_define.
+ pass
return 'x86_64'
# Add fixes here as bugs are reported.
return trial
@@ -132,6 +144,15 @@ def detect_cpu(compilers):
else:
trial = platform.machine().lower()
if trial in ('amd64', 'x64'):
+ trial = 'x86_64'
+ if trial == 'x86_64':
+ # Same check as above for cpu_family
+ for c in compilers.values():
+ try:
+ if c.has_define('__i386__'):
+ return 'i686' # All 64 bit cpus have at least this level of x86 support.
+ except mesonlib.MesonException:
+ pass
return 'x86_64'
# Add fixes here as bugs are reported.
return trial
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 4466f22..224f98e 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2132,6 +2132,8 @@ requirements use the version keyword argument instead.''')
raise InvalidArguments('Must not go into subprojects dir with subdir(), use subproject() instead.')
prev_subdir = self.subdir
subdir = os.path.join(prev_subdir, args[0])
+ if os.path.isabs(subdir):
+ raise InvalidArguments('Subdir argument must be a relative path.')
if subdir in self.visited_subdirs:
raise InvalidArguments('Tried to enter directory "%s", which has already been visited.'
% subdir)
@@ -2255,8 +2257,27 @@ requirements use the version keyword argument instead.''')
@stringArgs
def func_include_directories(self, node, args, kwargs):
- absbase = os.path.join(self.environment.get_source_dir(), self.subdir)
+ src_root = self.environment.get_source_dir()
+ absbase = os.path.join(src_root, self.subdir)
for a in args:
+ if a.startswith(src_root):
+ raise InvalidArguments('''Tried to form an absolute path to a source dir. You should not do that but use
+relative paths instead.
+
+To get include path to any directory relative to the current dir do
+
+incdir = include_directories(dirname)
+
+After this incdir will contain both the current source dir as well as the
+corresponding build dir. It can then be used in any subdirectory and
+Meson will take care of all the busywork to make paths work.
+
+Dirname can even be '.' to mark the current directory. Though you should
+remember that the current source and build directories are always
+put in the include directories by default so you only need to do
+include_directories('.') if you intend to use the result in a
+different subdirectory.
+''')
absdir = os.path.join(absbase, a)
if not os.path.isdir(absdir):
raise InvalidArguments('Include dir %s does not exist.' % a)
diff --git a/mesontest.py b/mesontest.py
index f5da103..3545ed8 100755
--- a/mesontest.py
+++ b/mesontest.py
@@ -25,6 +25,7 @@ import time, datetime, multiprocessing, json
import concurrent.futures as conc
import platform
import signal
+import random
# GNU autotools interprets a return code of 77 from tests it executes to
# mean that the test should be skipped.
@@ -221,6 +222,14 @@ class TestHarness:
if len(test.extra_paths) > 0:
child_env['PATH'] += ';'.join([''] + test.extra_paths)
+ # If MALLOC_PERTURB_ is not set, or if it is set to an empty value,
+ # (i.e., the test or the environment don't explicitly set it), set
+ # it ourselves. We do this unconditionally because it is extremely
+ # useful to have in tests.
+ # Setting MALLOC_PERTURB_="0" will completely disable this feature.
+ if 'MALLOC_PERTURB_' not in child_env or not child_env['MALLOC_PERTURB_']:
+ child_env['MALLOC_PERTURB_'] = str(random.randint(1, 255))
+
setsid = None
stdout = None
stderr = None
diff --git a/test cases/common/56 custom target/meson.build b/test cases/common/56 custom target/meson.build
index fd59fbd..2e6f69c 100644
--- a/test cases/common/56 custom target/meson.build
+++ b/test cases/common/56 custom target/meson.build
@@ -8,11 +8,13 @@ endif
# Note that this will not add a dependency to the compiler executable.
# Code will not be rebuilt if it changes.
comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py')
+# Test that files() in command: works. The compiler just discards it.
+useless = files('installed_files.txt')
mytarget = custom_target('bindat',
output : 'data.dat',
input : 'data_source.txt',
-command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@'],
+command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@', useless],
install : true,
install_dir : 'subdir'
)
diff --git a/test cases/common/56 custom target/my_compiler.py b/test cases/common/56 custom target/my_compiler.py
index 4ba2da6..f46d23a 100755
--- a/test cases/common/56 custom target/my_compiler.py
+++ b/test cases/common/56 custom target/my_compiler.py
@@ -1,16 +1,21 @@
#!/usr/bin/env python3
+import os
import sys
+assert(os.path.exists(sys.argv[3]))
+
+args = sys.argv[:-1]
+
if __name__ == '__main__':
- if len(sys.argv) != 3 or not sys.argv[1].startswith('--input') or \
- not sys.argv[2].startswith('--output'):
- print(sys.argv[0], '--input=input_file --output=output_file')
+ if len(args) != 3 or not args[1].startswith('--input') or \
+ not args[2].startswith('--output'):
+ print(args[0], '--input=input_file --output=output_file')
sys.exit(1)
- with open(sys.argv[1].split('=')[1]) as f:
+ with open(args[1].split('=')[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n':
print('Malformed input')
sys.exit(1)
- with open(sys.argv[2].split('=')[1], 'w') as ofile:
+ with open(args[2].split('=')[1], 'w') as ofile:
ofile.write('This is a binary output file.\n')
diff --git a/test cases/failing/42 abs subdir/bob/meson.build b/test cases/failing/42 abs subdir/bob/meson.build
new file mode 100644
index 0000000..7bbf4b2
--- /dev/null
+++ b/test cases/failing/42 abs subdir/bob/meson.build
@@ -0,0 +1,2 @@
+# This file is never reached.
+x = 3
diff --git a/test cases/failing/42 abs subdir/meson.build b/test cases/failing/42 abs subdir/meson.build
new file mode 100644
index 0000000..8c23224
--- /dev/null
+++ b/test cases/failing/42 abs subdir/meson.build
@@ -0,0 +1,6 @@
+project('abs subdir', 'c')
+
+# For some reason people insist on doing this, probably
+# because Make has taught them to never rely on anything.
+subdir(join_paths(meson.source_root(), 'bob'))
+
diff --git a/test cases/failing/42 abspath to srcdir/meson.build b/test cases/failing/42 abspath to srcdir/meson.build
new file mode 100644
index 0000000..964a19b
--- /dev/null
+++ b/test cases/failing/42 abspath to srcdir/meson.build
@@ -0,0 +1,3 @@
+project('meson', 'c')
+
+include_directories(meson.current_source_dir())
diff --git a/test cases/linuxlike/5 dependency versions/meson.build b/test cases/linuxlike/5 dependency versions/meson.build
index 20b3df5..1b01cd6 100644
--- a/test cases/linuxlike/5 dependency versions/meson.build
+++ b/test cases/linuxlike/5 dependency versions/meson.build
@@ -1,4 +1,4 @@
-project('dep versions', 'c')
+project('dep versions', 'c', 'cpp')
# Find external dependency without version
zlib = dependency('zlib')