annotate build-aux/get-source-mtime.sh @ 25800:7b2312def76b

build: ensure hg commands are not affected by user settings * get-source-mtime.sh, mk-hg-id.sh (hg_safe): New shell function to call hg commands safely.
author Mike Miller <mtmiller@octave.org>
date Wed, 15 Aug 2018 13:03:29 -0700
parents 6652d3823428
children 00f796120a6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
1 #! /bin/sh
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
2 #
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 # Copyright (C) 2017-2018 Mike Miller
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
4 #
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
5 # This file is part of Octave.
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
6 #
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24077
diff changeset
7 # Octave is free software: you can redistribute it and/or modify it
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
8 # under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24077
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
10 # (at your option) any later version.
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
11 #
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
12 # Octave is distributed in the hope that it will be useful, but
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
15 # GNU General Public License for more details.
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
16 #
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
18 # along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24077
diff changeset
19 # <https://www.gnu.org/licenses/>.
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
20
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
21 # Generate a timestamp that best represents the last modification time
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
22 # of this source tree. The time value is printed on stdout in units of
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
23 # time_t. If a reasonable representation of the source tree last
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
24 # modification time can't be determined, then the current system time is
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
25 # printed instead. A valid time_t value is always printed on stdout.
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
26
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
27 set -e
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
28
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
29 PERL=${PERL:-perl}
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
30 SED=${SED:-sed}
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
31
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
32 if [ $# -ne 1 ]; then
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
33 echo "usage: get-source-mtime.sh SRCDIR" 1>&2
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
34 exit 1
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
35 fi
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
36
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
37 srcdir="$1"
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
38
25800
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
39 ## A user's ~/.hgrc may redefine or add default options to any hg subcommand,
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
40 ## potentially altering its behavior and possibly its standard output. Always
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
41 ## run hg subcommands with configuration variables set to ensure that the
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
42 ## user's preferences do not influence the expected behavior.
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
43 hg_safe ()
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
44 {
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
45 cmd=$1; shift
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
46 hg --config alias.${cmd}=${cmd} --config defaults.${cmd}= ${cmd} "$@"
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
47 }
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
48
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
49 if [ x"$SOURCE_DATE_EPOCH" != x ]; then
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
50 # Allow the source modification time to be overridden by SOURCE_DATE_EPOCH
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
51 t=$SOURCE_DATE_EPOCH
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
52 elif [ -d $srcdir/.hg ]; then
25800
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
53 t=$( cd $srcdir && hg_safe log --rev . --template '{date|hgdate}' )
24077
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
54 t=$( echo $t | $SED -n 's/^\([0-9]\+\) .*/\1/p' )
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
55 elif [ -f $srcdir/HG-ID ]; then
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
56 t=$( $PERL -e '@s = stat($ARGV[0]); print($s[9]) if @s;' $srcdir/HG-ID )
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
57 elif [ -f $srcdir/configure ]; then
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
58 t=$( $PERL -e '@s = stat($ARGV[0]); print($s[9]) if @s;' $srcdir/configure )
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
59 fi
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
60
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
61 if [ x"$t" = x ]; then
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
62 t=$( date +%s )
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
63 fi
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
64
e483dcb5777d build the source distribution archives reproducibly
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
65 echo $t