You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2013/12/05 19:09:32 UTC

git commit: Added git sha, tag and branch in state.json.

Updated Branches:
  refs/heads/master d6535587e -> 3f176033d


Added git sha, tag and branch in state.json.

Exposing build revisions and branch names can help diagnosing problems
with slaves and masters in development settings.

This patch fetches git sha, tag and branch of repo (if available) and
fills option variables BUILD_GIT_SHA, BUILD_GIT_TAG and BUILD_GIT_BRANCH
accordingly. If variables are set, master and slave state.json expose
and sets fields "git_sha", "git_tag" and "git_branch".

Review: https://reviews.apache.org/r/15169


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3f176033
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3f176033
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3f176033

Branch: refs/heads/master
Commit: 3f176033da6f35f47c7823cce6dd482f7acf1cee
Parents: d653558
Author: Niklas Q. Nielsen <ni...@mesosphere.io>
Authored: Thu Dec 5 17:33:08 2013 +0000
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Thu Dec 5 18:07:18 2013 +0000

----------------------------------------------------------------------
 configure.ac         |  1 +
 src/Makefile.am      | 18 ++++++++++++++++++
 src/common/build.cpp | 20 ++++++++++++++++++++
 src/common/build.hpp |  3 +++
 src/master/http.cpp  | 13 +++++++++++++
 src/slave/http.cpp   | 13 +++++++++++++
 6 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 63e5ce3..f69908a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -519,5 +519,6 @@ We need libsasl2 for authentication!
 -------------------------------------------------------------------
 ])])
 
+AM_CONDITIONAL([GIT_REPO], [test -d ${srcdir}"/.git"])
 
 AC_OUTPUT

http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index abef3d2..42dafbc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -260,10 +260,28 @@ libmesos_no_3rdparty_la_LIBADD = # Initialized to enable using +=.
 noinst_LTLIBRARIES += libbuild.la
 libbuild_la_SOURCES = common/build.cpp
 libbuild_la_CPPFLAGS = $(AM_CPPFLAGS)
+libbuild_la_CPPFLAGS += $(MESOS_CPPFLAGS)
 libbuild_la_CPPFLAGS += -DBUILD_DATE="\"$$(date '+%Y-%m-%d %H:%M:%S')\""
 libbuild_la_CPPFLAGS += -DBUILD_TIME="\"$$(date '+%s')\""
 libbuild_la_CPPFLAGS += -DBUILD_USER="\"$$USER\""
 
+if GIT_REPO
+    BUILD_GIT_SHA=$$(sh -c 'cd $(top_srcdir); \
+        SHA=`git log -n 1 --format=%H 2> /dev/null` && \
+	echo -DBUILD_GIT_SHA=\"$$SHA\"')
+    libbuild_la_CPPFLAGS += $(BUILD_GIT_SHA)
+
+    BUILD_GIT_BRANCH=$$(sh -c 'cd $(top_srcdir); \
+        BRANCH=`git symbolic-ref HEAD 2> /dev/null` && \
+        echo -DBUILD_GIT_BRANCH=\"$$BRANCH\"')
+    libbuild_la_CPPFLAGS += $(BUILD_GIT_BRANCH)
+
+    BUILD_GIT_TAG=$$(sh -c 'cd $(top_srcdir); \
+        TAG=`git describe --exact --tags 2> /dev/null` && \
+        echo -DBUILD_GIT_TAG=\"$$TAG\"')
+    libbuild_la_CPPFLAGS += $(BUILD_GIT_TAG)
+endif
+
 # We need to escape the build flags properly.
 BUILD_FLAGS = $(echo $(MESOS_CPPFLAGS) $(CPPFLAGS) | sed 's/\"/\\\"/g')	\
               $(echo $(AM_CFLAGS) $(CFLAGS) | sed 's/\"/\\\"/g')	\

http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/src/common/build.cpp
----------------------------------------------------------------------
diff --git a/src/common/build.cpp b/src/common/build.cpp
index 960b017..eed08ed 100644
--- a/src/common/build.cpp
+++ b/src/common/build.cpp
@@ -20,6 +20,9 @@
 
 #include <string>
 
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+
 #include "common/build.hpp"
 
 namespace mesos {
@@ -31,6 +34,23 @@ const double TIME = atof(BUILD_TIME);
 const std::string USER = BUILD_USER;
 const std::string FLAGS = BUILD_FLAGS;
 
+#ifdef BUILD_GIT_SHA
+const Option<std::string> GIT_SHA = std::string(BUILD_GIT_SHA);
+#else
+const Option<std::string> GIT_SHA = None();
+#endif
+
+#ifdef BUILD_GIT_BRANCH
+const Option<std::string> GIT_BRANCH = std::string(BUILD_GIT_BRANCH);
+#else
+const Option<std::string> GIT_BRANCH = None();
+#endif
+
+#ifdef BUILD_GIT_TAG
+const Option<std::string> GIT_TAG = std::string(BUILD_GIT_TAG);
+#else
+const Option<std::string> GIT_TAG = None();
+#endif
 } // namespace build {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/src/common/build.hpp
----------------------------------------------------------------------
diff --git a/src/common/build.hpp b/src/common/build.hpp
index c0e2a64..115e9cc 100644
--- a/src/common/build.hpp
+++ b/src/common/build.hpp
@@ -28,6 +28,9 @@ extern const std::string DATE;
 extern const double TIME;
 extern const std::string USER;
 extern const std::string FLAGS;
+extern const Option<std::string> GIT_SHA;
+extern const Option<std::string> GIT_BRANCH;
+extern const Option<std::string> GIT_TAG;
 
 } // namespace build {
 } // namespace internal {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 3463365..d7cd89f 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -374,6 +374,19 @@ Future<Response> Master::Http::state(const Request& request)
 
   JSON::Object object;
   object.values["version"] = MESOS_VERSION;
+
+  if (build::GIT_SHA.isSome()) {
+    object.values["git_sha"] = build::GIT_SHA.get();
+  }
+
+  if (build::GIT_BRANCH.isSome()) {
+    object.values["git_branch"] = build::GIT_BRANCH.get();
+  }
+
+  if (build::GIT_TAG.isSome()) {
+    object.values["git_tag"] = build::GIT_TAG.get();
+  }
+
   object.values["build_date"] = build::DATE;
   object.values["build_time"] = build::TIME;
   object.values["build_user"] = build::USER;

http://git-wip-us.apache.org/repos/asf/mesos/blob/3f176033/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index d667e4d..3316fdf 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -303,6 +303,19 @@ Future<Response> Slave::Http::state(const Request& request)
 
   JSON::Object object;
   object.values["version"] = MESOS_VERSION;
+
+  if (build::GIT_SHA.isSome()) {
+    object.values["git_sha"] = build::GIT_SHA.get();
+  }
+
+  if (build::GIT_BRANCH.isSome()) {
+    object.values["git_branch"] = build::GIT_BRANCH.get();
+  }
+
+  if (build::GIT_TAG.isSome()) {
+    object.values["git_tag"] = build::GIT_TAG.get();
+  }
+
   object.values["build_date"] = build::DATE;
   object.values["build_time"] = build::TIME;
   object.values["build_user"] = build::USER;