diff --git a/doc/how-to-create-an-iceoryx2-release.md b/doc/how-to-create-an-iceoryx2-release.md index dfdf9f69f..d5a5d1e04 100644 --- a/doc/how-to-create-an-iceoryx2-release.md +++ b/doc/how-to-create-an-iceoryx2-release.md @@ -79,10 +79,11 @@ number is `Xold.Yold.Zold`. 10. Adjust the `` to `X.Y.Z` in `$GIT_ROOT$/package.xml`. 11. Call `rg "Xold\.Yold\.Zold"` and adjust all findings. * C and C++ examples, `BUILD.bazel` & `CMakeLists.txt` -12. **Merge all changes to `main`.** -13. Set tag on GitHub and add the release document as notes to the tag +12. Adjust the major, minor and patch version number in `iceoryx2_bb_elementary::PackageVersion` +13. **Merge all changes to `main`.** +14. Set tag on GitHub and add the release document as notes to the tag description. Add also a link to the file. -14. Check the order of all dependencies in +15. Check the order of all dependencies in `$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh`. When calling `cargo publish -p $PACKAGE$` all dependencies, also dev-dependencies, must be already published to `crates.io` via `cargo publish -p`. Verify the @@ -92,7 +93,7 @@ number is `Xold.Yold.Zold`. * If the publish script was started and a crate requires a dependency which is not available on `crates.io` the release has to be redone and the patch version has to increase by one for the whole workspace. -15. Call `$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh` and publish +16. Call `$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh` and publish all crates on `crates.io` and `docs.rs`. -16. Verify that the release looks fine on `docs.rs` (click through the +17. Verify that the release looks fine on `docs.rs` (click through the documentation to check if everything was generated correctly) diff --git a/iceoryx2-bb/elementary/src/package_version.rs b/iceoryx2-bb/elementary/src/package_version.rs index 9dc710240..d38753cd7 100644 --- a/iceoryx2-bb/elementary/src/package_version.rs +++ b/iceoryx2-bb/elementary/src/package_version.rs @@ -10,8 +10,7 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -use iceoryx2_pal_concurrency_sync::iox_atomic::IoxAtomicU64; -use std::{fmt::Display, sync::atomic::Ordering}; +use std::fmt::Display; /// Represents the crates version acquired through the internal environment variables set by cargo, /// ("CARGO_PKG_VERSION_{MAJOR|MINOR|PATCH}"). @@ -63,33 +62,11 @@ impl PackageVersion { /// Returns the current [`PackageVersion`] pub fn get() -> PackageVersion { - static PACKAGE_VERSION: IoxAtomicU64 = IoxAtomicU64::new(0); + const MAJOR: u16 = 0; + const MINOR: u16 = 4; + const PATCH: u16 = 1; - if PACKAGE_VERSION.load(Ordering::Relaxed) == 0 { - let major = option_env!("CARGO_PKG_VERSION_MAJOR") - .and_then(|s| s.parse::().ok()) - .unwrap_or(u16::MAX); - let minor = option_env!("CARGO_PKG_VERSION_MINOR") - .and_then(|s| s.parse::().ok()) - .unwrap_or(u16::MAX); - let patch = option_env!("CARGO_PKG_VERSION_PATCH") - .and_then(|s| s.parse::().ok()) - .unwrap_or(u16::MAX); - - if major == 0 && minor == 0 && patch == 0 { - PACKAGE_VERSION.store( - PackageVersion::from_version(u16::MAX, u16::MAX, u16::MAX).0, - Ordering::Relaxed, - ); - } else { - PACKAGE_VERSION.store( - PackageVersion::from_version(major, minor, patch).0, - Ordering::Relaxed, - ); - } - } - - PackageVersion::from_u64(PACKAGE_VERSION.load(Ordering::Relaxed)) + PackageVersion::from_version(MAJOR, MINOR, PATCH) } } diff --git a/iceoryx2-bb/elementary/tests/package_version_tests.rs b/iceoryx2-bb/elementary/tests/package_version_tests.rs new file mode 100644 index 000000000..ecdc4134e --- /dev/null +++ b/iceoryx2-bb/elementary/tests/package_version_tests.rs @@ -0,0 +1,35 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use iceoryx2_bb_elementary::package_version::PackageVersion; +use iceoryx2_bb_testing::assert_that; + +#[test] +fn package_version_works() { + let major = option_env!("CARGO_PKG_VERSION_MAJOR") + .and_then(|s| s.parse::().ok()) + .expect("Contains a valid major version number."); + let minor = option_env!("CARGO_PKG_VERSION_MINOR") + .and_then(|s| s.parse::().ok()) + .expect("Contains a valid minor version number."); + let patch = option_env!("CARGO_PKG_VERSION_PATCH") + .and_then(|s| s.parse::().ok()) + .expect("Contains a valid patch version number."); + + let sut = PackageVersion::get(); + + assert_that!(sut.major(), eq major); + assert_that!(sut.minor(), eq minor); + assert_that!(sut.patch(), eq patch); + + assert_that!(major == 0 && minor == 0 && patch == 0, eq false); +}