tools-build

Gregory Bleiker 2024-08-28T19:53:20.229619Z

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.

Alex Miller (Clojure team) 2024-08-28T20:01:18.162439Z

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?

Alex Miller (Clojure team) 2024-08-28T20:03:15.006299Z

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)

seancorfield 2024-08-28T20:24:44.746949Z

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?

Gregory Bleiker 2024-08-29T16:07:39.881739Z

@seancorfield I actually pass in target-dir, just named the parameter wrong.

Gregory Bleiker 2024-08-29T16:10:11.211219Z

@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

seancorfield 2024-08-29T17:09:09.747109Z

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.

seancorfield 2024-08-29T17:10:22.497679Z

I'll add an example like this to the deps-new docs.

Gregory Bleiker 2024-08-29T17:16:13.693509Z

@seancorfield that's it! finally working. Thanks A LOT!

seancorfield 2024-08-29T17:18:16.466729Z

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!