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

[3.2] replace git commands from nodeos' & launcher's cmake with libversion usage #71

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 libraries/version/include/eosio/version/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ namespace eosio { namespace version {
///< Grab the full version information of the client; example: `v1.8.0-rc1-7de458254[-dirty]`
const std::string& version_full();

///< Grab the full git hash hex string; example: `f3b24a2118df7d98659511897cfde6de0e4a375b`
const std::string& version_hash();
} }
5 changes: 5 additions & 0 deletions libraries/version/src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ namespace eosio { namespace version {
return version;
}

const std::string& version_hash() {
static const std::string vhash{_version_hash()};
Copy link
Member

Choose a reason for hiding this comment

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

Seems like an odd thing to keep around for the life of the application. Looks like a copy paste from above, but the same thing goes for those as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was just following how it was done before, it does seem unnecessary

Copy link
Member Author

Choose a reason for hiding this comment

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

@heifner is refactoring libversion something you want to see done?

Copy link
Member

Choose a reason for hiding this comment

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

Not a huge priority, so this is fine for now.

return vhash;
}

} }
4 changes: 4 additions & 0 deletions libraries/version/src/version_impl.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ namespace eosio { namespace version {
}
}

std::string _version_hash() {
return version_hash;
}

} }
3 changes: 3 additions & 0 deletions libraries/version/src/version_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ namespace eosio { namespace version {
///< Helper function for `version_full()`
std::string _version_full();

///< Helper function for `version_hash()`
std::string _version_hash();

} }
17 changes: 1 addition & 16 deletions programs/eosio-launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@ if( UNIX AND NOT APPLE )
set(rt_library rt )
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 "launcher_BUILD_VERSION"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Git commit revision: ${launcher_BUILD_VERSION}")
else()
set(launcher_BUILD_VERSION 0)
endif()
endif()

configure_file(config.hpp.in config.hpp ESCAPE_QUOTES)

target_include_directories(eosio-launcher PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(eosio-launcher
PRIVATE eosio_chain fc Boost::program_options ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
PRIVATE eosio_chain version fc Boost::program_options ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )

install( TARGETS
eosio-launcher
Expand Down
1 change: 0 additions & 1 deletion programs/eosio-launcher/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define CONFIG_HPP_IN

namespace eosio { namespace launcher { namespace config {
constexpr char version_str[] = "${launcher_BUILD_VERSION}";
constexpr char node_executable_name[] = "${NODE_EXECUTABLE_NAME}";
}}}

Expand Down
3 changes: 2 additions & 1 deletion programs/eosio-launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <netinet/in.h>
#include <net/if.h>
#include <eosio/chain/genesis_state.hpp>
#include <eosio/version/version.hpp>

#include "config.hpp"

Expand Down Expand Up @@ -2026,7 +2027,7 @@ int main (int argc, char *argv[]) {
return 0;
}
if (vmap.count("version") > 0) {
cout << eosio::launcher::config::version_str << endl;
cout << eosio::version::version_full() << endl;
return 0;
}

Expand Down
17 changes: 0 additions & 17 deletions programs/nodeos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ if( UNIX AND NOT APPLE )
set(rt_library rt )
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 "nodeos_BUILD_VERSION"
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Git commit revision: ${nodeos_BUILD_VERSION}")
else()
set(nodeos_BUILD_VERSION 0)
endif()
else()
set(nodeos_BUILD_VERSION 0)
endif()

configure_file(config.hpp.in config.hpp ESCAPE_QUOTES)

target_include_directories(${NODE_EXECUTABLE_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
1 change: 0 additions & 1 deletion programs/nodeos/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define CONFIG_HPP_IN

namespace eosio { namespace nodeos { namespace config {
constexpr uint64_t version = 0x${nodeos_BUILD_VERSION};
const string node_executable_name = "${NODE_EXECUTABLE_NAME}";
}}}

Expand Down
5 changes: 4 additions & 1 deletion programs/nodeos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ enum return_codes {
int main(int argc, char** argv)
{
try {
app().set_version(eosio::nodeos::config::version);
uint32_t short_hash = 0;
fc::from_hex(eosio::version::version_hash(), (char*)&short_hash, sizeof(short_hash));

app().set_version(htonl(short_hash));
app().set_version_string(eosio::version::version_client());
app().set_full_version_string(eosio::version::version_full());

Expand Down