-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cmake versioning feature (#165)
* Added cmake versioning feature * Modified a comment --------- Co-authored-by: Ubuntu <[email protected]> Co-authored-by: Nikhil Kamath <[email protected]>
- Loading branch information
1 parent
5c9cd01
commit b9d706f
Showing
6 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,110 @@ | ||
# This CMake module is used to generate semantic version information for the AWS IoT Secure Tunneling Local Proxy | ||
# and inject it into our source code, making the version information available to the compiled binary | ||
# so that it can be written to the logs for debugging purposes. To increment the major/minor versions | ||
# of the Secure Tunneling Local Proxy, this module expects to find a git tag in the form of "v1.0", where the first number | ||
# is the major version and the second number is the minor version. This module will search starting at HEAD | ||
# until it finds the latest versioned tag - git tags that do not start with "v" will be ignored. | ||
# | ||
# Additionally, the PATCH version of the version number is automatically incremented based on the number of commits | ||
# that we see between the current revision and the latest Git tag. For more information on Semantic Versioning, | ||
# check out https://semver.org/ and for more information on Git tags, check out https://git-scm.com/book/en/v2/Git-Basics-Tagging | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
# Marking Secure Tunneling Local Proxy directory safe | ||
execute_process(COMMAND git config --global --add safe.directory ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
# Check to make sure we have Git info for this package | ||
execute_process(COMMAND git log --pretty=format:'%h' -n 1 | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE GIT_INFO) | ||
|
||
function (load_version_from_file) | ||
# Git is not available (this is the case if the source is packaged as an archive), get version from file | ||
file(STRINGS ${CMAKE_SOURCE_DIR}/.version ${PROJECT_NAME}_VERSION_LIST) | ||
string(REPLACE "*" ";" ${PROJECT_NAME}_VERSION_LIST ${${PROJECT_NAME}_VERSION_LIST}) | ||
# Set partial versions | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 0 ${PROJECT_NAME}_VERSION_STRING_FULL) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 1 ${PROJECT_NAME}_VERSION_STRING) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 2 ${PROJECT_NAME}_VERSION_MAJOR) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 3 ${PROJECT_NAME}_VERSION_MINOR) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 4 ${PROJECT_NAME}_VERSION_PATCH) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 5 ${PROJECT_NAME}_VERSION_AHEAD) | ||
list(GET ${PROJECT_NAME}_VERSION_LIST 6 ${PROJECT_NAME}_VERSION_GIT_SHA) | ||
unset(${PROJECT_NAME}_VERSION_LIST) | ||
|
||
message("-- Failed to infer patch version from git, loaded AWS IoT Secure Tunneling Local Proxy version from file: ${${PROJECT_NAME}_VERSION_STRING_FULL}") | ||
endfunction() | ||
|
||
if (GIT_VERSION AND NOT ${GIT_INFO} STREQUAL "") | ||
message("-- Using Git to calculate AWS IoT Secure Tunneling Local Proxy version information...") | ||
|
||
# Get last tag from git - this only matches tags starting with v, so we ignore non-versioning tags | ||
execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags --match "v[0-9]*" | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_STRING | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
RESULT_VARIABLE exit) | ||
|
||
if (NOT exit EQUAL 0) | ||
load_version_from_file() | ||
return() | ||
endif() | ||
|
||
# Determine how many commits since last tag | ||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list ${${PROJECT_NAME}_VERSION_STRING}..HEAD --count | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_AHEAD | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
RESULT_VARIABLE exit) | ||
|
||
if (NOT exit EQUAL 0) | ||
load_version_from_file() | ||
return() | ||
endif() | ||
|
||
# Get current commit SHA from git | ||
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_GIT_SHA | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
RESULT_VARIABLE exit) | ||
|
||
if (NOT exit EQUAL 0) | ||
load_version_from_file() | ||
return() | ||
endif() | ||
|
||
# Collect the partial versions into a list | ||
string(REGEX MATCHALL "[0-9]+" ${PROJECT_NAME}_PARTIAL_VERSION_LIST | ||
${${PROJECT_NAME}_VERSION_STRING}) | ||
|
||
# Set the version numbers | ||
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST | ||
0 ${PROJECT_NAME}_VERSION_MAJOR) | ||
list(GET ${PROJECT_NAME}_PARTIAL_VERSION_LIST | ||
1 ${PROJECT_NAME}_VERSION_MINOR) | ||
set(${PROJECT_NAME}_VERSION_PATCH ${${PROJECT_NAME}_VERSION_AHEAD}) | ||
|
||
# Unset the list | ||
unset(${PROJECT_NAME}_PARTIAL_VERSION_LIST) | ||
|
||
# Set full project version string | ||
set(${PROJECT_NAME}_VERSION_STRING_FULL | ||
v${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}-${${PROJECT_NAME}_VERSION_GIT_SHA}) | ||
|
||
|
||
message("-- Generated AWS IoT Secure Tunneling Local Proxy version: ${${PROJECT_NAME}_VERSION_STRING_FULL}") | ||
# Save version to file (which will be used when Git is not available | ||
# or VERSION_UPDATE_FROM_GIT is disabled) | ||
file(WRITE ${CMAKE_SOURCE_DIR}/.version ${${PROJECT_NAME}_VERSION_STRING_FULL} | ||
"*" ${${PROJECT_NAME}_VERSION_STRING} | ||
"*" ${${PROJECT_NAME}_VERSION_MAJOR} | ||
"*" ${${PROJECT_NAME}_VERSION_MINOR} | ||
"*" ${${PROJECT_NAME}_VERSION_PATCH} | ||
"*" ${${PROJECT_NAME}_VERSION_AHEAD} | ||
"*" ${${PROJECT_NAME}_VERSION_GIT_SHA}) | ||
|
||
# exit from cmake processing | ||
return() | ||
endif() |
This file contains 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,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/** | ||
* CMake will inject version information into this file at compile time, and will | ||
* make it accessible to our source code as "Version.h" | ||
*/ | ||
#ifndef AWS_IOT_SECURE_TUNNELING_LOCAL_PROXY_VERSION_H | ||
#define AWS_IOT_SECURE_TUNNELING_LOCAL_PROXY_VERSION_H | ||
|
||
#define LOCAL_PROXY_VERSION_FULL "${${PROJECT_NAME}_VERSION_STRING_FULL}" | ||
#define LOCAL_PROXY_VERSION "${${PROJECT_NAME}_VERSION_STRING}" | ||
|
||
#endif // AWS_IOT_SECURE_TUNNELING_LOCAL_PROXY_VERSION_H |
This file contains 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 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 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