-
Notifications
You must be signed in to change notification settings - Fork 118
Iox2 1351 package version api #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ComicSansMS
wants to merge
3
commits into
eclipse-iceoryx:main
Choose a base branch
from
ekxide:iox2-1351-package-version-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) 2026 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 | ||
|
|
||
| #ifndef IOX2_VERSION_HPP | ||
| #define IOX2_VERSION_HPP | ||
|
|
||
| #include "iox2/internal/iceoryx2.hpp" | ||
|
|
||
| #include <cstdint> | ||
| #include <iosfwd> | ||
|
|
||
| namespace iox2 { | ||
|
|
||
| /// Version number. | ||
| struct PackageVersion { | ||
| std::uint16_t major; | ||
| std::uint16_t minor; | ||
| std::uint16_t patch; | ||
| }; | ||
|
|
||
| /// Returns the crates version acquired through the internal environment variables set by cargo, | ||
| /// ("CARGO_PKG_VERSION_{MAJOR|MINOR|PATCH}"). | ||
| PackageVersion package_version(); | ||
|
|
||
| auto operator<<(std::ostream& stream, const PackageVersion& version) -> std::ostream&; | ||
| auto operator==(const PackageVersion& lhs, const PackageVersion& rhs) -> bool; | ||
| auto operator<(const PackageVersion& lhs, const PackageVersion& rhs) -> bool; | ||
|
|
||
| } // namespace iox2 | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) 2026 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 | ||
|
|
||
| #include "iox2/version.hpp" | ||
|
|
||
| #include <ostream> | ||
|
|
||
| namespace iox2 { | ||
|
|
||
| PackageVersion package_version() { | ||
| iox2_package_version_t const v = iox2_package_version(); | ||
| return PackageVersion { v.major, v.minor, v.patch }; | ||
| } | ||
|
|
||
| auto operator<<(std::ostream& stream, const PackageVersion& version) -> std::ostream& { | ||
| return stream << version.major << '.' << version.minor << '.' << version.patch; | ||
| } | ||
|
|
||
| auto operator==(const PackageVersion& lhs, const PackageVersion& rhs) -> bool { | ||
| return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch; | ||
| } | ||
|
|
||
| auto operator<(const PackageVersion& lhs, const PackageVersion& rhs) -> bool { | ||
| if (lhs.major != rhs.major) { | ||
| return lhs.major < rhs.major; | ||
| } else if (lhs.minor != rhs.minor) { | ||
| return lhs.minor < rhs.minor; | ||
| } else { | ||
| return lhs.patch < rhs.patch; | ||
| } | ||
| } | ||
|
|
||
| } // namespace iox2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // Copyright (c) 2026 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 | ||
|
|
||
| #include "iox2/version.hpp" | ||
| #include "test.hpp" | ||
|
|
||
| #include <sstream> | ||
|
|
||
| namespace { | ||
| using namespace iox2; | ||
|
|
||
| TEST(VersionTest, version_obtains_version_number) { | ||
| ASSERT_EQ(package_version().major, 0); | ||
| ASSERT_EQ(package_version().minor, 8); | ||
| ASSERT_EQ(package_version().patch, 999); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_compare_equal_if_all_components_are_equal) { | ||
| PackageVersion sut1; | ||
| sut1.major = 1; | ||
| sut1.minor = 2; | ||
| sut1.patch = 3; | ||
| PackageVersion sut2; | ||
| sut2.major = 1; | ||
| sut2.minor = 2; | ||
| sut2.patch = 3; | ||
| EXPECT_EQ(sut1, sut1); | ||
| EXPECT_EQ(sut1, sut2); | ||
| EXPECT_EQ(sut2, sut1); | ||
| sut1.major = 25; | ||
| sut1.minor = 22; | ||
| sut1.patch = 0; | ||
| sut2.major = 25; | ||
| sut2.minor = 22; | ||
| sut2.patch = 0; | ||
| EXPECT_EQ(sut1, sut1); | ||
| EXPECT_EQ(sut1, sut2); | ||
| EXPECT_EQ(sut2, sut1); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_do_not_compare_equal_if_major_version_differs) { | ||
| PackageVersion sut1; | ||
| sut1.major = 1; | ||
| sut1.minor = 2; | ||
| sut1.patch = 3; | ||
| PackageVersion sut2; | ||
| sut2.major = 0; | ||
| sut2.minor = 2; | ||
| sut2.patch = 3; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| sut1.major = 99; | ||
| sut2.major = 6; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_do_not_compare_equal_if_minor_version_differs) { | ||
| PackageVersion sut1; | ||
| sut1.major = 1; | ||
| sut1.minor = 2; | ||
| sut1.patch = 3; | ||
| PackageVersion sut2; | ||
| sut2.major = 1; | ||
| sut2.minor = 0; | ||
| sut2.patch = 3; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| sut1.minor = 99; | ||
| sut2.minor = 6; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_do_not_compare_equal_if_patch_version_differs) { | ||
| PackageVersion sut1; | ||
| sut1.major = 1; | ||
| sut1.minor = 2; | ||
| sut1.patch = 3; | ||
| PackageVersion sut2; | ||
| sut2.major = 1; | ||
| sut2.minor = 2; | ||
| sut2.patch = 0; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| sut1.patch = 99; | ||
| sut2.patch = 6; | ||
| EXPECT_FALSE(sut1 == sut2); | ||
| EXPECT_FALSE(sut2 == sut1); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_less_compares_lexicographically) { | ||
| PackageVersion sut1; | ||
| sut1.major = 1; | ||
| sut1.minor = 2; | ||
| sut1.patch = 3; | ||
| PackageVersion sut2; | ||
| sut2.major = 2; | ||
| sut2.minor = 2; | ||
| sut2.patch = 3; | ||
| EXPECT_LT(sut1, sut2); | ||
| EXPECT_FALSE(sut2 < sut1); | ||
| sut2.major = sut1.major; | ||
| sut2.minor = 3; | ||
| EXPECT_LT(sut1, sut2); | ||
| EXPECT_FALSE(sut2 < sut1); | ||
| sut2.minor = sut1.minor; | ||
| sut2.patch = 4; | ||
| EXPECT_LT(sut1, sut2); | ||
| EXPECT_FALSE(sut2 < sut1); | ||
| sut2.patch = sut1.patch; | ||
| EXPECT_FALSE(sut1 < sut2); | ||
| EXPECT_FALSE(sut2 < sut1); | ||
| } | ||
|
|
||
| TEST(VersionTest, version_numbers_ostream_insertion_produces_version_string) { | ||
| std::stringstream sstr; | ||
| PackageVersion sut; | ||
| sut.major = 0; | ||
| sut.minor = 0; | ||
| sut.patch = 0; | ||
| sstr << sut; | ||
| ASSERT_FALSE(sstr.fail()); | ||
| EXPECT_STREQ(sstr.str().c_str(), "0.0.0"); | ||
| sstr = std::stringstream {}; | ||
| sut.major = 22; | ||
| sut.minor = 4; | ||
| sut.patch = 102; | ||
| sstr << sut; | ||
| ASSERT_FALSE(sstr.fail()); | ||
| EXPECT_STREQ(sstr.str().c_str(), "22.4.102"); | ||
| } | ||
|
|
||
| } // namespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Food for thought. In iceoryx classic, we generated a C header from the version set in cmake. See also -> https://github.com/eclipse-iceoryx/iceoryx/blob/main/iceoryx_platform/cmake/iceoryx_versions.h.in
This gave us the option to use the version info for deprecation macros like this -> https://github.com/eclipse-iceoryx/iceoryx/blob/main/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/optional.hpp#L22
It's on my todo list to also introduce this macros for iceoryx2 once we reached 1.0, in order to provide a smoother migration path if we deprecate an API call. So, having an analogous C header would help.