wordgrinder icon indicating copy to clipboard operation
wordgrinder copied to clipboard

Setting SOURCE_DATE_EPOCH doesn't work on non-GNU systems

Open ryandesign opened this issue 5 years ago • 2 comments

If I set SOURCE_DATE_EPOCH to something when running make, the DATE gets set to the empty string.

If I build with hide set to nothing, then I see that the reason for this is:

/bin/sh: LC_ALL: command not found

If I fix that by replacing LC_ALL with LC_ALL=C in your Makefile, then it still fails with:

date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

I am on macOS, which uses a BSD-derived date command that does not understand the GNU-specific options you are passing to it.

ryandesign avatar Nov 07 '20 05:11 ryandesign

Here are links to the various manuals:

There doesn't seem to be a cross-POSIX way of doing what @davidgiven wants to do, which is convert a Unix timestamp into a day month year in UTC. The BSDs and macOS would need something like date -r "$SOURCE_DATE_EPOCH". Meanwhile, GNU and Busybox systems need to use -d or --date. Maybe the Makefile (or build.lua) could check for which system the user is on and choose a date command that way.

This can be done entirely in Lua with

os.date('!%d %B %Y', tonumber(os.getenv('SOURCE_DATE_EPOCH')))

~~Interesting note, I'm pretty sure this is undocumented.~~ It also doesn't support the leading dash that removes zero padding.

averms avatar Nov 09 '20 20:11 averms

I'll admit, I think that patch was actually an NMA from Debian, so I never actually thought about this at all.

The easiest thing is probably to do it in Lua.

davidgiven avatar Nov 09 '20 20:11 davidgiven