Skip to content

Commit

Permalink
Add version information (#177)
Browse files Browse the repository at this point in the history
* manager: add support for --version command line parameter

This adds the Unix/Linux traditional commmand line argument "--version"
so that it is possible to retrieve the version of the binary.

Example output:
/usr/bin/manager (everest-framework 0.10.1)

Signed-off-by: Michael Heimpold <[email protected]>

* ModuleLoader: add support to print version via command line

The generated code of each C++ module uses the module loader for
processing command line parameters etc.
This is why we have to extend the class and pass the version information
from the generated files into the framework library here.

Signed-off-by: Michael Heimpold <[email protected]>

* Add additional backwards compatible ModuleLoader constructor
* Move version information header to everest-cmake v0.3

It is now automatically generated in ${CMAKE_CURRENT_BINARY_DIR}/generated/include/version_information.hpp

* Display everest-core version during startup from a generated file

This file can be generated during a build of everest-core

* Make EVerest logo more colorful
* Bump version to 0.15.0
* Bump needed version of everest-cmake
* Move to buildkit v1.2.0

Signed-off-by: Kai-Uwe Hermann <[email protected]>

---------

Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Kai-Uwe Hermann <[email protected]>
Co-authored-by: Michael Heimpold <[email protected]>
  • Loading branch information
hikinggrass and mhei authored Jun 14, 2024
1 parent 4950071 commit 5836534
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cmake_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
- 'ubuntu-22.04'
- 'large-ubuntu-22.04-xxl'

env:
BUILD_KIT_IMAGE: ghcr.io/everest/build-kit-alpine:v1.2.0

jobs:
build:
name: Build and Test
Expand Down Expand Up @@ -39,8 +42,8 @@ jobs:
rsync -a source/.ci/build-kit/ scripts
- name: Pull build-kit docker image
run: |
docker pull --quiet ghcr.io/everest/build-kit-alpine:latest
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
docker pull --quiet ${{ env.BUILD_KIT_IMAGE }}
docker image tag ${{ env.BUILD_KIT_IMAGE }} build-kit
- name: Compile
run: |
docker run \
Expand Down
14 changes: 13 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ genrule(
""",
)

genrule(
name = "version_information",
outs = ["include/generated/version_information.hpp"],
cmd = """
echo "#pragma once" > $@
echo "#define PROJECT_NAME \\"everest-framework\\"" >> $@
echo "#define PROJECT_DESCRIPTION \\"\\"" >> $@
echo "#define PROJECT_VERSION \\"\\"" >> $@
echo "#define GIT_VERSION \\"\\"" >> $@
""",
)

cc_library(
name = "framework",
srcs = glob(["lib/**/*.cpp"]),
hdrs = glob(["include/**/*.hpp"]) + [":compile_time_settings"],
hdrs = glob(["include/**/*.hpp"]) + [":compile_time_settings", ":version_information"],
copts = ["-std=c++17"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.14)

project(everest-framework
VERSION 0.14.2
VERSION 0.15.0
DESCRIPTION "The open operating system for e-mobility charging stations"
LANGUAGES CXX C
)

find_package(everest-cmake 0.1 REQUIRED
find_package(everest-cmake 0.4 REQUIRED
PATHS ../everest-cmake
)

Expand Down
14 changes: 13 additions & 1 deletion include/framework/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct RuntimeSettings {

std::string run_as_user;

std::string version_information;

nlohmann::json config;

bool validate_schema;
Expand All @@ -144,17 +146,27 @@ struct ModuleCallbacks {
const std::function<void()>& ready);
};

struct VersionInformation {
std::string project_name;
std::string project_version;
std::string git_version;
};

class ModuleLoader {
private:
std::shared_ptr<RuntimeSettings> runtime_settings;
std::string module_id;
std::string original_process_name;
ModuleCallbacks callbacks;
VersionInformation version_information;

bool parse_command_line(int argc, char* argv[]);

public:
explicit ModuleLoader(int argc, char* argv[], ModuleCallbacks callbacks);
explicit ModuleLoader(int argc, char* argv[], ModuleCallbacks callbacks) :
ModuleLoader(argc, argv, callbacks, {"undefined project", "undefined version", "undefined git version"}){};
explicit ModuleLoader(int argc, char* argv[], ModuleCallbacks callbacks,
const VersionInformation version_information);

int initialize();
};
Expand Down
1 change: 0 additions & 1 deletion lib/everest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ void Everest::telemetry_publish(const std::string& category, const std::string&
void Everest::signal_ready() {
BOOST_LOG_FUNCTION();

// EVLOG_info << "Module " << this->module_id << " initialized.";
const auto ready_topic = fmt::format("{}/ready", this->config.mqtt_module_prefix(this->module_id));

this->mqtt_abstraction.publish(ready_topic, json(true));
Expand Down
21 changes: 19 additions & 2 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <algorithm>
#include <cstdlib>
#include <fstream>

#include <boost/program_options.hpp>

Expand Down Expand Up @@ -368,6 +369,13 @@ RuntimeSettings::RuntimeSettings(const std::string& prefix_, const std::string&
validate_schema = defaults::VALIDATE_SCHEMA;
}
run_as_user = settings.value("run_as_user", "");
auto version_information_path = data_dir / "version_information.txt";
if (fs::exists(version_information_path)) {
std::ifstream ifs(version_information_path.string());
version_information = std::string(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
} else {
version_information = "unknown";
}
}

ModuleCallbacks::ModuleCallbacks(const std::function<void(ModuleAdapter module_adapter)>& register_module_adapter,
Expand All @@ -377,8 +385,9 @@ ModuleCallbacks::ModuleCallbacks(const std::function<void(ModuleAdapter module_a
register_module_adapter(register_module_adapter), everest_register(everest_register), init(init), ready(ready) {
}

ModuleLoader::ModuleLoader(int argc, char* argv[], ModuleCallbacks callbacks) :
runtime_settings(nullptr), callbacks(callbacks) {
ModuleLoader::ModuleLoader(int argc, char* argv[], ModuleCallbacks callbacks,
const VersionInformation version_information) :
runtime_settings(nullptr), callbacks(callbacks), version_information(version_information) {
if (!this->parse_command_line(argc, argv)) {
return;
}
Expand Down Expand Up @@ -525,6 +534,7 @@ int ModuleLoader::initialize() {

bool ModuleLoader::parse_command_line(int argc, char* argv[]) {
po::options_description desc("EVerest");
desc.add_options()("version", "Print version and exit");
desc.add_options()("help,h", "produce help message");
desc.add_options()("prefix", po::value<std::string>(), "Set main EVerest directory");
desc.add_options()("module,m", po::value<std::string>(),
Expand All @@ -541,6 +551,13 @@ bool ModuleLoader::parse_command_line(int argc, char* argv[]) {
return false;
}

if (vm.count("version") != 0) {
std::cout << argv[0] << " (" << this->version_information.project_name << " "
<< this->version_information.project_version << " " << this->version_information.git_version << ")"
<< std::endl;
return false;
}

const auto prefix_opt = parse_string_option(vm, "prefix");
const auto config_opt = parse_string_option(vm, "config");
this->runtime_settings = std::make_unique<RuntimeSettings>(prefix_opt, config_opt);
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ target_sources(manager
system_unix.cpp
manager.cpp
)
# generate version information header
evc_generate_version_information()
target_include_directories(manager
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/generated/include
)

target_link_libraries(manager
PRIVATE
Expand Down
42 changes: 36 additions & 6 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "controller/ipc.hpp"
#include "system_unix.hpp"
#include <generated/version_information.hpp>

namespace po = boost::program_options;
namespace fs = std::filesystem;
Expand Down Expand Up @@ -464,12 +465,34 @@ int boot(const po::variables_map& vm) {

Logging::init(rs->logging_config_file.string());

EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " ________ __ _ ");
EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " | ____\\ \\ / / | | ");
EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " | |__ \\ \\ / /__ _ __ ___ ___| |_ ");
EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " | __| \\ \\/ / _ \\ '__/ _ \\/ __| __|");
EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " | |____ \\ / __/ | | __/\\__ \\ |_ ");
EVLOG_info << fmt::format(TERMINAL_STYLE_BLUE, " |______| \\/ \\___|_| \\___||___/\\__|");
EVLOG_info << " \033[0;1;35;95m_\033[0;1;31;91m__\033[0;1;33;93m__\033[0;1;32;92m__\033[0;1;36;96m_\033[0m "
"\033[0;1;31;91m_\033[0;1;33;93m_\033[0m \033[0;1;36;96m_\033[0m ";
EVLOG_info << " \033[0;1;31;91m|\033[0m \033[0;1;33;93m_\033[0;1;32;92m__\033[0;1;36;96m_\\\033[0m "
"\033[0;1;34;94m\\\033[0m \033[0;1;33;93m/\033[0m \033[0;1;32;92m/\033[0m "
"\033[0;1;34;94m|\033[0m \033[0;1;35;95m|\033[0m";
EVLOG_info
<< " \033[0;1;33;93m|\033[0m \033[0;1;32;92m|_\033[0;1;36;96m_\033[0m \033[0;1;35;95m\\\033[0m "
"\033[0;1;31;91m\\\033[0m \033[0;1;33;93m/\033[0m \033[0;1;32;92m/\033[0;1;36;96m__\033[0m "
"\033[0;1;34;94m_\033[0m \033[0;1;35;95m_\033[0;1;31;91m_\033[0m \033[0;1;33;93m__\033[0;1;32;92m_\033[0m "
"\033[0;1;36;96m_\033[0;1;34;94m__\033[0;1;35;95m|\033[0m \033[0;1;31;91m|_\033[0m";
EVLOG_info << " \033[0;1;32;92m|\033[0m \033[0;1;36;96m_\033[0;1;34;94m_|\033[0m \033[0;1;31;91m\\\033[0m "
"\033[0;1;33;93m\\\033[0;1;32;92m/\033[0m \033[0;1;36;96m/\033[0m \033[0;1;34;94m_\033[0m "
"\033[0;1;35;95m\\\033[0m \033[0;1;31;91m'_\033[0;1;33;93m_/\033[0m \033[0;1;32;92m_\033[0m "
"\033[0;1;36;96m\\\033[0;1;34;94m/\033[0m \033[0;1;35;95m__\033[0;1;31;91m|\033[0m "
"\033[0;1;33;93m__\033[0;1;32;92m|\033[0m";
EVLOG_info << " \033[0;1;36;96m|\033[0m \033[0;1;34;94m|_\033[0;1;35;95m__\033[0;1;31;91m_\033[0m "
"\033[0;1;32;92m\\\033[0m \033[0;1;36;96m/\033[0m \033[0;1;35;95m__\033[0;1;31;91m/\033[0m "
"\033[0;1;33;93m|\033[0m \033[0;1;32;92m|\033[0m "
"\033[0;1;36;96m_\033[0;1;34;94m_/\033[0;1;35;95m\\_\033[0;1;31;91m_\033[0m \033[0;1;33;93m\\\033[0m "
"\033[0;1;32;92m|_\033[0m";
EVLOG_info << " \033[0;1;34;94m|_\033[0;1;35;95m__\033[0;1;31;91m__\033[0;1;33;93m_|\033[0m "
"\033[0;1;36;96m\\\033[0;1;34;94m/\033[0m "
"\033[0;1;35;95m\\_\033[0;1;31;91m__\033[0;1;33;93m|_\033[0;1;32;92m|\033[0m "
"\033[0;1;36;96m\\\033[0;1;34;94m__\033[0;1;35;95m_|\033[0;1;31;91m|_\033[0;1;33;93m__\033[0;1;32;"
"92m/\\\033[0;1;36;96m__\033[0;1;34;94m|\033[0m";
EVLOG_info << "";
EVLOG_info << PROJECT_NAME << " " << PROJECT_VERSION << " " << GIT_VERSION;
EVLOG_info << rs->version_information;
EVLOG_info << "";

if (rs->mqtt_broker_socket_path.empty()) {
Expand Down Expand Up @@ -715,6 +738,7 @@ int boot(const po::variables_map& vm) {

int main(int argc, char* argv[]) {
po::options_description desc("EVerest manager");
desc.add_options()("version", "Print version and exit");
desc.add_options()("help,h", "produce help message");
desc.add_options()("check", "Check and validate all config files and exit (0=success)");
desc.add_options()("dump", po::value<std::string>(),
Expand Down Expand Up @@ -746,6 +770,12 @@ int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}

if (vm.count("version") != 0) {
std::cout << argv[0] << " (" << PROJECT_NAME << " " << PROJECT_VERSION << " " << GIT_VERSION << ") "
<< std::endl;
return EXIT_SUCCESS;
}

return boot(vm);

} catch (const BootException& e) {
Expand Down

0 comments on commit 5836534

Please sign in to comment.