Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libnvme/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if want_libnvme
)

############################################################################
subdir('src') # declares: libnvme_dep
libnvme_srcroot = meson.current_source_dir() # needed by tools/generator
subdir('tools/generator') # generate code needed by src below
subdir('src') # declares: libnvme_dep
subdir('libnvme')
if get_option('tests')
subdir('test')
Expand Down
9 changes: 9 additions & 0 deletions libnvme/src/nvme/accessors.ld → libnvme/src/accessors.ld
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

/**
* This file is part of libnvme.
*
* Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries.
* Authors: Martin Belanger <[email protected]>
*
*/

LIBNVME_ACCESSORS_3 {
global:
Expand Down
5 changes: 2 additions & 3 deletions libnvme/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ else
sources += 'nvme/no-json.c'
endif

subdir('nvme') # declares: accessors_ld_full_path

deps = [
config_dep,
ccan_dep,
Expand All @@ -66,10 +64,11 @@ deps = [

nvme_ld = meson.current_source_dir() / 'libnvme.ld'
nvmf_ld = meson.current_source_dir() / 'libnvmf.ld'
accessors_ld = meson.current_source_dir() / 'accessors.ld'

link_args = [
'-Wl,--version-script=@0@'.format(nvme_ld),
'-Wl,--version-script=@0@'.format(accessors_ld_full_path),
'-Wl,--version-script=@0@'.format(accessors_ld),
]

libconf = configuration_data()
Expand Down
3 changes: 3 additions & 0 deletions libnvme/src/nvme/accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___|
*
* Auto-generated struct member accessors (setter/getter)
*
* To update run: meson compile -C [BUILD-DIR] update-accessors
* Or: make update-accessors
*/
#include <stdlib.h>
#include <string.h>
Expand Down
3 changes: 3 additions & 0 deletions libnvme/src/nvme/accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___|
*
* Auto-generated struct member accessors (setter/getter)
*
* To update run: meson compile -C [BUILD-DIR] update-accessors
* Or: make update-accessors
*/
#ifndef _ACCESSORS_H_
#define _ACCESSORS_H_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
#define GET_FMT "%s_get_%s" /* alternate name: "%s_%s_get" */

/* checkpatch requires C99 // SPDX in *.c and block-style SPDX in *.h */
static const char *spdx_c = "// SPDX-License-Identifier: LGPL-2.1-or-later";

Check failure on line 71 in libnvme/tools/generator/generate-accessors.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
static const char *spdx_h = "/* SPDX-License-Identifier: LGPL-2.1-or-later */";

Check failure on line 72 in libnvme/tools/generator/generate-accessors.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
static const char *spdx_ld = "# SPDX-License-Identifier: LGPL-2.1-or-later";

Check failure on line 73 in libnvme/tools/generator/generate-accessors.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead

static const char *banner =
"/**\n"
Expand All @@ -85,6 +86,9 @@
" * \\____|\\___|_| |_|\\___|_| \\__,_|\\__\\___|\\__,_| \\____\\___/ \\__,_|\\___|\n"
" *\n"
" * Auto-generated struct member accessors (setter/getter)\n"
" *\n"
" * To update run: meson compile -C [BUILD-DIR] update-accessors\n"
" * Or: make update-accessors\n"
" */";

/**
Expand Down Expand Up @@ -2095,9 +2099,13 @@
mkdir_fullpath(conf.l_fname, 0755); /* create output folder if needed */
generated_ld = fopen(conf.l_fname, "w");
fprintf(generated_ld,
"%s\n"
"\n"
"%s\n"
"\n"
"LIBNVME_ACCESSORS_3 {\n"
" global:\n");
" global:\n",
spdx_ld, banner);

/* Copy temporary file to output */
append_file(generated_ld, tmp_ld_map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# pre-generated and committed to the source tree. They are NOT
# regenerated during a normal build.
#
# To regenerate them after changing private.h or structs-to-include.txt:
# To regenerate them after changing private.h or the include/exclude lists:
#
# meson compile -C <build-dir> update-accessors

Expand All @@ -19,12 +19,19 @@
# Usage: meson compile -C <build-dir> update-accessors
# ---------------------------------------------------------------------------

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

generate_accessors = executable(
'generate-accessors',
'generate-accessors.c',
c_args: ['-D_GNU_SOURCE'],
[
'generate-accessors.c',
],
c_args: [
'-D_GNU_SOURCE',
],
dependencies: [
config_dep,
],
Expand All @@ -35,12 +42,13 @@ generate_accessors = executable(
run_target(
'update-accessors',
command: [
meson.current_source_dir() / 'update-accessors.sh',
'update-accessors.sh',
generate_accessors,
meson.current_source_dir(),
libnvme_src_nvme,
libnvme_src,
meson.current_source_dir() / 'generate-accessors-include.list',
meson.current_source_dir() / 'generate-accessors-exclude.list',
meson.current_source_dir() / 'private.h',
libnvme_src_nvme / 'private.h',
],
depends: generate_accessors,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
#
# Arguments (supplied by the Meson run_target):
# $1 path to the compiled generate-accessors binary
# $2 source directory (where to write the files back)
# $3 path to generate-accessors-include.list
# $4 path to generate-accessors-exclude.list
# $5 ... one or more input headers (wildcards are accepted)
# $2 source directory for accessors.c and accessors.h (src/nvme/)
# $3 source directory for accessors.ld (src/)
# $4 path to generate-accessors-include.list
# $5 path to generate-accessors-exclude.list
# $6 ... one or more input headers (wildcards are accepted)

set -euo pipefail

GENERATOR="${1:?missing generator binary}"
SRCDIR="${2:?missing source directory}"
INCL_FILE="${3:?missing file generate-accessors-include.list}"
EXCL_FILE="${4:?missing file generate-accessors-exclude.list}"
shift 4
NVME_SRCDIR="${2:?missing nvme source directory}"
LD_SRCDIR="${3:?missing ld source directory}"
INCL_FILE="${4:?missing file generate-accessors-include.list}"
EXCL_FILE="${5:?missing file generate-accessors-exclude.list}"
shift 5
INPUT_HEADERS=("$@")
[ ${#INPUT_HEADERS[@]} -gt 0 ] || { echo "error: no input headers specified" >&2; exit 1; }

Expand All @@ -53,12 +55,12 @@ echo "Regenerating accessor files..."
# ---------------------------------------------------------------------------
changed=0
for f in accessors.h accessors.c; do
dest="$SRCDIR/$f"
dest="$NVME_SRCDIR/$f"
if [ -f "$dest" ] && cmp -s "$TMPDIR/$f" "$dest"; then
printf " unchanged: %s\n" "$f"
else
# Write to a sibling temp file then rename for atomicity
tmp_dest=$(mktemp "$SRCDIR/.${f}.XXXXXX")
tmp_dest=$(mktemp "$NVME_SRCDIR/.${f}.XXXXXX")
cp "$TMPDIR/$f" "$tmp_dest"
mv -f "$tmp_dest" "$dest"
printf " updated: %s\n" "$f"
Expand All @@ -68,7 +70,7 @@ done

echo ""
if [ "$changed" -gt 0 ]; then
printf "%d file(s) updated in %s\n" "$changed" "$SRCDIR"
printf "%d file(s) updated in %s\n" "$changed" "$NVME_SRCDIR"
echo "Don't forget to commit the updated files."
else
echo "All accessor source files are up to date."
Expand All @@ -91,7 +93,7 @@ extract_syms() {
}

extract_syms "$TMPDIR/accessors.ld" > "$TMPDIR/syms_new.txt"
extract_syms "$SRCDIR/accessors.ld" > "$TMPDIR/syms_old.txt"
extract_syms "$LD_SRCDIR/accessors.ld" > "$TMPDIR/syms_old.txt"

added=$(comm -23 "$TMPDIR/syms_new.txt" "$TMPDIR/syms_old.txt")
removed=$(comm -13 "$TMPDIR/syms_new.txt" "$TMPDIR/syms_old.txt")
Expand Down