annotate build-aux/mk-hg-id.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
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 #! /bin/sh
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@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) 2016-2018 John W. Eaton
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 #
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 # This file is part of Octave.
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 #
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
7 # Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
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: 23220
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
diff changeset
10 # (at your option) any later version.
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 #
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
diff changeset
12 # Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22020
diff changeset
15 # GNU General Public License for more details.
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 #
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@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: 23220
diff changeset
19 # <https://www.gnu.org/licenses/>.
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 # Generate a header file that provides the public symbols from Octave's
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 # autoconf-generated config.h file. See the notes at the top of the
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 # generated octave-config.h file for more details.
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 set -e
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 if [ $# -ne 1 ] && [ $# -ne 2 ]; then
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 echo "usage: mk-hg-id.sh SRCDIR [--disable]" 1>&2
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 exit 1
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 fi
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 srcdir="$1"
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 hg_id=HG-ID
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 move_if_change="$srcdir/build-aux/move-if-change"
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
25800
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
37 ## 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
38 ## 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
39 ## 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
40 ## 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
41 hg_safe ()
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
42 {
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
43 cmd=$1; shift
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
44 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
45 }
7b2312def76b build: ensure hg commands are not affected by user settings
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
46
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 if [ $# -eq 2 ] && [ x"$2" = x--disable ]; then
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 echo "hg-id-disabled" > ${hg_id}-t
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 ${move_if_change} ${hg_id}-t ${hg_id}
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 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
51 ( cd $srcdir && hg_safe identify --id || echo "unknown" ) > ${hg_id}-t
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 ${move_if_change} ${hg_id}-t ${hg_id}
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 elif [ ! -f $srcdir/${hg_id} ]; then
22020
e154d23b2fd1 maint: reduce multiple mentions of the HG-ID file name and contents
Mike Miller <mtmiller@octave.org>
parents: 21976
diff changeset
54 echo "WARNING: $srcdir/${hg_id} is missing!" 1>&2
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 echo "unknown" > ${hg_id}-t && mv ${hg_id}-t ${hg_id}
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 else
22020
e154d23b2fd1 maint: reduce multiple mentions of the HG-ID file name and contents
Mike Miller <mtmiller@octave.org>
parents: 21976
diff changeset
57 echo "preserving existing ${hg_id} file" 1>&2
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 if [ "x$srcdir" != "x." ] && [ -f $srcdir/${hg_id} ] && [ ! -f ${hg_id} ]; then
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 cp ${srcdir}/${hg_id} ${hg_id}
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 touch -r ${srcdir}/${hg_id} ${hg_id}
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 fi
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 fi
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if [ "`cat ${hg_id}`" = "hg-id-disabled" ]; then
22020
e154d23b2fd1 maint: reduce multiple mentions of the HG-ID file name and contents
Mike Miller <mtmiller@octave.org>
parents: 21976
diff changeset
65 echo "WARNING: ${hg_id} is 'hg-id-disabled'" 1>&2
21976
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 fi
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
f6e119d0bdfd avoid tagging HG-ID as .PHONY
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 cat ${hg_id}