Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paulus/fix spaces2 #3

Closed
wants to merge 16 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dependency-reduced-pom.xml
target
out
4 changes: 4 additions & 0 deletions demo/src/foo/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns foo.core)

(defn -main [& args]
(prn args))
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<properties>
<clojure.version>1.9.0</clojure.version>
<tools.deps.version>0.5.460</tools.deps.version>
<tools.deps.version>0.5.461-SNAPSHOT</tools.deps.version>
</properties>

<dependencies>
Expand Down
4 changes: 4 additions & 0 deletions script/demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.."

bash -x out/inst/bin/clojure -Srepro -Sdeps '{:paths ["demo/src"] :aliases {:space {:main-opts ["-m" "foo.core" "-co" "{:aot-cache true}"]}}}' -Aspace
107 changes: 107 additions & 0 deletions script/explode
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.."

# Explodes the first argument passed, string, into an array
#
# Arguments are separated by newlines. A literal newline must be escaped with a
# backslash. A backslah needs to be escaped as \\. A single trailing newline
# will be ignored. Results are written to global array `args'.

function explode() {
s="$1"

# Remove trailing newline

if [[ "${s:$((${#s}-1)):1}" == $'\n' ]]; then
s=${s:0:${#s}-1}
fi

args=()

if [[ "$s" != "" ]]; then
arg=""

for (( i=0; i<${#s}; i++ )); do
c="${s:$i:1}"

if [[ "$c" == $'\n' ]]; then
args+=("$arg")
arg=""
elif [[ "$c" == "\\" ]]; then
# Interpret next character literally
i=$((i + 1))
c="${s:$i:1}"
arg="${arg}${c}"
else
arg="${arg}${c}"
fi
done

args+=("$arg")
fi
}

# ---------------
# Unit tests

function dump() {
python -c "import sys, json; sys.stdout.write(json.dumps(sys.argv[1:]))" "$@"
}

function check() {
if [[ "${args[@]+"${args[@]}"}" == "" ]]; then
# Corner case, Bash array oddity
actual="[]"
else
# Normal casek
actual="$(dump "${args[@]+"${args[@]}"}")"
fi
if [[ "$actual" != "$expected" ]]; then
echo "Assertion failed"
printf "actual: %s\n" "$actual"
printf "expected: %s\n" "$expected"
exit 1
else
echo "Ok"
fi
}

explode $'foo bar'
expected='["foo bar"]'
check

explode $'foo\nbar'
expected='["foo", "bar"]'
check

explode $'foo\nbar\n'
expected='["foo", "bar"]'
check

explode $'foo\nbar '
expected='["foo", "bar "]'
check

explode $'-co\n{:aot-cache true}'
expected='["-co", "{:aot-cache true}"]'
check

explode $''
expected='[]'
check

explode $'\nfoo'
expected='["", "foo"]'
check

explode $'\nfoo\n\nbar'
expected='["", "foo", "", "bar"]'
check

explode $'foo\\\nbar'
expected='["foo\nbar"]'
check

explode $'foo\\'
expected='["foo"]'
check
16 changes: 16 additions & 0 deletions script/try
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.."

set -x

pushd ../tools.deps.alpha
mvn install
popd

script/package.sh
rm -rf out
mkdir -p out
tar xfzv target/*.tar.gz -C out
mkdir -p out/inst
cd out/clojure-tools
./install.sh "$(realpath ../inst)"
2 changes: 1 addition & 1 deletion src/main/resources/clojure
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ else
jvm_cache_opts=($(cat "$jvm_file"))
fi
if [[ -e "$main_file" ]]; then
main_cache_opts=($(cat "$main_file"))
eval "main_cache_opts=($(cat "$main_file"))"
fi
exec "$JAVA_CMD" "${jvm_cache_opts[@]}" "${jvm_opts[@]}" "-Dclojure.libfile=$libs_file" -classpath "$cp" clojure.main "${main_cache_opts[@]}" "$@"
fi
1 change: 1 addition & 0 deletions test.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-co {:aot-cache\ true}