aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2021-06-12 21:39:59 +0200
committerDylan Baker <dylan@pnwbakers.com>2021-06-14 09:36:28 -0700
commitbc6df45663564b0be1faead61a07f224da1b387f (patch)
tree220006b1e0cf3d1a794ea2a28c1ce1d7e9183920
parentfc93c07e9ed47d2701ebe99e2e45f1d878b42078 (diff)
downloadmeson-bc6df45663564b0be1faead61a07f224da1b387f.zip
meson-bc6df45663564b0be1faead61a07f224da1b387f.tar.gz
meson-bc6df45663564b0be1faead61a07f224da1b387f.tar.bz2
Fix issue with generated Cython code in a subdir
This is a follow-up to gh-8706, which contained the initial fix to ninjabackend.py but somehow lost it. This re-applies the fix and adds a test for it. Without the fix, the error is: ninja: error: 'ct2.pyx', needed by 'libdir/ct2.cpython-39-x86_64-linux-gnu.so.p/ct2.pyx.c', missing and no known rule to make it
-rw-r--r--mesonbuild/backend/ninjabackend.py2
-rw-r--r--test cases/cython/2 generated sources/libdir/gen.py14
-rw-r--r--test cases/cython/2 generated sources/libdir/meson.build10
-rw-r--r--test cases/cython/2 generated sources/meson.build9
4 files changed, 35 insertions, 0 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index db50f6a..688149b 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1583,6 +1583,8 @@ int dummy;
for ssrc in gen.get_outputs():
if isinstance(gen, GeneratedList):
ssrc = os.path.join(self.get_target_private_dir(target) , ssrc)
+ else:
+ ssrc = os.path.join(gen.get_subdir(), ssrc)
if ssrc.endswith('.pyx'):
args = args.copy()
output = os.path.join(self.get_target_private_dir(target), f'{ssrc}.c')
diff --git a/test cases/cython/2 generated sources/libdir/gen.py b/test cases/cython/2 generated sources/libdir/gen.py
new file mode 100644
index 0000000..5c0a82d
--- /dev/null
+++ b/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/test cases/cython/2 generated sources/libdir/meson.build b/test cases/cython/2 generated sources/libdir/meson.build
new file mode 100644
index 0000000..e9259bd
--- /dev/null
+++ b/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/test cases/cython/2 generated sources/meson.build b/test cases/cython/2 generated sources/meson.build
index c9a9b6a..89dacfa 100644
--- a/test cases/cython/2 generated sources/meson.build
+++ b/test cases/cython/2 generated sources/meson.build
@@ -59,3 +59,12 @@ test(
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]
+)