Blob Blame History Raw
From 987e819b8fb8e36e660340931270a2ade02c439e Mon Sep 17 00:00:00 2001
From: Gabriel Scherer <gabriel.scherer@gmail.com>
Date: Thu, 26 Sep 2019 21:46:03 +0200
Subject: [PATCH 04/12] Merge pull request #8979 from
 gasche/fix-Makefile.menhir

Fix tools/check-parser-uptodate-or-warn.sh

(cherry picked from commit f075ab6fdeedc8d53ececd1184d69a1cc35c0fd5)
---
 Changes                                |  3 +++
 Makefile                               |  6 +++---
 tools/check-parser-uptodate-or-warn.sh | 21 +++++++++++++++++----
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/Changes b/Changes
index 355cb1a94..63cac3ef9 100644
--- a/Changes
+++ b/Changes
@@ -5,6 +5,9 @@ OCaml 4.09 maintenance branch:
   dummy locations
   (Armaël Guéneau, review by Gabriel Scherer)
 
+- #8965, #8979: Alpine build failure caused by check-parser-uptodate-or-warn.sh
+  (Gabriel Scherer and David Allsopp, report by Anton Kochkov)
+
 OCaml 4.09.0 (19 September 2019):
 ---------------------------------
 
diff --git a/Makefile b/Makefile
index 47548c79d..7ac446f62 100644
--- a/Makefile
+++ b/Makefile
@@ -1076,10 +1076,10 @@ parsing/camlinternalMenhirLib.mli: boot/menhir/menhirLib.mli
 
 parsing/parser.ml: boot/menhir/parser.ml parsing/parser.mly \
   tools/check-parser-uptodate-or-warn.sh
-	@tools/check-parser-uptodate-or-warn.sh
-	cat $< | sed "s/MenhirLib/CamlinternalMenhirLib/g" > $@
+	@-tools/check-parser-uptodate-or-warn.sh
+	sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
 parsing/parser.mli: boot/menhir/parser.mli
-	cat $< | sed "s/MenhirLib/CamlinternalMenhirLib/g" > $@
+	sed "s/MenhirLib/CamlinternalMenhirLib/g" $< > $@
 
 
 partialclean:: partialclean-menhir
diff --git a/tools/check-parser-uptodate-or-warn.sh b/tools/check-parser-uptodate-or-warn.sh
index 5502eae54..2f07619a6 100755
--- a/tools/check-parser-uptodate-or-warn.sh
+++ b/tools/check-parser-uptodate-or-warn.sh
@@ -15,6 +15,9 @@
 #*                                                                        *
 #**************************************************************************
 
+# stop early if we are not on a development version
+grep -Fq '+dev' VERSION || exit 0
+
 # We try to warn if the user edits parsing/parser.mly but forgets to
 # rebuild the generated parser. Our heuristic is to use the file
 # modification timestamp, but just testing
@@ -24,15 +27,20 @@
 # seconds after boot/menhir/parser.ml.
 
 # mtime(): access a file's last modification time as a timestamp,
-# using either GNU coreutils' stat --format, or BSD/macos stat -f.
+# using either
+#  GNU coreutils' stat --format, or
+#  busybox's stat -c, or
+#  BSD/macOS stat -f.
 # Default to 0 if 'stat' is not available.
 
 stat . 2>/dev/null 1>/dev/null
 if test $? != 0
 then MTIME=""
-elif test -n "$(stat --version 2>/dev/null | grep coreutils)"
+elif stat --version 2>/dev/null | grep -Fq 'coreutils'
 then MTIME="stat --format %Y"
-else MTIME="stat -f %m"
+elif stat 2>&1 | grep -Fq 'busybox'
+then MTIME="stat -c %Y"
+else MTIME="stat -f %m" # BSD stat?
 fi
 
 mtime() {
@@ -45,7 +53,12 @@ mtime() {
 # The check itself
 SOURCE_MTIME=$(mtime parsing/parser.mly)
 GENERATED_MTIME=$(mtime boot/menhir/parser.ml)
-if test $SOURCE_MTIME -gt $(( $GENERATED_MTIME + 10 ))
+if test -z "$SOURCE_MTIME" -o -z "$GENERATED_MTIME"
+then
+  echo
+  tput setaf 3; tput bold; printf "Warning: "; tput sgr0
+  echo "Failed to check if boot/menhir/parser.ml is up-to-date."
+elif test "$SOURCE_MTIME" -gt $(( GENERATED_MTIME + 10 ))
 then
   echo
   tput setaf 3; tput bold; printf "Warning: "; tput sgr0
-- 
2.23.0