[m-rev.] for review: record the git revision the Mercury compiler was compiled with
Sebastian Godelet
sebastian.godelet at outlook.com
Sat Apr 4 16:24:57 AEDT 2015
Hi,
I think this functionality would be nice to have as I've seen it
already in some other tools which are configured and build from git
repositories.
Sebastian.
--
Record the git revision the Mercury compiler was compiled with
It can be useful to check the git revision from which the Mercury
compiler was compiled from.
compiler/handle_options.m:
In display_compiler_version/2 write out the git revision the
compiler was compiled from.
configure.ac:
define GIT_REVISION macro and collect git describe output,
also define MR_GIT_REVISION in lieu of MR_VERSION.
library/library.m:
Move version/2 to version/3 and also output the git revision of the
compiler. Make version/2 a wrapper for version/3 by ignoring the
git revision output.
java/runtime/Constants.java.in:
library/erlang_conf.hrl.in:
runtime/mercury_conf.h.in:
runtime/mercury_dotnet.cs.in:
Add the grade specific MR_GIT_REVISION constant.
--
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index 5add9c3..98d2693 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -2566,9 +2566,10 @@ usage_errors(Errors, !IO) :-
usage(!IO).
display_compiler_version(!IO) :-
- library.version(Version, Fullarch),
+ library.version(Version, Fullarch, GitRevision),
io.write_strings([
"Mercury Compiler, version ", Version, ", on ", Fullarch, "\n",
+ "Git revision ", GitRevision, "\n",
"Copyright (C) 1993-2012 The University of Melbourne\n",
"Copyright (C) 2013-2015 The Mercury team\n"
], !IO).
diff --git a/configure.ac b/configure.ac
index b11f4b1..d21c243 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,16 @@ AC_CANONICAL_HOST
FULLARCH="$host"
AC_SUBST(FULLARCH)
AC_DEFINE_UNQUOTED(MR_FULLARCH, "$FULLARCH")
+AC_MSG_CHECKING([git revision])
+GIT_REVISION=$(git describe --tags 2>/dev/null)
+if test -z "$GIT_REVISION"; then
+ AC_MSG_RESULT([no])
+ GIT_REVISION="unknown"
+else
+ AC_MSG_RESULT([$GIT_REVISION])
+fi
+AC_SUBST(GIT_VESION)
+AC_DEFINE_UNQUOTED(MR_GIT_REVISION, "$GIT_REVISION")
. ./VERSION
AC_DEFINE_UNQUOTED(MR_VERSION, "$VERSION")
if test "$prefix" = "NONE"; then
@@ -268,6 +278,7 @@ AC_SUBST(CYGPATHU)
PREFIX="`$CYGPATH $PREFIX`"
LIBDIR="`$CYGPATH $PREFIX/lib/mercury`"
NONSHARED_LIB_DIR=${MERCURY_NONSHARED_LIB_DIR=$PREFIX/lib/nonshared}
+AC_SUBST(GIT_REVISION)
AC_SUBST(VERSION)
AC_SUBST(PREFIX)
AC_SUBST(NONSHARED_LIB_DIR)
diff --git a/java/runtime/Constants.java.in b/java/runtime/Constants.java.in
index 2731d32..49b797e 100644
--- a/java/runtime/Constants.java.in
+++ b/java/runtime/Constants.java.in
@@ -13,4 +13,5 @@ package jmercury.runtime;
public class Constants {
public static final java.lang.String MR_VERSION = "@VERSION@";
public static final java.lang.String MR_FULLARCH = "@FULLARCH@";
+ public static final java.lang.String MR_GIT_REVISION = "@GIT_REVISION@";
}
diff --git a/library/erlang_conf.hrl.in b/library/erlang_conf.hrl.in
index 4fa064d..752b6ba 100644
--- a/library/erlang_conf.hrl.in
+++ b/library/erlang_conf.hrl.in
@@ -19,6 +19,7 @@
-define(MR_VERSION, "@VERSION@").
-define(MR_FULLARCH, "@FULLARCH@").
+-define(MR_GIT_REVISION, "@GIT_REVISION@").
-endif.
diff --git a/library/library.m b/library/library.m
index 5b7fff9..87fa88a 100644
--- a/library/library.m
+++ b/library/library.m
@@ -21,6 +21,10 @@
%
:- pred library.version(string::out, string::out) is det.
+ % version(VersionString, FullarchString, GitRevision)
+ %
+:- pred library.version(string::out, string::out, string::out) is det.
+
:- implementation.
% Everything below here is not intended to be part of the public
interface,
@@ -178,52 +182,62 @@
").
% library.version must be implemented using pragma foreign_proc,
-% so we can get at the MR_VERSION and MR_FULLARCH configuration
-% parameters. We can't just generate library.m from library.m.in
-% at configuration time, because that would cause bootstrapping problems --
-% we might not have a Mercury compiler around to compile library.m with.
+% so we can get at the MR_VERSION, MR_FULLARCH and MR_GIT_REVISION
+% configuration parameters. We can't just generate library.m from
+% library.m.in at configuration time, because that would cause
+% bootstrapping problems -- we might not have a Mercury compiler
+% around to compile library.m with.
% We can't allow library.version to inlined into other modules. The
Erlang
% definition depends on erlang_conf.hrl, which will only be included
by this
% module and not installed.
:- pragma no_inline(library.version/2).
+:- pragma no_inline(library.version/3).
+
+library.version(Version::out, Fullarch::out) :-
+ library.version(Version, Fullarch, _GitRevision).
:- pragma foreign_proc("C",
- library.version(Version::out, Fullarch::out),
+ library.version(Version::out, Fullarch::out, GitRevision::out),
[will_not_call_mercury, promise_pure, thread_safe,
will_not_modify_trail],
"
MR_ConstString version_string = MR_VERSION;
MR_ConstString fullarch_string = MR_FULLARCH;
+ MR_ConstString git_revision_string = MR_GIT_REVISION;
/*
** Cast away const needed here, because Mercury declares Version
** with type MR_String rather than MR_ConstString.
*/
Version = (MR_String) (MR_Word) version_string;
Fullarch = (MR_String) (MR_Word) fullarch_string;
+ GitRevision = (MR_String) (MR_Word) git_revision_string;
").
:- pragma foreign_proc("C#",
- library.version(Version::out, Fullarch::out),
+ library.version(Version::out, Fullarch::out, GitRevision::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
Version = runtime.Constants.MR_VERSION;
Fullarch = runtime.Constants.MR_FULLARCH;
+ GitRevision = runtime.Constants.MR_GIT_REVISION;
").
:- pragma foreign_proc("Java",
- library.version(Version::out, Fullarch::out),
+ library.version(Version::out, Fullarch::out, GitRevision::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
Version = jmercury.runtime.Constants.MR_VERSION;
Fullarch = jmercury.runtime.Constants.MR_FULLARCH;
+ GitRevision = jmercury.runtime.Constants.MR_GIT_REVISION;
").
:- pragma foreign_proc("Erlang",
- library.version(Version::out, Fullarch::out),
+ library.version(Version::out, Fullarch::out, GitRevision::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
Version = << ?MR_VERSION >>,
- Fullarch = << ?MR_FULLARCH >>
+ Fullarch = << ?MR_FULLARCH >>,
+ GitRevision = << ?MR_GIT_REVISION >>
").
%---------------------------------------------------------------------------%
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index d70d1e5..9796b1d 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -497,6 +497,11 @@
#define MR_FULLARCH "unknown"
/*
+** Which git revision is used to build Mercury?
+*/
+#define MR_GIT_REVISION "unknown"
+
+/*
** Should we build the Mercury libraries as Windows DLLs?
*/
#undef MR_USE_DLLS
diff --git a/runtime/mercury_dotnet.cs.in b/runtime/mercury_dotnet.cs.in
index 938c523..a9d35ae 100644
--- a/runtime/mercury_dotnet.cs.in
+++ b/runtime/mercury_dotnet.cs.in
@@ -1005,11 +1005,12 @@ public class ThreadLocalMutables
public class Constants
{
- public static readonly int MR_PREDICATE = 0;
- public static readonly int MR_FUNCTION = 1;
+ public static readonly int MR_PREDICATE = 0;
+ public static readonly int MR_FUNCTION = 1;
- public static readonly string MR_VERSION = "@VERSION@";
- public static readonly string MR_FULLARCH = "@FULLARCH@";
+ public static readonly string MR_VERSION = "@VERSION@";
+ public static readonly string MR_FULLARCH = "@FULLARCH@";
+ public static readonly string MR_GIT_REVISION = "@GIT_REVISION@";
}
/*---------------------------------------------------------------------------*/
More information about the reviews
mailing list