Skip to content

Commit

Permalink
Add new executable flag to check if main or release version (#1038)
Browse files Browse the repository at this point in the history
* now prints version and 'dev' if 'releases' is not in branch name

* updated version.h file to not have generated branch name, should get overwriten either way

* added version.h to .gitignore

* intermediate commit to remove history of version.h

* added version.h to .gitignore, with no history of file
  • Loading branch information
christag-ni authored Feb 14, 2024
1 parent ee196a5 commit 461ab76
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ gens
.vscode
__pycache__/
.venv
/generated/version.h
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ if(WIN32)
)
endif()

execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Generate version header file
# This file requires product name and version info that mako does not know, but CMake does
configure_file(
Expand Down
11 changes: 0 additions & 11 deletions generated/version.h

This file was deleted.

13 changes: 13 additions & 0 deletions source/server/core_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "windows/console_ctrl_handler.h"
#endif

#include "version.h"

using FeatureState = nidevice_grpc::FeatureToggles::FeatureState;

struct ServerConfiguration {
Expand Down Expand Up @@ -185,6 +187,17 @@ Options parse_options(int argc, char** argv)
nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, usage);
exit(EXIT_SUCCESS);
}
else if (strcmp("--version", argv[i]) == 0) {
std::string string_kNiDeviceGrpcBranchName(nidevice_grpc::kNiDeviceGrpcBranchName);
if (string_kNiDeviceGrpcBranchName.rfind("releases", 0) == 0) {
nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, nidevice_grpc::kNiDeviceGrpcFileVersion);
}
else {
nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, nidevice_grpc::kNiDeviceGrpcFileVersion);
nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, "dev");
}
exit(EXIT_SUCCESS);
}
else if (i == argc - 1) {
options.config_file_path = argv[i];
}
Expand Down
1 change: 1 addition & 0 deletions source/server/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nidevice_grpc {

static constexpr const char* kNiDeviceGrpcFileVersion = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0";
static constexpr const char* kNiDeviceGrpcOriginalFileName = "ni_grpc_device_server.exe";
static constexpr const char* kNiDeviceGrpcBranchName = "@GIT_BRANCH@";

}

Expand Down

0 comments on commit 461ab76

Please sign in to comment.