From d1aaa97df629f3fe3edd1bc499f31caf238a1473 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 18 Jan 2020 18:25:38 +0100 Subject: [PATCH] sci: record file metadata on var --- sci | 2 +- src/babashka/main.clj | 5 ++--- test/babashka/file_var_test.clj | 5 +++-- test/babashka/scripts/file_var.bb | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sci b/sci index 35ed8cce..c84dbaa1 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 35ed8cced594f2733ca02d9b7c0b2e7a984adfb3 +Subproject commit c84dbaa110cf01b56be38f58c5a7f14cc030f90d diff --git a/src/babashka/main.clj b/src/babashka/main.clj index d9c59fc2..d4d3e973 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -191,7 +191,7 @@ Everything after that is bound to *command-line-args*.")) (defn load-file* [sci-ctx f] (let [f (io/file f) s (slurp f)] - (sci/with-bindings {vars/file-var (.getCanonicalPath f)} + (sci/with-bindings {vars/current-file (.getCanonicalPath f)} (eval-string* sci-ctx s)))) (defn eval* [sci-ctx form] @@ -303,14 +303,13 @@ Everything after that is bound to *command-line-args*.")) (let [res (cp/source-for-namespace loader namespace nil)] (when uberscript (swap! uberscript-sources conj (:source res))) res))) - _ (when file (vars/bindRoot vars/file-var (.getCanonicalPath (io/file file)))) + _ (when file (vars/bindRoot vars/current-file (.getCanonicalPath (io/file file)))) ctx {:aliases aliases :namespaces (-> namespaces (assoc 'clojure.core (assoc core-extras '*command-line-args* (sci/new-dynamic-var '*command-line-args* command-line-args) - '*file* vars/file-var '*warn-on-reflection* reflection-var)) (assoc-in ['clojure.java.io 'resource] #(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true})))) diff --git a/test/babashka/file_var_test.clj b/test/babashka/file_var_test.clj index 909373bb..0ab76cb9 100644 --- a/test/babashka/file_var_test.clj +++ b/test/babashka/file_var_test.clj @@ -8,10 +8,11 @@ (apply tu/bb (when (some? input) (str input)) (map str args))) (deftest file-var-test - (let [[f1 f2 f3] + (let [[f1 f2 f3 f4] (str/split (bb nil "--classpath" "test/babashka/scripts" "test/babashka/scripts/file_var.bb") #"\n")] (is (str/ends-with? f1 "file_var_classpath.bb")) (is (str/ends-with? f2 "loaded_by_file_var.bb")) - (is (str/ends-with? f3 "file_var.bb")))) + (is (str/ends-with? f3 "file_var.bb")) + (is (str/ends-with? f4 "file_var.bb")))) diff --git a/test/babashka/scripts/file_var.bb b/test/babashka/scripts/file_var.bb index a35bf126..d92a8976 100644 --- a/test/babashka/scripts/file_var.bb +++ b/test/babashka/scripts/file_var.bb @@ -4,3 +4,5 @@ (require '[file-var-classpath]) (load-file (io/file "test" "babashka" "scripts" "loaded_by_file_var.bb")) (println *file*) +(defn foo []) +(println (:file (meta #'foo)))