diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-01-15 21:28:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-15 21:28:10 +0200 |
commit | cfc33ac4212cb59b4ace3d3f404227366ffa5daf (patch) | |
tree | be33d78b12bf2ed8fe4d2607b8fc16100ea30c96 | |
parent | 7a28f387e26eb982ab50c3d44a909e706129a09a (diff) | |
parent | 21d85058253ea8fbfb16c8c8f696d21b863f32dd (diff) | |
download | meson-cfc33ac4212cb59b4ace3d3f404227366ffa5daf.zip meson-cfc33ac4212cb59b4ace3d3f404227366ffa5daf.tar.gz meson-cfc33ac4212cb59b4ace3d3f404227366ffa5daf.tar.bz2 |
Merge pull request #1303 from mesonbuild/buildonall
Add kwarg build_by_default
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 16 | ||||
-rw-r--r-- | mesonbuild/build.py | 55 | ||||
-rwxr-xr-x | run_unittests.py | 11 | ||||
-rw-r--r-- | test cases/unit/5 build by default/foo.c | 6 | ||||
-rw-r--r-- | test cases/unit/5 build by default/meson.build | 13 | ||||
-rw-r--r-- | test cases/unit/5 build by default/mygen.py | 8 | ||||
-rw-r--r-- | test cases/unit/5 build by default/source.txt | 1 |
7 files changed, 75 insertions, 35 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 218e128..cdffb76 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2160,21 +2160,21 @@ rule FORTRAN_DEP_HACK elem.add_item('pool', 'console') elem.write(outfile) + def get_build_by_default_targets(self): + result = [] + for t in self.build.get_targets().values(): + if t.build_by_default or t.install or t.build_always: + result.append(t) + return result + def generate_ending(self, outfile): targetlist = [] ctlist = [] - for t in self.build.get_targets().values(): - # RunTargets are meant to be invoked manually - if isinstance(t, build.RunTarget): - continue + for t in self.get_build_by_default_targets(): if isinstance(t, build.CustomTarget): # Create a list of all custom target outputs for o in t.get_outputs(): ctlist.append(os.path.join(self.get_target_dir(t), o)) - # CustomTargets that aren't installed should only be built if - # they are used by something else or are to always be built - if not (t.install or t.build_always): - continue # Add the first output of each target to the 'all' target so that # they are all built targetlist.append(os.path.join(self.get_target_dir(t), t.get_outputs()[0])) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index cc33d39..2ca1404 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_by_default': True, } # These contain kwargs supported by both static and shared libraries. These are @@ -252,11 +253,29 @@ class EnvironmentVariables(): env[name] = method(full_env, name, values, kwargs) return env - -class BuildTarget(): - def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): +class Target: + def __init__(self, name, subdir, build_by_default): self.name = name self.subdir = subdir + self.build_by_default = build_by_default + self.install = False + self.build_always = False + + def get_basename(self): + return self.name + + def get_subdir(self): + return self.subdir + + def process_kwargs(self, kwargs): + if 'build_by_default' in kwargs: + self.build_by_default = kwargs['build_by_default'] + if not isinstance(self.build_by_default, bool): + raise InvalidArguments('build_by_default must be a boolean value.') + +class BuildTarget(Target): + def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): + 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') @@ -507,6 +526,7 @@ class BuildTarget(): 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) @@ -643,9 +663,6 @@ class BuildTarget(): if not isinstance(self.pic, bool): raise InvalidArguments('Argument pic to static library {!r} must be boolean'.format(self.name)) - def get_subdir(self): - return self.subdir - def get_filename(self): return self.filename @@ -672,9 +689,6 @@ class BuildTarget(): transitive_deps += t.get_dependencies() return transitive_deps - def get_basename(self): - return self.name - def get_source_subdir(self): return self.subdir @@ -1229,7 +1243,7 @@ class SharedModule(SharedLibrary): raise MesonException('Shared modules must not specify the soversion kwarg.') super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) -class CustomTarget: +class CustomTarget(Target): known_kwargs = {'input': True, 'output': True, 'command': True, @@ -1243,8 +1257,7 @@ class CustomTarget: } def __init__(self, name, subdir, kwargs, absolute_paths=False): - self.name = name - self.subdir = subdir + super().__init__(name, subdir, False) self.dependencies = [] self.extra_depends = [] self.depend_files = [] # Files that this target depends on but are not on the command line. @@ -1279,6 +1292,7 @@ class CustomTarget: 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] @@ -1368,9 +1382,6 @@ class CustomTarget: mlog.debug(i) raise InvalidArguments('Unknown type {!r} in depend_files.'.format(type(i).__name__)) - def get_basename(self): - return self.name - def get_dependencies(self): return self.dependencies @@ -1380,9 +1391,6 @@ class CustomTarget: def get_custom_install_dir(self): return self.install_dir - def get_subdir(self): - return self.subdir - def get_outputs(self): return self.output @@ -1398,13 +1406,12 @@ class CustomTarget: def type_suffix(self): return "@cus" -class RunTarget: +class RunTarget(Target): def __init__(self, name, command, args, dependencies, subdir): - self.name = name + super().__init__(name, subdir, False) self.command = command self.args = args self.dependencies = dependencies - self.subdir = subdir def __repr__(self): repr_str = "<{0} {1}: {2}>" @@ -1413,9 +1420,6 @@ class RunTarget: def get_id(self): return self.name + self.type_suffix() - def get_basename(self): - return self.name - def get_dependencies(self): return self.dependencies @@ -1425,9 +1429,6 @@ class RunTarget: def get_sources(self): return [] - def get_subdir(self): - return self.subdir - def should_install(self): return False diff --git a/run_unittests.py b/run_unittests.py index adc0e7f..123bca8 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_by_default(self): + testdir = os.path.join(self.unit_test_dir, '5 build by default') + 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/5 build by default/foo.c b/test cases/unit/5 build by default/foo.c new file mode 100644 index 0000000..ca97916 --- /dev/null +++ b/test cases/unit/5 build by default/foo.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(int argc, char **argv) { + printf("Existentialism.\n"); + return 0; +} diff --git a/test cases/unit/5 build by default/meson.build b/test cases/unit/5 build by default/meson.build new file mode 100644 index 0000000..67c5cc2 --- /dev/null +++ b/test cases/unit/5 build by default/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_by_default : false) +comp = files('mygen.py') +mytarget = custom_target('gendat', + output : 'generated.dat', + input : 'source.txt', + command : [py3] + comp + ['@INPUT@', '@OUTPUT@'], + build_by_default : true, +) diff --git a/test cases/unit/5 build by default/mygen.py b/test cases/unit/5 build by default/mygen.py new file mode 100644 index 0000000..5a74153 --- /dev/null +++ b/test cases/unit/5 build by default/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/5 build by default/source.txt b/test cases/unit/5 build by default/source.txt new file mode 100644 index 0000000..3573f4b --- /dev/null +++ b/test cases/unit/5 build by default/source.txt @@ -0,0 +1 @@ +I am a bunch of text. |