Skip to content

Commit

Permalink
- Change updaterevision to a CMake script
Browse files Browse the repository at this point in the history
The benefit to this is fairly small, but it does mean a little less work needs
to be done in the build scripts for cross compiling. The C version wasn't
especially concise so it was not obviously better in any way.
  • Loading branch information
Blzut3 authored and coelckers committed Feb 2, 2020
1 parent d527866 commit 62e9e0c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 185 deletions.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -426,9 +426,9 @@ endif()
# Update gitinfo.h

add_custom_target( revision_check ALL
COMMAND updaterevision src/gitinfo.h
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/tools/updaterevision/UpdateRevision.cmake" src/gitinfo.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS updaterevision )
)

# Libraries ZDoom needs

Expand Down
1 change: 0 additions & 1 deletion tools/CMakeLists.txt
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required( VERSION 2.8.7 )

add_subdirectory( re2c )
add_subdirectory( lemon )
add_subdirectory( updaterevision )
add_subdirectory( zipdir )

set( CROSS_EXPORTS ${CROSS_EXPORTS} PARENT_SCOPE )
24 changes: 0 additions & 24 deletions tools/updaterevision/CMakeLists.txt

This file was deleted.

91 changes: 91 additions & 0 deletions tools/updaterevision/UpdateRevision.cmake
@@ -0,0 +1,91 @@
#!/usr/bin/cmake -P

# UpdateRevision.cmake
#
# Public domain. This program uses git commands command to get
# various bits of repository status for a particular directory
# and writes it into a header file so that it can be used for a
# project's versioning.

# Boilerplate to return a variable from a function.
macro(ret_var VAR)
set(${VAR} "${${VAR}}" PARENT_SCOPE)
endmacro()

# Populate variables "Hash", "Tag", and "Timestamp" with relevant information
# from source repository. If anything goes wrong return something in "Error."
function(query_repo_info)
execute_process(
COMMAND git describe --tags --dirty=-m
RESULT_VARIABLE Error
OUTPUT_VARIABLE Tag
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT "${Error}" STREQUAL "0")
ret_var(Error)
return()
endif()

execute_process(
COMMAND git log -1 "--format=%ai;%H"
RESULT_VARIABLE Error
OUTPUT_VARIABLE CommitInfo
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT "${Error}" STREQUAL "0")
ret_var(Error)
return()
endif()

list(GET CommitInfo 0 Timestamp)
list(GET CommitInfo 1 Hash)

ret_var(Tag)
ret_var(Timestamp)
ret_var(Hash)
endfunction()

# Although configure_file doesn't overwrite the file if the contents are the
# same we can't easily observe that to change the status message. This
# function parses the existing file (if it exists) and puts the hash in
# variable "OldHash"
function(get_existing_hash File)
if(EXISTS "${File}")
file(STRINGS "${File}" OldHash LIMIT_COUNT 1)
if(OldHash)
string(SUBSTRING "${OldHash}" 3 -1 OldHash)
ret_var(OldHash)
endif()
endif()
endfunction()

function(main)
if(NOT CMAKE_ARGC EQUAL 4) # cmake -P UpdateRevision.cmake <OutputFile>
message("Usage: ${CMAKE_ARGV2} <path to gitinfo.h>")
return()
endif()
set(OutputFile "${CMAKE_ARGV3}")

get_filename_component(ScriptDir "${CMAKE_SCRIPT_MODE_FILE}" DIRECTORY)

query_repo_info()
if(NOT Hash)
message("Failed to get commit info: ${Error}")
set(Hash "0")
set(Tag "<unknown version>")
set(Timestamp "")
endif()

get_existing_hash("${OutputFile}")
if(Hash STREQUAL OldHash)
message("${OutputFile} is up to date at commit ${Tag}.")
return()
endif()

configure_file("${ScriptDir}/gitinfo.h.in" "${OutputFile}")
message("${OutputFile} updated to commit ${Tag}.")
endfunction()

main()
8 changes: 8 additions & 0 deletions tools/updaterevision/gitinfo.h.in
@@ -0,0 +1,8 @@
// @Hash@
//
// This file was automatically generated by the
// updaterevision tool. Do not edit by hand.

#define GIT_DESCRIPTION "@Tag@"
#define GIT_HASH "@Hash@"
#define GIT_TIME "@Timestamp@"
6 changes: 0 additions & 6 deletions tools/updaterevision/trustinfo.rc

This file was deleted.

16 changes: 0 additions & 16 deletions tools/updaterevision/trustinfo.txt

This file was deleted.

136 changes: 0 additions & 136 deletions tools/updaterevision/updaterevision.c

This file was deleted.

0 comments on commit 62e9e0c

Please sign in to comment.