diff --git a/.travis.yml b/.travis.yml index b3346a163..fbb11ac76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ compiler: env: - MESON_ARGS="" - - MESON_ARGS="--unity" + - MESON_ARGS="--unity=on" language: - cpp diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index a77047bf0..6a00d1727 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -306,7 +306,7 @@ class Backend: # With unity builds, there's just one object that contains all the # sources, and we only support extracting all the objects in this mode, # so just return that. - if self.get_option_for_target('unity', target): + if self.is_unity(target): comp = get_compiler_for_source(extobj.target.compilers.values(), extobj.srclist[0]) # There is a potential conflict here, but it is unlikely that @@ -607,6 +607,13 @@ class Backend: libs.append(os.path.join(self.get_target_dir(t), f)) return libs + def is_unity(self, target): + optval = self.get_option_for_target('unity', target) + if optval == 'on' or (optval == 'subprojects' and target.subproject != ''): + return True + return False + + def get_custom_target_sources(self, target): ''' Custom target sources can be of various object types; strings, File, diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index dc05d3489..fa7b9c018 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -343,7 +343,7 @@ int dummy; outname = self.get_target_filename(target) obj_list = [] use_pch = self.environment.coredata.base_options.get('b_pch', False) - is_unity = self.get_option_for_target('unity', target) + is_unity = self.is_unity(target) if use_pch and target.has_pch(): pch_objects = self.generate_pch(target, outfile) else: diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 99375215b..432bdd02f 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -614,7 +614,7 @@ class Vs2010Backend(backends.Backend): # Prefix to use to access the source tree's subdir from the vcxproj dir proj_to_src_dir = os.path.join(proj_to_src_root, target.subdir) (sources, headers, objects, languages) = self.split_sources(target.sources) - if self.get_option_for_target('unity', target): + if self.is_unity(target): sources = self.generate_unity_files(target, sources) compiler = self._get_cl_compiler(target) buildtype_args = compiler.get_buildtype_args(self.buildtype) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 6815b0c6f..bcbe31880 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -307,7 +307,8 @@ class BuildTarget(Target): super().__init__(name, subdir, True) self.subproject = subproject # Can not be calculated from subdir as subproject dirname can be changed per project. self.is_cross = is_cross - self.is_unity = environment.coredata.get_builtin_option('unity') + unity_opt = environment.coredata.get_builtin_option('unity') + self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '') self.environment = environment self.sources = [] self.compilers = OrderedDict() diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 27f1dd7a4..b9b889dea 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -295,7 +295,7 @@ def get_builtin_option_default(optname): builtin_options = { 'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'], 'strip': [UserBooleanOption, 'Strip targets on install.', False], - 'unity': [UserBooleanOption, 'Unity build.', False], + 'unity': [UserComboOption, 'Unity build.', ['on', 'off', 'subprojects'], 'off'], 'prefix': [UserStringOption, 'Installation prefix.', default_prefix()], 'libdir': [UserStringOption, 'Library directory.', default_libdir()], 'libexecdir': [UserStringOption, 'Library executable directory.', default_libexecdir()], diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 18f91eadf..d00338b4b 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1188,7 +1188,10 @@ class MesonMain(InterpreterObject): raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname) def is_unity_method(self, args, kwargs): - return self.build.environment.coredata.get_builtin_option('unity') + optval = self.interpreter.environment.coredata.get_builtin_option('unity') + if optval == 'on' or (optval == 'subprojects' and self.interpreter.subproject != ''): + return True + return False def is_subproject_method(self, args, kwargs): return self.interpreter.is_subproject() diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 51041cc0b..7e4be7f92 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -54,7 +54,7 @@ add_builtin_argument('sharedstatedir') add_builtin_argument('backend') add_builtin_argument('buildtype') add_builtin_argument('strip', action='store_true') -add_builtin_argument('unity', action='store_true') +add_builtin_argument('unity') add_builtin_argument('werror', action='store_true') add_builtin_argument('layout') add_builtin_argument('default-library') diff --git a/run_unittests.py b/run_unittests.py index 7bdd57b3b..e8ecbb271 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -390,8 +390,11 @@ class BasePlatformTests(unittest.TestCase): return output def init(self, srcdir, extra_args=None, default_args=True): + self.assertTrue(os.path.exists(srcdir)) if extra_args is None: extra_args = [] + if not isinstance(extra_args, list): + extra_args = [extra_args] args = [srcdir, self.builddir] if default_args: args += ['--prefix', self.prefix, @@ -1374,6 +1377,14 @@ class LinuxlikeTests(BasePlatformTests): cpp = env.detect_cpp_compiler(False) self._test_stds_impl(testdir, cpp, 'cpp') + def test_unity_subproj(self): + testdir = os.path.join(self.common_test_dir, '49 subproject') + self.init(testdir, extra_args='--unity=subprojects') + self.assertTrue(os.path.exists(os.path.join(self.builddir, 'subprojects/sublib/simpletest@exe/simpletest-unity.c'))) + self.assertTrue(os.path.exists(os.path.join(self.builddir, 'subprojects/sublib/sublib@sha/sublib-unity.c'))) + self.assertFalse(os.path.exists(os.path.join(self.builddir, 'user@exe/user-unity.c'))) + self.build() + def test_installed_modes(self): ''' Test that files installed by these tests have the correct permissions. diff --git a/test cases/common/139 override options/meson.build b/test cases/common/139 override options/meson.build index 0db05131f..4dd8d797e 100644 --- a/test cases/common/139 override options/meson.build +++ b/test cases/common/139 override options/meson.build @@ -1,8 +1,6 @@ project('option override', 'c', - default_options : 'unity=true') + default_options : 'unity=on') executable('mustunity', 'one.c', 'two.c') executable('notunity', 'three.c', 'four.c', - override_options : ['unity=false']) - - + override_options : ['unity=off'])