]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Use SOURCE_DATE_EPOCH for timestamp if present
authorMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 01:14:54 +0000 (11:14 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 05:14:30 +0000 (15:14 +1000)
The Debian reproducible builds effort suggests using
this environment variable for timestamps.

CMakeLists.txt
cmake/formatdate.py [new file with mode: 0755]

index 24061c42059f9d259743224d854bb121823c84cb..d80b3d4c9fb7bdb6b05cb8d39085ffd94a0929a2 100644 (file)
@@ -14,8 +14,6 @@ set (HS_VERSION ${HS_MAJOR_VERSION}.${HS_MINOR_VERSION}.${HS_PATCH_VERSION})
 set (CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo"
      CACHE STRING "" FORCE)
 
-string (TIMESTAMP BUILD_DATE "%Y-%m-%d")
-
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
@@ -98,6 +96,18 @@ else()
     message(FATAL_ERROR "No python interpreter found")
 endif()
 
+# allow for reproducible builds - python for portability
+if (DEFINED ENV{SOURCE_DATE_EPOCH})
+      execute_process(
+          COMMAND "${PYTHON}" "${CMAKE_MODULE_PATH}/formatdate.py" "$ENV{SOURCE_DATE_EPOCH}"
+          OUTPUT_VARIABLE BUILD_DATE
+          OUTPUT_STRIP_TRAILING_WHITESPACE)
+else ()
+    string (TIMESTAMP BUILD_DATE "%Y-%m-%d")
+endif ()
+message(STATUS "Build date: ${BUILD_DATE}")
+
+
 if(${RAGEL} STREQUAL "RAGEL-NOTFOUND")
     message(FATAL_ERROR "Ragel state machine compiler not found")
 endif()
diff --git a/cmake/formatdate.py b/cmake/formatdate.py
new file mode 100755 (executable)
index 0000000..1b9c62d
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+from __future__ import print_function
+import os
+import sys
+import datetime
+
+def usage():
+    print("Usage:", os.path.basename(sys.argv[0]), "<seconds from epoch>")
+
+if len(sys.argv) != 2:
+    usage()
+    sys.exit(1)
+
+ts = sys.argv[1]
+
+build_date = datetime.datetime.utcfromtimestamp(int(ts))
+
+print(build_date.strftime("%Y-%m-%d"))