Skip to content

Commit

Permalink
Merge branch 'feat/version' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bbsan2k committed Apr 10, 2023
2 parents b58329e + 92d7b85 commit 5ddd995
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ jobs:
submodules: 'recursive'
fetch-depth: '0'
- run: |
git fetch --prune --tags
git tag --list
git fetch --all --tags
git fetch origin --tags --force
TAG=$(git describe --tags --exact-match HEAD --exclude=latest --exclude=nightly) || true
if [ $TAG ]
then
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ add_executable(sd2psx
src/arduino_wrapper/sd.cpp
src/arduino_wrapper/SPI.cpp

${CMAKE_CURRENT_BINARY_DIR}/src/version/version.c

ext/ESP8266SdFat/src/common/FmtNumber.cpp
ext/ESP8266SdFat/src/common/FsCache.cpp
ext/ESP8266SdFat/src/common/FsDateTime.cpp
Expand Down Expand Up @@ -135,6 +133,7 @@ target_link_libraries(sd2psx
lvgl::lvgl
gamedb
ps2boot
sd2psx_version
)

add_dependencies(sd2psx gamedb ps2boot)
Expand Down
33 changes: 9 additions & 24 deletions src/version/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
add_custom_target(sd2psx_version_generator ALL
COMMAND ${CMAKE_COMMAND}
-D SCRIPT_TEMPLATE=${CMAKE_CURRENT_SOURCE_DIR}/template/version.c
-D SCRIPT_WORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-D SCRIPT_OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.c
-P ${CMAKE_CURRENT_SOURCE_DIR}/script.cmake
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/version.c)

find_package(Git QUIET)

if(Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../.git")
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --all --tags --force)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match HEAD --exclude=latest --exclude=nightly
OUTPUT_VARIABLE SD2PSX_VERSION)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE SD2PSX_COMMIT)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE SD2PSX_BRANCH)
string(REGEX REPLACE "\n$" "" SD2PSX_VERSION "${SD2PSX_VERSION}")
string(REGEX REPLACE "\n$" "" SD2PSX_COMMIT "${SD2PSX_COMMIT}")
string(REGEX REPLACE "\n$" "" SD2PSX_BRANCH "${SD2PSX_BRANCH}")
if("${SD2PSX_VERSION}" STREQUAL "")
set(SD2PSX_VERSION "nightly-${SD2PSX_COMMIT}")
endif()
else()
set(SD2PSX_VERSION "None")
set(SD2PSX_COMMIT "None")
set(SD2PSX_BRANCH "None")
endif()


configure_file(${CMAKE_CURRENT_SOURCE_DIR}/template/version.c ${CMAKE_CURRENT_BINARY_DIR}/version.c @ONLY)
add_library(sd2psx_version STATIC ${CMAKE_CURRENT_BINARY_DIR}/version.c)
target_include_directories(sd2psx_version PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
34 changes: 34 additions & 0 deletions src/version/script.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.12)

find_package(Git QUIET)

if(Git_FOUND AND EXISTS "${SCRIPT_WORKING_DIR}/../../.git")
execute_process(COMMAND ${GIT_EXECUTABLE} fetch origin --tags --force WORKING_DIRECTORY ${SCRIPT_WORKING_DIR})
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match HEAD --exclude=latest --exclude=nightly
OUTPUT_VARIABLE SD2PSX_VERSION WORKING_DIRECTORY ${SCRIPT_WORKING_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE SD2PSX_COMMIT WORKING_DIRECTORY ${SCRIPT_WORKING_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE SD2PSX_BRANCH WORKING_DIRECTORY ${SCRIPT_WORKING_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "\n$" "" SD2PSX_VERSION "${SD2PSX_VERSION}")
string(REGEX REPLACE "\n$" "" SD2PSX_COMMIT "${SD2PSX_COMMIT}")
string(REGEX REPLACE "\n$" "" SD2PSX_BRANCH "${SD2PSX_BRANCH}")
if("${SD2PSX_VERSION}" STREQUAL "")
set(SD2PSX_VERSION "nightly")
endif()
else()
set(SD2PSX_VERSION "None")
set(SD2PSX_COMMIT "None")
set(SD2PSX_BRANCH "None")
endif()

file(READ ${SCRIPT_TEMPLATE} template_file)

string(REPLACE "@SD2PSX_VERSION@" ${SD2PSX_VERSION} template_file "${template_file}")
string(REPLACE "@SD2PSX_COMMIT@" ${SD2PSX_COMMIT} template_file "${template_file}")
string(REPLACE "@SD2PSX_BRANCH@" ${SD2PSX_BRANCH} template_file "${template_file}")

file(WRITE ${SCRIPT_OUTPUT_FILE} "${template_file}")
2 changes: 1 addition & 1 deletion src/version/template/version.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "version/version.h"
#include "version.h"

const char* sd2psx_version = "@SD2PSX_VERSION@";
const char* sd2psx_commit = "@SD2PSX_COMMIT@";
Expand Down

0 comments on commit 5ddd995

Please sign in to comment.