Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SOURCE_DATE_EPOCH #58

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions suse-buildsystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,51 @@ export QT_HASH_SEED=0
export PERL_HASH_SEED=42
export PYTHONHASHSEED=0
export FORCE_SOURCE_DATE=1 # for texlive to use SOURCE_DATE_EPOCH

if test ! -v SOURCE_DATE_EPOCH && test -f /.buildenv && test "Y" != "$(rpm --eval '%disable_obs_set_source_date_epoch')"; then
BROKEN_SOURCE_DATE_EPOCH="$(
. /.buildenv
if test -f "$TOPDIR/SOURCES/_scmsync.obsinfo" ; then
mtime="$(grep mtime "$TOPDIR/SOURCES/_scmsync.obsinfo" |cut -d ' ' -f 2)"
if test 1 -gt "$mtime" ; then
echo "WARNING mtime in \TOPDIR/SOURCES/_scmsync.obsinfo seems invalid as it is less than 1" >&2
fi
elif test -v BUILD_CHANGELOG_TIMESTAMP ; then
mtime=$BUILD_CHANGELOG_TIMESTAMP
if test 1 -gt "$mtime" ; then
echo "WARNING BUILD_CHANGELOG_TIMESTAMP in /.buildenv seems invalid as it is less than 1" >&2
fi
else
echo "WARNING could not set SOURCE_DATE_EPOCH, ensure mtime is in \$TOPDIR/SOURCES/_scmsync.obsinfo or BUILD_CHANGELOG_TIMESTAMP is set in /.buildenv" >&2
fi
echo "$mtime"
)"
if test -z "$BROKEN_SOURCE_DATE_EPOCH"; then
unset BROKEN_SOURCE_DATE_EPOCH
else
export BROKEN_SOURCE_DATE_EPOCH
fi
SOURCE_DATE_EPOCH="$(
. /.buildenv
if test -v BUILD_RELEASE && test -v BROKEN_SOURCE_DATE_EPOCH; then
counter="$(echo "$BUILD_RELEASE" |cut -d '.' -f 2)"
if test 1 -gt "$counter" ; then
echo "WARNING number after \".\" in BUILD_RELEASE in /.buildenv seems invalid as it is less than 1" >&2
fi
date=$(( BROKEN_SOURCE_DATE_EPOCH + counter ))
echo "setting SOURCE_DATE_EPOCH to $date" >&2
else
echo "WARNING could not set SOURCE_DATE_EPOCH, ensure BUILD_RELEASE is set in /.buildenv" >&2
fi
echo "$date"
)"
if test -z "$SOURCE_DATE_EPOCH"; then
unset SOURCE_DATE_EPOCH
else
export SOURCE_DATE_EPOCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a multiline string then with the subshell approach and warnings above. I am not sure this is useful behavior.
why are you doing this so complicated rather than simply setting SOURCE_DATE_EPOCH'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a subshell, because otherwise even non-exported variables would remain in the environment. So the only alternative I can come up with is to manually parse the .buildenv file and to unset every created intermediary variable. The subshell approach seemed easier to me.

None of the warnings are captured as they go to stderr, thus they will be seen in the buildlog.

fi
if test "$SOURCE_DATE_EPOCH" -ge "$(date '+%s')" ; then
echo "ERROR SOURCE_DATE_EPOCH is in the future, clamping mtime if used might fail in hard to notice way, returning error" >&2
JanZerebecki marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
fi