diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-06-08 10:50:38 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-06-09 11:38:40 +0200 |
commit | a00a972c7425232432364bf991e118d248578f0d (patch) | |
tree | 6a59f3ec71facdbea462773c6b2e5d1a65b6c9ac | |
parent | fbf44ebaf4ae80cbc10613b759beb1f0167b19c6 (diff) | |
download | dotty-a00a972c7425232432364bf991e118d248578f0d.tar.gz dotty-a00a972c7425232432364bf991e118d248578f0d.tar.bz2 dotty-a00a972c7425232432364bf991e118d248578f0d.zip |
Add date and hash to publishing version
-rw-r--r-- | project/Build.scala | 6 | ||||
-rw-r--r-- | project/VersionUtil.scala | 18 | ||||
-rwxr-xr-x | scripts/build/get-scala-commit-date | 16 | ||||
-rw-r--r-- | scripts/build/get-scala-commit-date.bat | 9 | ||||
-rwxr-xr-x | scripts/build/get-scala-commit-sha | 18 | ||||
-rw-r--r-- | scripts/build/get-scala-commit-sha.bat | 9 |
6 files changed, 74 insertions, 2 deletions
diff --git a/project/Build.scala b/project/Build.scala index c07fab230..85a7bb861 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -25,7 +25,8 @@ object DottyBuild extends Build { override def settings: Seq[Setting[_]] = { super.settings ++ Seq( scalaVersion in Global := "2.11.5", - version in Global := "0.1-SNAPSHOT", + version in Global := + "0.1-SNAPSHOT-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash, organization in Global := "ch.epfl.lamp", organizationName in Global := "LAMP/EPFL", organizationHomepage in Global := Some(url("http://lamp.epfl.ch")), @@ -208,7 +209,8 @@ object DottyBuild extends Build { "org.scala-sbt" % "api" % sbtVersion.value % "test", "org.specs2" %% "specs2" % "2.3.11" % "test" ), - version := "0.1.1-SNAPSHOT", + version := + "0.1.1-SNAPSHOT-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash, // The sources should be published with crossPaths := false, the binaries // are unused so it doesn't matter. crossPaths := false, diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala new file mode 100644 index 000000000..338cf2d95 --- /dev/null +++ b/project/VersionUtil.scala @@ -0,0 +1,18 @@ +import scala.sys.process.Process + +object VersionUtil { + def executeScript(scriptName: String) = { + val cmd = + if (System.getProperty("os.name").toLowerCase.contains("windows")) + s"cmd.exe /c scripts\\build\\$scriptName.bat -p" + else s"scripts/build/$scriptName" + Process(cmd).lines.head.trim + } + + /** Seven letters of the SHA hash is considered enough to uniquely identify a + * commit, albeit extremely large projects - such as the Linux kernel - need + * more letters to stay unique + */ + def gitHash = executeScript("get-scala-commit-sha").substring(0, 7) + def commitDate = executeScript("get-scala-commit-date") +} diff --git a/scripts/build/get-scala-commit-date b/scripts/build/get-scala-commit-date new file mode 100755 index 000000000..ef5b0f540 --- /dev/null +++ b/scripts/build/get-scala-commit-date @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# +# Usage: get-scala-commit-date [dir] +# Figures out current commit date of a git clone. +# If no dir is given, current working dir is used. +# +# Example build version string: +# 20120312 +# + +[[ $# -eq 0 ]] || cd "$1" + +lastcommitdate=$(git log --format="%ci" HEAD | head -n 1 | cut -d ' ' -f 1) + +# 20120324 +echo "${lastcommitdate//-/}" diff --git a/scripts/build/get-scala-commit-date.bat b/scripts/build/get-scala-commit-date.bat new file mode 100644 index 000000000..735a80b92 --- /dev/null +++ b/scripts/build/get-scala-commit-date.bat @@ -0,0 +1,9 @@ +@echo off +for %%X in (bash.exe) do (set FOUND=%%~$PATH:X) +if defined FOUND ( + bash "%~dp0\get-scala-commit-date" 2>NUL +) else ( + rem echo this script does not work with cmd.exe. please, install bash + echo unknown + exit 1 +) diff --git a/scripts/build/get-scala-commit-sha b/scripts/build/get-scala-commit-sha new file mode 100755 index 000000000..eab90a421 --- /dev/null +++ b/scripts/build/get-scala-commit-sha @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# +# Usage: get-scala-commit-sha [dir] +# Figures out current commit sha of a git clone. +# If no dir is given, current working dir is used. +# +# Example build version string: +# 6f1c486d0ba +# + +[[ $# -eq 0 ]] || cd "$1" + +# printf %016s is not portable for 0-padding, has to be a digit. +# so we're stuck disassembling it. +hash=$(git log -1 --format="%H" HEAD) +hash=${hash#g} +hash=${hash:0:10} +echo "$hash" diff --git a/scripts/build/get-scala-commit-sha.bat b/scripts/build/get-scala-commit-sha.bat new file mode 100644 index 000000000..6559a1912 --- /dev/null +++ b/scripts/build/get-scala-commit-sha.bat @@ -0,0 +1,9 @@ +@echo off +for %%X in (bash.exe) do (set FOUND=%%~$PATH:X) +if defined FOUND ( + bash "%~dp0\get-scala-commit-sha" 2>NUL +) else ( + rem echo this script does not work with cmd.exe. please, install bash + echo unknown + exit 1 +) |