aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/49 custom target
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/common/49 custom target')
-rw-r--r--meson/test cases/common/49 custom target/data_source.txt1
-rwxr-xr-xmeson/test cases/common/49 custom target/depfile/dep.py15
-rw-r--r--meson/test cases/common/49 custom target/depfile/meson.build7
-rw-r--r--meson/test cases/common/49 custom target/meson.build67
-rwxr-xr-xmeson/test cases/common/49 custom target/my_compiler.py22
-rw-r--r--meson/test cases/common/49 custom target/test.json5
6 files changed, 117 insertions, 0 deletions
diff --git a/meson/test cases/common/49 custom target/data_source.txt b/meson/test cases/common/49 custom target/data_source.txt
new file mode 100644
index 000000000..0c23cc0c3
--- /dev/null
+++ b/meson/test cases/common/49 custom target/data_source.txt
@@ -0,0 +1 @@
+This is a text only input file.
diff --git a/meson/test cases/common/49 custom target/depfile/dep.py b/meson/test cases/common/49 custom target/depfile/dep.py
new file mode 100755
index 000000000..c9e8f94dc
--- /dev/null
+++ b/meson/test cases/common/49 custom target/depfile/dep.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import sys, os
+from glob import glob
+
+_, srcdir, depfile, output = sys.argv
+
+depfiles = glob(os.path.join(srcdir, '*'))
+
+quoted_depfiles = [x.replace(' ', r'\ ') for x in depfiles]
+
+with open(output, 'w') as f:
+ f.write('I am the result of globbing.')
+with open(depfile, 'w') as f:
+ f.write('{}: {}\n'.format(output, ' '.join(quoted_depfiles)))
diff --git a/meson/test cases/common/49 custom target/depfile/meson.build b/meson/test cases/common/49 custom target/depfile/meson.build
new file mode 100644
index 000000000..46bca7405
--- /dev/null
+++ b/meson/test cases/common/49 custom target/depfile/meson.build
@@ -0,0 +1,7 @@
+
+
+mytarget = custom_target('depfile',
+ output : 'dep.dat',
+ depfile : 'dep.dat.d',
+ command : [find_program('dep.py'), meson.current_source_dir(), '@DEPFILE@', '@OUTPUT@'],
+)
diff --git a/meson/test cases/common/49 custom target/meson.build b/meson/test cases/common/49 custom target/meson.build
new file mode 100644
index 000000000..52e8630dc
--- /dev/null
+++ b/meson/test cases/common/49 custom target/meson.build
@@ -0,0 +1,67 @@
+project('custom target', 'c')
+
+python = find_program('python3', required : false)
+if not python.found()
+ python = find_program('python')
+endif
+
+# Note that this will not add a dependency to the compiler executable.
+# Code will not be rebuilt if it changes.
+comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py')
+# Test that files() in command: works. The compiler just discards it.
+useless = files('test.json')
+
+mytarget = custom_target('bindat',
+output : 'data.dat',
+input : 'data_source.txt',
+command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@', useless],
+env: {'MY_COMPILER_ENV': 'value'},
+install : true,
+install_dir : 'subdir'
+)
+
+has_not_changed = false
+if is_disabler(mytarget)
+ has_not_changed = true
+else
+ has_not_changed = true
+endif
+assert(has_not_changed, 'Custom target has changed.')
+
+assert(not is_disabler(mytarget), 'Custom target is a disabler.')
+
+mytarget_disabler = custom_target('bindat',
+output : 'data.dat',
+input : 'data_source.txt',
+command : [disabler(), comp, '--input=@INPUT@', '--output=@OUTPUT@', useless],
+install : true,
+install_dir : 'subdir'
+)
+
+if mytarget_disabler.found()
+ mytarget_disabled = false
+else
+ mytarget_disabled = true
+endif
+
+assert(mytarget_disabled, 'Disabled custom target should not be found.')
+
+mytarget_disabler = custom_target('bindat',
+output : 'data.dat',
+input : disabler(),
+command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@', useless],
+install : true,
+install_dir : 'subdir'
+)
+
+assert(is_disabler(mytarget_disabler), 'Disabled custom target is not a disabler.')
+
+if mytarget_disabler.found()
+ mytarget_disabled = false
+else
+ mytarget_disabled = true
+endif
+
+assert(mytarget_disabled, 'Disabled custom target should not be found.')
+
+subdir('depfile')
diff --git a/meson/test cases/common/49 custom target/my_compiler.py b/meson/test cases/common/49 custom target/my_compiler.py
new file mode 100755
index 000000000..986911124
--- /dev/null
+++ b/meson/test cases/common/49 custom target/my_compiler.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+
+assert(os.path.exists(sys.argv[3]))
+
+args = sys.argv[:-1]
+
+if __name__ == '__main__':
+ assert os.environ['MY_COMPILER_ENV'] == 'value'
+ if len(args) != 3 or not args[1].startswith('--input') or \
+ not args[2].startswith('--output'):
+ print(args[0], '--input=input_file --output=output_file')
+ sys.exit(1)
+ with open(args[1].split('=')[1]) as f:
+ ifile = f.read()
+ if ifile != 'This is a text only input file.\n':
+ print('Malformed input')
+ sys.exit(1)
+ with open(args[2].split('=')[1], 'w') as ofile:
+ ofile.write('This is a binary output file.\n')
diff --git a/meson/test cases/common/49 custom target/test.json b/meson/test cases/common/49 custom target/test.json
new file mode 100644
index 000000000..ba66b024a
--- /dev/null
+++ b/meson/test cases/common/49 custom target/test.json
@@ -0,0 +1,5 @@
+{
+ "installed": [
+ {"type": "file", "file": "usr/subdir/data.dat"}
+ ]
+}