From 2ac4bea2206f788364a1886a9234ff6a270445e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kami=CE=BB=20Shakirov?= Date: Tue, 6 Apr 2021 20:42:04 +0600 Subject: [PATCH] [ install ] Check if 'realpath' exists for Chez and Racket backends (#1210) --- .editorconfig | 14 +++++++---- .gitignore | 31 +++++++++++------------- bootstrap-stage1-chez.sh | 8 +++---- bootstrap-stage1-racket.sh | 8 +++---- bootstrap-stage2.sh | 2 +- bootstrap/idris2-boot | 20 ---------------- bootstrap/idris2-boot.sh | 30 ++++++++++++++++++++++++ bootstrap/idris2-rktboot | 15 ------------ bootstrap/idris2-rktboot.sh | 31 ++++++++++++++++++++++++ src/Compiler/Scheme/Chez.idr | 39 +++++++++++++++++++----------- src/Compiler/Scheme/Racket.idr | 43 +++++++++++++++++----------------- tests/Makefile | 1 + tests/chez/chez010/run | 4 ++-- tests/chez/chez013/run | 4 ++-- tests/chez/chez022/run | 4 ++-- 15 files changed, 148 insertions(+), 106 deletions(-) mode change 100644 => 100755 bootstrap-stage1-chez.sh mode change 100644 => 100755 bootstrap-stage1-racket.sh mode change 100644 => 100755 bootstrap-stage2.sh delete mode 100755 bootstrap/idris2-boot create mode 100755 bootstrap/idris2-boot.sh delete mode 100755 bootstrap/idris2-rktboot create mode 100755 bootstrap/idris2-rktboot.sh diff --git a/.editorconfig b/.editorconfig index e24adb262..df97ed627 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,12 +9,12 @@ trim_trailing_whitespace = true charset = utf-8 # Idris source files -[{*.idr,*.ipkg,*.tex,*.yaff,*.lidr}] +[*.{idr,ipkg,tex,yaff,lidr}] indent_style = space indent_size = 2 # Various configuration files -[*.yml,.ecrc] +[{*.yml,.ecrc}] indent_style = space indent_size = 2 @@ -22,7 +22,7 @@ indent_size = 2 indent_style = space indent_size = 4 -[{*.c,*.h}] +[*.{c,h}] indent_style = space indent_size = 4 @@ -30,7 +30,13 @@ indent_size = 4 indent_style = space indent_size = 2 -[{*.sh,*.bat}] +[*.sh] +indent_style = space +indent_size = 4 +shell_variant = posix +switch_case_indent = true + +[*.bat] indent_style = space indent_size = 4 diff --git a/.gitignore b/.gitignore index 983f4c465..8666feeda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -idris2docs_venv -result -*~ *.ibc *.ttc *.ttm @@ -10,14 +7,9 @@ result *.dll *.dylib -# Editor/IDE Related -.\#* # Emacs swap file -*~ # Vim swap file -# VS Code -.vscode/* - /build +idris2docs_venv /docs/build /libs/**/build @@ -27,22 +19,27 @@ result /tests/**/*.so /tests/**/*.dylib /tests/**/*.dll -/tests/build/exec /benchmark/**/build /benchmark/*.csv -/src/IdrisPaths.idr - /bootstrap/bin/ /bootstrap/lib/ -/bootstrap/idris2-0*/ -/bootstrap/idris2_app/idris2-boot* +/bootstrap/idris2-[0-9]*/ +/bootstrap/idris2_app/idris2-boot.* /bootstrap/idris2_app/libidris2_support.* -/bootstrap/idris2-boot -/bootstrap/idris2-boot.rkt + +/src/IdrisPaths.idr /custom.mk -#Mac OS +# NixOS +/result + +# Editor/IDE Related +*~ # Vim swap file +.\#* # Emacs swap file +.vscode/* # VS Code + +# macOS .DS_Store diff --git a/bootstrap-stage1-chez.sh b/bootstrap-stage1-chez.sh old mode 100644 new mode 100755 index 41a1039ce..fd7bc27c0 --- a/bootstrap-stage1-chez.sh +++ b/bootstrap-stage1-chez.sh @@ -1,15 +1,15 @@ #!/bin/sh -set -e # Exit on any error +set -e # exit on any error -echo "bootstrapping SCHEME=$SCHEME IDRIS2_VERSION=$IDRIS2_VERSION" if [ -z "$SCHEME" ] || [ -z "$IDRIS2_VERSION" ]; then - echo "Required ENV not set." + echo "Required SCHEME or IDRIS2_VERSION env is not set." if [ -z "$SCHEME" ]; then echo "Invoke with SCHEME=[name of chez scheme executable]" fi exit 1 fi +echo "Bootstrapping SCHEME=$SCHEME IDRIS2_VERSION=$IDRIS2_VERSION" # Compile the bootstrap scheme # TODO: Move boot-build to Makefile in bootstrap/Makefile @@ -20,5 +20,5 @@ ${SCHEME} --script compile.ss # Put the result in the usual place where the target goes mkdir -p ../build/exec mkdir -p ../build/exec/idris2_app -install idris2-boot ../build/exec/idris2 +install idris2-boot.sh ../build/exec/idris2 install idris2_app/* ../build/exec/idris2_app diff --git a/bootstrap-stage1-racket.sh b/bootstrap-stage1-racket.sh old mode 100644 new mode 100755 index a63b526d3..bb5c06f41 --- a/bootstrap-stage1-racket.sh +++ b/bootstrap-stage1-racket.sh @@ -1,12 +1,12 @@ #!/bin/sh -set -e # Exit on any error +set -e # exit on any error -echo "bootstrapping IDRIS2_VERSION=$IDRIS2_VERSION" if [ -z "$IDRIS2_VERSION" ]; then - echo "Required ENV not set." + echo "Required IDRIS2_VERSION env is not set." exit 1 fi +echo "Bootstrapping IDRIS2_VERSION=$IDRIS2_VERSION" # Compile the bootstrap scheme cd bootstrap @@ -16,5 +16,5 @@ raco exe idris2_app/idris2-boot.rkt # Put the result in the usual place where the target goes mkdir -p ../build/exec mkdir -p ../build/exec/idris2_app -install idris2-rktboot ../build/exec/idris2 +install idris2-rktboot.sh ../build/exec/idris2 install idris2_app/* ../build/exec/idris2_app diff --git a/bootstrap-stage2.sh b/bootstrap-stage2.sh old mode 100644 new mode 100755 index ea7e0a772..3521ce2d5 --- a/bootstrap-stage2.sh +++ b/bootstrap-stage2.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -e # Exit on any error +set -e # exit on any error PREFIX=$PWD/bootstrap diff --git a/bootstrap/idris2-boot b/bootstrap/idris2-boot deleted file mode 100755 index 2ac27ff88..000000000 --- a/bootstrap/idris2-boot +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -case `uname -s` in - OpenBSD|FreeBSD|NetBSD) - DIR="`grealpath $0`" - ;; - - *) - DIR="`realpath $0`" - ;; -esac - -if test -z "${SCHEME}"; then - echo "SCHEME env var is not set" >&2 - exit 1 -fi - -export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`dirname "$DIR"`/"idris2_app"" -export PATH="`dirname "$DIR"`/"idris2_app":$PATH" -${SCHEME} --script "`dirname $DIR`"/"idris2_app/idris2-boot.so" "$@" diff --git a/bootstrap/idris2-boot.sh b/bootstrap/idris2-boot.sh new file mode 100755 index 000000000..800eb9b7f --- /dev/null +++ b/bootstrap/idris2-boot.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -e # exit on any error + +if [ -z "$SCHEME" ]; then + echo "Required SCHEME env is not set." + exit 1 +fi + +case $(uname -s) in + OpenBSD | FreeBSD | NetBSD) + REALPATH="grealpath" + ;; + + *) + REALPATH="realpath" + ;; +esac + +if ! command -v "$REALPATH" >/dev/null; then + echo "$REALPATH is required for Chez code generator." + exit 1 +fi + +DIR=$(dirname "$($REALPATH "$0")") +LD_LIBRARY_PATH="$DIR/idris2_app":$LD_LIBRARY_PATH +PATH="$DIR/idris2_app":$PATH +export LD_LIBRARY_PATH PATH + +${SCHEME} --script "$DIR/idris2_app/idris2-boot.so" "$@" diff --git a/bootstrap/idris2-rktboot b/bootstrap/idris2-rktboot deleted file mode 100755 index ff922cdd1..000000000 --- a/bootstrap/idris2-rktboot +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -case `uname -s` in - OpenBSD|FreeBSD|NetBSD) - DIR="`grealpath $0`" - ;; - - *) - DIR="`realpath $0`" - ;; -esac - -export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`dirname "$DIR"`/"idris2_app"" -export PATH="`dirname "$DIR"`/"idris2_app":$PATH" -"`dirname $DIR`"/"idris2_app/idris2-boot" "$@" diff --git a/bootstrap/idris2-rktboot.sh b/bootstrap/idris2-rktboot.sh new file mode 100755 index 000000000..f3973e0f4 --- /dev/null +++ b/bootstrap/idris2-rktboot.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -e # exit on any error + +if [ -z "$IDRIS2_VERSION" ]; then + echo "Required IDRIS2_VERSION env is not set." + exit 1 +fi +echo "Bootstrapping IDRIS2_VERSION=$IDRIS2_VERSION" + +case $(uname -s) in + OpenBSD | FreeBSD | NetBSD) + REALPATH="grealpath" + ;; + + *) + REALPATH="realpath" + ;; +esac + +if ! command -v "$REALPATH" >/dev/null; then + echo "$REALPATH is required for Racket code generator." + exit 1 +fi + +DIR=$(dirname "$($REALPATH "$0")") +LD_LIBRARY_PATH="$DIR/idris2_app":$LD_LIBRARY_PATH +PATH="$DIR/idris2_app":$PATH +export LD_LIBRARY_PATH PATH + +"$DIR/idris2_app/idris2-boot" "$@" diff --git a/src/Compiler/Scheme/Chez.idr b/src/Compiler/Scheme/Chez.idr index e3882e3c8..3e5ecb763 100644 --- a/src/Compiler/Scheme/Chez.idr +++ b/src/Compiler/Scheme/Chez.idr @@ -342,18 +342,26 @@ startChez : String -> String -> String startChez appdir target = unlines [ "#!/bin/sh" , "" - , "case `uname -s` in " - , " OpenBSD|FreeBSD|NetBSD) " - , " DIR=\"`grealpath $0`\"" - , " ;; " - , " " - , " *) " - , " DIR=\"`realpath $0`\" " - , " ;; " - , "esac " + , "set -e # exit on any error" , "" - , "export LD_LIBRARY_PATH=\"`dirname \"$DIR\"`/\"" ++ appdir ++ "\":$LD_LIBRARY_PATH\"" - , "\"`dirname \"$DIR\"`\"/\"" ++ target ++ "\" \"$@\"" + , "case $(uname -s) in " + , " OpenBSD | FreeBSD | NetBSD)" + , " REALPATH=\"grealpath\" " + , " ;; " + , " " + , " *) " + , " REALPATH=\"realpath\" " + , " ;; " + , "esac " + , "" + , "if ! command -v \"$REALPATH\" >/dev/null; then " + , " echo \"$REALPATH is required for Chez code generator.\"" + , " exit 1 " + , "fi " + , "" + , "DIR=$(dirname \"$($REALPATH \"$0\")\")" + , "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ "\":$LD_LIBRARY_PATH" + , "\"$DIR/" ++ target ++ "\" \"$@\"" ] startChezCmd : String -> String -> String -> String @@ -367,10 +375,13 @@ startChezCmd chez appdir target = unlines startChezWinSh : String -> String -> String -> String startChezWinSh chez appdir target = unlines [ "#!/bin/sh" - , "DIR=\"`realpath \"$0\"`\"" + , "" + , "set -e # exit on any error" + , "" + , "DIR=$(dirname \"$(realpath \"$0\")\")" , "CHEZ=$(cygpath \"" ++ chez ++"\")" - , "export PATH=\"`dirname \"$DIR\"`/\"" ++ appdir ++ "\":$PATH\"" - , "\"$CHEZ\" --script \"$(dirname \"$DIR\")/" ++ target ++ "\" \"$@\"" + , "export PATH=\"$DIR/" ++ appdir ++ "\":$PATH" + , "\"$CHEZ\" --script \"$DIR/" ++ target ++ "\" \"$@\"" ] ||| Compile a TT expression to Chez Scheme diff --git a/src/Compiler/Scheme/Racket.idr b/src/Compiler/Scheme/Racket.idr index 09a47d31a..a5816d65e 100644 --- a/src/Compiler/Scheme/Racket.idr +++ b/src/Compiler/Scheme/Racket.idr @@ -327,18 +327,26 @@ startRacket : String -> String -> String -> String startRacket racket appdir target = unlines [ "#!/bin/sh" , "" - , "case `uname -s` in " - , " OpenBSD|FreeBSD|NetBSD) " - , " DIR=\"`grealpath $0`\"" - , " ;; " - , " " - , " *) " - , " DIR=\"`realpath $0`\" " - , " ;; " - , "esac " + , "set -e # exit on any error" , "" - , "export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH:`dirname \"$DIR\"`/\"" ++ appdir ++ "\"\"" - , racket ++ "\"`dirname \"$DIR\"`\"/\"" ++ target ++ "\" \"$@\"" + , "case $(uname -s) in " + , " OpenBSD | FreeBSD | NetBSD)" + , " REALPATH=\"grealpath\" " + , " ;; " + , " " + , " *) " + , " REALPATH=\"realpath\" " + , " ;; " + , "esac " + , "" + , "if ! command -v \"$REALPATH\" >/dev/null; then " + , " echo \"$REALPATH is required for Racket code generator.\"" + , " exit 1 " + , "fi " + , "" + , "DIR=$(dirname \"$($REALPATH \"$0\")\")" + , "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ "\":$LD_LIBRARY_PATH" + , racket ++ "\"$DIR/" ++ target ++ "\" \"$@\"" ] startRacketCmd : String -> String -> String -> String @@ -353,17 +361,10 @@ startRacketWinSh : String -> String -> String -> String startRacketWinSh racket appdir target = unlines [ "#!/bin/sh" , "" - , "case `uname -s` in " - , " OpenBSD|FreeBSD|NetBSD) " - , " DIR=\"`grealpath $0`\"" - , " ;; " - , " " - , " *) " - , " DIR=\"`realpath $0`\" " - , " ;; " - , "esac " + , "set -e # exit on any error" , "" - , "export PATH=\"`dirname \"$DIR\"`/\"" ++ appdir ++ "\":$PATH\"" + , "DIR=$(dirname \"$(realpath \"$0\")\")" + , "export PATH=\"$DIR/" ++ appdir ++ "\":$PATH" , racket ++ "\"" ++ target ++ "\" \"$@\"" ] diff --git a/tests/Makefile b/tests/Makefile index ad65ac343..b16f018d6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -11,6 +11,7 @@ testbin: clean: $(RM) -r build + $(RM) -r **/**/build @find . -type f -name 'output' -exec rm -rf {} \; @find . -type f -name '*.ttc' -exec rm -f {} \; @find . -type f -name '*.ttm' -exec rm -f {} \; diff --git a/tests/chez/chez010/run b/tests/chez/chez010/run index 0cf8860b2..95cb5d36f 100755 --- a/tests/chez/chez010/run +++ b/tests/chez/chez010/run @@ -1,5 +1,5 @@ -case `uname -s` in - OpenBSD|FreeBSD|NetBSD) +case $(uname -s) in + OpenBSD | FreeBSD | NetBSD) MAKE=gmake ;; diff --git a/tests/chez/chez013/run b/tests/chez/chez013/run index e8cd032a7..3c756a9c4 100755 --- a/tests/chez/chez013/run +++ b/tests/chez/chez013/run @@ -1,5 +1,5 @@ -case `uname -s` in - OpenBSD|FreeBSD|NetBSD) +case $(uname -s) in + OpenBSD | FreeBSD | NetBSD) MAKE=gmake ;; diff --git a/tests/chez/chez022/run b/tests/chez/chez022/run index 34ce76ed6..563e10ce6 100755 --- a/tests/chez/chez022/run +++ b/tests/chez/chez022/run @@ -1,5 +1,5 @@ -case `uname -s` in - OpenBSD|FreeBSD|NetBSD) +case $(uname -s) in + OpenBSD | FreeBSD | NetBSD) MAKE=gmake ;;