Hi kre,

> > So I think `:-' is the wrong test, and `-' should be used.
...
> really?   Is failing (well, planning to fail, and faliing at that)
> when the SOURCE_DATE_EPOCH is set to a null string, rather than
> treating that as the same as not set at all really that important?

It tells the reader that an empty value, an error, isn't ignored as if
it wasn't specified.

> > How about
> >
> >     fmt='%Y-%m-%d %T %z'
>
> Since this always uses date -u (correctly I think) the %z is overkill,

It shows if the `-u' on the unknown platform had the desired effect as
long as the build's timezone isn't already UTC0.

> just use
>       fmt='%Y-%m-%d %TZ'
> instead.   And maybe make it more isoish by using T instead of the space.

`2018-07-24T15:09:29Z' is more awkward for this human to parse than
`2018-07-24 15:09:29 +0000'.

> With null "$now" that ends up doing the 'date -u +"$fmt"' (which is
> definitely not a reproducible build, but I guess that is the point)

Yes.

> but is most certainly not obeying the:
>
>       The value MUST be an ... (otherwise) the build process SHOULD
>       exit with a non-zero error code.

But it will throw up a non-reproducible build, as would, like you say,
misleading the reader by ignoring an empty string as if it's valid.

> If that is to be ignored anyway (which I think is reasonable - anyone
> who wants a correct reproducible build should give the correct value)

That's like saying no error checking should occur because if no errors
are intended then they shouldn't be caused.

> ps: the "" around the date=$( ) are not really needed - they do no
> harm but provide no benefit either.

No, because it's a variable assignment.  My fingers are used to doing it
in other cases when I don't want word-splitting or globbing.

How about

    $ git di config/version.sh
    diff --git config/version.sh config/version.sh
    index 5b76808f..12bb220d 100755
    --- config/version.sh
    +++ config/version.sh
    @@ -12,7 +12,16 @@ if test -d "$srcdir/.git"; then
     else
         git=
     fi
    -date="`TZ=GMT0 date +'%Y-%m-%d %T'` +0000"
    +
    +fmt='%Y-%m-%d %T %z'
    +now=${SOURCE_DATE_EPOCH-$(date +%s)}
    +if date -u -d @42 +"$fmt" >/dev/null 2>&1; then   # Coreutils.
    +    date=$(date -u -d "@$now" +"$fmt")
    +elif date -u -r 42 +"$fmt" >/dev/null 2>&1; then   # BSD.
    +    date=$(date -u -r "$now" +"$fmt")
    +else   # Posix, ignoring SOURCE_DATE_EPOCH.
    +    date=$(date -u +"$fmt")
    +fi
     
     cat <<E
     char *version_str = "nmh-$version$git built $date on $host";
    $ 
    $ config/version.sh nonesuch
    char *version_str = "nmh-nonesuch built 2018-07-24 15:36:41 +0000 on orac";
    char *version_num = "nmh-nonesuch";
    char *user_agent = "nmh/nonesuch";
    $ 
    $ SOURCE_DATE_EPOCH=7242 config/version.sh nonesuch
    char *version_str = "nmh-nonesuch built 1970-01-01 02:00:42 +0000 on orac";
    char *version_num = "nmh-nonesuch";
    char *user_agent = "nmh/nonesuch";
    $ 

It determines the style of date(1) to invoke without relying on user
input, then when that's known it invokes it again with the desired
number of seconds but without discarding stderr in case of problems, and
the existing `set -e' would exit on an error.

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy

-- 
nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers

Reply via email to