Fork me on GitHub
#tools-deps
<
2022-01-28
>
imre17:01:49

Is there a way to force clojure -Spath to return absolute paths even for project paths like str:test?

Alex Miller (Clojure team)17:01:54

No - what problem are you trying to solve?

imre17:01:01

merge classpaths from multiple clojure projects in subfolders

imre17:01:42

for some analyzer step in our ci

imre17:01:01

but that's fine, I can work around it, just wanted to check if there was a way

imre17:01:59

one more thing: will Clojure always treat the deps.edn in the current directory the Project source or is there a way to override that? like clojure -Spath -depsedn=./subfolder/deps.edn?

imre17:01:44

I'm guessing not, based on the reference

imre17:01:47

yep, appears so, nevermind 🙂

seancorfield17:01:49

@U08BJGV6E If you don't mind omitting the user deps.edn, you could point the CLJ_CONFIG env var at the subfolder and clojure would treat that as your user deps.edn instead. It would still then also include the project deps.edn however.

seancorfield17:01:54

You could also do -Sdeps '{:deps {subfolder/code {:local/root "subfolder"}}}' -Spath which would give you a combined classpath of that subfolder and the project deps.edn files.

imre17:01:01

Thank you I figured it is actually easier to just go (cd subfolder && clojure -Spath ) instead

imre17:01:21

those are nice tricks though

seancorfield17:01:54

If you want "multiple clojure projects in subfolders", the :local/root deps might be the way to go there? If you only want one subfolder, then cd is definitely easier.

imre17:01:19

but does carry the caveats of considering any deps.edn in the cwd - my intention is to examine projects in multiple subfolders in isolation

imre17:01:44

so what I ended up doing is looping over subfolders and going cd in parentheses

imre17:01:11

that keeps it clean and doesn't mix .cpcaches either

1
borkdude19:01:43

Another trick:

clojure -Spath -Sdeps '{:deps {current/deps {:local/root "."}}}'
and strip the leading relative directories

souenzzo21:01:24

clj -Spath | tr ':' '\n' | while read i; do realpath "$i"; done | tr '\n' ':'

imre21:01:19

@U2J4FRT2T thank you, a version of that is what I ended up arriving at!

borkdude21:01:51

Slightly longer version :)

clj -Spath | bb '(as-> *in* $ (slurp $) (str/trim $) (str/split $ #":") (map fs/real-path $) (str/join ":" $))'

1
imre22:01:55

find . -name deps.edn \
| while read p
do
  dirname "$p"
done \
| while read dp
do
  realpath "$dp"
done \
| sort \
| while read dp
do
  ( cd "$dp" && clojure -Spath -Sforce -Srepro \
    | tr ":" "\n" \
    | while read p
    do
      realpath "$p"
    done
  )
done \
| sort \
| uniq \
| tr "\n" ":"

Lukas Domagala01:01:20

> merge classpaths from multiple clojure projects in subfolders It feels like I’ve seen this request a few times in the last months, spread over different channels. Would it make sense to build some version of it into the cli?