Skip to content

Commit

Permalink
Fix handling of user-provided -e args
Browse files Browse the repository at this point in the history
Closes #58
  • Loading branch information
vemv committed Dec 3, 2023
1 parent 14cecde commit f3244ba
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install-deps: install-base
install-plugin: install-base
cd lein-plugin; lein with-profile -user install

# Usage: PROJECT_VERSION=1.18.6 make install
# Usage: PROJECT_VERSION=1.19.0 make install
# PROJECT_VERSION is needed because it's not computed dynamically
install: install-base install-deps install-plugin

Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEPS_MAIN_OPTS ?= "-M:dev:test"

# The enrich-classpath version to be injected.
# Feel free to upgrade this.
ENRICH_CLASSPATH_VERSION="1.18.6"
ENRICH_CLASSPATH_VERSION="1.19.0"

# Create and cache a `java` command. project.clj is mandatory; the others are optional but are taken into account for cache recomputation.
# It's important not to silence with step with @ syntax, so that Enrich progress can be seen as it resolves dependencies.
Expand Down
2 changes: 1 addition & 1 deletion lein-plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DEPS_MAIN_OPTS ?= "-M:dev:test"

# The enrich-classpath version to be injected.
# Feel free to upgrade this.
ENRICH_CLASSPATH_VERSION="1.18.6"
ENRICH_CLASSPATH_VERSION="1.19.0"

# Create and cache a `java` command. project.clj is mandatory; the others are optional but are taken into account for cache recomputation.
# It's important not to silence with step with @ syntax, so that Enrich progress can be seen as it resolves dependencies.
Expand Down
2 changes: 1 addition & 1 deletion tools.deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DEPS_MAIN_OPTS ?= "-M:dev:test"

# The enrich-classpath version to be injected.
# Feel free to upgrade this.
ENRICH_CLASSPATH_VERSION="1.18.6"
ENRICH_CLASSPATH_VERSION="1.19.0"

# Create and cache a `java` command. project.clj is mandatory; the others are optional but are taken into account for cache recomputation.
# It's important not to silence with step with @ syntax, so that Enrich progress can be seen as it resolves dependencies.
Expand Down
20 changes: 20 additions & 0 deletions tools.deps/src/cider/enrich_classpath/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@
args (into []
(remove (hash-set main extra-flag extra-value))
args)
eval-option (atom [])
args (reduce-kv (fn [acc ^long i x]
(let [j (dec i)]
(cond
(#{"-e" (pr-str "-e")} x)
(do
(swap! eval-option conj x)
acc)

(and (>= j 0)
(#{"-e" (pr-str "-e")} (nth args j)))
(do
(swap! eval-option conj (pr-str x))
acc)

:else
(conj acc x))))
[]
args)
main-opts (reduce-kv (fn [acc ^long i x]
(let [j (dec i)]
(conj acc (cond-> x
Expand Down Expand Up @@ -218,6 +237,7 @@
[]
(mapv (partial str "-J")
calculated-jvm-opts)))
(into @eval-option)
(into (if (seq main-opts)
main-opts
[]))
Expand Down
2 changes: 1 addition & 1 deletion tools.deps/src/cider/enrich_classpath/clojure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else
cd "$there"

# enrich-classpath will emit a command starting by "clojure", or print a stacktrace:
output=$(2>&1 "$clojure" -Sforce -Srepro -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.main.report=stderr -Sdeps '{:deps {mx.cider/tools.deps.enrich-classpath {:mvn/version "1.18.6"}}}' -M -m cider.enrich-classpath.clojure "$clojure" "$here" "true" "$@")
output=$(2>&1 "$clojure" -Sforce -Srepro -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.main.report=stderr -Sdeps '{:deps {mx.cider/tools.deps.enrich-classpath {:mvn/version "1.19.0"}}}' -M -m cider.enrich-classpath.clojure "$clojure" "$here" "true" "$@")
cmd=$(tail -n1 <(echo "$output"))

cd "$here"
Expand Down
14 changes: 13 additions & 1 deletion tools.deps/test/integration/cider/enrich_classpath/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,19 @@
["-A:eval"]
false)]
(is (string/includes? cp "-e \"(println \\\"foo\\\")\"")
"Escapes the -e value")))
"Escapes the -e value"))

(testing "https://github.com/clojure-emacs/enrich-classpath/issues/58"
(let [^String cp (sut/impl "clojure"
"deps.edn"
(str (io/file (System/getProperty "user.dir") "test-resources" "eval"))
["-e" "\"(+ 311 2)\""]
false)]
(is (string/ends-with? cp "-e \"\\\"(+ 311 2)\\\"\"")
"Honors a user-provided `-e`, placing it at the correct position")
(is (= (.indexOf cp "311")
(.lastIndexOf cp "311"))
"`-e` is effectively moved, so that it's not emitted twice"))))

(deftest path-aliases
(let [cp (sut/impl "clojure"
Expand Down

0 comments on commit f3244ba

Please sign in to comment.