Add versioning to logiops binaries

This commit is contained in:
PixlOne 2020-04-10 20:53:13 -04:00 committed by pixl
parent 7b304b85cf
commit 6e7445b197
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
2 changed files with 59 additions and 3 deletions

View File

@ -11,4 +11,41 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -Wextra")
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Git)
# Set version number
if(EXISTS ${CMAKE_SOURCE_DIR}/version.txt)
file(READ version.txt LOGIOPS_VERSION)
string(REGEX REPLACE "\n$" "" LOGIOPS_VERSION ${LOGIOPS_VERSION})
endif()
if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
execute_process(COMMAND ${GIT_EXECUTABLE}
rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE LOGIOPS_GIT_BRANCH)
string(REGEX REPLACE "\n$" "" LOGIOPS_GIT_BRANCH ${LOGIOPS_GIT_BRANCH})
if(LOGIOPS_GIT_BRANCH MATCHES "^tags/?")
STRING(REGEX REPLACE "^tags/" ""
LOGIOPS_VERSION ${LOGIOPS_GIT_BRANCH})
else()
execute_process(COMMAND ${GIT_EXECUTABLE}
rev-parse --short HEAD
OUTPUT_VARIABLE LOGIOPS_COMMIT_HASH)
string(REGEX REPLACE "\n$" "" LOGIOPS_COMMIT_HASH ${LOGIOPS_COMMIT_HASH})
if(LOGIOPS_VERSION)
string(APPEND LOGIOPS_VERSION -${LOGIOPS_COMMIT_HASH})
else()
set(LOGIOPS_VERSION git-${LOGIOPS_COMMIT_HASH})
endif()
endif()
endif()
if(LOGIOPS_VERSION)
message("LogiOps Version Number: ${LOGIOPS_VERSION}")
else()
set(LOGIOPS_VERSION "null")
endif()
add_definitions( -DLOGIOPS_VERSION="${LOGIOPS_VERSION}")
add_subdirectory(src/logid) add_subdirectory(src/logid)

View File

@ -19,6 +19,11 @@
#define evdev_name "logid" #define evdev_name "logid"
#define DEFAULT_CONFIG_FILE "/etc/logid.cfg" #define DEFAULT_CONFIG_FILE "/etc/logid.cfg"
#ifndef LOGIOPS_VERSION
#define LOGIOPS_VERSION "null"
#warning Version is undefined!
#endif
using namespace logid; using namespace logid;
LogLevel logid::global_verbosity = INFO; LogLevel logid::global_verbosity = INFO;
@ -31,7 +36,8 @@ enum class Option
None, None,
Verbose, Verbose,
Config, Config,
Help Help,
Version
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
@ -51,11 +57,15 @@ int main(int argc, char** argv)
if (op_str == "--verbose") option = Option::Verbose; if (op_str == "--verbose") option = Option::Verbose;
if (op_str == "--config") option = Option::Config; if (op_str == "--config") option = Option::Config;
if (op_str == "--help") option = Option::Help; if (op_str == "--help") option = Option::Help;
if (op_str == "--version") option = Option::Version;
break; break;
} }
case 'v': // Verbosity case 'v': // Verbosity
option = Option::Verbose; option = Option::Verbose;
break; break;
case 'V': //Version
option = Option::Version;
break;
case 'c': // Config file path case 'c': // Config file path
option = Option::Config; option = Option::Config;
break; break;
@ -103,14 +113,23 @@ int main(int argc, char** argv)
break; break;
} }
case Option::Help: case Option::Help:
printf(R"(Usage: %s [options] {
printf(R"(logid version %s
Usage: %s [options]
Possible options are: Possible options are:
-v,--verbose [level] Set log level to debug/info/warn/error (leave blank for debug) -v,--verbose [level] Set log level to debug/info/warn/error (leave blank for debug)
-V,--version Print version number
-c,--config [file path] Change config file from default at %s -c,--config [file path] Change config file from default at %s
-h,--help Print this message. -h,--help Print this message.
)", argv[0], DEFAULT_CONFIG_FILE); )", LOGIOPS_VERSION, argv[0], DEFAULT_CONFIG_FILE);
return EXIT_SUCCESS; return EXIT_SUCCESS;
}
case Option::Version:
{
printf("%s\n", LOGIOPS_VERSION);
return EXIT_SUCCESS;
}
case Option::None: case Option::None:
break; break;
} }