Skip to content
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

Provide version major/minor/patch macros #2014

Merged
merged 4 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Increment the:
* Fix Prometheus server crash on listening to already used port [#1986](https://github.com/open-telemetry/opentelemetry-cpp/pull/1986)
* [EXPORTER] Boolean environment variables not parsed per the spec
[#1982](https://github.com/open-telemetry/opentelemetry-cpp/pull/1982)
* Provide version major/minor/patch macros
[#2014](https://github.com/open-telemetry/opentelemetry-cpp/pull/2014)

## [1.8.2] 2023-01-31

Expand Down
4 changes: 4 additions & 0 deletions api/include/opentelemetry/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#define OPENTELEMETRY_ABI_VERSION_NO 1
#define OPENTELEMETRY_VERSION "1.8.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use # operator for preprocessor to define OPENTELEMETRY_VERSION with the new VERSION macros?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically possible, but the resulting code, with OPENTELEMETRY_CONCAT() and OPENTELEMETRY_STRINGIFY(), will be extremely obfuscated.

There is no risk that the string version goes out of sync with major/minor/patch versions, there is a unit test to catch this.

#define OPENTELEMETRY_VERSION_MAJOR 1
#define OPENTELEMETRY_VERSION_MINOR 8
#define OPENTELEMETRY_VERSION_PATCH 2

#define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO)

// clang-format off
Expand Down
15 changes: 15 additions & 0 deletions api/test/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "version_test",
srcs = [
"version_test.cc",
],
tags = [
"api",
"test",
],
deps = [
"//api",
"@com_google_googletest//:gtest_main",
],
)
8 changes: 8 additions & 0 deletions api/test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ gtest_add_tests(
TARGET timestamp_test
TEST_PREFIX trace.
TEST_LIST timestamp_test)

add_executable(version_test version_test.cc)
target_link_libraries(version_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
gtest_add_tests(
TARGET version_test
TEST_PREFIX version.
TEST_LIST version_test)
16 changes: 16 additions & 0 deletions api/test/core/version_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/version.h"

#include <gtest/gtest.h>

TEST(VersionTest, Consistency)
{
char expected[10];
snprintf(expected, sizeof(expected), "%d.%d.%d", OPENTELEMETRY_VERSION_MAJOR,
OPENTELEMETRY_VERSION_MINOR, OPENTELEMETRY_VERSION_PATCH);

std::string actual = OPENTELEMETRY_VERSION;
EXPECT_EQ(actual, expected);
}