Merge pull request #1303 from mesonbuild/buildonall

Add kwarg build_by_default
pull/1297/head
Jussi Pakkanen 8 years ago committed by GitHub
commit cfc33ac421
  1. 16
      mesonbuild/backend/ninjabackend.py
  2. 55
      mesonbuild/build.py
  3. 11
      run_unittests.py
  4. 6
      test cases/unit/5 build by default/foo.c
  5. 13
      test cases/unit/5 build by default/meson.build
  6. 8
      test cases/unit/5 build by default/mygen.py
  7. 1
      test cases/unit/5 build by default/source.txt

@ -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]))

@ -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

@ -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):

@ -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_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,
)

@ -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