[commit: ghc] master: Embed Git commit id into `ghc --info` output (73e5e2f)

git at git.haskell.org git at git.haskell.org
Thu Nov 27 20:59:40 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/73e5e2f8bade2d8b2b1ecae958fe12d0b24591ef/ghc

>---------------------------------------------------------------

commit 73e5e2f8bade2d8b2b1ecae958fe12d0b24591ef
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Thu Nov 27 10:50:51 2014 +0100

    Embed Git commit id into `ghc --info` output
    
    Since we switched to a Git submodule based GHC Git repo, `ghc.git`'s
    commit id uniquely identifies the state of the GHC source-tree. So
    having that information embedded into the `ghc` executable provides
    valuable information to track accurately (especially when created by
    buildbots) from which source-tree-state a given `ghc` snapshot
    (distribution) was generated.
    
    So this commit adds a new field `"Project Git commit id"` to the
    `ghc --info` meta-data containing the `./configure`-time Git commit id
    as reported by `git rev-parse HEAD`.
    
    This field can also be queried with `ghc --print-project-git-commit-id`.
    
    For source distributions, the file `GIT_COMMIT_ID` is created (with some
    sanity checking to detect stale commit ids, as that would render this
    information rather useless)
    
    Reviewed By: austin
    
    Differential Revision: https://phabricator.haskell.org/D528


>---------------------------------------------------------------

73e5e2f8bade2d8b2b1ecae958fe12d0b24591ef
 .gitignore                |  1 +
 aclocal.m4                | 18 ++++++++++++++++++
 compiler/ghc.mk           |  2 ++
 compiler/main/DynFlags.hs |  1 +
 configure.ac              |  1 +
 ghc.mk                    | 18 ++++++++++++++++--
 ghc/Main.hs               |  1 +
 mk/project.mk.in          |  1 +
 8 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5a58ed2..7d53060 100644
--- a/.gitignore
+++ b/.gitignore
@@ -153,3 +153,4 @@ _darcs/
 
 .tm_properties
 VERSION
+GIT_COMMIT_ID
diff --git a/aclocal.m4 b/aclocal.m4
index b41bf41..2aa55d7 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1581,11 +1581,29 @@ if test "$RELEASE" = "NO"; then
         dnl less likely to go wrong.
         PACKAGE_VERSION=${PACKAGE_VERSION}.`date +%Y%m%d`
     fi
+
+    AC_MSG_CHECKING([for GHC Git commit id])
+    if test -d .git; then
+        git_commit_id=`git rev-parse HEAD`
+        if test -n "$git_commit_id" 2>&1 >/dev/null; then true; else
+            AC_MSG_ERROR([failed to detect revision: check that git is in your path])
+        fi
+        PACKAGE_GIT_COMMIT_ID=$git_commit_id
+        AC_MSG_RESULT(inferred $PACKAGE_GIT_COMMIT_ID)
+    elif test -f GIT_COMMIT_ID; then
+        PACKAGE_GIT_COMMIT_ID=`cat GIT_COMMIT_ID`
+        AC_MSG_RESULT(given $PACKAGE_GIT_COMMIT_ID)
+    else
+        AC_MSG_WARN([cannot determine snapshot revision: no .git directory and no 'GIT_COMMIT_ID' file])
+        PACKAGE_GIT_COMMIT_ID="0000000000000000000000000000000000000000"
+    fi
+
 fi
 
 # Some renamings
 AC_SUBST([ProjectName], [$PACKAGE_NAME])
 AC_SUBST([ProjectVersion], [$PACKAGE_VERSION])
