From 7abc7c64b08f349a97dce5484d9e12d4e03896e9 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 14 Jan 2017 16:46:37 +0200 Subject: Created base class for all targets and moved common functionality there. --- mesonbuild/build.py | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 8fa6ada..05595c3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -252,11 +252,22 @@ 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_on_all): self.name = name self.subdir = subdir + self.build_on_all = build_on_all + + def get_basename(self): + return self.name + + def get_subdir(self): + return self.subdir + + +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') @@ -643,9 +654,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 +680,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 @@ -1227,7 +1232,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, @@ -1241,8 +1246,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. @@ -1366,9 +1370,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 @@ -1378,9 +1379,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 @@ -1396,13 +1394,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}>" @@ -1411,9 +1408,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 @@ -1423,9 +1417,6 @@ class RunTarget: def get_sources(self): return [] - def get_subdir(self): - return self.subdir - def should_install(self): return False -- cgit v1.1 From b1087f011cb815a5214791ab92e7214e01b45b72 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 14 Jan 2017 17:01:07 +0200 Subject: Moved detection of targets to build on all into own function. --- mesonbuild/backend/ninjabackend.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e6f82d1..cace3b3 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2160,21 +2160,26 @@ rule FORTRAN_DEP_HACK elem.add_item('pool', 'console') elem.write(outfile) + def get_build_on_all_targets(self): + result = [] + for t in self.build.get_targets().values(): + if t.build_on_all: + 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): 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_on_all_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])) -- cgit v1.1 From db8ad2a4bd4ed1e962e1cbfa76bd8abdf5e83b0e Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 14 Jan 2017 17:36:12 +0200 Subject: 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 cace3b3..a051baf 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 05595c3..555d0b9 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 adc0e7f..cc4b1f3 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 0000000..ca97916 --- /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 0000000..5a746a5 --- /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 0000000..5a74153 --- /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 0000000..3573f4b --- /dev/null +++ b/test cases/unit/4 build on all/source.txt @@ -0,0 +1 @@ +I am a bunch of text. -- cgit v1.1 From 58878b998d4a4a144c271edb2091904f05c0668c Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 15 Jan 2017 02:01:21 +0200 Subject: Get rid of hasattr. --- mesonbuild/backend/ninjabackend.py | 4 +--- mesonbuild/build.py | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index a051baf..e861bf7 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2163,9 +2163,7 @@ 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 or \ - (hasattr(t, 'install') and t.install) or\ - (hasattr(t, 'build_always') and t.build_always): + if t.build_on_all or t.install or t.build_always: result.append(t) return result diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 555d0b9..b01c280 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -258,6 +258,8 @@ class Target: self.name = name self.subdir = subdir self.build_on_all = build_on_all + self.install = False + self.build_always = False def get_basename(self): return self.name -- cgit v1.1 From 21d85058253ea8fbfb16c8c8f696d21b863f32dd Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 15 Jan 2017 14:51:34 +0200 Subject: build_by_default it is. --- mesonbuild/backend/ninjabackend.py | 6 +++--- mesonbuild/build.py | 14 +++++++------- run_unittests.py | 4 ++-- 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 - test cases/unit/5 build by default/foo.c | 6 ++++++ test cases/unit/5 build by default/meson.build | 13 +++++++++++++ test cases/unit/5 build by default/mygen.py | 8 ++++++++ test cases/unit/5 build by default/source.txt | 1 + 11 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 test cases/unit/4 build on all/foo.c delete mode 100644 test cases/unit/4 build on all/meson.build delete mode 100644 test cases/unit/4 build on all/mygen.py delete mode 100644 test cases/unit/4 build on all/source.txt create mode 100644 test cases/unit/5 build by default/foo.c create mode 100644 test cases/unit/5 build by default/meson.build create mode 100644 test cases/unit/5 build by default/mygen.py create mode 100644 test cases/unit/5 build by default/source.txt diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e861bf7..668d6c4 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2160,17 +2160,17 @@ rule FORTRAN_DEP_HACK elem.add_item('pool', 'console') elem.write(outfile) - def get_build_on_all_targets(self): + def get_build_by_default_targets(self): result = [] for t in self.build.get_targets().values(): - if t.build_on_all or t.install or t.build_always: + 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.get_build_on_all_targets(): + 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(): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b01c280..91815fa 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -44,7 +44,7 @@ known_basic_kwargs = {'install': True, 'sources': True, 'objects': True, 'native': True, - 'build_on_all': True, + 'build_by_default': True, } # These contain kwargs supported by both static and shared libraries. These are @@ -254,10 +254,10 @@ class EnvironmentVariables(): return env class Target: - def __init__(self, name, subdir, build_on_all): + def __init__(self, name, subdir, build_by_default): self.name = name self.subdir = subdir - self.build_on_all = build_on_all + self.build_by_default = build_by_default self.install = False self.build_always = False @@ -268,10 +268,10 @@ class Target: 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.') + 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): diff --git a/run_unittests.py b/run_unittests.py index cc4b1f3..123bca8 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -526,8 +526,8 @@ 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') + 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') diff --git a/test cases/unit/4 build on all/foo.c b/test cases/unit/4 build on all/foo.c deleted file mode 100644 index ca97916..0000000 --- a/test cases/unit/4 build on all/foo.c +++ /dev/null @@ -1,6 +0,0 @@ -#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 deleted file mode 100644 index 5a746a5..0000000 --- a/test cases/unit/4 build on all/meson.build +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 5a74153..0000000 --- a/test cases/unit/4 build on all/mygen.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/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 deleted file mode 100644 index 3573f4b..0000000 --- a/test cases/unit/4 build on all/source.txt +++ /dev/null @@ -1 +0,0 @@ -I am a bunch of text. 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 + +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. -- cgit v1.1