[#532] Prefer .getAbsoluteFile over .getCanonicalFile for preserving
This commit is contained in:
parent
6c5f7ef964
commit
9b68099543
7 changed files with 25 additions and 12 deletions
|
|
@ -568,7 +568,7 @@ Babashka sets the following system properties:
|
|||
|
||||
- `babashka.version`: the version string, e.g. `"1.2.0"`
|
||||
- `babashka.main`: the `--main` argument
|
||||
- `babashka.file`: the `--file` argument (normalized using `.getCanonicalPath`)
|
||||
- `babashka.file`: the `--file` argument (normalized using `.getAbsolutePath`)
|
||||
|
||||
## `__name__ == "__main__"` pattern
|
||||
|
||||
|
|
|
|||
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit 12ab6c489e0a2a6eba56c108e63b86c53287ab7e
|
||||
Subproject commit 2e4d6e027688a9518b9cb25b9f26e274321ac8ab
|
||||
|
|
@ -19,8 +19,8 @@
|
|||
(when (.exists f)
|
||||
(if url?
|
||||
;; manual conversion, faster than going through .toURI
|
||||
(java.net.URL. "file" nil (.getCanonicalPath f))
|
||||
{:file (.getCanonicalPath f)
|
||||
(java.net.URL. "file" nil (.getAbsolutePath f))
|
||||
{:file (.getAbsolutePath f)
|
||||
:source (slurp f)}))))
|
||||
resource-paths)))
|
||||
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
(if url?
|
||||
;; manual conversion, faster than going through .toURI
|
||||
(java.net.URL. "jar" nil
|
||||
(str "file:" (.getCanonicalPath jar-file) "!/" path))
|
||||
(str "file:" (.getAbsolutePath jar-file) "!/" path))
|
||||
{:file path
|
||||
:source (slurp (.getInputStream jar entry))})))
|
||||
resource-paths)))
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
(let [f (io/file f)
|
||||
s (slurp f)]
|
||||
(sci/with-bindings {sci/ns @sci/ns
|
||||
sci/file (.getCanonicalPath f)}
|
||||
sci/file (.getAbsolutePath f)}
|
||||
(sci/eval-string* sci-ctx s))))
|
||||
{:sci.impl/op :needs-ctx}))
|
||||
|
||||
|
|
@ -484,9 +484,9 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
(when uberscript (swap! uberscript-sources conj (:source res)))
|
||||
res)))
|
||||
_ (when file
|
||||
(let [canonical-path (.getCanonicalPath (io/file file))]
|
||||
(vars/bindRoot sci/file canonical-path)
|
||||
(System/setProperty "babashka.file" canonical-path)))
|
||||
(let [abs-path (.getAbsolutePath (io/file file))]
|
||||
(vars/bindRoot sci/file abs-path)
|
||||
(System/setProperty "babashka.file" abs-path)))
|
||||
;; TODO: pull more of these values to compile time
|
||||
opts {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
(ns babashka.file-var-test
|
||||
(:require
|
||||
[babashka.test-utils :as tu]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :as t :refer [deftest is]]))
|
||||
[clojure.test :as t :refer [deftest is testing]]))
|
||||
|
||||
(defn bb [input & args]
|
||||
(apply tu/bb (when (some? input) (str input)) (map str args)))
|
||||
|
|
@ -15,4 +16,9 @@
|
|||
(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? f4 "file_var.bb"))))
|
||||
(is (str/ends-with? f4 "file_var.bb")))
|
||||
(testing "file var uses absolute path"
|
||||
(is (str/includes?
|
||||
(bb nil (io/file "test" ".." "test"
|
||||
"babashka" "scripts" "simple_file_var.bb"))
|
||||
".."))))
|
||||
|
|
|
|||
|
|
@ -519,7 +519,13 @@
|
|||
(is (= "true\nfalse\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property1.clj")))))
|
||||
(is (= "true\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property2.clj"))))))
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property2.clj")))))
|
||||
(is (apply =
|
||||
(bb nil (.getPath (io/file "test" "babashka" "scripts" "simple_file_var.bb")))))
|
||||
(let [res (bb nil (.getPath (io/file "test" ".." "test" "babashka"
|
||||
"scripts" "simple_file_var.bb")))]
|
||||
(is (apply = res))
|
||||
(is (str/includes? (first res) ".."))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
|
|
|
|||
1
test/babashka/scripts/simple_file_var.bb
Normal file
1
test/babashka/scripts/simple_file_var.bb
Normal file
|
|
@ -0,0 +1 @@
|
|||
[*file* (System/getProperty "babashka.file")]
|
||||
Loading…
Reference in a new issue