diff --git a/AGENTS.md b/AGENTS.md index 6fdec16..27347ea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ scripts/format.sh --fix # rewrite in place ### 1.2 Notes -- `meson setup` generates the optional `ppack_version.h` into the build directory; `ppack.h` does not include it. +- `include/ppack.h` defines the version macros, and `meson setup` fails when they differ from `project(version:)`, so a release updates both. `include/ppack_version.h` is a deprecated header that includes `ppack.h`. - `PPACK_PAYLOAD_BITS` (default 64) sizes only the `PPACK_PAYLOAD_UNITS` buffer macro; every call takes the payload size explicitly. `PPACK_SIMULATE_16BIT_MAU` selects the 16-bit storage model on a host, for tests only. The only Meson option is `build_tests`. - The test suite builds twice, native and with `PPACK_SIMULATE_16BIT_MAU`. `tests/compatibility` is a separate Meson project that compares against the pinned 2.4.0 source; the command is in `CONTRIBUTING.md`. diff --git a/CHANGELOG.md b/CHANGELOG.md index e179020..25f4164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed +- `ppack.h` defines `PPACK_VERSION_MAJOR`, `_MINOR`, `_PATCH`, `PPACK_VERSION`, `PPACK_VERSION_STRING` and a new `PPACK_VERSION_NUMBER` (`long`, `MAJOR * 10000 + MINOR * 100 + PATCH`), so a copied-in header carries its version. `ppack_version.h` is no longer generated; it is installed as a deprecated header that includes `ppack.h`. Meson fails to configure when the header and `project(version:)` disagree, and the build needs Meson 0.57 or later. - CI installs Meson, Ninja and gcovr with `uv` instead of `pip` and `apt`. - The README is a short landing page, with the integration guide, API reference and design record in `docs/integration.md`, `docs/api.md` and `docs/design.md`. The large-payload verification record is part of `docs/design.md`. diff --git a/config/ppack_version.h.in b/config/ppack_version.h.in deleted file mode 100644 index 3071acd..0000000 --- a/config/ppack_version.h.in +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @file ppack_version.h - * @brief Version information for the ppack library. - * - * Generated by Meson from config/ppack_version.h.in. - */ - -#ifndef PPACK_VERSION_H -#define PPACK_VERSION_H - -#define PPACK_VERSION @VERSION@ -#define PPACK_VERSION_MAJOR @MAJOR@ -#define PPACK_VERSION_MINOR @MINOR@ -#define PPACK_VERSION_PATCH @PATCH@ - -#define PPACK_VERSION_STRING "@MAJOR@.@MINOR@.@PATCH@" - -#endif /* PPACK_VERSION_H */ diff --git a/docs/api.md b/docs/api.md index 20ddf43..2dadb7c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -213,3 +213,25 @@ parameters_load(const ppack_byte_t record[1024u / PPACK_ADDR_UNIT_BITS]) ### Other uses The same table pattern serves I²C and SPI device frames, register images, fixed telemetry packets, and binary exchange between nodes of different addressing models, which see the same bytes. + +## Version + +`ppack.h` defines the release it belongs to, so a copied-in header still identifies itself: + + +```c +#define PPACK_VERSION_MAJOR 2 +#define PPACK_VERSION_MINOR 5 +#define PPACK_VERSION_PATCH 0 +#define PPACK_VERSION "2.5.0" +``` + +`PPACK_VERSION_NUMBER` is `MAJOR * 10000 + MINOR * 100 + PATCH` as a `long`, so it holds any version where `int` is 16 bits. Compare it in the preprocessor to require a minimum release: + +```c +#if PPACK_VERSION_NUMBER < 20500L +#error "ppack 2.5.0 or later is required" +#endif +``` + +`PPACK_VERSION_STRING` is the same string as `PPACK_VERSION`. `ppack_version.h` is a deprecated header that includes `ppack.h`, kept so existing includes compile until the next major release. diff --git a/docs/integration.md b/docs/integration.md index 38edfbb..3dd3e70 100644 --- a/docs/integration.md +++ b/docs/integration.md @@ -28,7 +28,7 @@ Keep both headers on the same include path, because `ppack.h` includes `ppack_pl #include "ppack.h" ``` -`ppack_version.h` exists only in Meson builds. +`ppack.h` defines the version macros described in [api.md](api.md#version). ## Meson subproject @@ -58,10 +58,9 @@ The headers install to a `ppack/` subdirectory, and the `pkg-config` flags add t ```c #include -#include ``` -`ppack_version.h` defines `PPACK_VERSION` and `PPACK_VERSION_STRING` as the version string, and `PPACK_VERSION_MAJOR`, `PPACK_VERSION_MINOR` and `PPACK_VERSION_PATCH` as integers. +`ppack_version.h` is installed beside it as a deprecated header that includes `ppack.h`. ## Buffer sizing diff --git a/include/ppack.h b/include/ppack.h index 8977c42..73df93d 100644 --- a/include/ppack.h +++ b/include/ppack.h @@ -22,6 +22,32 @@ extern "C" { #include "ppack_platform.h" +/* ================ VERSION ================================================= */ + +/** + * @name Version + * @brief Release of this header, for diagnostics and @c #if checks. + * + * @details + * @c PPACK_VERSION_NUMBER is @c MAJOR*10000 @c + @c MINOR*100 + * @c + @c PATCH with type @c long, so it cannot overflow where @c int is + * 16 bits. The Meson build fails to configure when these values differ + * from the project version. + * @{ + */ +/* cppcheck-suppress-begin misra-c2012-2.5 ; @deviation Public version macros + * for consumer diagnostics and #if checks; the library does not use them. */ +#define PPACK_VERSION_MAJOR 2 +#define PPACK_VERSION_MINOR 5 +#define PPACK_VERSION_PATCH 0 +#define PPACK_VERSION "2.5.0" +#define PPACK_VERSION_STRING PPACK_VERSION +#define PPACK_VERSION_NUMBER \ + ((PPACK_VERSION_MAJOR * 10000L) + (PPACK_VERSION_MINOR * 100L) \ + + PPACK_VERSION_PATCH) +/* cppcheck-suppress-end misra-c2012-2.5 ; @deviation As above. */ +/** @} */ + /* * Re-export the platform abstraction so users picking up ppack.h get * ppack_byte_t and PPACK_PAYLOAD_UNITS for portable buffer declarations diff --git a/include/ppack_version.h b/include/ppack_version.h new file mode 100644 index 0000000..0018b91 --- /dev/null +++ b/include/ppack_version.h @@ -0,0 +1,19 @@ +/** + * SPDX-License-Identifier: MIT + * + * @file ppack_version.h + * + * @brief + * Deprecated: the version macros are defined in ppack.h. + * + * @details + * This header includes ppack.h so that existing includes keep compiling. + * It will be removed in the next major release. + */ + +#ifndef PPACK_VERSION_H +#define PPACK_VERSION_H + +#include "ppack.h" + +#endif /* PPACK_VERSION_H */ diff --git a/meson.build b/meson.build index 3f040a9..385bf0a 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,7 @@ project( 'ppack', 'c', version: '2.5.0', + meson_version: '>=0.57.0', default_options: [ 'c_std=c11', 'warning_level=3', @@ -11,27 +12,27 @@ project( license: 'MIT', ) -# === Version header =========================================================== - -ver = meson.project_version().split('.') - -major = ver[0].to_int() -minor = ver[1].to_int() -patch = ver[2].to_int() - -conf = configuration_data() -conf.set_quoted('VERSION', meson.project_version()) -conf.set('MAJOR', major) -conf.set('MINOR', minor) -conf.set('PATCH', patch) - -configure_file( - input: 'config' / 'ppack_version.h.in', - output: 'ppack_version.h', - configuration: conf, - install: true, - install_dir: get_option('includedir') / 'ppack', -) +# === Version ================================================================== +# include/ppack.h defines the version macros, so a copy-in build has them. +# Configuration fails when they differ from the project version. + +fs = import('fs') +version_parts = meson.project_version().split('.') +version_macros = { + 'PPACK_VERSION_MAJOR': version_parts[0], + 'PPACK_VERSION_MINOR': version_parts[1], + 'PPACK_VERSION_PATCH': version_parts[2], + 'PPACK_VERSION': '"' + meson.project_version() + '"', +} +header_lines = [] +foreach line : fs.read('include' / 'ppack.h').split('\n') + header_lines += ' '.join(line.split()) +endforeach +foreach name, value : version_macros + if '#define @0@ @1@'.format(name, value) not in header_lines + error('include/ppack.h must define @0@ as @1@'.format(name, value)) + endif +endforeach # === Include directories ====================================================== @@ -52,7 +53,10 @@ ppack_lib = static_library( ) # Install public header -install_headers(['include/ppack.h', 'include/ppack_platform.h'], subdir: 'ppack') +install_headers( + ['include/ppack.h', 'include/ppack_platform.h', 'include/ppack_version.h'], + subdir: 'ppack', +) ppack_dep = declare_dependency( include_directories: public_headers, diff --git a/tests/test_edge.c b/tests/test_edge.c index 197467f..8f46c9f 100644 --- a/tests/test_edge.c +++ b/tests/test_edge.c @@ -7,6 +7,7 @@ */ #include "ppack.h" +#include "ppack_version.h" #include "test_fixtures.h" #include "test_harness.h" #include @@ -424,6 +425,15 @@ TEST_CASE(test_full_payload) TEST_ASSERT(unpacked.field_uint32 == 0x9ABCDEF0); } +/* The deprecated version header still exposes the macros from ppack.h. */ +TEST_CASE(test_version_macros) +{ + TEST_ASSERT(PPACK_VERSION_NUMBER + == ((PPACK_VERSION_MAJOR * 10000L) + + (PPACK_VERSION_MINOR * 100L) + PPACK_VERSION_PATCH)); + TEST_ASSERT(PPACK_VERSION_STRING[0] != '\0'); +} + void run_edge_tests(void) { @@ -446,4 +456,5 @@ run_edge_tests(void) run_test(test_1bit_field_zero, "test_1bit_field_zero"); run_test(test_overlapping_fields, "test_overlapping_fields"); run_test(test_full_payload, "test_full_payload"); + run_test(test_version_macros, "test_version_macros"); }