dundalek/closh

Referring to def'd var blows up program

Closed this issue · 5 comments

repro.cljs

(when (clojure.string/blank? (getenv "JAR")) (setenv "JAR" "lambda.jar"))
(def target-name (str "target/uberjar/" (getenv "JAR")))
(defn jar-not-exists? [] (not (sh-ok test -f (str target-name))))

(when (jar-not-exists?) (source-shell "mkdir -p target/uberjar/; touch target/uberjar/lambda.jar"))

rm -f (str target-name)

(when (jar-not-exists?) (sh echo (str (str target-name) " was not created.")))

repro.sh

#!/bin/bash

closh < `dirname $0`/repro.cljs

Running repro.sh blows up on the rm -f (str target-name) line. Any reference to target-name or to (getenv "JAR") there will cause the same blowup.

Also a simple ls after a reference to either target-name or (getenv "JAR") will cause the same.

The program exits with a success code of 0 (and the lines after blow up do not execute).

Related: #2

Here is a workaround:

jclosh.sh

#!/bin/bash

tmppipe=$(mktemp -u)
mkfifo -m 600 "$tmppipe"
closh < "$tmppipe" & > 1
closh_pid=$!

while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "$line" > "$tmppipe";
done < "$1"

wait $closh_pid

Use it like so:

$ jclosh.sh repro.cljs

Thanks for the repro. Could you explain what is the principle behind the workaround? It seems it feeds the input via fifo pipe. What is the difference from the plain file redirection?

Line-by-line rather than all at once. I have no idea why this would matter but it does.

Initial iteration of script mode has now landed in the latest JVM version release v0.4, you can read how to use it in the scripting docs.