|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# Build Jane Syntax files with the opam switch's OCaml. This verifies |
| 6 | +# that they can be put into public release with minimal changes; |
| 7 | +# see Note [Buildable with upstream] in ocaml/parsing/jane_syntax.mli |
| 8 | + |
| 9 | +cd $(git rev-parse --show-toplevel)/ocaml |
| 10 | + |
| 11 | +files_in_dependency_order=( |
| 12 | + utils/language_extension_kernel.{mli,ml} |
| 13 | + language_extension.ml |
| 14 | + parsing/jane_asttypes.mli |
| 15 | + parsing/{jane_syntax_parsing,jane_syntax}.{mli,ml} |
| 16 | +) |
| 17 | + |
| 18 | +function basenames_in_dependency_order() { |
| 19 | + printf "%s\n" "${files_in_dependency_order[@]}" | xargs -n 1 basename |
| 20 | +} |
| 21 | + |
| 22 | +# language_extension.ml is stubbed later, so we don't copy anything |
| 23 | +# from ocaml/ for it. |
| 24 | +function source_files_in_ocaml_dir() { |
| 25 | + printf "%s\n" "${files_in_dependency_order[@]}" | grep -v '^language_extension.ml$' |
| 26 | +} |
| 27 | + |
| 28 | +# Copy files to another directory before compiling so we're confident |
| 29 | +# we're not using the build artifacts of an earlier build. |
| 30 | +tmp=$(mktemp -d) |
| 31 | +cp $(source_files_in_ocaml_dir) "$tmp" |
| 32 | + |
| 33 | +cd "$tmp" |
| 34 | + |
| 35 | +# Stub [Language_extension] in the same way we do internally. |
| 36 | +cat > language_extension.ml <<EOF |
| 37 | +include Language_extension_kernel |
| 38 | +let is_enabled _ = true |
| 39 | +let is_at_least _ _ = true |
| 40 | +EOF |
| 41 | + |
| 42 | +if ! ocamlc -stop-after typing -I +compiler-libs \ |
| 43 | + $(basenames_in_dependency_order) |
| 44 | +then |
| 45 | + echo "Jane Syntax files failed to build with upstream OCaml" |
| 46 | + echo "See Note [Buildable with upstream] in ocaml/parsing/jane_syntax.mli" |
| 47 | + exit 2 |
| 48 | +else |
| 49 | + # Print the typechecked interfaces to support the assertion that this check |
| 50 | + # is actually checking anything. |
| 51 | + echo "Jane Syntax files built with upstream OCaml:" |
| 52 | + ocamlc -i -I +compiler-libs $(basenames_in_dependency_order) |
| 53 | +fi |
0 commit comments