]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
build: Add support for meson build system
authorDaniel Wagner <dwagner@suse.de>
Mon, 11 Oct 2021 16:59:22 +0000 (18:59 +0200)
committerDaniel Wagner <dwagner@suse.de>
Wed, 13 Oct 2021 11:51:04 +0000 (13:51 +0200)
Add meson build system. I tried to mimic the existing Makefile style
but there are a couple of noteworthy differentiation.

 - meson has the concept of subprojects. It is able to download (via
   git) the dependencies (libnvme) and add them directly into the
   build system unless the library is found on the host machine
   (PKG_CONFIG_PATH needs to point to libnvme). This makes git
   submodules unnecessary. The nice thing is that we get a very simple
   setup for CI. meson knows how to download and the dependencies into
   the build.

   To make all this work the git submodule needs to be removed when we
   start using meson to build the project. 'meson dist' bundles
   libnvme into the final tar. We could obviously remove it again via
   add_dist_script but this seems not worth the time.

 - meson uses project_version() to set the version string. This is
   usually just a string (or read from a file). I added the script
   hack so that we keep the versioning consistent with the Makefile,
   e.g. that tar file has the 'git describe' version and 'nvme
   --version' says the same. For a new release, the script
   'nvme-cli-version' needs to be updated (like NVME-VERSION_GEN) and
   the release needs to be tagged before one runs 'meson dist'. I
   guess in the long run we could just set the project_version string
   in meson.build and introduce a package_version which is based on
   git. This is how systemd handles this.

 - The github workflow disables the unit tests for nvme-cli (but not
   for libnvme) by not installing nose2. Those tests fail at the
   moment.

There are still many things very rough or missing, e.g. the install
targets. But this seems like a good first version to get things going.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
.github/workflows/meson.yml [new file with mode: 0644]
.gitignore
meson.build [new file with mode: 0644]
nvme-cli-version [new file with mode: 0755]
plugins/meson.build [new file with mode: 0644]
subprojects/libnvme.wrap [new file with mode: 0644]
tests/meson.build [new file with mode: 0644]
util/meson.build [new file with mode: 0644]

diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml
new file mode 100644 (file)
index 0000000..37eecdc
--- /dev/null
@@ -0,0 +1,26 @@
+name: libnvme meson CI
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+  workflow_dispatch:
+
+jobs:
+  meson-build:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: install libraries
+        run: sudo apt-get install libjson-c-dev
+      - uses: actions/checkout@v2
+      - uses: actions/setup-python@v1
+      # - name: install python dependencies
+      #   run: |
+      #     python -m pip install --upgrade pip
+      #     pip install nose nose2
+      - uses: BSFishy/meson-build@v1.0.3
+        with:
+          action: test
index 8e5ae0008dfb7be271f1c16c07a59e65ab88721f..4158820c40ba17481f9e1e5683c7f954161c4cec 100644 (file)
@@ -9,6 +9,8 @@ nvme.spec
 nvme-*.tar.gz
 version
 
+subprojects/libnvme
+
 cscope.*
 
 /debian/files
