print_version.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/bin/sh
  2. ## Copyright (c) 2016 Minoca Corp. All Rights Reserved.
  3. ##
  4. ## Script Name:
  5. ##
  6. ## print_version.sh <file> <form> <major> <minor> <revision> <release>
  7. ## <serial> <build_string>
  8. ##
  9. ## Abstract:
  10. ##
  11. ## This script either prints the current version, or creates a version.h
  12. ## header file.
  13. ##
  14. ## Author:
  15. ##
  16. ## Evan Green 13-May-2014
  17. ##
  18. ## Environment:
  19. ##
  20. ## Minoca (Windows) Build
  21. ##
  22. file="$1"
  23. form="$2"
  24. major="$3"
  25. minor="$4"
  26. revision="$5"
  27. release="$6"
  28. serial="$7"
  29. build_string="$8"
  30. [ "$major" ] || major=0
  31. [ "$minor" ] || minor=0
  32. [ "$revision" ] || revision=0
  33. [ "$release" ] || release=SystemReleaseDevelopment
  34. license="All rights reserved."
  35. cd $SRCROOT/os
  36. ##
  37. ## The serial number is the commit count. Use the hardcoded version in a file
  38. ## if it's supplied, or generate by counting commits in git.
  39. ##
  40. if [ -z "$serial" ]; then
  41. if [ -r "$SRCROOT/os/revision" ]; then
  42. serial=`cat "$SRCROOT/os/revision"`
  43. else
  44. ##
  45. ## If this is the OS repository and it has not been git replaced with
  46. ## the old history, add 1000.
  47. ##
  48. os_init_rev=1598fc5f1734f7d7ee01e014ee64e131601b78a7
  49. serial=`git rev-list --count HEAD`
  50. if [ x`git rev-list --max-parents=0 HEAD` = x$os_init_rev ]; then
  51. serial=$(($serial + 1000))
  52. else
  53. serial=$(($serial + 1))
  54. fi
  55. fi
  56. fi
  57. ##
  58. ## Get the build time in seconds since the Minoca epoch, which is January 1,
  59. ## 2000.
  60. ##
  61. build_time=$((`date +%s` - 978307200))
  62. build_time_string=`date "+%b %d %Y %H:%M:%S"`
  63. ##
  64. ## Generate the build string if needed.
  65. ##
  66. if [ -z "$build_string" ]; then
  67. if [ -r "$SRCROOT/os/branch" ]; then
  68. branch=`cat $SRCROOT/os/branch`
  69. else
  70. branch=`git rev-parse --abbrev-ref HEAD`
  71. fi
  72. if [ -r "$SRCROOT/os/commit" ]; then
  73. commit=`cat $SRCROOT/os/commit`
  74. else
  75. commit=`git rev-parse HEAD`
  76. fi
  77. commit_abbrev=`echo $commit | cut -c1-7`
  78. commit8=`echo $commit | cut -c1-8`
  79. user="$USER"
  80. [ $user ] || user="$LOGNAME"
  81. [ $user ] || user="$USERNAME"
  82. [ "$user" = root ] && user=
  83. [ $VARIANT ] && build_string="${VARIANT}-"
  84. [ $user ] && build_string="${build_string}${user}-"
  85. [ $branch != "master" ] && build_string="${build_string}${branch}-"
  86. build_string="${build_string}${commit_abbrev}"
  87. build_string="$build_string $build_time_string"
  88. fi
  89. ##
  90. ## For simple revisions, just print out the basic version number.
  91. ##
  92. if [ "$form" == "simple" ]; then
  93. printf "$major.$minor.$revision.$serial" > $file
  94. exit 0
  95. fi
  96. if [ "$form" != "header" ]; then
  97. echo "Error: unknown form $form."
  98. exit 1
  99. fi
  100. comment_year=`date +%Y`
  101. comment_date=`date +%e-%b-%Y`
  102. file_name=`basename $file`
  103. cat >"$file" <<_EOS
  104. /*++
  105. Copyright (c) $comment_year Minoca Corp. All Rights Reserved
  106. Module Name:
  107. $file_name
  108. Abstract:
  109. This header contains generated version information.
  110. This file is automatically generated.
  111. Author:
  112. Minoca Build $comment_date
  113. --*/
  114. //
  115. // ---------------------------------------------------------------- Definitions
  116. //
  117. #define VERSION_MAJOR $major
  118. #define VERSION_MINOR $minor
  119. #define VERSION_REVISION $revision
  120. #define VERSION_RELEASE $release
  121. #define VERSION_SERIAL $serial
  122. #define VERSION_BUILD_STRING "$build_string"
  123. #define VERSION_BUILD_TIME $build_time
  124. #define VERSION_BUILD_TIME_STRING "$build_time_string"
  125. //
  126. // The full commit number string.
  127. //
  128. #define VERSION_COMMIT_STRING "$commit"
  129. //
  130. // The abbreviated commit number string.
  131. //
  132. #define VERSION_COMMIT_ABBREVIATED "$commit_abbrev"
  133. //
  134. // An integer of the first 32 bits of the commit.
  135. //
  136. #define VERSION_COMMIT_NUMBER 0x$commit8
  137. //
  138. // The current branch name.
  139. //
  140. #define VERSION_BRANCH "$branch"
  141. //
  142. // The user name of the soul doing the building.
  143. //
  144. #define VERSION_BUILD_USER "$user"
  145. //
  146. // The license under which the software is released.
  147. //
  148. #define VERSION_LICENSE "$license"
  149. _EOS