This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7468 from EOSIO/version-library
Versioning library
- Loading branch information
Showing
10 changed files
with
205 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
function(GENERATE_VERSION_METADATA) | ||
# Execute `git` to grab the corresponding data. | ||
execute_process( | ||
COMMAND ${GIT_EXEC} rev-parse HEAD | ||
WORKING_DIRECTORY ${SRC_DIR} | ||
OUTPUT_VARIABLE V_HASH | ||
ERROR_QUIET | ||
OUTPUT_STRIP_TRAILING_WHITESPACE ) | ||
execute_process( | ||
COMMAND ${GIT_EXEC} diff --quiet | ||
WORKING_DIRECTORY ${SRC_DIR} | ||
RESULT_VARIABLE V_DIRTY | ||
ERROR_QUIET | ||
OUTPUT_STRIP_TRAILING_WHITESPACE ) | ||
|
||
# If `V_DIRTY` is equal to 1, we know that the repository is dirty and vice versa. | ||
if(${V_DIRTY}) | ||
set(V_DIRTY "true") | ||
else() | ||
set(V_DIRTY "false") | ||
endif() | ||
|
||
# Define the proper version metadata for the file `version_impl.cpp.in`. | ||
set(_VERSION_MAJOR_ ${V_MAJOR}) | ||
set(_VERSION_MINOR_ ${V_MINOR}) | ||
set(_VERSION_PATCH_ ${V_PATCH}) | ||
set(_VERSION_SUFFIX_ ${V_SUFFIX}) | ||
set(_VERSION_HASH_ ${V_HASH}) | ||
set(_VERSION_DIRTY_ ${V_DIRTY}) | ||
|
||
# Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. | ||
configure_file( | ||
${CUR_SRC_DIR}/src/version_impl.cpp.in | ||
${CUR_BIN_DIR}/src/version_impl.cpp | ||
@ONLY ) | ||
endfunction(GENERATE_VERSION_METADATA) | ||
|
||
GENERATE_VERSION_METADATA() |
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,49 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(Version) | ||
|
||
# Define the version metadata by default, in case `git` cannot be found. | ||
set(_VERSION_MAJOR_ "unknown") | ||
set(_VERSION_MINOR_ "") | ||
set(_VERSION_PATCH_ "") | ||
set(_VERSION_SUFFIX_ "") | ||
set(_VERSION_HASH_ "") | ||
set(_VERSION_DIRTY_ "") | ||
|
||
# Construct the library target. | ||
add_library( | ||
version | ||
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" | ||
"${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp") | ||
|
||
# Make dependencies visible to the given target library to be constructed. | ||
target_include_directories( | ||
version | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" | ||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) | ||
|
||
# Create a custom target to update the version metadata upon every build. | ||
find_package(Git) | ||
if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) | ||
add_custom_target( | ||
evaluate_every_build ALL | ||
COMMAND ${CMAKE_COMMAND} -DGIT_EXEC=${GIT_EXECUTABLE} | ||
-DCUR_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR} | ||
-DCUR_SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} | ||
-DSRC_DIR=${CMAKE_SOURCE_DIR} | ||
-DV_MAJOR=${VERSION_MAJOR} | ||
-DV_MINOR=${VERSION_MINOR} | ||
-DV_PATCH=${VERSION_PATCH} | ||
-DV_SUFFIX=${VERSION_SUFFIX} | ||
-P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake | ||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp | ||
COMMENT "Updating version metadata..." VERBATIM ) | ||
|
||
# Create a dependency for the given library target. | ||
add_dependencies(version evaluate_every_build) | ||
else() | ||
# Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. | ||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in | ||
${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp | ||
@ONLY ) | ||
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,18 @@ | ||
/** | ||
* @file version.hpp | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> // std::string | ||
|
||
namespace eosio { namespace version { | ||
|
||
///< Grab the basic version information of the client; example: `v1.8.0-rc1` | ||
const std::string& version_client(); | ||
|
||
///< Grab the full version information of the client; example: `v1.8.0-rc1-7de458254[-dirty]` | ||
const std::string& version_full(); | ||
|
||
} } |
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,20 @@ | ||
/** | ||
* @file version.cpp | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
|
||
#include "version_impl.hpp" | ||
|
||
namespace eosio { namespace version { | ||
|
||
const std::string& version_client() { | ||
static const std::string version{_version_client()}; | ||
return version; | ||
} | ||
|
||
const std::string& version_full() { | ||
static const std::string version{_version_full()}; | ||
return version; | ||
} | ||
|
||
} } |
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,45 @@ | ||
/** | ||
* @file version_impl.cpp.in | ||
* @copyright defined in eos/LICENSE | ||
* \warning This file is machine generated. DO NOT EDIT. See version_impl.cpp.in for changes. | ||
*/ | ||
|
||
#include "version_impl.hpp" | ||
|
||
namespace eosio { namespace version { | ||
|
||
const std::string version_major {"@_VERSION_MAJOR_@" }; | ||
const std::string version_minor {"@_VERSION_MINOR_@" }; | ||
const std::string version_patch {"@_VERSION_PATCH_@" }; | ||
const std::string version_suffix{"@_VERSION_SUFFIX_@"}; | ||
const std::string version_hash {"@_VERSION_HASH_@" }; | ||
const bool version_dirty { @_VERSION_DIRTY_@ }; | ||
|
||
std::string _version_client() { | ||
if (version_major == "unknown") { | ||
std::string version{"unknown"}; | ||
return version; | ||
} | ||
else { | ||
std::string version{'v' + version_major + '.' + version_minor + '.' + version_patch + '-' + version_suffix}; | ||
return version; | ||
} | ||
} | ||
|
||
std::string _version_full() { | ||
if (version_major == "unknown") { | ||
std::string version{"unknown"}; | ||
return version; | ||
} | ||
else { | ||
std::string version{'v' + version_major + '.' + version_minor + '.' + version_patch + '-' + version_suffix + '-' + version_hash}; | ||
|
||
if (version_dirty == true) { | ||
version += "-dirty"; | ||
} | ||
|
||
return version; | ||
} | ||
} | ||
|
||
} } |
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,18 @@ | ||
/** | ||
* @file version_impl.hpp | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> // std::string | ||
|
||
namespace eosio { namespace version { | ||
|
||
///< Helper function for `version_client()` | ||
std::string _version_client(); | ||
|
||
///< Helper function for `version_full()` | ||
std::string _version_full(); | ||
|
||
} } |
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