Last active
September 4, 2019 11:33
-
-
Save jwhitbeck/7a6dab9162a3dbf660b9e05d4a27f2a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 617e99a2ec13b1e725a3b2604511ecb530ee689a Mon Sep 17 00:00:00 2001 | |
From: sean <sean@sean-xps2> | |
Date: Tue, 3 Sep 2019 09:50:46 +0200 | |
Subject: [PATCH] Canonicalize local roots | |
When reading a deps file, turn relative paths names in :local/root | |
coordinates into absolute pathnames. The parent directory of the deps | |
file, not the current directory, is used in the conversion. | |
In a monorepo, the clojure CLI's config-dir deps.edn file might | |
contain relative paths to other parts of the repo. | |
For example, let's consider the following monorepo. | |
config/ | |
clojure/ | |
deps.edn | |
tools/ | |
lint/ | |
deps.edn | |
src/... | |
B/ | |
deps.edn | |
src/.. | |
A/ | |
deps.edn | |
src/... | |
Let's image we want to add a repo-wide linting alias in | |
config/clojure/deps.edn. | |
{:aliases | |
{:lint {:extra-deps {acme/lint {:local/root ../../tools/lint}} | |
:main-opts ["-m" "acme.lint.core"]}}} | |
Developers set CLJ_CONFIG="config/clojure/deps.edn" in their shell | |
configuration. Clojure linting code lives at "tools/lint/deps.edn". | |
In all projects in the repo (e.g. at "A/deps.den", and | |
"tools/B/deps.den"), we would like `clojure -A:lint` to run the | |
linters. | |
Running `clojure -A:lint` in directory A, however, adds | |
"A/../../tools/lint/src" to the classpath, rather than | |
"A/../tools/lint/src" or "/path/to/repo/tools/lint/src". | |
This patch fixes the issue by turning the relative paths into absolute | |
paths upon reading the deps.edn file. | |
--- | |
src/main/clojure/clojure/tools/deps/alpha/reader.clj | 10 +++++++++- | |
1 file changed, 9 insertions(+), 1 deletion(-) | |
diff --git a/src/main/clojure/clojure/tools/deps/alpha/reader.clj b/src/main/clojure/clojure/tools/deps/alpha/reader.clj | |
index ec59b2b..898006b 100644 | |
--- a/src/main/clojure/clojure/tools/deps/alpha/reader.clj | |
+++ b/src/main/clojure/clojure/tools/deps/alpha/reader.clj | |
@@ -66,11 +66,19 @@ | |
(vector? %) ((fn [v] (mapv canonicalize-sym v)))) | |
deps-map)) | |
+(defn- canonicalize-local-roots | |
+ [deps-map] | |
+ (walk/postwalk | |
+ #(cond-> % | |
+ (and (map? %) (find % :local/root)) (update :local/root (comp dir/canonicalize jio/file))) | |
+ deps-map)) | |
+ | |
(defn slurp-deps | |
"Read a single deps.edn file from disk and canonicalize symbols, | |
return a deps map." | |
[dep-file] | |
- (-> dep-file slurp-edn-map canonicalize-all-syms)) | |
+ (dir/with-dir (-> dep-file jio/file .getAbsoluteFile .getParentFile) | |
+ (-> dep-file slurp-edn-map canonicalize-all-syms canonicalize-local-roots))) | |
(defn- merge-or-replace | |
"If maps, merge, otherwise replace" | |
-- | |
2.17.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment