Skip to content

Commit c9c158d

Browse files
authored
Improve versioning (#362)
* Set version number in CMakeLists.txt Version number gets sent to C code through preprocessor symbols and to doxygen through environmental variables. Also cleaned up printing of doxygen documentation to show only major.minor at top of page but major.minor.patch in a note on the main page. Also did a bit more cleaning up of doxygen docs. Users don't have access to version numbers now, because we are basing them on CMake variables at our compile time, rather than hard coding them in the header. What I think will make more sense is to templatize the version.h file to actually paste those numbers in there based on the values CMake is holding. * Go back to hard coded version numbers in version.h - Removed add_compile_definitions which needs a minimum of CMake 3.12 - Users have access to version numbers again, but we need to store them in two places * Auto generate version.h with the correct version numbers This does almost everything we need with version numbers in both C and Doxygen code, except for one thing: version.h is not yet being properly installed on make install * Make newly generated version.h file get installed properly Also cleaned up some cruft in CMakeLists.txt * bugfix: public version.h cannot depend on private/config.h Reversed the order of the dependency and kept user agent string stuff entirely in private header file. Public version string no longer contains git repo info, but user agent string still does. * clang formatting * Move user agent string stuff to separate private header file Also remove version unit test that wasn't really a unit test * style check fix
1 parent 9210dd1 commit c9c158d

File tree

7 files changed

+78
-50
lines changed

7 files changed

+78
-50
lines changed

CMakeLists.txt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ include(FindOpenSSL)
4848

4949
set(PROJECT_NAME aws-encryption-sdk)
5050

51+
# Version number of the SDK to be consumed by C code and Doxygen
52+
set(MAJOR 0)
53+
set(MINOR 2)
54+
set(PATCH 0)
55+
5156
# Compiler feature tests and feature flags
5257
set(USE_ASM TRUE
5358
CACHE BOOL "Enable use of inline assembler, if supported by the compiler and platform")
@@ -72,14 +77,19 @@ CHECK_C_SOURCE_COMPILES("
7277
int main() { return __builtin_expect(0, 0); }
7378
" HAVE_BUILTIN_EXPECT)
7479

80+
# Generate includable header files exposing build-time configuration
81+
set(GENERATED_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/generated/include")
82+
set(GENERATED_CONFIG_HEADER "${GENERATED_INCLUDE}/aws/cryptosdk/private/config.h")
83+
set(GENERATED_VERSION_HEADER "${GENERATED_INCLUDE}/aws/cryptosdk/version.h")
84+
85+
configure_file("include/aws/cryptosdk/version.h.in"
86+
${GENERATED_VERSION_HEADER}
87+
ESCAPE_QUOTES)
88+
7589
file(GLOB AWS_CRYPTOSDK_HEADERS
7690
# Headers subject to API/ABI stability guarantees
7791
"include/aws/cryptosdk/*.h"
78-
)
79-
80-
file(GLOB AWS_CRYPTOSDK_PRIV_HEADERS
81-
# Headers not installed with the library
82-
"include/aws/cryptosdk/private/*.h"
92+
${GENERATED_VERSION_HEADER}
8393
)
8494

8595
file(GLOB AWS_CRYPTOSDK_SRC
@@ -91,10 +101,6 @@ if (PERFORM_HEADER_CHECK)
91101
add_subdirectory(cmake/header-tester)
92102
endif()
93103

94-
# Generate includable header files exposing build-time configuration
95-
set(GENERATED_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/generated/include")
96-
set(GENERATED_CONFIG_HEADER "${GENERATED_INCLUDE}/aws/cryptosdk/private/config.h")
97-
98104
# Also expose git revision information in user-agent
99105
include(GitRevision)
100106
FindGitRevision(git_revision)
@@ -115,22 +121,13 @@ if(HAVE_LIBRT)
115121
set(PLATFORM_LIBS ${PLATFORM_LIBS} "pthread")
116122
endif()
117123

118-
file(GLOB CORE_HEADERS
119-
${AWS_CRYPTOSDK_HEADERS}
120-
${GENERATED_CONFIG_HEADER}
121-
)
122-
123-
file(GLOB CORE_SRC
124-
${AWS_CRYPTOSDK_SRC}
125-
)
126-
127124
if(BUILD_SHARED_LIBS)
128125
set(LIBTYPE SHARED)
129126
else()
130127
set(LIBTYPE STATIC)
131128
endif()
132129

133-
add_library(${PROJECT_NAME} ${LIBTYPE} ${CORE_HEADERS} ${CORE_SRC})
130+
add_library(${PROJECT_NAME} ${LIBTYPE} ${AWS_CRYPTOSDK_HEADERS} ${AWS_CRYPTOSDK_SRC})
134131
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99)
135132
aws_cryptosdk_set_common_properties(${PROJECT_NAME})
136133

@@ -147,7 +144,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-c-common)
147144

148145
# Some of our unit tests need to access private symbols. Build a static library for their use.
149146
# We'll use the shared lib for integration tests.
150-
add_library(aws-encryption-sdk-test EXCLUDE_FROM_ALL STATIC ${CORE_HEADERS} ${CORE_SRC})
147+
add_library(aws-encryption-sdk-test EXCLUDE_FROM_ALL STATIC ${AWS_CRYPTOSDK_HEADERS} ${AWS_CRYPTOSDK_SRC})
151148
set_target_properties(aws-encryption-sdk-test PROPERTIES LINKER_LANGUAGE C C_STANDARD 99)
152149
aws_cryptosdk_set_common_properties(aws-encryption-sdk-test)
153150

@@ -168,7 +165,7 @@ include(CodeCoverageTargets)
168165
# Installation logic
169166
aws_install_target(
170167
TARGET ${CMAKE_PROJECT_NAME}
171-
HEADERS ${CORE_HEADERS}
168+
HEADERS ${AWS_CRYPTOSDK_HEADERS}
172169
HEADER_ROOTS ${GENERATED_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/include
173170
)
174171

@@ -226,7 +223,7 @@ if (BUILD_DOC)
226223
set(DOXYGEN_CONFIG_FILE_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/doxygen/doxygen.config)
227224
configure_file(${DOXYGEN_CONFIG_FILE_IN} ${DOXYGEN_CONFIG_FILE_GENERATED} @ONLY)
228225
add_custom_target(doc_doxygen ALL
229-
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG_FILE_GENERATED}
226+
COMMAND ${CMAKE_COMMAND} -E env MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG_FILE_GENERATED}
230227
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
231228
COMMENT "Generating Doxygen documentation"
232229
VERBATIM)

aws-encryption-sdk-cpp/source/kms_keyring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* limitations under the License.
1414
*/
1515
#include <aws/cryptosdk/private/kms_keyring.h>
16-
#include <aws/cryptosdk/version.h>
1716

1817
#include <aws/core/utils/Outcome.h>
1918
#include <aws/core/utils/logging/LogMacros.h>
2019
#include <aws/core/utils/memory/MemorySystemInterface.h>
2120
#include <aws/core/utils/memory/stl/AWSAllocator.h>
2221
#include <aws/cryptosdk/list_utils.h>
2322
#include <aws/cryptosdk/private/cpputils.h>
23+
#include <aws/cryptosdk/private/user_agent.h>
2424
#include <aws/kms/model/DecryptRequest.h>
2525
#include <aws/kms/model/DecryptResult.h>
2626
#include <aws/kms/model/EncryptRequest.h>
@@ -328,7 +328,7 @@ Aws::Cryptosdk::Private::KmsKeyringImpl::KmsKeyringImpl(
328328
static std::shared_ptr<KMS::KMSClient> CreateDefaultKmsClient(const Aws::String &region) {
329329
Aws::Client::ClientConfiguration client_configuration;
330330
client_configuration.region = region;
331-
client_configuration.userAgent += " " AWS_CRYPTOSDK_VERSION_UA "/kms-keyring-cpp";
331+
client_configuration.userAgent += " " AWS_CRYPTOSDK_PRIVATE_VERSION_UA "/kms-keyring-cpp";
332332
#ifdef VALGRIND_TESTS
333333
// When running under valgrind, the default timeouts are too slow
334334
client_configuration.requestTimeoutMs = 10000;

doxygen/doxygen.config.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#---------------------------------------------------------------------------
66
DOXYFILE_ENCODING = UTF-8
77
PROJECT_NAME = "AWS Encryption SDK for C"
8-
PROJECT_NUMBER = 0.2.x
9-
PROJECT_BRIEF = "AWS Encryption SDK for C"
8+
PROJECT_NUMBER = v$(MAJOR).$(MINOR)
9+
PROJECT_BRIEF =
1010
PROJECT_LOGO =
1111
OUTPUT_DIRECTORY = doxygen
1212
CREATE_SUBDIRS = NO
@@ -112,7 +112,8 @@ WARN_LOGFILE =
112112
# Configuration options related to the input files
113113
#---------------------------------------------------------------------------
114114
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/include \
115-
@CMAKE_CURRENT_SOURCE_DIR@/aws-encryption-sdk-cpp/include
115+
@CMAKE_CURRENT_SOURCE_DIR@/aws-encryption-sdk-cpp/include \
116+
@GENERATED_INCLUDE@
116117
INPUT_ENCODING = UTF-8
117118
FILE_PATTERNS = *.h \
118119
*.md

include/aws/cryptosdk/private/config.h.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* implied. See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
1615
#ifndef AWS_CRYPTOSDK_PRIVATE_CONFIG_H
1716
#define AWS_CRYPTOSDK_PRIVATE_CONFIG_H 1
1817

@@ -24,6 +23,10 @@
2423
// not on a tag, we'll add the git revision to the version strings
2524
#cmakedefine AWS_CRYPTOSDK_PRIVATE_GITVERSION "@AWS_CRYPTOSDK_PRIVATE_GITVERSION@"
2625

26+
#ifndef AWS_CRYPTOSDK_PRIVATE_GITVERSION
27+
# define AWS_CRYPTOSDK_PRIVATE_GITVERSION ""
28+
#endif
29+
2730
#ifdef __CPROVER__
2831

2932
// Disable all compiler, and go to bare C
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is
6+
* located at
7+
*
8+
* http://aws.amazon.com/apache2.0/
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
* implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#ifndef AWS_CRYPTOSDK_PRIVATE_USER_AGENT_H
16+
#define AWS_CRYPTOSDK_PRIVATE_USER_AGENT_H
17+
18+
#include <aws/cryptosdk/private/config.h>
19+
#include <aws/cryptosdk/version.h>
20+
21+
// A string constant containing version information in a human-readable form, with git repo info.
22+
#define AWS_CRYPTOSDK_PRIVATE_VERSION_STR \
23+
AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE(AWS_CRYPTOSDK_VERSION_MAJOR) \
24+
"." AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE(AWS_CRYPTOSDK_VERSION_MINOR) "." AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE( \
25+
AWS_CRYPTOSDK_VERSION_PATCH) AWS_CRYPTOSDK_PRIVATE_GITVERSION
26+
27+
// A string constant containing version information in a form suitable for a user-agent string.
28+
#define AWS_CRYPTOSDK_PRIVATE_VERSION_UA "aws-encryption-sdk-c/" AWS_CRYPTOSDK_PRIVATE_VERSION_STR
29+
30+
#endif // AWS_CRYPTOSDK_PRIVATE_USER_AGENT_H

include/aws/cryptosdk/version.h renamed to include/aws/cryptosdk/version.h.in

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#ifndef AWS_CRYPTOSDK_VERSION_H
1717
#define AWS_CRYPTOSDK_VERSION_H
1818

19-
#include <aws/cryptosdk/private/config.h>
20-
2119
/*! \mainpage The AWS Encryption SDK for C
2220
*
2321
* The AWS Encryption SDK for C is a client-side encryption library designed to make it easy for
@@ -26,13 +24,10 @@
2624
* the AWS Encryption SDKs in all languages, see the
2725
* <a href="https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html">Developer Guide</a>.
2826
*
29-
* <b>This library is currently in public preview.</b>
30-
* Feel free to check out the code and give it a spin, but be aware that the APIs are still in flux.
31-
* We'd love to hear your feedback on the APIs before they're fully nailed down.
32-
*
3327
* Source code and installation instructions are available in
3428
* <a href="https://github.com/awslabs/aws-encryption-sdk-c">the GitHub repository</a>.
3529
*
30+
* This API documentation was generated from the v@MAJOR@.@MINOR@.@PATCH@ source code.
3631
*
3732
* <b>License</b>
3833
*
@@ -44,37 +39,38 @@
4439
*
4540
* This section defines version macros that can be used to query the current version of the Encryption SDK.
4641
* For prerelease builds, the version constants will generally contain the anticipated version of the upcoming
47-
* release; if a git working copy is detected at build time, we will include that revision in the version
48-
* strings, but not in the numeric version constants.
42+
* release.
4943
*
5044
* @{
5145
*/
5246

53-
#ifndef AWS_CRYPTOSDK_PRIVATE_GITVERSION
54-
# define AWS_CRYPTOSDK_PRIVATE_GITVERSION ""
55-
#endif
56-
57-
#define AWS_CRYPTOSDK_VERSION_MAJOR 0
58-
#define AWS_CRYPTOSDK_VERSION_MINOR 2
59-
#define AWS_CRYPTOSDK_VERSION_PATCH 0
60-
6147
#ifndef AWS_CRYPTOSDK_DOXYGEN // undocumented private helpers
6248
# define AWS_CRYPTOSDK_PRIVATE_QUOTEARG(a) # a
6349
# define AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE(a) AWS_CRYPTOSDK_PRIVATE_QUOTEARG(a)
6450
#endif
6551

52+
/**
53+
* The major version number. See VERSIONING.rst for details on versioning policy.
54+
*/
55+
#define AWS_CRYPTOSDK_VERSION_MAJOR @MAJOR@
56+
57+
/**
58+
* The minor version number. See VERSIONING.rst for details on versioning policy.
59+
*/
60+
#define AWS_CRYPTOSDK_VERSION_MINOR @MINOR@
61+
62+
/**
63+
* The patch version number. See VERSIONING.rst for details on versioning policy.
64+
*/
65+
#define AWS_CRYPTOSDK_VERSION_PATCH @PATCH@
66+
6667
/**
6768
* A string constant containing version information in a human-readable form.
6869
*/
6970
#define AWS_CRYPTOSDK_VERSION_STR \
7071
AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE(AWS_CRYPTOSDK_VERSION_MAJOR) \
7172
"." AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE(AWS_CRYPTOSDK_VERSION_MINOR) "." AWS_CRYPTOSDK_PRIVATE_EXPANDQUOTE( \
72-
AWS_CRYPTOSDK_VERSION_PATCH) AWS_CRYPTOSDK_PRIVATE_GITVERSION
73-
74-
/**
75-
* A string constant containing version information in a form suitable for a user-agent string.
76-
*/
77-
#define AWS_CRYPTOSDK_VERSION_UA "aws-encryption-sdk-c/" AWS_CRYPTOSDK_VERSION_STR
73+
AWS_CRYPTOSDK_VERSION_PATCH)
7874

7975
/** @} */ // doxygen group versioning
8076

tests/unit/testing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern struct test_case raw_rsa_keyring_encrypt_test_cases[];
3838
extern struct test_case local_cache_test_cases[];
3939
extern struct test_case caching_cmm_test_cases[];
4040
extern struct test_case keyring_trace_test_cases[];
41+
extern struct test_case version_test_cases[];
4142

4243
#define TEST_ASSERT(cond) \
4344
do { \

0 commit comments

Comments
 (0)