From db8ad2a4bd4ed1e962e1cbfa76bd8abdf5e83b0e Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 14 Jan 2017 17:36:12 +0200 Subject: [PATCH] Add test for build_on_all. --- mesonbuild/backend/ninjabackend.py | 9 +++------ mesonbuild/build.py | 8 ++++++++ run_unittests.py | 11 +++++++++++ test cases/unit/4 build on all/foo.c | 6 ++++++ test cases/unit/4 build on all/meson.build | 13 +++++++++++++ test cases/unit/4 build on all/mygen.py | 8 ++++++++ test cases/unit/4 build on all/source.txt | 1 + 7 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 test cases/unit/4 build on all/foo.c create mode 100644 test cases/unit/4 build on all/meson.build create mode 100644 test cases/unit/4 build on all/mygen.py create mode 100644 test cases/unit/4 build on all/source.txt diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index cace3b3b2..a051bafa0 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -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): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 05595c30e..555d0b990 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -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] diff --git a/run_unittests.py b/run_unittests.py index adc0e7fc9..cc4b1f339 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -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): diff --git a/test cases/unit/4 build on all/foo.c b/test cases/unit/4 build on all/foo.c new file mode 100644 index 000000000..ca9791619 --- /dev/null +++ b/test cases/unit/4 build on all/foo.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + printf("Existentialism.\n"); + return 0; +} diff --git a/test cases/unit/4 build on all/meson.build b/test cases/unit/4 build on all/meson.build new file mode 100644 index 000000000..5a746a505 --- /dev/null +++ b/test cases/unit/4 build on all/meson.build @@ -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, +) diff --git a/test cases/unit/4 build on all/mygen.py b/test cases/unit/4 build on all/mygen.py new file mode 100644 index 000000000..5a74153ee --- /dev/null +++ b/test cases/unit/4 build on all/mygen.py @@ -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()) diff --git a/test cases/unit/4 build on all/source.txt b/test cases/unit/4 build on all/source.txt new file mode 100644 index 000000000..3573f4b21 --- /dev/null +++ b/test cases/unit/4 build on all/source.txt @@ -0,0 +1 @@ +I am a bunch of text.