aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-05-21 23:47:23 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-05-21 23:47:23 +0300
commitee0607ddf92b0d4e3cf9a075db6c2e2f4439400e (patch)
tree5776d8b7c254c7b78c5d0e556ee2f6720e2c3b84
parent2ecd2ea65a3c3a81e83d298ed815984b4107b9da (diff)
downloadmeson-ee0607ddf92b0d4e3cf9a075db6c2e2f4439400e.zip
meson-ee0607ddf92b0d4e3cf9a075db6c2e2f4439400e.tar.gz
meson-ee0607ddf92b0d4e3cf9a075db6c2e2f4439400e.tar.bz2
Can use outputs of targets as inputs of custom targets.
-rw-r--r--build.py12
-rw-r--r--ninjabackend.py3
-rw-r--r--test cases/common/57 custom target chain/data_source.txt1
-rw-r--r--test cases/common/57 custom target chain/installed_files.txt1
-rw-r--r--test cases/common/57 custom target chain/meson.build21
-rwxr-xr-xtest cases/common/57 custom target chain/my_compiler.py14
-rwxr-xr-xtest cases/common/57 custom target chain/my_compiler2.py14
7 files changed, 62 insertions, 4 deletions
diff --git a/build.py b/build.py
index 8640e8b..fef3e53 100644
--- a/build.py
+++ b/build.py
@@ -203,7 +203,7 @@ class BuildTarget():
for i in self.link_targets:
result += i.get_rpaths()
return result
-
+
def get_custom_install_dir(self):
return self.custom_install_dir
@@ -567,6 +567,7 @@ class CustomTarget:
def __init__(self, name, subdir, kwargs):
self.name = name
self.subdir = subdir
+ self.dependencies = []
self.process_kwargs(kwargs)
def process_kwargs(self, kwargs):
@@ -586,10 +587,15 @@ class CustomTarget:
for i, c in enumerate(cmd):
if hasattr(c, 'ep'):
c = c.ep
+ if hasattr(c, 'held_object'):
+ c = c.held_object
if isinstance(c, str):
final_cmd.append(c)
elif isinstance(c, dependencies.ExternalProgram):
final_cmd.append(c.get_command())
+ elif isinstance(c, BuildTarget) or isinstance(c, CustomTarget):
+ self.dependencies.append(c)
+ final_cmd.append(os.path.join(c.get_subdir(), c.get_filename()))
else:
raise InvalidArguments('Argument %s in "command" is invalid.' % i)
self.command = final_cmd
@@ -609,14 +615,14 @@ class CustomTarget:
return self.name
def get_dependencies(self):
- return []
+ return self.dependencies
def should_install(self):
return self.install
def get_custom_install_dir(self):
return self.install_dir
-
+
def get_subdir(self):
return self.subdir
diff --git a/ninjabackend.py b/ninjabackend.py
index ff491b7..45e19dd 100644
--- a/ninjabackend.py
+++ b/ninjabackend.py
@@ -136,7 +136,8 @@ class NinjaBackend(backends.Backend):
def generate_custom_target(self, target, outfile):
ofilename = os.path.join(target.subdir, target.output)
- elem = NinjaBuildElement(ofilename, 'CUSTOM_COMMAND', '')
+ deps = [os.path.join(i.get_subdir(), i.get_filename()) for i in target.get_dependencies()]
+ elem = NinjaBuildElement(ofilename, 'CUSTOM_COMMAND', deps)
elem.add_item('COMMAND', target.command)
elem.write(outfile)
self.processed_targets[target.name] = True
diff --git a/test cases/common/57 custom target chain/data_source.txt b/test cases/common/57 custom target chain/data_source.txt
new file mode 100644
index 0000000..0c23cc0
--- /dev/null
+++ b/test cases/common/57 custom target chain/data_source.txt
@@ -0,0 +1 @@
+This is a text only input file.
diff --git a/test cases/common/57 custom target chain/installed_files.txt b/test cases/common/57 custom target chain/installed_files.txt
new file mode 100644
index 0000000..c5f8bd7
--- /dev/null
+++ b/test cases/common/57 custom target chain/installed_files.txt
@@ -0,0 +1 @@
+subdir/data2.dat
diff --git a/test cases/common/57 custom target chain/meson.build b/test cases/common/57 custom target chain/meson.build
new file mode 100644
index 0000000..7bfcddb
--- /dev/null
+++ b/test cases/common/57 custom target chain/meson.build
@@ -0,0 +1,21 @@
+project('custom target', 'c')
+
+python = find_program('python3')
+
+comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py')
+comp2 = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler2.py')
+infile = '@0@/@1@'.format(meson.current_source_dir(), 'data_source.txt')
+outfile = '@0@/@1@'.format(meson.current_build_dir(), 'data.dat')
+outfile2 = '@0@/@1@'.format(meson.current_build_dir(), 'data2.dat')
+
+mytarget = custom_target('bindat',
+output : 'data.dat',
+command : [python, comp, infile, outfile],
+)
+
+mytarget2 = custom_target('bindat2',
+output : 'data2.dat',
+command : [python, comp2, mytarget, outfile2],
+install : true,
+install_dir : 'subdir'
+)
diff --git a/test cases/common/57 custom target chain/my_compiler.py b/test cases/common/57 custom target chain/my_compiler.py
new file mode 100755
index 0000000..3165cf8
--- /dev/null
+++ b/test cases/common/57 custom target chain/my_compiler.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python3
+
+import sys
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print(sys.argv[0], 'input_file output_file')
+ sys.exit(1)
+ ifile = open(sys.argv[1]).read()
+ if ifile != 'This is a text only input file.\n':
+ print('Malformed input')
+ sys.exit(1)
+ ofile = open(sys.argv[2], 'w')
+ ofile.write('This is a binary output file.\n')
diff --git a/test cases/common/57 custom target chain/my_compiler2.py b/test cases/common/57 custom target chain/my_compiler2.py
new file mode 100755
index 0000000..8c767b1
--- /dev/null
+++ b/test cases/common/57 custom target chain/my_compiler2.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python3
+
+import sys
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print(sys.argv[0], 'input_file output_file')
+ sys.exit(1)
+ ifile = open(sys.argv[1]).read()
+ if ifile != 'This is a binary output file.\n':
+ print('Malformed input')
+ sys.exit(1)
+ ofile = open(sys.argv[2], 'w')
+ ofile.write('This is a different binary output file.\n')