Skip to content

Commit

Permalink
DR-i#1565: set VERSION_NUMBER_PATCHLEVEL even on git log failure
Browse files Browse the repository at this point in the history
We try different ways to set VERSION_NUMBER_PATCHLEVEL on git log failure.

Review-URL: https://codereview.appspot.com/289680043
  • Loading branch information
zhaoqin committed Apr 4, 2016
1 parent 7d69d23 commit fe9124b
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions CMakeLists.txt
Expand Up @@ -160,7 +160,7 @@ endif (TOOL_DR_HEAPSTAT)
# release version as the patchlevel ver# to distinguish
# We used to use the svn revision (i#83) and we leave that code in place
# (for now at least) for anyone building an old checkout.
# For git, we follow i#1565 and use a date.
# For git, we follow DRi#1565 and use a date.
set(VERSION_NUMBER_PATCHLEVEL 0)
if (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
find_program(SVN svn DOC "subversion client")
Expand All @@ -184,22 +184,41 @@ else (EXISTS "${PROJECT_SOURCE_DIR}/.svn")
# We want the committer date (not author date) (xref DRi#1565). We request
# UNIX timestamp format and then divide down to days to get a small enough
# number for the Windows resource limits.
#
# XXX DRi#1565: to support building when not in a git repo (e.g., from a source
# tarball) we should add support for a local file holding the version.
execute_process(COMMAND ${GIT} log -n 1 --format=%ct
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_result
ERROR_VARIABLE git_err
OUTPUT_VARIABLE git_out)
if (git_result OR git_err)
message(FATAL_ERROR "*** ${GIT} log failed: ***\n${git_err}")
message("*** ${GIT} log failed: ***\n${git_err}")
else (git_result OR git_err)
math(EXPR daycount "${git_out} / (60*60*24)")
endif (git_result OR git_err)
math(EXPR daycount "${git_out} / (60*60*24)")
if (daycount)
set(VERSION_NUMBER_PATCHLEVEL "${daycount}")
endif ()
endif (GIT)
if (NOT daycount)
# XXX DRi#1565: to support building when not in a git repo (e.g., from a source
# tarball) we use date to get current time for timestamp.
# This is not ideal as it confuses the build timestamp with the commit
# timestamp. We should add support for a local file holding the version.
find_program(DATE date DOC "system date")
if (DATE)
execute_process(COMMAND ${DATE} +%s
RESULT_VARIABLE date_result
ERROR_VARIABLE date_err
OUTPUT_VARIABLE date_out)
if (date_result OR date_err)
message("*** ${DATE} failed: ***\n${date_err}")
else (date_result OR date_err)
math(EXPR daycount "${date_out} / (60*60*24)")
endif (date_result OR date_err)
endif (DATE)
endif (NOT daycount)
if (NOT daycount)
# set a much further date in the future to avoid confusing
# this fake date with the real date from git log
set(daycount 33333)
endif (NOT daycount)
set(VERSION_NUMBER_PATCHLEVEL "${daycount}")
endif (EXISTS "${PROJECT_SOURCE_DIR}/.git")
endif (EXISTS "${PROJECT_SOURCE_DIR}/.svn")

Expand Down

0 comments on commit fe9124b

Please sign in to comment.