Add test for build_on_all.

pull/1303/head
Jussi Pakkanen 8 years ago
parent b1087f011c
commit db8ad2a4bd
  1. 9
      mesonbuild/backend/ninjabackend.py
  2. 8
      mesonbuild/build.py
  3. 11
      run_unittests.py
  4. 6
      test cases/unit/4 build on all/foo.c
  5. 13
      test cases/unit/4 build on all/meson.build
  6. 8
      test cases/unit/4 build on all/mygen.py
  7. 1
      test cases/unit/4 build on all/source.txt

@ -2163,13 +2163,10 @@ rule FORTRAN_DEP_HACK
def get_build_on_all_targets(self):
result = []
for t in self.build.get_targets().values():
if t.build_on_all:
if t.build_on_all or \
(hasattr(t, 'install') and t.install) or\
(hasattr(t, 'build_always') and t.build_always):
result.append(t)
# CustomTargets that aren't installed should only be built if
# they are used by something else or are to always be built
if isinstance(t, build.CustomTarget):
if t.install or t.build_always:
result.append(t)
return result
def generate_ending(self, outfile):

@ -44,6 +44,7 @@ known_basic_kwargs = {'install': True,
'sources': True,
'objects': True,
'native': True,
'build_on_all': True,
}
# These contain kwargs supported by both static and shared libraries. These are
@ -264,6 +265,11 @@ class Target:
def get_subdir(self):
return self.subdir
def process_kwargs(self, kwargs):
if 'build_on_all' in kwargs:
self.build_on_all = kwargs['build_on_all']
if not isinstance(self.build_on_all, bool):
raise InvalidArguments('build_on_all must be a boolean value.')
class BuildTarget(Target):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
@ -518,6 +524,7 @@ class BuildTarget(Target):
return self.custom_install_dir
def process_kwargs(self, kwargs, environment):
super().process_kwargs(kwargs)
self.copy_kwargs(kwargs)
kwargs.get('modules', [])
self.need_install = kwargs.get('install', self.need_install)
@ -1281,6 +1288,7 @@ class CustomTarget(Target):
return deps
def process_kwargs(self, kwargs):
super().process_kwargs(kwargs)
self.sources = kwargs.get('input', [])
if not isinstance(self.sources, list):
self.sources = [self.sources]

@ -526,6 +526,17 @@ class LinuxlikeTests(unittest.TestCase):
self._test_stds_impl(testdir, cpp, 'cpp')
def test_build_on_all(self):
testdir = os.path.join(self.unit_test_dir, '4 build on all')
self.init(testdir)
self.build()
genfile = os.path.join(self.builddir, 'generated.dat')
exe = os.path.join(self.builddir, 'fooprog')
self.assertTrue(os.path.exists(genfile))
self.assertFalse(os.path.exists(exe))
self._run(self.ninja_command + ['fooprog'])
self.assertTrue(os.path.exists(exe))
class RewriterTests(unittest.TestCase):
def setUp(self):

@ -0,0 +1,6 @@
#include<stdio.h>
int main(int argc, char **argv) {
printf("Existentialism.\n");
return 0;
}

@ -0,0 +1,13 @@
project('build on all', 'c')
py3_mod = import('python3')
py3 = py3_mod.find_python()
executable('fooprog', 'foo.c', build_on_all : false)
comp = files('mygen.py')
mytarget = custom_target('gendat',
output : 'generated.dat',
input : 'source.txt',
command : [py3] + comp + ['@INPUT@', '@OUTPUT@'],
build_on_all : true,
)

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import sys
ifile = open(sys.argv[1])
ofile = open(sys.argv[2], 'w')
ofile.write(ifile.read())
Loading…
Cancel
Save