+AC_SUBST([ProjectGitCommitId], [$PACKAGE_GIT_COMMIT_ID])
 
 # Split PACKAGE_VERSION into (possibly empty) parts
 VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/`
diff --git a/compiler/ghc.mk b/compiler/ghc.mk
index ffa91a5..2912aab 100644
--- a/compiler/ghc.mk
+++ b/compiler/ghc.mk
@@ -67,6 +67,8 @@ compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
 	@echo                                                               >> $@
 	@echo 'cProjectName          :: String'                             >> $@
 	@echo 'cProjectName          = "$(ProjectName)"'                    >> $@
+	@echo 'cProjectGitCommitId   :: String'				    >> $@
+	@echo 'cProjectGitCommitId   = "$(ProjectGitCommitId)"'		    >> $@
 	@echo 'cProjectVersion       :: String'                             >> $@
 	@echo 'cProjectVersion       = "$(ProjectVersion)"'                 >> $@
 	@echo 'cProjectVersionInt    :: String'                             >> $@
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index d6f620f..11e5c32 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -3781,6 +3781,7 @@ compilerInfo dflags
       -- key)
     : rawSettings dflags
    ++ [("Project version",             cProjectVersion),
+       ("Project Git commit id",       cProjectGitCommitId),
        ("Booter version",              cBooterVersion),
        ("Stage",                       cStage),
        ("Build platform",              cBuildPlatformString),
diff --git a/configure.ac b/configure.ac
index ca9f220..97fdc2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1005,6 +1005,7 @@ echo ["
 Configure completed successfully.
 
    Building GHC version  : $ProjectVersion
+          Git commit id  : $ProjectGitCommitId
 
    Build platform        : $BuildPlatform
    Host platform         : $HostPlatform
diff --git a/ghc.mk b/ghc.mk
index a93628a..c47104d 100644
--- a/ghc.mk
+++ b/ghc.mk
@@ -1109,13 +1109,27 @@ SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
 SRC_DIST_GHC_FILES += \
     configure.ac config.guess config.sub configure \
     aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
-    settings.in VERSION \
+    settings.in VERSION GIT_COMMIT_ID \
     boot packages ghc.mk
 
 VERSION :
 	echo $(ProjectVersion) >VERSION
 
-sdist : VERSION
+.PHONY: GIT_COMMIT_ID
+GIT_COMMIT_ID:
+	@if test -d .git && test "`git rev-parse HEAD`" != "$(ProjectGitCommitId)"; then \
+	   echo "******************************************************************************"; \
+	   echo "Stale ProjectGitCommitId (=$(ProjectGitCommitId)) detected!"; \
+           echo "'git rev-parse HEAD' says: `git rev-parse HEAD`"; \
+	   echo "Please re-run './configure' before creating source-distribution"; \
+	   echo "******************************************************************************"; \
+	   exit 1; \
+	fi
+	@if test -f $@ && test "`cat $@`" = "$(ProjectGitCommitId)"; \
+	then echo "$@ needs no update"; \
+	else echo "update $@ ($(ProjectGitCommitId))"; echo -n "$(ProjectGitCommitId)" > $@; fi
+
+sdist : VERSION GIT_COMMIT_ID
 
 # Use:
 #     $(call sdist_ghc_file,compiler,stage2,cmm,Foo/Bar,CmmLex,x)
diff --git a/ghc/Main.hs b/ghc/Main.hs
index d706914..f0539df 100644
--- a/ghc/Main.hs
+++ b/ghc/Main.hs
@@ -541,6 +541,7 @@ mode_flags =
   ] ++
   [ defFlag k'                      (PassFlag (setMode (printSetting k)))
   | k <- ["Project version",
+          "Project Git commit id",
           "Booter version",
           "Stage",
           "Build platform",
diff --git a/mk/project.mk.in b/mk/project.mk.in
index 129b540..a5fe210 100644
--- a/mk/project.mk.in
+++ b/mk/project.mk.in
@@ -31,6 +31,7 @@ ProjectVersionInt = @ProjectVersionInt@
 ProjectPatchLevel = @ProjectPatchLevel@
 ProjectPatchLevel1 = @ProjectPatchLevel1@
 ProjectPatchLevel2 = @ProjectPatchLevel2@
+ProjectGitCommitId = @ProjectGitCommitId@
 
 ################################################################################
 #



More information about the ghc-commits mailing list