-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
129 lines (102 loc) · 3.27 KB
/
check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# DO NOT EDIT THIS FILE
TARGETS="ogit.cmo command.cmo state.cmo test.cmo renderer.cmo plumbing.cmo porcelain.cmo"
ZIP=project.zip
ZIPCHECKFILE=main.ml
OCAMLBUILD="ocamlbuild -use-ocamlfind"
OPAMV=2.*
OCAMLV=4.11.*
OCAMLVM1=4.10.2
OUNITV=2.*
BLUE="\033[0;34m"
RED="\033[0;31m"
NOCOLOR="\033[0m"
print_meta () {
printf "\n🐫 $BLUE<><> $1 <><>$NOCOLOR\n\n"
}
print_info () {
printf "$1\n"
}
print_err () {
printf "$RED$1$NOCOLOR\n"
}
print_fatal () {
print_err "\n$1\n"
}
print_meta "Checking your OCaml environment"
environment=good
OPAM_LOCATION="$(command -v opam)"
if [[ $OPAM_LOCATION == "" ]]; then
print_err "OPAM is NOT available. This is bad."
environment=bad
else
print_info "OPAM is available. Good."
fi
OPAM_VERSION="$(opam --version)"
if [[ $OPAM_VERSION =~ $OPAMV ]]; then
print_info "OPAM version $OPAM_VERSION is installed. Good."
else
print_err "OPAM version $OPAMV is NOT installed. This is bad."
print_err "The installed version is: $OPAM_VERSION"
environment=bad
fi
OCAMLC_VERSION="$(ocamlc --version 2>&1)"
if [[ $OCAMLC_VERSION =~ $OCAMLV ]]; then
print_info "OCaml compiler version $OCAMLC_VERSION is active. Good."
else
PLATFORM_NAME="$(uname -sm)"
if [[ $PLATFORM_NAME == "Darwin arm64" ]] && [[ $OCAMLC_VERSION == $OCAMLVM1 ]]; then
print_info "OCaml compiler version $OCAMLC_VERSION is active on Apple Silicon. Good."
else
print_err "OCaml compiler version $OCAMLV is NOT active. This is bad."
print_err "The active version is: $OCAMLC_VERSION"
environment=bad
fi
fi
OUNIT_VERSION="$(opam info ounit -f version 2>&1)"
if [[ $OUNIT_VERSION =~ $OUNITV ]]; then
print_info "OUnit version $OUNIT_VERSION is active. Good."
else
print_err "OUnit version $OUNITV is NOT active. This is bad."
print_err "The active version of OUnit is: $OUNIT_VERSION"
environment=bad
fi
if [[ ! $environment == good ]]; then
print_fatal "Your OCaml environment is broken."
exit 1
fi
print_meta "Checking whether your code compiles"
$OCAMLBUILD $TARGETS
if [[ $? -ne 0 ]]; then
print_fatal "Your code does not compile."
exit 1
fi
print_meta "Congratulations! You have passed [make check]."
if [[ $1 != "final" ]]; then
exit 0
fi
print_meta "Checking for zip file"
if [[ -x "$(command -v md5)" ]]; then
MD5=md5
elif [[ -x "$(command -v md5sum)" ]]; then
MD5=md5sum
else
print_fatal "Unable to find a working MD5 command."
exit 1
fi
if [[ ! -f "$ZIP" ]]; then
print_fatal "Your ZIP file cannot be found. Run [make zip] and try again."
exit 1
fi
if ! zipinfo -1 "$ZIP" | grep -q "^$ZIPCHECKFILE$"; then
print_fatal "Your ZIP file is malformed. Remove it then run [make zip] and try again."
exit 1
fi
if zipinfo -1 "$ZIP" | grep -q "_build"; then
print_fatal "Your ZIP file is malformed. Remove it then run [make zip] and try again."
exit 1
fi
print_meta "Congratulations! You have passed [make finalcheck]."
$MD5 $ZIP
print_info "\nRemember to submit the ZIP file produced by [make zip],\n\
rather than attempting to create the ZIP file yourself."