Skip to content

Commit 74d11e2

Browse files
Martin Belangerigaw
authored andcommitted
libnvme: move accessor generator to tools/generator/
The code generator (generate-accessors.c, update-accessors.sh, and supporting files) does not belong alongside the library source in src/nvme/. Move it to tools/generator/ to make clear it is developer tooling rather than library code. While at it: - Move accessors.ld from src/nvme/ to src/, alongside the other version scripts (libnvme.ld, libnvmf.ld). src/meson.build now picks it up directly via meson.current_source_dir(), so no cross-directory variable passing is needed. - Eliminate src/nvme/meson.build; its generator build rules move to tools/generator/meson.build. - Add a banner to the generated accessors.ld (SPDX, copyright, ASCII logo, and regeneration instructions) matching the banners already present in accessors.c and accessors.h. The generated files (accessors.c, accessors.h) remain in src/nvme/ where the compiler expects them. Signed-off-by: Martin Belanger <[email protected]>
1 parent 07e0fb1 commit 74d11e2

11 files changed

Lines changed: 58 additions & 24 deletions

libnvme/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ if want_libnvme
3030
)
3131

3232
############################################################################
33-
subdir('src') # declares: libnvme_dep
33+
libnvme_srcroot = meson.current_source_dir() # needed by tools/generator
34+
subdir('tools/generator') # generate code needed by src below
35+
subdir('src') # declares: libnvme_dep
3436
subdir('libnvme')
3537
if get_option('tests')
3638
subdir('test')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
3+
/**
4+
* This file is part of libnvme.
5+
*
6+
* Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries.
7+
* Authors: Martin Belanger <[email protected]>
8+
*
9+
*/
110

211
LIBNVME_ACCESSORS_3 {
312
global:

libnvme/src/meson.build

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ else
5656
sources += 'nvme/no-json.c'
5757
endif
5858

59-
subdir('nvme') # declares: accessors_ld_full_path
60-
6159
deps = [
6260
config_dep,
6361
ccan_dep,
@@ -70,10 +68,11 @@ deps = [
7068

7169
nvme_ld = meson.current_source_dir() / 'libnvme.ld'
7270
nvmf_ld = meson.current_source_dir() / 'libnvmf.ld'
71+
accessors_ld = meson.current_source_dir() / 'accessors.ld'
7372

7473
link_args = [
7574
'-Wl,--version-script=@0@'.format(nvme_ld),
76-
'-Wl,--version-script=@0@'.format(accessors_ld_full_path),
75+
'-Wl,--version-script=@0@'.format(accessors_ld),
7776
]
7877

7978
libconf = configuration_data()

libnvme/src/nvme/accessors.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___|
1414
*
1515
* Auto-generated struct member accessors (setter/getter)
16+
*
17+
* To update run: meson compile -C [BUILD-DIR] update-accessors
18+
* Or: make update-accessors
1619
*/
1720
#include <stdlib.h>
1821
#include <string.h>

libnvme/src/nvme/accessors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___|
1414
*
1515
* Auto-generated struct member accessors (setter/getter)
16+
*
17+
* To update run: meson compile -C [BUILD-DIR] update-accessors
18+
* Or: make update-accessors
1619
*/
1720
#ifndef _ACCESSORS_H_
1821
#define _ACCESSORS_H_
File renamed without changes.
File renamed without changes.

libnvme/src/nvme/generate-accessors.c renamed to libnvme/tools/generator/generate-accessors.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
/* checkpatch requires C99 // SPDX in *.c and block-style SPDX in *.h */
7171
static const char *spdx_c = "// SPDX-License-Identifier: LGPL-2.1-or-later";
7272
static const char *spdx_h = "/* SPDX-License-Identifier: LGPL-2.1-or-later */";
73+
static const char *spdx_ld = "# SPDX-License-Identifier: LGPL-2.1-or-later";
7374

7475
static const char *banner =
7576
"/**\n"
@@ -85,6 +86,9 @@ static const char *banner =
8586
" * \\____|\\___|_| |_|\\___|_| \\__,_|\\__\\___|\\__,_| \\____\\___/ \\__,_|\\___|\n"
8687
" *\n"
8788
" * Auto-generated struct member accessors (setter/getter)\n"
89+
" *\n"
90+
" * To update run: meson compile -C [BUILD-DIR] update-accessors\n"
91+
" * Or: make update-accessors\n"
8892
" */";
8993

9094
/**
@@ -2095,9 +2099,13 @@ int main(int argc, char *argv[])
20952099
mkdir_fullpath(conf.l_fname, 0755); /* create output folder if needed */
20962100
generated_ld = fopen(conf.l_fname, "w");
20972101
fprintf(generated_ld,
2102+
"%s\n"
2103+
"\n"
2104+
"%s\n"
20982105
"\n"
20992106
"LIBNVME_ACCESSORS_3 {\n"
2100-
" global:\n");
2107+
" global:\n",
2108+
spdx_ld, banner);
21012109

21022110
/* Copy temporary file to output */
21032111
append_file(generated_ld, tmp_ld_map);
File renamed without changes.
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# pre-generated and committed to the source tree. They are NOT
1010
# regenerated during a normal build.
1111
#
12-
# To regenerate them after changing private.h or structs-to-include.txt:
12+
# To regenerate them after changing private.h or the include/exclude lists:
1313
#
1414
# meson compile -C <build-dir> update-accessors
1515

@@ -19,12 +19,19 @@
1919
# Usage: meson compile -C <build-dir> update-accessors
2020
# ---------------------------------------------------------------------------
2121

22-
accessors_ld_full_path = meson.current_source_dir() / 'accessors.ld'
22+
# Generated source files go to src/nvme/ (alongside the library sources).
23+
# The generated version script goes to src/ (alongside the other .ld files).
24+
libnvme_src = libnvme_srcroot / 'src'
25+
libnvme_src_nvme = libnvme_src / 'nvme'
2326

2427
generate_accessors = executable(
2528
'generate-accessors',
26-
'generate-accessors.c',
27-
c_args: ['-D_GNU_SOURCE'],
29+
[
30+
'generate-accessors.c',
31+
],
32+
c_args: [
33+
'-D_GNU_SOURCE',
34+
],
2835
dependencies: [
2936
config_dep,
3037
],
@@ -35,12 +42,13 @@ generate_accessors = executable(
3542
run_target(
3643
'update-accessors',
3744
command: [
38-
meson.current_source_dir() / 'update-accessors.sh',
45+
'update-accessors.sh',
3946
generate_accessors,
40-
meson.current_source_dir(),
47+
libnvme_src_nvme,
48+
libnvme_src,
4149
meson.current_source_dir() / 'generate-accessors-include.list',
4250
meson.current_source_dir() / 'generate-accessors-exclude.list',
43-
meson.current_source_dir() / 'private.h',
51+
libnvme_src_nvme / 'private.h',
4452
],
4553
depends: generate_accessors,
4654
)

0 commit comments

Comments
 (0)