aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/cython/2 generated sources
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/cython/2 generated sources')
-rw-r--r--meson/test cases/cython/2 generated sources/configure.pyx.in2
-rw-r--r--meson/test cases/cython/2 generated sources/g.in2
-rw-r--r--meson/test cases/cython/2 generated sources/gen.py14
-rwxr-xr-xmeson/test cases/cython/2 generated sources/generator.py12
-rw-r--r--meson/test cases/cython/2 generated sources/libdir/gen.py14
-rw-r--r--meson/test cases/cython/2 generated sources/libdir/meson.build10
-rw-r--r--meson/test cases/cython/2 generated sources/meson.build80
-rw-r--r--meson/test cases/cython/2 generated sources/test.py13
8 files changed, 147 insertions, 0 deletions
diff --git a/meson/test cases/cython/2 generated sources/configure.pyx.in b/meson/test cases/cython/2 generated sources/configure.pyx.in
new file mode 100644
index 000000000..1c44f6d42
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/configure.pyx.in
@@ -0,0 +1,2 @@
+cpdef func():
+ return "Hello, World!"
diff --git a/meson/test cases/cython/2 generated sources/g.in b/meson/test cases/cython/2 generated sources/g.in
new file mode 100644
index 000000000..1c44f6d42
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/g.in
@@ -0,0 +1,2 @@
+cpdef func():
+ return "Hello, World!"
diff --git a/meson/test cases/cython/2 generated sources/gen.py b/meson/test cases/cython/2 generated sources/gen.py
new file mode 100644
index 000000000..5c0a82d56
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/gen.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import textwrap
+
+parser = argparse.ArgumentParser()
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.output, 'w') as f:
+ f.write(textwrap.dedent('''\
+ cpdef func():
+ return "Hello, World!"
+ '''))
diff --git a/meson/test cases/cython/2 generated sources/generator.py b/meson/test cases/cython/2 generated sources/generator.py
new file mode 100755
index 000000000..77de85569
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/generator.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument('input')
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.input, 'r') as i, open(args.output, 'w') as o:
+ o.write(i.read())
diff --git a/meson/test cases/cython/2 generated sources/libdir/gen.py b/meson/test cases/cython/2 generated sources/libdir/gen.py
new file mode 100644
index 000000000..5c0a82d56
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/libdir/gen.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import textwrap
+
+parser = argparse.ArgumentParser()
+parser.add_argument('output')
+args = parser.parse_args()
+
+with open(args.output, 'w') as f:
+ f.write(textwrap.dedent('''\
+ cpdef func():
+ return "Hello, World!"
+ '''))
diff --git a/meson/test cases/cython/2 generated sources/libdir/meson.build b/meson/test cases/cython/2 generated sources/libdir/meson.build
new file mode 100644
index 000000000..e9259bdad
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/libdir/meson.build
@@ -0,0 +1,10 @@
+ct2 = custom_target(
+ 'ct2',
+ input : 'gen.py',
+ output : 'ct2.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+ct2_ext = py3.extension_module('ct2', ct2, dependencies : py3_dep)
+
+pydir = meson.current_build_dir()
diff --git a/meson/test cases/cython/2 generated sources/meson.build b/meson/test cases/cython/2 generated sources/meson.build
new file mode 100644
index 000000000..cfe62602d
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/meson.build
@@ -0,0 +1,80 @@
+project(
+ 'generated cython sources',
+ ['cython'],
+)
+
+py_mod = import('python')
+py3 = py_mod.find_installation('python3')
+py3_dep = py3.dependency(required : false)
+if not py3_dep.found()
+ error('MESON_SKIP_TEST: Python library not found.')
+endif
+
+ct = custom_target(
+ 'ct',
+ input : 'gen.py',
+ output : 'ct.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+ct_ext = py3.extension_module('ct', ct, dependencies : py3_dep)
+
+test(
+ 'custom target',
+ py3,
+ args : [files('test.py'), 'ct'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+# Test a CustomTargetIndex
+cti = custom_target(
+ 'cti',
+ input : 'gen.py',
+ output : 'cti.pyx',
+ command : [py3, '@INPUT@', '@OUTPUT@'],
+)
+
+cti_ext = py3.extension_module('cti', cti[0], dependencies : py3_dep)
+
+cf = configure_file(
+ input : 'configure.pyx.in',
+ output : 'cf.pyx',
+ copy : true,
+)
+
+cf_ext = py3.extension_module('cf', cf, dependencies : py3_dep)
+
+test(
+ 'configure file',
+ py3,
+ args : [files('test.py'), 'cf'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+gen = generator(
+ find_program('generator.py'),
+ arguments : ['@INPUT@', '@OUTPUT@'],
+ output : '@BASENAME@.pyx',
+)
+
+g_ext = py3.extension_module(
+ 'g',
+ gen.process('g.in'),
+ dependencies : py3_dep,
+)
+
+test(
+ 'generator',
+ py3,
+ args : [files('test.py'), 'g'],
+ env : ['PYTHONPATH=' + meson.current_build_dir()]
+)
+
+subdir('libdir')
+
+test(
+ 'custom target in subdir',
+ py3,
+ args : [files('test.py'), 'ct2'],
+ env : ['PYTHONPATH=' + pydir]
+)
diff --git a/meson/test cases/cython/2 generated sources/test.py b/meson/test cases/cython/2 generated sources/test.py
new file mode 100644
index 000000000..307283f26
--- /dev/null
+++ b/meson/test cases/cython/2 generated sources/test.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: Apache-2.0
+
+import argparse
+import importlib
+
+parser = argparse.ArgumentParser()
+parser.add_argument('mod')
+args = parser.parse_args()
+
+mod = importlib.import_module(args.mod)
+
+assert mod.func() == 'Hello, World!'