Skip to content

Commit 497c018

Browse files
committed
TST: rework the sharedlib-in-package test package
This reorganizes the test package to a flatter layout that helps visualizing all the parts involved in the test and introduces an asymmetry between the source layout and the installation layout that demonstrates the bugs in the RPATH handling.
1 parent 2706ec4 commit 497c018

File tree

13 files changed

+91
-76
lines changed

13 files changed

+91
-76
lines changed

tests/packages/sharedlib-in-package/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ project('sharedlib-in-package', 'c', version: '1.0.0')
66

77
py = import('python').find_installation(pure: false)
88

9+
subdir('src')
910
subdir('mypkg')

tests/packages/sharedlib-in-package/mypkg/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _append_to_sharedlib_load_path():
4545
# end-literalinclude
4646

4747

48-
from ._example import example_prod, example_sum #noqa: E402
48+
from ._example import prodsum # noqa: E402
4949

5050

51-
__all__ = ['example_prod', 'example_sum']
51+
__all__ = ['prodsum']

tests/packages/sharedlib-in-package/mypkg/_examplemod.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,23 @@
44

55
#include <Python.h>
66

7-
#include "examplelib.h"
8-
#include "examplelib2.h"
7+
#include "lib.h"
98

10-
static PyObject* example_sum(PyObject* self, PyObject *args)
9+
static PyObject* example_prodsum(PyObject* self, PyObject *args)
1110
{
12-
int a, b;
13-
if (!PyArg_ParseTuple(args, "ii", &a, &b)) {
14-
return NULL;
15-
}
11+
int a, b, x;
1612

17-
long result = sum(a, b);
18-
19-
return PyLong_FromLong(result);
20-
}
21-
22-
static PyObject* example_prod(PyObject* self, PyObject *args)
23-
{
24-
int a, b;
25-
if (!PyArg_ParseTuple(args, "ii", &a, &b)) {
13+
if (!PyArg_ParseTuple(args, "iii", &a, &b, &x)) {
2614
return NULL;
2715
}
2816

29-
long result = prod(a, b);
17+
long result = prodsum(a, b, x);
3018

3119
return PyLong_FromLong(result);
3220
}
3321

3422
static PyMethodDef methods[] = {
35-
{"example_prod", (PyCFunction)example_prod, METH_VARARGS, NULL},
36-
{"example_sum", (PyCFunction)example_sum, METH_VARARGS, NULL},
23+
{"prodsum", (PyCFunction)example_prodsum, METH_VARARGS, NULL},
3724
{NULL, NULL, 0, NULL},
3825
};
3926

tests/packages/sharedlib-in-package/mypkg/examplelib.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/packages/sharedlib-in-package/mypkg/examplelib.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/packages/sharedlib-in-package/mypkg/meson.build

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,10 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
if meson.get_compiler('c').get_id() in ['msvc', 'clang-cl', 'intel-cl']
6-
export_dll_args = ['-DMYPKG_DLL_EXPORTS']
7-
import_dll_args = ['-DMYPKG_DLL_IMPORTS']
8-
else
9-
export_dll_args = []
10-
import_dll_args = []
11-
endif
12-
13-
example_lib = shared_library(
14-
'examplelib',
15-
'examplelib.c',
16-
c_args: export_dll_args,
17-
install: true,
18-
install_dir: py.get_install_dir() / 'mypkg',
19-
)
20-
21-
example_lib_dep = declare_dependency(
22-
compile_args: import_dll_args,
23-
link_with: example_lib,
24-
)
25-
26-
subdir('sub')
27-
285
py.extension_module(
296
'_example',
307
'_examplemod.c',
31-
dependencies: [example_lib_dep, example_lib2_dep],
32-
include_directories: 'sub',
8+
dependencies: lib_dep,
339
install: true,
3410
subdir: 'mypkg',
3511
install_rpath: '$ORIGIN',

tests/packages/sharedlib-in-package/mypkg/sub/examplelib2.h

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: 2022 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include "lib.h"
6+
#include "sublib.h"
7+
8+
int prodsum(int a, int b, int x) {
9+
return prod(a, x) + b;
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-FileCopyrightText: 2022 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#if defined(MYPKG_DLL_EXPORTS)
6+
#define EXPORT __declspec(dllexport)
7+
#elif defined(MYPKG_DLL_IMPORTS)
8+
#define EXPORT __declspec(dllimport)
9+
#else
10+
#define EXPORT
11+
#endif
12+
13+
EXPORT int prodsum(int a, int b, int x);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: 2022 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
if meson.get_compiler('c').get_id() in ['msvc', 'clang-cl', 'intel-cl']
6+
export_dll_args = ['-DMYPKG_DLL_EXPORTS']
7+
import_dll_args = ['-DMYPKG_DLL_IMPORTS']
8+
else
9+
export_dll_args = []
10+
import_dll_args = []
11+
endif
12+
13+
sublib = shared_library(
14+
'sublib',
15+
'sublib.c',
16+
c_args: export_dll_args,
17+
install: true,
18+
install_dir: py.get_install_dir() / 'mypkg/sub',
19+
)
20+
21+
sublib_dep = declare_dependency(
22+
compile_args: import_dll_args,
23+
link_with: sublib,
24+
)
25+
26+
lib = shared_library(
27+
'lib',
28+
'lib.c',
29+
dependencies: sublib_dep,
30+
c_args: export_dll_args,
31+
install: true,
32+
install_dir: py.get_install_dir() / 'mypkg',
33+
install_rpath: '$ORIGIN/sub',
34+
)
35+
36+
lib_dep = declare_dependency(
37+
compile_args: import_dll_args,
38+
link_with: lib,
39+
include_directories: include_directories('.'),
40+
)

0 commit comments

Comments
 (0)