Author Topic: How to specify version  (Read 1491 times)

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
How to specify version
« on: 30 May 2011, 00:32:22 »
I've seen people are specifying the version as git-master but this is a moving target - a week from now it could be several commits away. It should really only be used to specify that it is master branch. The commit hash or number of commits from a tag should also be included (git describe does both). This is contradictory to what is being used for version in the crash logs (other places too?). Perhaps there is a way to create a file that is updated each build like here. It would also solve the issue with build date in the crash logs (it only updates if the file with the preprossor string is explicitly told to compile).

Edit:
This could be used in CMake to add a custom build rule. http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_command
Code: [Select]
add_custom_command(TARGET target
                     PRE_BUILD | PRE_LINK | POST_BUILD
                     COMMAND command1 [ARGS] [args1...]
                     [COMMAND command2 [ARGS] [args2...] ...]
                     [WORKING_DIRECTORY dir]
                     [COMMENT comment] [VERBATIM])
Something like this for source/game/CMakeLists.txt:
Code: [Select]
if(WIN32)
add_custom_command(TARGET glestadv PRE_LINK COMMAND version.bat)
else(WIN32)
add_custom_command(TARGET glestadv PRE_LINK COMMAND version.sh)
endif(WIN32)

Edit2:
I've committed something that might work (it does for me anyway with VS).
« Last Edit: 30 May 2011, 05:42:54 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

Yggdrasil

  • Local Moderator
  • Ornithopter
  • ********
  • Posts: 408
    • View Profile
Re: How to specify version
« Reply #1 on: 30 May 2011, 12:43:50 »
Mhmm, doesn't really work for me. game_incs holds a list of folders where headers are located, not header files. The shell script creates version.c instead of version.cpp.

Anyway we already set the version in cmake through projectConfig.h, so maybe it's better to do it in cmake. Something like this:
Code: [Select]
# only run this when we build from git, not tarball, and we haven't set GAE_VERSION explicitly
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GAE_VERSION STREQUAL "git-master")
        find_package(Git REQUIRED)
        execute_process(COMMAND "${GIT_EXECUTABLE}" describe
                WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
                RESULT_VARIABLE res
                OUTPUT_VARIABLE GAE_VERSION
                OUTPUT_STRIP_TRAILING_WHITESPACE
        )
        message("GAE_VERSION is ${GAE_VERSION}")
endif()
The git-master comparison is probably a bit silly and looks strange but it should work because the new GAE_VERSION from git describe isn't written to the cmake cache. That's why another run of cmake reads the old value from the cache and we can change it again.

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: How to specify version
« Reply #2 on: 30 May 2011, 13:57:31 »
Mhmm, doesn't really work for me. game_incs holds a list of folders where headers are located, not header files. The shell script creates version.c instead of version.cpp.
It should be ok to remove the game_incs line since I think version.h is added like pch.h from the same folder. I forgot to change the filename, I will fix, thanks.

Anyway we already set the version in cmake through projectConfig.h, so maybe it's better to do it in cmake. Something like this:
I think the big problem doing it that way is the overhead of modifying a header each build. The script way completes in under a second. The scripts also include build datetime. We might be able to do without the CMake set version string since git describe includes the last tag, so when we go to tag 0.4 it will display "0.4-0-[hash]" (maybe? or just the tag), although it might be good to keep it to specify the branch.

Edit:
It might be good to add other information like build_platform and build_configuration.
« Last Edit: 31 May 2011, 01:02:04 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: How to specify version
« Reply #3 on: 3 June 2011, 11:16:19 »
Anyway we already set the version in cmake through projectConfig.h, so maybe it's better to do it in cmake. Something like this:
I think the big problem doing it that way is the overhead of modifying a header each build. The script way completes in under a second.
:thumbup:

Quote
Edit:
It might be good to add other information like build_platform and build_configuration.

It might also be good to write build_git_sha into the log files too (and send to stdout as well maybe).
Glest Advanced Engine - Code Monkey

Timeline | Downloads

 

anything