Skip to content

Commit 5aef13b

Browse files
Martin Belangerigaw
authored andcommitted
libnvme: add accessor code generation
This adds a code generator that parses struct definitions and generates accessor functions (setters/getters). Signed-off-by: Martin Belanger <[email protected]>
1 parent 920ae83 commit 5aef13b

File tree

18 files changed

+2414
-124
lines changed

18 files changed

+2414
-124
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ tests/nvmetests
1717
tests/*.pyc
1818

1919
.build
20+
.build-ci
2021
.cache

ccan/meson.build

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ sources = [
1212
]
1313

1414
if get_option('buildtype') == 'debug'
15-
add_project_arguments('-DCCAN_LIST_DEBUG=1', language : ['c'])
16-
add_project_arguments('-DCCAN_STR_DEBUG=1', language : ['c'])
15+
add_project_arguments('-DCCAN_LIST_DEBUG=1', language: ['c'])
16+
add_project_arguments('-DCCAN_STR_DEBUG=1', language: ['c'])
1717
endif
1818

1919
libccan = static_library(
2020
'ccan',
2121
sources,
2222
install: false,
23-
include_directories: [incdir, ],
2423
dependencies: [config_dep, ],
2524
)
25+
26+
ccan_dep = declare_dependency(
27+
include_directories: '.',
28+
link_with: libccan,
29+
)

libnvme/examples/meson.build

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,83 @@
88
executable(
99
'telemetry-listen',
1010
['telemetry-listen.c'],
11-
dependencies: [libnvme_dep, config_dep],
12-
include_directories: [incdir, ]
11+
dependencies: [
12+
config_dep,
13+
ccan_dep,
14+
libnvme_dep,
15+
],
1316
)
1417

1518
executable(
1619
'display-columnar',
1720
['display-columnar.c'],
18-
dependencies: [libnvme_dep, config_dep],
19-
include_directories: [incdir, ]
21+
dependencies: [
22+
config_dep,
23+
ccan_dep,
24+
libnvme_dep,
25+
],
2026
)
2127

2228
executable(
2329
'display-tree',
2430
['display-tree.c'],
25-
dependencies: [libnvme_dep, config_dep],
26-
include_directories: [incdir, ]
31+
dependencies: [
32+
config_dep,
33+
ccan_dep,
34+
libnvme_dep,
35+
],
2736
)
2837

2938
executable(
3039
'discover-loop',
3140
['discover-loop.c'],
32-
dependencies: [libnvme_dep, config_dep],
33-
include_directories: [incdir, ]
41+
dependencies: [
42+
config_dep,
43+
ccan_dep,
44+
libnvme_dep,
45+
],
3446
)
3547

3648
executable(
3749
'mi-mctp',
3850
['mi-mctp.c'],
39-
dependencies: [libnvme_dep, config_dep],
40-
include_directories: [incdir, ]
51+
dependencies: [
52+
config_dep,
53+
ccan_dep,
54+
libnvme_dep,
55+
],
4156
)
4257

4358
executable(
4459
'mi-mctp-csi-test',
4560
['mi-mctp-csi-test.c'],
46-
dependencies: [libnvme_dep, config_dep, threads_dep],
47-
include_directories: [incdir, ]
61+
dependencies: [
62+
config_dep,
63+
ccan_dep,
64+
libnvme_dep,
65+
threads_dep,
66+
],
4867
)
4968

5069
executable(
5170
'mi-mctp-ae',
5271
['mi-mctp-ae.c'],
53-
dependencies: [libnvme_dep, config_dep],
54-
include_directories: [incdir, ]
72+
dependencies: [
73+
config_dep,
74+
ccan_dep,
75+
libnvme_dep,
76+
],
5577
)
5678

5779
if libdbus_dep.found()
5880
executable(
5981
'mi-conf',
6082
['mi-conf.c'],
61-
dependencies: [libnvme_dep, config_dep, libdbus_dep],
62-
include_directories: [incdir, ]
83+
dependencies: [
84+
config_dep,
85+
ccan_dep,
86+
libnvme_dep,
87+
libdbus_dep,
88+
],
6389
)
6490
endif

libnvme/libnvme/meson.build

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,10 @@ if want_python
2525
nvme_py = pymod_swig[0]
2626
nvme_wrap_c = pymod_swig[1]
2727

28-
if meson.version().version_compare('>=1.4.0')
29-
nvme_py_path = nvme_py.full_path()
30-
else
31-
nvme_py_path = meson.current_build_dir() / 'nvme.py'
32-
endif
33-
3428
pynvme_clib = python3.extension_module(
3529
'_nvme',
3630
nvme_wrap_c,
37-
dependencies : [libnvme_dep, py3_dep, config_dep],
38-
include_directories: [incdir, ],
39-
link_with: [libccan],
31+
dependencies: [config_dep, ccan_dep, libnvme_dep, py3_dep],
4032
install: true,
4133
subdir: 'libnvme',
4234
)
@@ -47,6 +39,11 @@ if want_python
4739
# python nvme.py module using this dependency. This basically sets the
4840
# variable "nvme_py_path" to the full path of the nvme.py file that
4941
# was built by SWIG above.
42+
if meson.version().version_compare('>=1.4.0')
43+
nvme_py_path = nvme_py.full_path()
44+
else
45+
nvme_py_path = meson.current_build_dir() / 'nvme.py'
46+
endif
5047
python3_libnvme_dep = declare_dependency(
5148
sources: nvme_py,
5249
variables: {

libnvme/meson.build

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Authors: Martin Belanger <[email protected]>
77
#
88
if want_libnvme
9-
if openssl_dep.found() and meson.can_run_host_binaries()
9+
if openssl_dep.found() and meson.can_run_host_binaries()
1010
if openssl_dep.type_name() != 'internal'
1111
# Check for a bug in the EVP_PKEY_CTX_add1_hkdf_info implementation
1212
res = cc.run(
@@ -22,14 +22,14 @@ if openssl_dep.found() and meson.can_run_host_binaries()
2222
endif
2323
endif
2424

25-
################################################################################
25+
############################################################################
2626
configure_file(
2727
input: 'libnvme.spec.in',
2828
output: 'libnvme.spec',
2929
configuration: substs,
3030
)
3131

32-
################################################################################
32+
############################################################################
3333
subdir('src') # declares: libnvme_dep
3434
subdir('libnvme')
3535
if get_option('tests')
@@ -40,6 +40,23 @@ if openssl_dep.found() and meson.can_run_host_binaries()
4040
endif
4141
subdir('doc')
4242
else
43-
libnvme_dep = dependency('libnvme', required: want_nvme)
43+
# Fallback to using a pre-installed libnvme (if available)
44+
if std_prefix
45+
# When prefix points to a standard location, meson can use
46+
# standard methods (e.g. pkg-config) to find the library.
47+
libnvme_dep = dependency(
48+
'libnvme',
49+
version: '>=@0@'.format(libnvme_so_version),
50+
required: want_nvme,
51+
)
52+
else
53+
# When prefix points to a non-standard location
54+
# let's ask the C compiler to find the library for us.
55+
libnvme_dep = cc.find_library(
56+
'nvme',
57+
dirs: prefixdir / get_option('libdir'),
58+
required: want_nvme,
59+
)
60+
endif
4461
endif
4562

libnvme/src/meson.build

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,39 @@ else
2727
sources += 'nvme/no-json.c'
2828
endif
2929

30+
# Generate accessors (setter/getter functions)
31+
subdir('nvme') # declares: accessors_dep, accessors_ld_full_path
32+
3033
deps = [
3134
config_dep,
35+
ccan_dep,
3236
json_c_dep,
3337
keyutils_dep,
3438
libdbus_dep,
3539
liburing_dep,
3640
openssl_dep,
41+
accessors_dep,
3742
]
3843

39-
source_dir = meson.current_source_dir()
4044
mapfile = 'libnvme.map'
41-
version_script_arg = join_paths(source_dir, mapfile)
4245

4346
libnvme = library(
4447
'nvme', # produces libnvme.so
4548
sources,
4649
version: libnvme_so_version,
47-
link_args: ['-Wl,--version-script=' + version_script_arg],
50+
link_args: [
51+
'-Wl,--version-script=@0@'.format(meson.current_source_dir() / mapfile),
52+
'-Wl,--version-script=@0@'.format(accessors_ld_full_path),
53+
],
4854
dependencies: deps,
49-
link_depends: mapfile,
50-
include_directories: [incdir, ],
5155
install: true,
52-
link_with: libccan,
5356
)
5457

5558
pkg = import('pkgconfig')
5659
pkg.generate(libnvme,
5760
filebase: 'libnvme',
5861
name: 'libnvme',
59-
version: meson.project_version(),
62+
version: libnvme_so_version,
6063
description: 'Manage "libnvme" subsystem devices (Non-volatile Memory Express)',
6164
url: 'https://github.com/linux-nvme/nvme-cli/',
6265
)
@@ -66,6 +69,7 @@ libnvme_dep = declare_dependency(
6669
json_c_dep.partial_dependency(compile_args: true, includes: true),
6770
],
6871
link_with: libnvme,
72+
include_directories: '.',
6973
)
7074

7175
# test library with all symbols visible, to use for MI unit tests. Should
@@ -74,13 +78,12 @@ libnvme_test = library(
7478
'nvme-test', # produces libnvme-test.so
7579
sources,
7680
dependencies: deps,
77-
include_directories: [incdir, ],
7881
install: false,
79-
link_with: libccan,
8082
)
8183

8284
libnvme_test_dep = declare_dependency(
8385
link_with: libnvme_test,
86+
include_directories: '.',
8487
)
8588

8689
mode = 'rw-r--r--'

0 commit comments

Comments
 (0)