diff --git a/CHANGELOG.md b/CHANGELOG.md index cd716fa9..4727e259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ For a list of breaking changes, check [here](#breaking-changes). A preview of the next release can be installed from [babashka-dev-builds](https://github.com/babashka/babashka-dev-builds). +## Unreleased + +- [#1204](https://github.com/babashka/babashka/issues/1204) add property `babashka.config` to reflect `bb.edn` location ([@mknoszlig](https://github.com/mknoszlig)) + ## 0.7.7 (2022-03-04) ### New diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 3c6e1d2c..42020e46 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -933,6 +933,8 @@ Use bb run --help to show this help output. bb-edn-file (or config "bb.edn") bb-edn (when (fs/exists? bb-edn-file) + (System/setProperty "babashka.config" + (.getAbsolutePath (io/file bb-edn-file))) (let [raw-string (slurp bb-edn-file) edn (edn/read-string raw-string) edn (assoc edn diff --git a/test-resources/babashka/config_property.clj b/test-resources/babashka/config_property.clj new file mode 100644 index 00000000..cf81e7fc --- /dev/null +++ b/test-resources/babashka/config_property.clj @@ -0,0 +1,9 @@ +(ns babashka.config-property + (:require [babashka.fs :as fs])) + +(def prop (System/getProperty "babashka.config")) + +(prn (boolean (seq prop))) + +(when prop + (prn (fs/exists? (System/getProperty "babashka.config")))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 26e56666..976d2644 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -603,6 +603,13 @@ (testing "bb executes the empty expression and doesn't start a REPL" (is (working? (test-utils/bb nil "-e" ""))))) +(deftest config-property-test + (is (= "true\ntrue\n" + (test-utils/with-config {:tasks {}} + (test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "config_property.clj")))))) + (is (= "false\n" + (test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "config_property.clj")))))) + (deftest file-property-test (is (= "true\nfalse\n" (test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property1.clj"))))) diff --git a/test/babashka/test_utils.clj b/test/babashka/test_utils.clj index fb55ca3e..d9c24cd1 100644 --- a/test/babashka/test_utils.clj +++ b/test/babashka/test_utils.clj @@ -48,6 +48,7 @@ (reset! cp/cp-state nil) (reset! main/env {}) (vreset! common/bb-edn nil) + (System/clearProperty "babashka.config") (let [args (cond-> args *bb-edn-path* (->> (list* "--config" *bb-edn-path* "--deps-root" "."))) os (java.io.StringWriter.)