package / ocaml-base-compiler.4.10.0 / tools / check-parser-uptodate-or-warn.sh
1 #!/bin/sh
2
3 #**************************************************************************
4 #* *
5 #* OCaml *
6 #* *
7 #* Gabriel Scherer, projet Parsifal, INRIA Saclay *
8 #* *
9 #* Copyright 2018 Institut National de Recherche en Informatique et *
10 #* en Automatique. *
11 #* *
12 #* All rights reserved. This file is distributed under the terms of *
13 #* the GNU Lesser General Public License version 2.1, with the *
14 #* special exception on linking described in the file LICENSE. *
15 #* *
16 #**************************************************************************
17
18 # stop early if we are not on a development version
19 grep -Fq '+dev' VERSION || exit 0
20
21 # We try to warn if the user edits parsing/parser.mly but forgets to
22 # rebuild the generated parser. Our heuristic is to use the file
23 # modification timestamp, but just testing
24 # (parsing/parser.mly -nt boot/menhir/parser.ml)
25 # is not robust to clone/checkout refreshing the files in an arbitrary
26 # order, so we check whether parser.mly was modified at least 10
27 # seconds after boot/menhir/parser.ml.
28
29 # mtime(): access a file's last modification time as a timestamp,
30 # using either
31 # GNU coreutils' stat --format, or
32 # busybox's stat -c, or
33 # BSD/macOS stat -f.
34 # Default to 0 if 'stat' is not available.
35
36 stat . 2>/dev/null 1>/dev/null
37 if test $? != 0
38 then MTIME=""
39 elif stat --version 2>/dev/null | grep -Fq 'coreutils'
40 then MTIME="stat --format %Y"
41 elif stat 2>&1 | grep -Fq 'busybox'
42 then MTIME="stat -c %Y"
43 else MTIME="stat -f %m" # BSD stat?
44 fi
45
46 mtime() {
47 if test -z "$MTIME"
48 then echo 0
49 else $MTIME "$1"
50 fi
51 }
52
53 # The check itself
54 SOURCE_MTIME=$(mtime parsing/parser.mly)
55 GENERATED_MTIME=$(mtime boot/menhir/parser.ml)
56 if test -z "$SOURCE_MTIME" -o -z "$GENERATED_MTIME"
57 then
58 echo
59 tput setaf 3; tput bold; printf "Warning: "; tput sgr0
60 echo "Failed to check if boot/menhir/parser.ml is up-to-date."
61 elif test "$SOURCE_MTIME" -gt $(( GENERATED_MTIME + 10 ))
62 then
63 echo
64 tput setaf 3; tput bold; printf "Warning: "; tput sgr0
65 echo "Your 'parser.mly' file is more recent than the parser in 'boot/'."
66 echo "Its changes will be ignored unless you run:"
67 echo " make promote-menhir"
68 echo
69 fi
70