Added git branch name and short hash to moonlight binary

This commit is contained in:
Albert Andaluz 2019-10-15 15:41:19 +02:00 committed by Iwan Timmer
parent fe1c203b10
commit 4528b78d81
4 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,7 @@ project(moonlight-embedded VERSION 2.4.10 LANGUAGES C)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
SET(CMAKE_C_STANDARD 99) SET(CMAKE_C_STANDARD 99)
include(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake) include(${CMAKE_ROOT}/Modules/GNUInstallDirs.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/generate_version_header.cmake)
aux_source_directory(./src SRC_LIST) aux_source_directory(./src SRC_LIST)
list(APPEND SRC_LIST ./src/input/evdev.c ./src/input/mapping.c ./src/input/udev.c) list(APPEND SRC_LIST ./src/input/evdev.c ./src/input/mapping.c ./src/input/udev.c)

View File

@ -0,0 +1,29 @@
include(FindGit)
if(GIT_FOUND AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
set(GIT_BRANCH "")
set(GIT_COMMIT_HASH "")
# Get the current working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} name-rev --name-only HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH0
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Clean Branch name to have only the branch
STRING(REGEX REPLACE "((origin))+" "" GIT_BRANCH1 ${GIT_BRANCH0})
STRING(REGEX REPLACE "((remotes))+" "" GIT_BRANCH2 ${GIT_BRANCH1})
STRING(REGEX REPLACE "\\/+" "" GIT_BRANCH3 ${GIT_BRANCH2})
STRING(REGEX REPLACE "~[0-9]*" "" GIT_BRANCH4 ${GIT_BRANCH3})
STRING(REGEX REPLACE "\\^[0-9]*" "" GIT_BRANCH ${GIT_BRANCH4})
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

View File

@ -20,5 +20,7 @@
#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define VERSION_MINOR @PROJECT_VERSION_MINOR@ #define VERSION_MINOR @PROJECT_VERSION_MINOR@
#define VERSION_PATCH @PROJECT_VERSION_PATCH@ #define VERSION_PATCH @PROJECT_VERSION_PATCH@
#cmakedefine GIT_BRANCH "@GIT_BRANCH@"
#cmakedefine GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
#define COMPILE_OPTIONS "@MOONLIGHT_OPTIONS@" #define COMPILE_OPTIONS "@MOONLIGHT_OPTIONS@"

View File

@ -151,7 +151,11 @@ static void stream(PSERVER_DATA server, PCONFIGURATION config, enum platform sys
} }
static void help() { static void help() {
#ifdef GIT_BRANCH
printf("Moonlight Embedded %d.%d.%d-%s-%s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, GIT_BRANCH, GIT_COMMIT_HASH);
#else
printf("Moonlight Embedded %d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); printf("Moonlight Embedded %d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
#endif
printf("Usage: moonlight [action] (options) [host]\n"); printf("Usage: moonlight [action] (options) [host]\n");
printf(" moonlight [configfile]\n"); printf(" moonlight [configfile]\n");
printf("\n Actions\n\n"); printf("\n Actions\n\n");