aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-04-03 16:41:45 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-04-11 08:23:49 +0000
commitcc56353c33f7be1c194ccea982285197f0056c00 (patch)
tree8238ce28395a4f3d9dfc2ef719a8ed588e407a69
parent6f946168d656f096a65d7ba09b1b1dd15fdbac0e (diff)
Read commit sha from .tag file as a fallback
The source artifacts in coin are not in a git repository, so the revision information was missing from the official binaries. Add .gitattributes with export-subst attribute for the .tag file to expand the placeholder when adding the file to archive. Task-number: QLS-856 Pick-to: 3.0 Change-Id: I6f584961e548a4b44d5a5fb52f49e7ca67ce4e9f Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r--.gitattributes3
-rw-r--r--.tag1
-rw-r--r--src/include/CMakeLists.txt8
3 files changed, 12 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..018cf2c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+.tag export-subst
+.gitignore export-ignore
+.gitattributes export-ignore
diff --git a/.tag b/.tag
new file mode 100644
index 0000000..6828f88
--- /dev/null
+++ b/.tag
@@ -0,0 +1 @@
+$Format:%H$
diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt
index d7abbe2..f96931b 100644
--- a/src/include/CMakeLists.txt
+++ b/src/include/CMakeLists.txt
@@ -12,5 +12,13 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)
+# If git command failed or resulting variable is empty, try to read from .tag file
+if (NOT GIT_COMMIT_SHA)
+ file(READ "${CMAKE_SOURCE_DIR}/.tag" TAG_CONTENT)
+ string(STRIP ${TAG_CONTENT} GIT_COMMIT_SHA)
+endif()
+
+message("Commit SHA: ${GIT_COMMIT_SHA}")
+
configure_file(commonsetup.h.in ${CMAKE_BINARY_DIR}/include/commonsetup.h)
configure_file(version.h.in ${CMAKE_BINARY_DIR}/include/version.h)