diff --git a/meson.build b/meson.build
new file mode 100644 (file)
index 0000000..625759f
--- /dev/null
@@ -0,0 +1,82 @@
+################################################################################
+project(
+    'nvme-cli', ['c', 'cpp'],
+    meson_version: '>= 0.47.0',
+    license: 'LGPLv2+',
+    version: run_command('./nvme-cli-version', check : true).stdout().strip(),
+    default_options: [
+      'c_std=gnu99',
+      'buildtype=release',
+      'prefix=/usr',
+    ]
+)
+
+################################################################################
+cc = meson.get_compiler('c')
+
+prefixdir  = get_option('prefix')
+libdir     = join_paths(prefixdir, get_option('libdir'))
+includedir = join_paths(prefixdir, get_option('includedir'))
+datadir    = join_paths(prefixdir, get_option('datadir'))
+mandir     = join_paths(prefixdir, get_option('mandir'))
+bindir     = join_paths(prefixdir, get_option('bindir'))
+
+###############################################################################
+conf = configuration_data()
+
+libnvme_dep = dependency('libnvme', fallback : ['libnvme', 'libnvme_static_dep'])
+
+# Check for libuuid availability
+libuuid = dependency('uuid', required: true)
+conf.set('LIBUUID', libuuid.found(), description: 'Is libuuid required?')
+
+# Check for libjson-c availability
+libjson = dependency('json-c', required: true)
+conf.set('LIBJSONC', libjson.found(), description: 'Is json-c required?')
+
+# Check for libhugetlbfs  availability
+libhugetlbfs = dependency('hugetlbfs', required: false)
+conf.set('LIBHUGETLBFS', libhugetlbfs.found(), description: 'Is libhugetlbfs required?')
+
+# Set the nvme-cli version
+conf.set('NVME_VERSION', '"' + meson.project_version() + '"')
+
+configure_file(
+    output: 'config-host.h',
+    configuration: conf
+)
+
+################################################################################
+substs = configuration_data()
+substs.set('NAME',    meson.project_name())
+substs.set('VERSION', meson.project_version())
+substs.set('LICENSE', meson.project_license()[0])
+configure_file(
+    input:         'nvme.spec.in',
+    output:        'nvme.spec',
+    configuration: substs,
+)
+
+################################################################################
+add_project_arguments(['-fomit-frame-pointer', '-D_GNU_SOURCE',
+                       '-include', 'config-host.h'], language : 'c')
+
+################################################################################
+sources = [
+  'fabrics.c',
+  'nvme.c',
+  'nvme-models.c',
+  'nvme-print.c',
+  'nvme-rpmb.c',
+  'plugin.c',
+]
+
+subdir('plugins')
+subdir('tests')
+subdir('util')
+
+executable(
+    'nvme',
+    sources,
+    dependencies: [ libnvme_dep, libuuid, libjson ],
+)
diff --git a/nvme-cli-version b/nvme-cli-version
new file mode 100755 (executable)
index 0000000..3a2987c
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+DEF_VER=v1.14
+
+LF='
+'
+
+if test -d .git -o -f .git &&
+       VN=$(git describe --tags --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null) &&
+       case "$VN" in
+       *$LF*) (exit 1) ;;
+       v[0-9]*)
+               git update-index -q --refresh
+               test -z "$(git diff-index --name-only HEAD --)" ||
+               VN="$VN-dirty" ;;
+       esac
+then
+       VN=$(echo "$VN" | sed -e 's/-/./g');
+else
+       VN="$DEF_VER"
+fi
+
+VN=$(expr "$VN" : v*'\(.*\)')
+
+echo "$VN"
+
+
diff --git a/plugins/meson.build b/plugins/meson.build
new file mode 100644 (file)
index 0000000..fc7c5e5
--- /dev/null
@@ -0,0 +1,20 @@
+sources += [
+  'plugins/amzn/amzn-nvme.c',
+  'plugins/dera/dera-nvme.c',
+  'plugins/huawei/huawei-nvme.c',
+  'plugins/intel/intel-nvme.c',
+  'plugins/memblaze/memblaze-nvme.c',
+  'plugins/micron/micron-nvme.c',
+  'plugins/netapp/netapp-nvme.c',
+  'plugins/nvidia/nvidia-nvme.c',
+  'plugins/scaleflux/sfx-nvme.c',
+  'plugins/seagate/seagate-nvme.c',
+  'plugins/shannon/shannon-nvme.c',
+  'plugins/toshiba/toshiba-nvme.c',
+  'plugins/transcend/transcend-nvme.c',
+  'plugins/virtium/virtium-nvme.c',
+  'plugins/wdc/wdc-utils.c',
+  'plugins/wdc/wdc-nvme.c',
+  'plugins/ymtc/ymtc-nvme.c',
+  'plugins/zns/zns.c',
+]
diff --git a/subprojects/libnvme.wrap b/subprojects/libnvme.wrap
new file mode 100644 (file)
index 0000000..b193572
--- /dev/null
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/linux-nvme/libnvme.git
+revision = head
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644 (file)
index 0000000..5acf2aa
--- /dev/null
@@ -0,0 +1,32 @@
+tests = [
+  'nvme_attach_detach_ns_test',
+  'nvme_compare_test',
+  'nvme_create_max_ns_test',
+  'nvme_error_log_test',
+  'nvme_flush_test',
+  'nvme_format_test',
+  'nvme_fw_log_test',
+  'nvme_get_features_test',
+  'nvme_id_ctrl_test',
+  'nvme_id_ns_test',
+  'nvme_read_write_test',
+  'nvme_simple_template_test',
+  'nvme_smart_log_test',
+  'nvme_test_io',
+  'nvme_test_logger',
+  'nvme_test',
+  'nvme_writeuncor_test',
+  'nvme_writezeros_test',
+]
+
+runtests = find_program('nose2', required : false)
+
+if runtests.found()
+  foreach t : tests
+    test(t, runtests,
+         args: ['--verbose', '--start-dir', meson.current_source_dir(), t],
+         workdir: meson.current_source_dir(),
+         env: ['PATH=' + meson.build_root() + ':/usr/bin:/usr/sbin'],
+         timeout: 500)
+  endforeach
+endif
diff --git a/util/meson.build b/util/meson.build
new file mode 100644 (file)
index 0000000..9b8e7cf
--- /dev/null
@@ -0,0 +1,7 @@
+sources += [
+  'util/argconfig.c',
+  'util/cleanup.c',
+  'util/json.c',
+  'util/parser.c',
+  'util/suffix.c',
+]