Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Versioning library #7468

Merged
merged 30 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
37 changes: 37 additions & 0 deletions CMakeModules/VersionUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(
VERSION 3.5 )

function(GENERATE_VERSION_METADATA)
find_package(Git)
if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE _VERSION_HASH_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
OUTPUT_VARIABLE _VERSION_DIRTY_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE )
string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_})
if("${_VERSION_DIRTY_}" STREQUAL "")
set(_VERSION_DIRTY_ "false")
else()
set(_VERSION_DIRTY_ "true")
endif()
set(_VERSION_MAJOR_ ${VERSION_MAJOR} PARENT_SCOPE)
set(_VERSION_MINOR_ ${VERSION_MINOR} PARENT_SCOPE)
set(_VERSION_PATCH_ ${VERSION_PATCH} PARENT_SCOPE)
set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} PARENT_SCOPE)
set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE)
set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE)
else()
set(_VERSION_MAJOR_ "unknown" PARENT_SCOPE)
set(_VERSION_MINOR_ "" PARENT_SCOPE)
set(_VERSION_PATCH_ "" PARENT_SCOPE)
set(_VERSION_SUFFIX_ "" PARENT_SCOPE)
set(_VERSION_HASH_ "" PARENT_SCOPE)
set(_VERSION_DIRTY_ "" PARENT_SCOPE)
endif()
endfunction()
1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_subdirectory( wasm-jit )
add_subdirectory( appbase )
add_subdirectory( chain )
add_subdirectory( testing )
add_subdirectory( version )

#turn tools&tests off; not needed for library build
set(BUILD_TESTS OFF CACHE BOOL "Build GTest-based tests")
Expand Down
48 changes: 48 additions & 0 deletions libraries/version/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(
VERSION 3.5 )

project(
Version )

# Found in directory `eos/CMakeModules/`.
include(
VersionUtils )

# Generate the most up-to-date version metadata of the repository.
GENERATE_VERSION_METADATA()
johndebord marked this conversation as resolved.
Show resolved Hide resolved

# Construct the library.
add_library(
version
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp" )

# Make dependencies visible.
target_include_directories(
version
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src/" )

# Install the library in the appropriate places.
johndebord marked this conversation as resolved.
Show resolved Hide resolved
install(
TARGETS
version
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ### Is this needed? It's just a library?
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ### Is this needed as both a static and dynamic lib?
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ### ...

# Install the header file in the appropriate place.
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version
DESTINATION
${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/
FILES_MATCHING PATTERN "*.hpp" )

# 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 )
18 changes: 18 additions & 0 deletions libraries/version/include/eosio/version/version.hpp
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();

} }
20 changes: 20 additions & 0 deletions libraries/version/src/version.cpp
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;
}

} }
36 changes: 36 additions & 0 deletions libraries/version/src/version_impl.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @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_@ };

const std::string& _version_client() {
static const std::string version{'v' + version_major +
'.' + version_minor +
'.' + version_patch +
'-' + version_suffix};
return version;
}

const std::string& _version_full() {
johndebord marked this conversation as resolved.
Show resolved Hide resolved
static const std::string version{'v' + version_major +
'.' + version_minor +
'.' + version_patch +
'-' + version_suffix +
'-' + version_hash +
'-' + ((version_dirty == true) ? ("true") : ("false"))};
return version;
}

} }
18 changes: 18 additions & 0 deletions libraries/version/src/version_impl.hpp
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()`
const std::string& _version_client();

///< Helper function for `version_full()`
const std::string& _version_full();

} }
19 changes: 1 addition & 18 deletions programs/cleos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ if( GPERFTOOLS_FOUND )
list( APPEND PLATFORM_SPECIFIC_LIBS tcmalloc )
endif()

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../.git)
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../.."
OUTPUT_VARIABLE "cleos_BUILD_VERSION"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Git commit revision: ${cleos_BUILD_VERSION}")
else()
set(cleos_BUILD_VERSION 0)
endif()
else()
set(cleos_BUILD_VERSION 0)
endif()

find_package(Intl REQUIRED)

set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
Expand All @@ -36,7 +19,7 @@ configure_file(config.hpp.in config.hpp ESCAPE_QUOTES)
target_include_directories(${CLI_CLIENT_EXECUTABLE_NAME} PUBLIC ${Intl_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries( ${CLI_CLIENT_EXECUTABLE_NAME}
PRIVATE appbase chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} )
PRIVATE appbase version chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} )


copy_bin( ${CLI_CLIENT_EXECUTABLE_NAME} )
Expand Down
11 changes: 5 additions & 6 deletions programs/cleos/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#pragma once

namespace eosio { namespace client { namespace config {
constexpr char version_str[] = "${cleos_BUILD_VERSION}";
constexpr char locale_path[] = "${LOCALEDIR}";
constexpr char locale_domain[] = "${LOCALEDOMAIN}";
constexpr char key_store_executable_name[] = "${KEY_STORE_EXECUTABLE_NAME}";
constexpr char node_executable_name[] = "${NODE_EXECUTABLE_NAME}";
}}}
constexpr char locale_path[] {"${LOCALEDIR}" };
constexpr char locale_domain[] {"${LOCALEDOMAIN}" };
constexpr char key_store_executable_name[]{"${KEY_STORE_EXECUTABLE_NAME}"};
constexpr char node_executable_name[] {"${NODE_EXECUTABLE_NAME}" };
} } }
10 changes: 8 additions & 2 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey
#include <eosio/chain_plugin/chain_plugin.hpp>
#include <eosio/chain/contract_types.hpp>

#include <eosio/version/version.hpp>

#pragma push_macro("N")
#undef N

Expand Down Expand Up @@ -2402,8 +2404,12 @@ int main( int argc, char** argv ) {
auto version = app.add_subcommand("version", localized("Retrieve version information"), false);
version->require_subcommand();

version->add_subcommand("client", localized("Retrieve version information of the client"))->set_callback([] {
std::cout << localized("Build version: ${ver}", ("ver", eosio::client::config::version_str)) << std::endl;
version->add_subcommand("client", localized("Retrieve basic version information of the client"))->set_callback([] {
std::cout << eosio::version::version_client() << '\n';
});

version->add_subcommand("full", localized("Retrieve full version information of the client"))->set_callback([] {
std::cout << eosio::version::version_full() << '\n';
});

// Create subcommand
Expand Down