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

Add version information #177

Merged
merged 18 commits into from
Jun 14, 2024
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
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 @@

std::string run_as_user;

std::string version_information;

Check notice on line 123 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L123

struct member 'RuntimeSettings::version_information' is never used.

nlohmann::json config;

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

struct VersionInformation {
std::string project_name;

Check notice on line 150 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L150

struct member 'VersionInformation::project_name' is never used.
std::string project_version;

Check notice on line 151 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L151

struct member 'VersionInformation::project_version' is never used.
std::string git_version;

Check notice on line 152 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L152

struct member 'VersionInformation::git_version' is never used.
};

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

Check notice on line 161 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L161

class member 'ModuleLoader::version_information' is never used.

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);

Check warning on line 169 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L169

Function parameter 'version_information' should be passed by const reference.

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
Loading