Make it possible to only do unity builds on subprojects.

pull/1620/head
Jussi Pakkanen 8 years ago
parent 4e1249c920
commit b48daeda1a
  1. 2
      .travis.yml
  2. 9
      mesonbuild/backend/backends.py
  3. 2
      mesonbuild/backend/ninjabackend.py
  4. 2
      mesonbuild/backend/vs2010backend.py
  5. 3
      mesonbuild/build.py
  6. 2
      mesonbuild/coredata.py
  7. 5
      mesonbuild/interpreter.py
  8. 2
      mesonbuild/mesonmain.py
  9. 11
      run_unittests.py
  10. 6
      test cases/common/139 override options/meson.build

@ -14,7 +14,7 @@ compiler:
env: env:
- MESON_ARGS="" - MESON_ARGS=""
- MESON_ARGS="--unity" - MESON_ARGS="--unity=on"
language: language:
- cpp - cpp

@ -306,7 +306,7 @@ class Backend:
# With unity builds, there's just one object that contains all the # With unity builds, there's just one object that contains all the
# sources, and we only support extracting all the objects in this mode, # sources, and we only support extracting all the objects in this mode,
# so just return that. # 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(), comp = get_compiler_for_source(extobj.target.compilers.values(),
extobj.srclist[0]) extobj.srclist[0])
# There is a potential conflict here, but it is unlikely that # 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)) libs.append(os.path.join(self.get_target_dir(t), f))
return libs 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): def get_custom_target_sources(self, target):
''' '''
Custom target sources can be of various object types; strings, File, Custom target sources can be of various object types; strings, File,

@ -343,7 +343,7 @@ int dummy;
outname = self.get_target_filename(target) outname = self.get_target_filename(target)
obj_list = [] obj_list = []
use_pch = self.environment.coredata.base_options.get('b_pch', False) 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(): if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, outfile) pch_objects = self.generate_pch(target, outfile)
else: else:

@ -614,7 +614,7 @@ class Vs2010Backend(backends.Backend):
# Prefix to use to access the source tree's subdir from the vcxproj dir # 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) proj_to_src_dir = os.path.join(proj_to_src_root, target.subdir)
(sources, headers, objects, languages) = self.split_sources(target.sources) (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) sources = self.generate_unity_files(target, sources)
compiler = self._get_cl_compiler(target) compiler = self._get_cl_compiler(target)
buildtype_args = compiler.get_buildtype_args(self.buildtype) buildtype_args = compiler.get_buildtype_args(self.buildtype)

@ -307,7 +307,8 @@ class BuildTarget(Target):
super().__init__(name, subdir, True) super().__init__(name, subdir, True)
self.subproject = subproject # Can not be calculated from subdir as subproject dirname can be changed per project. self.subproject = subproject # Can not be calculated from subdir as subproject dirname can be changed per project.
self.is_cross = is_cross 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.environment = environment
self.sources = [] self.sources = []
self.compilers = OrderedDict() self.compilers = OrderedDict()

@ -295,7 +295,7 @@ def get_builtin_option_default(optname):
builtin_options = { builtin_options = {
'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'], 'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'],
'strip': [UserBooleanOption, 'Strip targets on install.', False], '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()], 'prefix': [UserStringOption, 'Installation prefix.', default_prefix()],
'libdir': [UserStringOption, 'Library directory.', default_libdir()], 'libdir': [UserStringOption, 'Library directory.', default_libdir()],
'libexecdir': [UserStringOption, 'Library executable directory.', default_libexecdir()], 'libexecdir': [UserStringOption, 'Library executable directory.', default_libexecdir()],

@ -1188,7 +1188,10 @@ class MesonMain(InterpreterObject):
raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname) raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname)
def is_unity_method(self, args, kwargs): 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): def is_subproject_method(self, args, kwargs):
return self.interpreter.is_subproject() return self.interpreter.is_subproject()

@ -54,7 +54,7 @@ add_builtin_argument('sharedstatedir')
add_builtin_argument('backend') add_builtin_argument('backend')
add_builtin_argument('buildtype') add_builtin_argument('buildtype')
add_builtin_argument('strip', action='store_true') 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('werror', action='store_true')
add_builtin_argument('layout') add_builtin_argument('layout')
add_builtin_argument('default-library') add_builtin_argument('default-library')

@ -390,8 +390,11 @@ class BasePlatformTests(unittest.TestCase):
return output return output
def init(self, srcdir, extra_args=None, default_args=True): def init(self, srcdir, extra_args=None, default_args=True):
self.assertTrue(os.path.exists(srcdir))
if extra_args is None: if extra_args is None:
extra_args = [] extra_args = []
if not isinstance(extra_args, list):
extra_args = [extra_args]
args = [srcdir, self.builddir] args = [srcdir, self.builddir]
if default_args: if default_args:
args += ['--prefix', self.prefix, args += ['--prefix', self.prefix,
@ -1374,6 +1377,14 @@ class LinuxlikeTests(BasePlatformTests):
cpp = env.detect_cpp_compiler(False) cpp = env.detect_cpp_compiler(False)
self._test_stds_impl(testdir, cpp, 'cpp') 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): def test_installed_modes(self):
''' '''
Test that files installed by these tests have the correct permissions. Test that files installed by these tests have the correct permissions.

@ -1,8 +1,6 @@
project('option override', 'c', project('option override', 'c',
default_options : 'unity=true') default_options : 'unity=on')
executable('mustunity', 'one.c', 'two.c') executable('mustunity', 'one.c', 'two.c')
executable('notunity', 'three.c', 'four.c', executable('notunity', 'three.c', 'four.c',
override_options : ['unity=false']) override_options : ['unity=off'])

Loading…
Cancel
Save