I'm trying to run a process out of #deps-new. I'm struggling setting the root directory for the clojure command.
(defn cljd-init [template-dir]
"Init clojuredart file"
(let [basis (b/create-basis {:aliases [:build] :dir template-dir} )
cmds (b/java-command
{:basis basis
:main 'clojure.main
:main-args ["-m" "cljd.build" "init"]})
{:keys [exit]} (b/process cmds)]
(println exit)
(when-not (zero? exit) (throw (ex-info "Init failed" {})))))
I'm trying to set the directory with the :dir option (as per https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-create-basis) but this seems to have no effect. Also, I would have expected (:dir basis) to return that directory, but it returns nil . Any help greatly appreciated.the :dir is an option to create-basis, and is not part of the result, so that's expected. the :dir option should affect where the project deps.edn is read from - is that what you are expecting? and do you see that in the computed basis?
there were some bugs fixed in that relative dir stuff earlier this year, so I would also ensure you are on at least tools.build 0.10.1 (latest is 0.10.5)
Template-dir is where deps-new reads the source template from. Target-dir is where deps-new writes the new project to. Don't you want the latter?
@seancorfield I actually pass in target-dir, just named the parameter wrong.
@alexmiller the deps-new process is still a bit mysterious to me, but as far as I can tell I'm using 0.10.3. Tried bumping to 0.10.5 but no luck
Here's a working post-process-fn that runs clojure -M -m cognitect.test-runner in the freshly-created project:
(defn post-process-fn [edn data]
(let [basis (b/create-basis {:dir (:target-dir data) :aliases [:test]})
cmds (b/java-command {:basis basis
:main 'clojure.main
:main-args ["-m" "cognitect.test-runner"]})
{:keys [exit]}
(b/process (assoc cmds :dir (:target-dir data)))]
(println "Post-processing" edn "with" data "produced" exit)))
Note that the target-dir has to be passed into both create-basis -- as you are doing -- and process so the command is run inside that directory.I'll add an example like this to the deps-new docs.
@seancorfield that's it! finally working. Thanks A LOT!
See https://github.com/seancorfield/deps-new/blob/develop/doc/templates.md#programmatic-transformation for where I added the example. Feel free to create GH issues for any additional improvements to the docs you can think of!