Contemporary versions of Fedora automatically set SOURCE_DATE_EPOCH
based on the changelog entry date stamp. In scenarios where it already
is defined, we do not want to redefine it.

Additionally, when building the libvirt package in an Open Build Service
instance, the spec file is not present in %_specdir, but instead in %_sourcedir.

Signed-off-by: Neal Gompa <ngomp...@gmail.com>
---
 libvirt.spec.in | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 2a4324b974..eb0fba4b5a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1128,7 +1128,16 @@ exit 1
 
 # place macros above and build commands below this comment
 
-export SOURCE_DATE_EPOCH=$(stat --printf='%Y' %{_specdir}/%{name}.spec)
+if [ -z "${SOURCE_DATE_EPOCH}" ]; then
+# If SOURCE_DATE_EPOCH is not defined, set it based on spec file
+    if [ ! -f "%{_specdir}/%{name}.spec" ]; then
+        # OBS does not install the spec file into the specdir
+        SPECFILE_PATH="%{_sourcedir}/%{name}.spec"
+    else
+        SPECFILE_PATH="%{_specdir}/%{name}.spec"
+    fi
+    export SOURCE_DATE_EPOCH=$(stat --printf='%Y' ${SPECFILE_PATH})
+fi
 
 %meson \
            -Drunstatedir=%{_rundir} \
-- 
2.28.0

Reply via email to