From f3244ba4ff2282e5ac30a701fa38b0944d75eb00 Mon Sep 17 00:00:00 2001 From: vemv Date: Sun, 3 Dec 2023 21:08:28 +0100 Subject: [PATCH] Fix handling of user-provided `-e` args Closes https://github.com/clojure-emacs/enrich-classpath/issues/58 --- Makefile | 2 +- examples/Makefile | 2 +- lein-plugin/Makefile | 2 +- tools.deps/Makefile | 2 +- .../src/cider/enrich_classpath/clojure.clj | 20 +++++++++++++++++++ .../src/cider/enrich_classpath/clojure.sh | 2 +- .../cider/enrich_classpath/clojure.clj | 14 ++++++++++++- 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index bda64ec..f3cc8f2 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/examples/Makefile b/examples/Makefile index 73eb870..a44221b 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -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. diff --git a/lein-plugin/Makefile b/lein-plugin/Makefile index c350623..be74433 100644 --- a/lein-plugin/Makefile +++ b/lein-plugin/Makefile @@ -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. diff --git a/tools.deps/Makefile b/tools.deps/Makefile index d23add3..5665846 100644 --- a/tools.deps/Makefile +++ b/tools.deps/Makefile @@ -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. diff --git a/tools.deps/src/cider/enrich_classpath/clojure.clj b/tools.deps/src/cider/enrich_classpath/clojure.clj index 8114a0a..59d1484 100644 --- a/tools.deps/src/cider/enrich_classpath/clojure.clj +++ b/tools.deps/src/cider/enrich_classpath/clojure.clj @@ -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 @@ -218,6 +237,7 @@ [] (mapv (partial str "-J") calculated-jvm-opts))) + (into @eval-option) (into (if (seq main-opts) main-opts [])) diff --git a/tools.deps/src/cider/enrich_classpath/clojure.sh b/tools.deps/src/cider/enrich_classpath/clojure.sh index f20a4f7..9b8b3d2 100755 --- a/tools.deps/src/cider/enrich_classpath/clojure.sh +++ b/tools.deps/src/cider/enrich_classpath/clojure.sh @@ -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" diff --git a/tools.deps/test/integration/cider/enrich_classpath/clojure.clj b/tools.deps/test/integration/cider/enrich_classpath/clojure.clj index 2a2eb04..6dcded0 100644 --- a/tools.deps/test/integration/cider/enrich_classpath/clojure.clj +++ b/tools.deps/test/integration/cider/enrich_classpath/clojure.clj @@ -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"