[rb-general] using SOURCE_DATE_EPOCH with date
Daniel Shahaf
danielsh at apache.org
Thu Jan 5 16:36:41 CET 2017
Ximin Luo wrote on Wed, Jan 04, 2017 at 17:34:00 +0000:
> Bernhard M. Wiedemann:
> > Hi
> >
> > what is the best way to use SOURCE_DATE_EPOCH with date?
> >
> > I found
> > date ${SOURCE_DATE_EPOCH/#/--date=}
> > to be quite elegant, but it does not work with dash.
> >
> > date --date=@${SOURCE_DATE_EPOCH:-$(date +%s)}
> > does work with dash and bash, but is not as nice.
> >
> > Also there are longer variants like
> > https://github.com/jackaudio/jack2/pull/196/files
> >
> > that would not look nice when used in Makefiles.
> > Can you think of better ways than these?
> > And which one(s) should we recommend for patches we send upstream?
> >
>
> Hi Bernhard, see https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal#Reading_the_variable and feel free to edit this too.
>
> I don't think there is a "nicer" way for shell than the 2nd one that you already found.
A few other options:
date ${SOURCE_DATE_EPOCH:+"--date=@$SOURCE_DATE_EPOCH"} +%Y-%m-%d
date_format=%Y-%m-%d
date=`if [ -n "$SOURCE_DATE_EPOCH" ]; then
date -d "@$SOURCE_DATE_EPOCH" +"$date_format";
else
date +"$date_format";
fi`
(and see the wiki page for portability issues with -d/--date)
Cheers,
Daniel
More information about the rb-general
mailing list