Skip to content

Commit a00a972

Browse files
committed
Add date and hash to publishing version
1 parent fbf44eb commit a00a972

File tree

6 files changed

+74
-2
lines changed

6 files changed

+74
-2
lines changed

project/Build.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ object DottyBuild extends Build {
2525
override def settings: Seq[Setting[_]] = {
2626
super.settings ++ Seq(
2727
scalaVersion in Global := "2.11.5",
28-
version in Global := "0.1-SNAPSHOT",
28+
version in Global :=
29+
"0.1-SNAPSHOT-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash,
2930
organization in Global := "ch.epfl.lamp",
3031
organizationName in Global := "LAMP/EPFL",
3132
organizationHomepage in Global := Some(url("http://lamp.epfl.ch")),
@@ -208,7 +209,8 @@ object DottyBuild extends Build {
208209
"org.scala-sbt" % "api" % sbtVersion.value % "test",
209210
"org.specs2" %% "specs2" % "2.3.11" % "test"
210211
),
211-
version := "0.1.1-SNAPSHOT",
212+
version :=
213+
"0.1.1-SNAPSHOT-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash,
212214
// The sources should be published with crossPaths := false, the binaries
213215
// are unused so it doesn't matter.
214216
crossPaths := false,

project/VersionUtil.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.sys.process.Process
2+
3+
object VersionUtil {
4+
def executeScript(scriptName: String) = {
5+
val cmd =
6+
if (System.getProperty("os.name").toLowerCase.contains("windows"))
7+
s"cmd.exe /c scripts\\build\\$scriptName.bat -p"
8+
else s"scripts/build/$scriptName"
9+
Process(cmd).lines.head.trim
10+
}
11+
12+
/** Seven letters of the SHA hash is considered enough to uniquely identify a
13+
* commit, albeit extremely large projects - such as the Linux kernel - need
14+
* more letters to stay unique
15+
*/
16+
def gitHash = executeScript("get-scala-commit-sha").substring(0, 7)
17+
def commitDate = executeScript("get-scala-commit-date")
18+
}

scripts/build/get-scala-commit-date

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: get-scala-commit-date [dir]
4+
# Figures out current commit date of a git clone.
5+
# If no dir is given, current working dir is used.
6+
#
7+
# Example build version string:
8+
# 20120312
9+
#
10+
11+
[[ $# -eq 0 ]] || cd "$1"
12+
13+
lastcommitdate=$(git log --format="%ci" HEAD | head -n 1 | cut -d ' ' -f 1)
14+
15+
# 20120324
16+
echo "${lastcommitdate//-/}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
for %%X in (bash.exe) do (set FOUND=%%~$PATH:X)
3+
if defined FOUND (
4+
bash "%~dp0\get-scala-commit-date" 2>NUL
5+
) else (
6+
rem echo this script does not work with cmd.exe. please, install bash
7+
echo unknown
8+
exit 1
9+
)

scripts/build/get-scala-commit-sha

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage: get-scala-commit-sha [dir]
4+
# Figures out current commit sha of a git clone.
5+
# If no dir is given, current working dir is used.
6+
#
7+
# Example build version string:
8+
# 6f1c486d0ba
9+
#
10+
11+
[[ $# -eq 0 ]] || cd "$1"
12+
13+
# printf %016s is not portable for 0-padding, has to be a digit.
14+
# so we're stuck disassembling it.
15+
hash=$(git log -1 --format="%H" HEAD)
16+
hash=${hash#g}
17+
hash=${hash:0:10}
18+
echo "$hash"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
for %%X in (bash.exe) do (set FOUND=%%~$PATH:X)
3+
if defined FOUND (
4+
bash "%~dp0\get-scala-commit-sha" 2>NUL
5+
) else (
6+
rem echo this script does not work with cmd.exe. please, install bash
7+
echo unknown
8+
exit 1
9+
)

0 commit comments

Comments
 (0)