Isabelle/DOF is a novel Document Ontology Framework on top of Isabelle. Isabelle/DOF allows for both conventional typesetting as well as formal development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

273 lines
9.7 KiB

  1. #!/usr/bin/env bash
  2. # Copyright (c) 2018-2019 The University of Sheffield.
  3. # 2019-2020 The University of Exeter.
  4. # 2018-2020 The University of Paris-Saclay.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in
  13. # the documentation and/or other materials provided with the
  14. # distribution.
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  18. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  21. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  25. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. # POSSIBILITY OF SUCH DAMAGE.
  27. #
  28. # SPDX-License-Identifier: BSD-2-Clause
  29. #set -e
  30. shopt -s nocasematch
  31. # get global configuration
  32. if [ -d .git ]; then
  33. export `git show -s --format="COMMIT=%H DATE=%cd" --date=short | sed -e 's|-|/|g'`
  34. fi
  35. source .config
  36. print_help()
  37. {
  38. echo "Usage: install [OPTION] "
  39. echo ""
  40. echo "Run ..."
  41. echo ""
  42. echo " --help, -h display this help message"
  43. echo " --isabelle, -i isabelle isabelle command used for installation"
  44. echo " (default: $ISABELLE)"
  45. echo " --skip-patch-and-afp, -s skip installation of Isabelle/DOF patch for"
  46. echo " Isabelle and required AFP entries. "
  47. echo " USE AT YOUR OWN RISK (default: $SKIP)"
  48. }
  49. exit_error() {
  50. echo ""
  51. echo " *** Isabelle/DOF installation FAILED, please check the README.md for help ***"
  52. echo ""
  53. exit 1
  54. }
  55. check_isabelle_version() {
  56. echo "* Checking Isabelle version:"
  57. if [ "$ISABELLE_VERSION" != "$ACTUAL_ISABELLE_VERSION" ]; then
  58. echo " WARNING:"
  59. echo " The version of Isabelle (i.e., $ACTUAL_ISABELLE_VERSION) you are using"
  60. echo " IS NOT SUPPORTED"
  61. echo " by the current version of Isabelle/DOF. Please install a supported"
  62. echo " version of Isabelle and rerun the install script, providing the"
  63. echo " the \"isabelle\" command as argument."
  64. echo " Isabelle ($ISABELLE_VERSION) can be obtained from:"
  65. echo " $ISABELLE_URL"
  66. echo
  67. read -p " Still continue (y/N)? " -n 1 -r
  68. echo
  69. if [[ $REPLY =~ ^[Yy]$ ]];
  70. then
  71. echo " Continuing installation on your OWN risk."
  72. else
  73. exit_error
  74. fi
  75. else
  76. echo " Success: found supported Isabelle version ($ISABELLE_VERSION)"
  77. fi
  78. }
  79. check_afp_entries() {
  80. echo "* Checking availability of AFP entries:"
  81. missing=""
  82. required="Regular-Sets Functional-Automata"
  83. for afp in $required; do
  84. res=`$ISABELLE build -n $afp 2>/dev/null || true`
  85. if [ "$res" != "" ]; then
  86. echo " Success: found APF entry $afp."
  87. else
  88. echo " Warning: could not find AFP entry $afp."
  89. missing="$missing $afp"
  90. fi
  91. done
  92. if [ "$missing" != "" ]; then
  93. echo " Trying to install AFP (this might take a few *minutes*) ...."
  94. extract=""
  95. for e in $missing; do
  96. extract="$extract $AFP_DATE/thys/$e"
  97. done
  98. mkdir -p .afp
  99. if curl -s -L $AFP_URL | tar zxf - -C .afp $extract; then
  100. for e in $missing; do
  101. echo " Registering $e in $ISABELLE_HOME_USER/ROOTS"
  102. touch $ISABELLE_HOME_USER/ROOTS
  103. grep -q $PWD/.afp/$AFP_DATE/thys/$e $ISABELLE_HOME_USER/ROOTS || echo "$PWD/.afp/$AFP_DATE/thys/$e" >> $ISABELLE_HOME_USER/ROOTS
  104. done
  105. echo " AFP installation successful."
  106. else
  107. echo " FAILURE: could not find AFP entries: $missing."
  108. echo " Please obtain the AFP from"
  109. echo " $AFP_URL"
  110. echo " and follow the following instructions:"
  111. echo " https://www.isa-afp.org/using.html"
  112. exit_error
  113. fi
  114. fi
  115. }
  116. check_isa_dof_patch() {
  117. echo "* Check availability of Isabelle/DOF patch:"
  118. src="src/patches/thy_output.ML"
  119. dst="$ISABELLE_HOME/src/Pure/Thy/thy_output.ML"
  120. if command -v cmp > /dev/null 2>&1 && cmp -s "$src" "$dst" ; then
  121. echo " Success: latest Isabelle/DOF patch already applied"
  122. if isabelle process -e 'Thy_Output.set_meta_args_parser' &> /dev/null ; then
  123. true
  124. else
  125. echo " Warning: Isabelle/HOL needs to be rebuild to activate patch."
  126. fi
  127. else
  128. command -v cmp >/dev/null 2>&1 || echo " Warning: cmp not available, cannot check if patch is already applied."
  129. echo " Warning: Isabelle/DOF patch is not available or outdated."
  130. echo " Trying to patch system ...."
  131. if [ ! -f "$dst.backup-by-isadof-installer" ]; then
  132. cp -f "$dst" "$dst.backup-by-isadof-installer" || true;
  133. fi
  134. if (cp -f $src $dst) &> /dev/null; then
  135. echo " Applied patch successfully, Isabelle/HOL will be rebuilt during"
  136. echo " the next start of Isabelle."
  137. else
  138. echo " FAILURE: Could not apply Isabelle/DOF patch."
  139. echo " Please copy $src to $dst, e.g.:"
  140. echo " cp -f $src $dst"
  141. echo " and rebuild Isabelle/HOL."
  142. exit_error
  143. fi
  144. fi
  145. }
  146. check_old_installation(){
  147. echo "* Searching for existing installation:"
  148. if [[ -d "$ISABELLE_HOME_USER/DOF" ]]; then
  149. echo " Found old installation, moving it to $ISABELLE_HOME_USER/DOF.bak."
  150. rm -rf "$ISABELLE_HOME_USER/DOF.bak"
  151. mv "$ISABELLE_HOME_USER/DOF" "$ISABELLE_HOME_USER/DOF.bak"
  152. else
  153. echo " No old installation found."
  154. fi
  155. }
  156. install_and_register(){
  157. echo "* Installing Isabelle/DOF"
  158. DIR="$ISABELLE_HOME_USER/DOF/Tools"
  159. echo " - Installing Tools in $DIR"
  160. mkdir -p "$DIR"
  161. cp $GEN_DIR/Tools/* "$DIR"
  162. chmod 755 "$DIR"/*
  163. DIR="$ISABELLE_HOME_USER/DOF/document-template"
  164. echo " - Installing document templates in $DIR"
  165. mkdir -p "$DIR"
  166. cp $GEN_DIR/scripts/* "$DIR"
  167. cp $GEN_DIR/document-templates/* "$DIR"
  168. cp $GEN_DIR/DOF/*/*.sty "$DIR"
  169. ISABELLE_SHORT_VERSION=`echo $ISABELLE_VERSION | sed -e 's/:.*$//'`
  170. sed -i -e "s|%%% CONFIG %%%| \
  171. \\\\renewcommand{\\\\dof@isabelleversion}{$ISABELLE_SHORT_VERSION} \
  172. \\\\renewcommand{\\\\isabellelatestversion}{$DOF_LATEST_ISABELLE} \
  173. \\\\renewcommand{\\\\isabellefullversion}{$ISABELLE_VERSION\\\\xspace} \
  174. \\\\renewcommand{\\\\dof@version}{$DOF_VERSION} \
  175. \\\\renewcommand{\\\\doflatestversion}{$DOF_LATEST_VERSION} \
  176. \\\\renewcommand{\\\\isadoflatestdoi}{$DOF_LATEST_DOI} \
  177. \\\\renewcommand{\\\\isadofgenericdoi}{$DOF_GENERIC_DOI} \
  178. \\\\renewcommand{\\\\isabelleurl}{$ISABELLE_URL} \
  179. \\\\renewcommand{\\\\dofurl}{$DOF_URL} \
  180. \\\\renewcommand{\\\\dof@artifacturl}{https://$DOF_ARTIFACT_HOST/$DOF_ARTIFACT_DIR}|" \
  181. "$DIR/DOF-core.sty"
  182. DIR="$ISABELLE_HOME_USER/DOF/latex"
  183. echo " - Installing LaTeX styles in $DIR"
  184. mkdir -p "$DIR"
  185. cp $GEN_DIR/ontologies/*/*.sty "$DIR"
  186. DIR="$ISABELLE_HOME_USER/etc"
  187. echo " - Registering Isabelle/DOF"
  188. mkdir -p "$DIR"
  189. if [[ $ISABELLE_TOOLS = *DOF* ]]; then
  190. echo " * Tools already registered in $DIR/settings"
  191. else
  192. echo " * Registering tools in $DIR/settings"
  193. echo 'ISABELLE_TOOLS=$ISABELLE_TOOLS:$ISABELLE_HOME_USER/DOF/Tools' \
  194. >> "$DIR/settings"
  195. fi
  196. if [[ $ISABELLE_DOCS = *DOF* ]]; then
  197. echo " * Docs already registered in $DIR/settings"
  198. else
  199. echo " * Registering docs in $DIR/settings"
  200. echo "ISABELLE_DOCS=$PWD/doc"':$ISABELLE_DOCS' \
  201. >> "$DIR/settings"
  202. fi
  203. sed -i -e "s|<isadofurl>|$DOF_URL|" $ISABELLE_HOME_USER/DOF/*/*
  204. LTX_VERSION="$DATE $DOF_VERSION/$ISABELLE_SHORT_VERSION"
  205. sed -i -e "s|<isadofltxversion>|$LTX_VERSION|" $ISABELLE_HOME_USER/DOF/*/*
  206. touch $ISABELLE_HOME_USER/ROOTS
  207. grep -q $PWD'$' $ISABELLE_HOME_USER/ROOTS || echo "$PWD" >> $ISABELLE_HOME_USER/ROOTS
  208. }
  209. ISABELLE=`which isabelle`
  210. SKIP="false"
  211. while [ $# -gt 0 ]
  212. do
  213. case "$1" in
  214. --isabelle|-i)
  215. ISABELLE="$2";
  216. shift;;
  217. --skip-patch-and-afp|-s)
  218. SKIP="true";;
  219. --help|-h)
  220. print_help
  221. exit 0;;
  222. *) print_help
  223. exit 1;;
  224. esac
  225. shift
  226. done
  227. ACTUAL_ISABELLE_VERSION=`$ISABELLE version`
  228. GEN_DIR=src
  229. PROG=`echo $0 | sed 's|.*/||'`;
  230. VARS=`$ISABELLE getenv ISABELLE_HOME_USER ISABELLE_HOME ISABELLE_TOOLS ISABELLE_DOCS`
  231. for i in $VARS; do
  232. export "$i"
  233. done
  234. echo ""
  235. echo "Isabelle/DOF Installer"
  236. echo "======================"
  237. check_isabelle_version
  238. if [ "$SKIP" = "true" ]; then
  239. echo "* Warning: skipping installation of Isabelle patch and AFP entries."
  240. else
  241. check_isa_dof_patch
  242. check_afp_entries
  243. fi
  244. check_old_installation
  245. install_and_register
  246. echo "* Installation successful. Enjoy Isabelle/DOF, you can build the session"
  247. echo " Isabelle/DOF and all example documents by executing:"
  248. echo " $ISABELLE build -D ."
  249. exit 0