gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / rnp-add-version.cmake.patch
CommitLineData
7b754337
JW
1From b4326f4649ceb146d5cc74f8579b68d8dc8f51e6 Mon Sep 17 00:00:00 2001
2From: Justus Winter <teythoon@avior.uberspace.de>
3Date: Mon, 27 Jul 2020 14:00:25 +0200
4Subject: [PATCH 3/3] Add external version.cmake.
5
6This file is maintained in an external repository. It is only
7included in released versions. For building snapshots of RNP, a fixed
8snapshot of version.cmake is downloaded on demand. To avoid this,
9this patch explicitly provides the file.
10---
11 cmake/version.cmake | 146 ++++++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 146 insertions(+)
13 create mode 100644 cmake/version.cmake
14
15diff --git a/cmake/version.cmake b/cmake/version.cmake
16new file mode 100644
17index 00000000..514027aa
18--- /dev/null
19+++ b/cmake/version.cmake
20@@ -0,0 +1,146 @@
21+# Copyright (c) 2018 Ribose Inc.
22+# All rights reserved.
23+#
24+# Redistribution and use in source and binary forms, with or without
25+# modification, are permitted provided that the following conditions
26+# are met:
27+# 1. Redistributions of source code must retain the above copyright
28+# notice, this list of conditions and the following disclaimer.
29+# 2. Redistributions in binary form must reproduce the above copyright
30+# notice, this list of conditions and the following disclaimer in the
31+# documentation and/or other materials provided with the distribution.
32+#
33+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
37+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43+# POSSIBILITY OF SUCH DAMAGE.
44+
45+# desired length of commit hash
46+set(GIT_REV_LEN 7)
47+
48+# call git, store output in var (can fail)
49+macro(_git var)
50+ execute_process(
51+ COMMAND "${GIT_EXECUTABLE}" ${ARGN}
52+ WORKING_DIRECTORY "${source_dir}"
53+ RESULT_VARIABLE _git_ec
54+ OUTPUT_VARIABLE ${var}
55+ OUTPUT_STRIP_TRAILING_WHITESPACE
56+ ERROR_QUIET
57+ )
58+endmacro()
59+
60+# call git, store output in var (can not fail)
61+macro(git var)
62+ _git(${var} ${ARGN})
63+ if (NOT _git_ec EQUAL 0)
64+ string(REPLACE ";" " " args "${ARGN}")
65+ message(FATAL_ERROR "Failed to execute: git ${args}")
66+ endif()
67+endmacro()
68+
69+function(extract_version_info version var_prefix)
70+ # extract the main components
71+ # v1.9.0-3-g5b92266+1546836556
72+ # v1.9.0-3-g5b92266-dirty+1546836556
73+ string(REGEX MATCH "^v?([0-9]+\\.[0-9]+\\.[0-9]+)(-([0-9]+)-g([0-9a-f]+)(-dirty)?)?(\\+([0-9]+))?$" matches "${version}")
74+ if (NOT matches)
75+ message(FATAL_ERROR "Failed to extract version components.")
76+ endif()
77+ set(${var_prefix}_VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE) # 1.9.0
78+ if (NOT CMAKE_MATCH_3)
79+ set(CMAKE_MATCH_3 "0")
80+ endif()
81+ set(${var_prefix}_VERSION_NCOMMITS "${CMAKE_MATCH_3}" PARENT_SCOPE) # 3
82+ if (NOT CMAKE_MATCH_4)
83+ set(CMAKE_MATCH_4 "0")
84+ endif()
85+ set(${var_prefix}_VERSION_GIT_REV "${CMAKE_MATCH_4}" PARENT_SCOPE) # 5b92266
86+ if (CMAKE_MATCH_5 STREQUAL "-dirty")
87+ set(${var_prefix}_VERSION_IS_DIRTY TRUE PARENT_SCOPE)
88+ else()
89+ set(${var_prefix}_VERSION_IS_DIRTY FALSE PARENT_SCOPE)
90+ endif()
91+ # timestamp is optional, default to 0
92+ if (NOT CMAKE_MATCH_7)
93+ set(CMAKE_MATCH_7 "0")
94+ endif()
95+ set(${var_prefix}_VERSION_COMMIT_TIMESTAMP "${CMAKE_MATCH_7}" PARENT_SCOPE) # 1546836556
96+endfunction()
97+
98+function(determine_version source_dir var_prefix)
99+ if (EXISTS "${source_dir}/.git")
100+ # for GIT_EXECUTABLE
101+ find_package(Git REQUIRED)
102+ # get a description of the version, something like:
103+ # v1.9.1-0-g38ffe82 (a tagged release)
104+ # v1.9.1-0-g38ffe82-dirty (a tagged release with local modifications)
105+ # v1.9.0-3-g5b92266 (post-release snapshot)
106+ # v1.9.0-3-g5b92266-dirty (post-release snapshot with local modifications)
107+ _git(version describe --abbrev=${GIT_REV_LEN} --match "v[0-9]*" --long --dirty)
108+ if (NOT _git_ec EQUAL 0)
109+ # no annotated tags, fake one
110+ git(revision rev-parse --short=${GIT_REV_LEN} --verify HEAD)
111+ set(version "v0.0.0-0-g${revision}")
112+ # check if dirty (this won't detect untracked files, but should be ok)
113+ _git(changes diff-index --quiet HEAD --)
114+ if (NOT _git_ec EQUAL 0)
115+ string(APPEND version "-dirty")
116+ endif()
117+ # append the commit timestamp of the most recent commit (only
118+ # in non-release branches -- typically master)
119+ git(commit_timestamp show -s --format=%ct)
120+ string(APPEND version "+${commit_timestamp}")
121+ endif()
122+ else()
123+ # same as above, but used for snapshots
124+ file(STRINGS "${source_dir}/version.txt" version)
125+ endif()
126+ set(local_prefix "_determine_ver")
127+ extract_version_info("${version}" "${local_prefix}")
128+ foreach(suffix VERSION VERSION_NCOMMITS VERSION_GIT_REV VERSION_IS_DIRTY VERSION_COMMIT_TIMESTAMP)
129+ if (NOT DEFINED ${local_prefix}_${suffix})
130+ message(FATAL_ERROR "Unable to determine version.")
131+ endif()
132+ set(${var_prefix}_${suffix} "${${local_prefix}_${suffix}}" PARENT_SCOPE)
133+ message(STATUS "${var_prefix}_${suffix}: ${${local_prefix}_${suffix}}")
134+ endforeach()
135+ # Set VERSION_SUFFIX and VERSION_FULL. When making changes, be aware that
136+ # this is used in packaging as well and will affect ordering.
137+ # | state | version_full |
138+ # |------------------------------------------------|
139+ # | exact tag | 0.9.0 |
140+ # | exact tag, dirty | 0.9.0+git20180604 |
141+ # | after tag | 0.9.0+git20180604.1.085039f |
142+ # | no tag | 0.0.0+git20180604.2ee02af |
143+ string(TIMESTAMP date "%Y%m%d" UTC)
144+ set(version_suffix "")
145+ if ((NOT ${local_prefix}_VERSION_NCOMMITS EQUAL 0) OR (${local_prefix}_VERSION STREQUAL "0.0.0"))
146+ # 0.9.0+git20150604.4.289818b
147+ string(APPEND version_suffix "+git${date}")
148+ if (NOT ${local_prefix}_VERSION_NCOMMITS EQUAL 0)
149+ string(APPEND version_suffix ".${${local_prefix}_VERSION_NCOMMITS}")
150+ endif()
151+ string(APPEND version_suffix ".${${local_prefix}_VERSION_GIT_REV}")
152+ else()
153+ if (${local_prefix}_VERSION_IS_DIRTY)
154+ # 0.9.0+git20150604
155+ string(APPEND version_suffix "+git${date}")
156+ endif()
157+ endif()
158+ set(version_full "${${local_prefix}_VERSION}${version_suffix}")
159+ # set the results
160+ set(${var_prefix}_VERSION_SUFFIX "${version_suffix}" PARENT_SCOPE)
161+ set(${var_prefix}_VERSION_FULL "${version_full}" PARENT_SCOPE)
162+ # for informational purposes
163+ message(STATUS "${var_prefix}_VERSION_SUFFIX: ${version_suffix}")
164+ message(STATUS "${var_prefix}_VERSION_FULL: ${version_full}")
165+endfunction()
166+
167--
1682.20.1
169