mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From josep...@apache.org
Subject mesos git commit: CMake: Add `build_config.hpp.in` for `BUILD_TIME` variables.
Date Wed, 01 Mar 2017 22:54:13 GMT
Repository: mesos
Updated Branches:
  refs/heads/master ca5642cf0 -> 6d7b25adc


CMake: Add `build_config.hpp.in` for `BUILD_TIME` variables.

Commit c7fc1377b introduced a bug that prevented any incremental
recompilation.  By defining the `BUILD_TIME` in `MESOS_CPPFLAGS`,
every build was seen as having a root dependency (the flags)
change, causing a rebuild of every single source in Mesos
(especially bad on ccache-less systems).

This patch introduces a CMake `configure_file` directive which
takes in `build_config.hpp.in` and emits `build_config.hpp` with the
`BUILD_TIME`, `BUILD_DATE`, and `BUILD_USER` variables defined.
As this is a CMake-only file, we guard the new header with a static
definition `-DUSE_CMAKE_BUILD_CONFIG`.  The result is that the date,
time, and user are set at the point of configuration (invocation of
CMake) instead of at build, thus allowing for incremental rebuilds.

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


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

Branch: refs/heads/master
Commit: 6d7b25adc67af53ba987caf7c9e838b2e2aa85ca
Parents: ca5642c
Author: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
Authored: Tue Feb 28 17:49:33 2017 -0800
Committer: Joseph Wu <josephwu@apache.org>
Committed: Wed Mar 1 14:53:59 2017 -0800

----------------------------------------------------------------------
 cmake/CompilationConfigure.cmake | 21 ++++++++++++++++-----
 src/common/build.cpp             |  9 +++++++++
 src/common/build_config.hpp.in   | 26 ++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6d7b25ad/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 7808d1a..f9cb771 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -286,15 +286,28 @@ set(MESOS_CPPFLAGS
   -DPKGDATADIR="${DATA_INSTALL_PREFIX}"
   )
 
-# Add build information to Mesos flags.
+# Calculate some build information.
 string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S UTC" UTC)
-string(TIMESTAMP BUILD_TIME "%s" UTC)
 if (WIN32)
+  string(TIMESTAMP BUILD_TIME "%s" UTC)
   set(BUILD_USER "$ENV{USERNAME}")
 else (WIN32)
+  execute_process(
+    COMMAND date +%s
+    OUTPUT_VARIABLE BUILD_TIME
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
   set(BUILD_USER "$ENV{USER}")
 endif (WIN32)
 
+# Emit the BUILD_DATE, BUILD_TIME, and BUILD_USER variables into a file.
+# This will be updated each time `cmake` is run.
+configure_file(
+  "${CMAKE_SOURCE_DIR}/src/common/build_config.hpp.in"
+  "${CMAKE_BINARY_DIR}/src/common/build_config.hpp"
+  @ONLY
+  )
+
 # TODO(hausdorff): (MESOS-5902) Populate this value when we integrate Java
 # support.
 set(BUILD_JAVA_JVM_LIBRARY "")
@@ -305,9 +318,7 @@ set(BUILD_JAVA_JVM_LIBRARY "")
 set(MESOS_CPPFLAGS
   ${MESOS_CPPFLAGS}
   -DUSE_STATIC_LIB
-  -DBUILD_DATE="${BUILD_DATE}"
-  -DBUILD_TIME="${BUILD_TIME}"
-  -DBUILD_USER="${BUILD_USER}"
+  -DUSE_CMAKE_BUILD_CONFIG
   -DBUILD_JAVA_JVM_LIBRARY="${BUILD_JAVA_JVM_LIBRARY}"
   )
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/6d7b25ad/src/common/build.cpp
----------------------------------------------------------------------
diff --git a/src/common/build.cpp b/src/common/build.cpp
index 090b59f..971a8c9 100644
--- a/src/common/build.cpp
+++ b/src/common/build.cpp
@@ -23,6 +23,15 @@
 
 #include "common/build.hpp"
 
+// NOTE: On CMake, instead of defining `BUILD_DATE|TIME|USER` as
+// compiler flags, we instead emit a header file with the definitions.
+// This facilitates incremental builds as the compiler flags will
+// no longer change with every invocation of the build.
+// TODO(josephw): After deprecating autotools, remove this guard.
+#ifdef USE_CMAKE_BUILD_CONFIG
+#include "common/build_config.hpp"
+#endif // USE_CMAKE_BUILD_CONFIG
+
 namespace mesos {
 namespace internal {
 namespace build {

http://git-wip-us.apache.org/repos/asf/mesos/blob/6d7b25ad/src/common/build_config.hpp.in
----------------------------------------------------------------------
diff --git a/src/common/build_config.hpp.in b/src/common/build_config.hpp.in
new file mode 100644
index 0000000..174d8aa
--- /dev/null
+++ b/src/common/build_config.hpp.in
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __COMMON_BUILD_CONFIG_HPP__
+#define __COMMON_BUILD_CONFIG_HPP__
+
+#cmakedefine BUILD_DATE "@BUILD_DATE@"
+#cmakedefine BUILD_TIME "@BUILD_TIME@"
+#cmakedefine BUILD_USER "@BUILD_USER@"
+
+// TODO(andschwa): Define GIT_SHA etc. for parity with autotools.
+
+#endif // __COMMON_BUILD_CONFIG_HPP__


Mime
View raw message