diff options
Diffstat (limited to 'build_files')
-rw-r--r-- | build_files/cmake/buildinfo.cmake | 84 | ||||
-rw-r--r-- | build_files/scons/tools/Blender.py | 25 |
2 files changed, 97 insertions, 12 deletions
diff --git a/build_files/cmake/buildinfo.cmake b/build_files/cmake/buildinfo.cmake index e68015e36d3..ae2f87b49be 100644 --- a/build_files/cmake/buildinfo.cmake +++ b/build_files/cmake/buildinfo.cmake @@ -1,16 +1,82 @@ # This is called by cmake as an extermal process from # ./source/creator/CMakeLists.txt to write ./source/creator/buildinfo.h -# The FindSubversion.cmake module is part of the standard distribution -include(FindSubversion) - # Extract working copy information for SOURCE_DIR into MY_XXX variables # with a default in case anything fails, for examble when using git-svn -set(MY_WC_REVISION "unknown") +set(MY_WC_HASH "") +set(MY_WC_BRANCH "") +set(MY_WC_CHANGE "unknown") + # Guess if this is a SVN working copy and then look up the revision -if(EXISTS ${SOURCE_DIR}/.svn/) - if(Subversion_FOUND) - Subversion_WC_INFO(${SOURCE_DIR} MY) +if(EXISTS ${SOURCE_DIR}/.git/) + if(EXISTS ${SOURCE_DIR}/.git/) + # The FindSubversion.cmake module is part of the standard distribution + include(FindGit) + if(GIT_FOUND) + execute_process(COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE MY_WC_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE MY_WC_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Get latest version tag + execute_process(COMMAND git describe --match "v[0-9]*" --abbrev=0 + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE _git_latest_version_tag + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT _git_latest_version_tag STREQUAL "") + execute_process(COMMAND git rev-list HEAD ^${_git_latest_version_tag} --count + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE MY_WC_CHANGE + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + # For the time being we don't have annotated release tags, + # count all the revisions in branch. + execute_process(COMMAND git rev-list HEAD --count + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE MY_WC_CHANGE + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + + # Update GIT index before getting dirty files + execute_process(COMMAND git update-index -q --refresh + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process(COMMAND git diff-index --name-only HEAD -- + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE _git_changed_files + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT _git_changed_files STREQUAL "") + set(MY_WC_CHANGE "${MY_WC_CHANGE}M") + endif() + + unset(_git_changed_files) + unset(_git_latest_version_tag) + endif() + endif() +else() + # Some crazy folks like me could have hacked git-svn chekout in a way + # so svnversion gives proper svn revision for themm which required having + # empty .svn folder. + # + # For such a crazy blokes put svn check into an else branch. + # + # (sergey) + if(EXISTS ${SOURCE_DIR}/.svn/) + # The FindSubversion.cmake module is part of the standard distribution + include(FindSubversion) + + if(Subversion_FOUND) + Subversion_WC_INFO(${SOURCE_DIR} MY) + set(MY_WC_CHANGE "${MY_WC_REVISION}") + endif() endif() endif() @@ -27,7 +93,9 @@ endif() # Write a file with the SVNVERSION define file(WRITE buildinfo.h.txt - "#define BUILD_REV \"${MY_WC_REVISION}\"\n" + "#define BUILD_HASH \"${MY_WC_HASH}\"\n" + "#define BUILD_CHANGE \"${MY_WC_CHANGE}\"\n" + "#define BUILD_BRANCH \"${MY_WC_BRANCH}\"\n" "#define BUILD_DATE \"${BUILD_DATE}\"\n" "#define BUILD_TIME \"${BUILD_TIME}\"\n" ) diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py index f181f290104..b79ba991b9a 100644 --- a/build_files/scons/tools/Blender.py +++ b/build_files/scons/tools/Blender.py @@ -410,9 +410,24 @@ def buildinfo(lenv, build_type): """ build_date = time.strftime ("%Y-%m-%d") build_time = time.strftime ("%H:%M:%S") - build_rev = os.popen('svnversion').read()[:-1] # remove \n - if build_rev == '': - build_rev = '-UNKNOWN-' + if os.path.isdir(os.path.abspath('.git')): + latest_version_tag = os.popen('git describe --match "v[0-9]*" --abbrev=0').read().strip() + if latest_version_tag: + build_change = os.popen('git rev-list HEAD ' + latest_version_tag + ' --count').read().strip() + else: + build_change = os.popen('git rev-list HEAD --count').read().strip() + + build_hash = os.popen('git rev-parse --short HEAD').read().strip() + build_branch = os.popen('git rev-parse --abbrev-ref HEAD').read().strip() + elif os.path.isdir(os.path.abspath('.svn')): + build_hash = '' + build_change = os.popen('svnversion').read()[:-1] # remove \n + build_branch = '' + else: + build_hash = '' + build_change = 'unknown' + build_branch = '' + if lenv['BF_DEBUG']: build_type = "Debug" build_cflags = ' '.join(lenv['CFLAGS'] + lenv['CCFLAGS'] + lenv['BF_DEBUG_CCFLAGS'] + lenv['CPPFLAGS']) @@ -429,7 +444,9 @@ def buildinfo(lenv, build_type): lenv.Append (CPPDEFINES = ['BUILD_TIME=\\"%s\\"'%(build_time), 'BUILD_DATE=\\"%s\\"'%(build_date), 'BUILD_TYPE=\\"%s\\"'%(build_type), - 'BUILD_REV=\\"%s\\"'%(build_rev), + 'BUILD_HASH=\\"%s\\"'%(build_hash), + 'BUILD_CHANGE=\\"%s\\"'%(build_change), + 'BUILD_BRANCH=\\"%s\\"'%(build_branch), 'WITH_BUILDINFO', 'BUILD_PLATFORM=\\"%s:%s\\"'%(platform.system(), platform.architecture()[0]), 'BUILD_CFLAGS=\\"%s\\"'%(build_cflags), |