aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-04-02 16:43:35 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-04-02 16:43:35 +0300
commite87d3c07ad3943ccd7a17f01ff900136c8a394c6 (patch)
tree420377eef30264658c5b43b26cd7be7fa76efc6a
parenta3544847ca1414a23d7afe2a77848ea777bba1b0 (diff)
downloadmeson-e87d3c07ad3943ccd7a17f01ff900136c8a394c6.zip
meson-e87d3c07ad3943ccd7a17f01ff900136c8a394c6.tar.gz
meson-e87d3c07ad3943ccd7a17f01ff900136c8a394c6.tar.bz2
Can specify explicit dependencies for custom targets.
-rw-r--r--build.py14
-rw-r--r--ninjabackend.py6
-rwxr-xr-xtest cases/common/78 ctarget dependency/gen1.py10
-rwxr-xr-xtest cases/common/78 ctarget dependency/gen2.py9
-rw-r--r--test cases/common/78 ctarget dependency/input.dat1
-rw-r--r--test cases/common/78 ctarget dependency/meson.build20
6 files changed, 59 insertions, 1 deletions
diff --git a/build.py b/build.py
index 8efb356..dae1270 100644
--- a/build.py
+++ b/build.py
@@ -668,11 +668,14 @@ class CustomTarget:
'command' : True,
'install' : True,
'install_dir' : True,
- 'build_always' : True}
+ 'build_always' : True,
+ 'depends' : True}
+
def __init__(self, name, subdir, kwargs):
self.name = name
self.subdir = subdir
self.dependencies = []
+ self.extra_depends = []
self.process_kwargs(kwargs)
self.extra_files = []
self.install_rpath = ''
@@ -744,6 +747,15 @@ class CustomTarget:
self.build_always = kwargs.get('build_always', False)
if not isinstance(self.build_always, bool):
raise InvalidArguments('Argument build_always must be a boolean.')
+ extra_deps = kwargs.get('depends', [])
+ if not isinstance(extra_deps, list):
+ extra_deps = [extra_deps]
+ for ed in extra_deps:
+ while hasattr(ed, 'held_object'):
+ ed = ed.held_object
+ if not isinstance(ed, CustomTarget) and not isinstance(ed, BuildTarget):
+ raise InvalidArguments('Can only depend on toplevel targets.')
+ self.extra_depends.append(ed)
def get_basename(self):
return self.name
diff --git a/ninjabackend.py b/ninjabackend.py
index d467c07..741e72d 100644
--- a/ninjabackend.py
+++ b/ninjabackend.py
@@ -283,6 +283,12 @@ class NinjaBackend(backends.Backend):
if target.build_always:
deps.append('PHONY')
elem = NinjaBuildElement(ofilenames, 'CUSTOM_COMMAND', deps)
+ for d in target.extra_depends:
+ tmp = d.get_filename()
+ if not isinstance(tmp, list):
+ tmp = [tmp]
+ for fname in tmp:
+ elem.add_dep(os.path.join(d.get_subdir(), fname))
cmd = []
for i in target.command:
for (j, src) in enumerate(srcs):
diff --git a/test cases/common/78 ctarget dependency/gen1.py b/test cases/common/78 ctarget dependency/gen1.py
new file mode 100755
index 0000000..64b8e6d
--- /dev/null
+++ b/test cases/common/78 ctarget dependency/gen1.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+
+import time, sys
+
+# Make sure other script runs first if dependency
+# is missing.
+time.sleep(0.5)
+
+contents = open(sys.argv[1], 'r').read()
+open(sys.argv[2], 'w').write(contents)
diff --git a/test cases/common/78 ctarget dependency/gen2.py b/test cases/common/78 ctarget dependency/gen2.py
new file mode 100755
index 0000000..3f3595b
--- /dev/null
+++ b/test cases/common/78 ctarget dependency/gen2.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python3
+
+import sys
+from glob import glob
+
+files = glob('*.tmp')
+assert(len(files) == 1)
+
+open(sys.argv[1], 'w').write(open(files[0], 'r').read())
diff --git a/test cases/common/78 ctarget dependency/input.dat b/test cases/common/78 ctarget dependency/input.dat
new file mode 100644
index 0000000..7af91e2
--- /dev/null
+++ b/test cases/common/78 ctarget dependency/input.dat
@@ -0,0 +1 @@
+This is a piece of text.
diff --git a/test cases/common/78 ctarget dependency/meson.build b/test cases/common/78 ctarget dependency/meson.build
new file mode 100644
index 0000000..baed2da
--- /dev/null
+++ b/test cases/common/78 ctarget dependency/meson.build
@@ -0,0 +1,20 @@
+project('custom target dependency', 'c')
+
+# Sometimes custom targets do not take input files
+# but instead do globbing or some similar wackiness.
+# In this case we need to be able to specify a
+# manual dependency between two custom targets,
+# if one needs to be run before the other.
+
+g1 = find_program('gen1.py')
+g2 = find_program('gen2.py')
+
+c1 = custom_target('medput',
+input : 'input.dat',
+output : 'medput.tmp',
+command : [g1, '@INPUT@', '@OUTPUT@'])
+
+custom_target('output',
+output : 'output.dat',
+command : [g2, '@OUTPUT@'],
+depends : c1)