Skip to content

Commit 14a1880

Browse files
committed
improve method for managing hg ID in build
* Makefile.am (HG-ID): New rule to generate HG-ID file in the build directory. (HG_ID_VAR): Get value from HG-ID file. (DISABLE_HG_ID_OPTION): New variable. * build-aux/mk-hg-id.sh: Simply display ID of current revision instead of creating HG-ID file. If the disable option is supplied, display "hg-id-disabled". If a $srcdir/.hg directory exists, attempt to get the ID from Mercurial. Otherwise, display the contents of $srcdir/HG-ID if it exists. If the ID is not found, display "unknown-hg-id".
1 parent 27c9a6b commit 14a1880

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

Makefile.am

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ BUILT_DISTFILES += \
154154
INSTALL.OCTAVE \
155155
NEWS
156156

157+
if AMCOND_ENABLE_HG_ID
158+
DISABLE_HG_ID_OPTION :=
159+
else
160+
DISABLE_HG_ID_OPTION := --disable
161+
endif
162+
163+
## The mk-hg-id.sh script will be executed each time Make runs to
164+
## update the HG-ID file in the build tree if it is out of date.
165+
166+
HG-ID:
167+
$(AM_V_GEN)$(SHELL) $(top_srcdir)/build-aux/mk-hg-id.sh "$(srcdir)" $(DISABLE_HG_ID_OPTION) > $@-t && \
168+
$(simple_move_if_change_rule)
169+
.PHONY: HG-ID
170+
171+
HG_ID_VAR = $(shell cat ${top_builddir}/HG-ID)
172+
157173
EXTRA_DIST += \
158174
CITATION \
159175
COPYING \
@@ -403,18 +419,6 @@ ChangeLog:
403419
$(AM_V_GEN)$(changelog-from-hg-log)
404420
.PHONY: ChangeLog
405421

406-
## The mk-hg-id.sh script will be executed each time Make runs. It will
407-
## update the HG-ID file in the build tree if it is out of date. As a side
408-
## effect, HG_ID_VAR is assigned the contents of the file.
409-
410-
if AMCOND_ENABLE_HG_ID
411-
HG_ID_VAR := \
412-
$(shell $(SHELL) $(top_srcdir)/build-aux/mk-hg-id.sh "$(srcdir)")
413-
else
414-
HG_ID_VAR := \
415-
$(shell $(SHELL) $(top_srcdir)/build-aux/mk-hg-id.sh "$(srcdir)" --disable)
416-
endif
417-
418422
octetc_DATA += \
419423
CITATION \
420424
NEWS

build-aux/mk-hg-id.sh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
##
2626
########################################################################
2727

28-
# Generate a header file that provides the public symbols from Octave's
29-
# autoconf-generated config.h file. See the notes at the top of the
30-
# generated octave-config.h file for more details.
28+
## Display the Mercurial ID of the current revision. If the source tree
29+
## does not appear to be a Mercurial repo but does contain a file named
30+
## HG-ID, display the contents of that file. If that file does not
31+
## exist, or the Mercurial fails to provide the ID, display
32+
## "unknown-hg-id". If invoked with the --disable option, display
33+
## "hg-id-disabled".
3134

3235
set -e
3336

@@ -39,33 +42,25 @@ fi
3942
srcdir="$1"
4043

4144
hg_id=HG-ID
42-
move_if_change="$srcdir/build-aux/move-if-change"
4345

4446
## A user's ~/.hgrc may redefine or add default options to any hg subcommand,
4547
## potentially altering its behavior and possibly its standard output. Always
4648
## run hg subcommands with configuration variables set to ensure that the
4749
## user's preferences do not influence the expected behavior.
50+
4851
hg_safe ()
4952
{
5053
cmd=$1; shift
5154
hg --config alias.${cmd}=${cmd} --config defaults.${cmd}= ${cmd} "$@"
5255
}
5356

5457
if [ $# -eq 2 ] && [ x"$2" = x--disable ]; then
55-
echo "hg-id-disabled" > ${hg_id}-t
56-
${move_if_change} ${hg_id}-t ${hg_id}
57-
elif [ -d $srcdir/.hg ]; then
58-
( cd $srcdir && hg_safe identify --id || echo "unknown" ) > ${hg_id}-t
59-
${move_if_change} ${hg_id}-t ${hg_id}
60-
elif [ ! -f $srcdir/${hg_id} ]; then
61-
echo "WARNING: $srcdir/${hg_id} is missing!" 1>&2
62-
echo "unknown" > ${hg_id}-t && mv ${hg_id}-t ${hg_id}
58+
echo "hg-id-disabled"
59+
elif [ -d "$srcdir/.hg" ]; then
60+
( cd "$srcdir" && hg_safe identify --id || echo "unknown-hg-id" )
61+
elif [ ! -f "$srcdir/$hg_id" ]; then
62+
echo "WARNING: $srcdir/$hg_id is missing!" 1>&2
63+
echo "unknown-hg-id"
6364
else
64-
echo "preserving existing ${hg_id} file" 1>&2
65-
if [ "x$srcdir" != "x." ] && [ -f $srcdir/${hg_id} ] && [ ! -f ${hg_id} ]; then
66-
cp ${srcdir}/${hg_id} ${hg_id}
67-
touch -r ${srcdir}/${hg_id} ${hg_id}
68-
fi
65+
cat "$srcdir/$hg_id"
6966
fi
70-
71-
cat ${hg_id}

0 commit comments

Comments
 (0)