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

Allow to override build date with SOURCE_DATE_EPOCH #31

Merged
merged 1 commit into from Jul 1, 2019

Conversation

bmwiedemann
Copy link
Contributor

in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
This date call works with various variants of date.

Also use UTC to be independent of timezone.

@codecov-io
Copy link

codecov-io commented Jun 28, 2019

Codecov Report

No coverage uploaded for pull request base (master@1df34c4). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master     #31   +/-   ##
========================================
  Coverage          ?   73.3%           
========================================
  Files             ?      15           
  Lines             ?     487           
  Branches          ?       0           
========================================
  Hits              ?     357           
  Misses            ?     103           
  Partials          ?      27

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1df34c4...2e40a6e. Read the comment docs.

Copy link
Owner

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

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

Thanks for reporting this and providing a fix too! It makes absolute sense to make the build reproducible. As far as I understand, this is just the first step until the build is fully reproducible. For example, the build environment is also not well controlled.

Can you also make sure to include a a sign-off line in your commit, for example git commit --amend --signoff?

Makefile Outdated
@@ -34,9 +34,15 @@ CHECKSUMS += $(BUNDLE).sha256

VERSION_PACKAGE := $(REPOPATH)/pkg/rakkess/version

DATE_FMT = %Y-%m-%dT%H:%M:%SZ
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
Copy link
Owner

Choose a reason for hiding this comment

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

I'm a bit worried about all the alternatives here. Quoting the spec for SOURCE_DATE_EPOCH:

The value MUST be an ASCII representation of an integer with no fractional component, identical to the output format of date +%s.

That seems to be covered by the first alternative.

The second looks as if it is using a reference file to obtain a timestamp. As this is not specified by the spec, why should we do that?

Finally, the last alternative seems to be a fallback in case the other ones failed. Here I would rather fail fast and fail the build instead of pretending that everything went fine. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to handle different variants of date - the first is for GNU date as used in every GNU/Linux distribution, the 2nd for FreeBSD date and the 3rd one as fallback (e.g. DOS and Solaris date) that have no way to make the output reproducible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you think, that this program will never be built outside of GNU/Linux, we can simplify the code.

Copy link
Owner

Choose a reason for hiding this comment

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

I see. So I think the last variant is obsolete, because on these systems people should simply not set the SOURCE_DATE_EPOCH env var and the build will do as expected.
And for the two remaining alternatives, a comment would be nice, such as

GNU and BSD date require different options for a fixed date

I don't mind if the comment is in code or in the commit message, whatever you prefer.

in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
This date call works with various variants of date.

Also use UTC to be independent of timezone.

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
@corneliusweig corneliusweig merged commit 6f7f2f5 into corneliusweig:master Jul 1, 2019
@corneliusweig
Copy link
Owner

Thanks again for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants