tools-build

roklenarcic 2025-03-10T17:56:03.824369Z

I am trying to run from clojure.tools.build.api:

(api/process {:command-args ["git" "log" "--after=2025-01-01" "--pretty=format:%D%n%B"]
              :out :capture
              :err :capture})
and the REPL just blocks. When I do this instead:
(:out (apply sh "git" "log" "--after=2025-01-01" "--pretty=format:%D%n%B"))
it executes instantly. Am I forgetting something?

Alex Miller (Clojure team) 2025-03-25T22:55:03.056629Z

Released tools.build 0.10.8 with a fix for this (basically just replacing the impl with calls into the Clojure 1.12 clojure.java.process)

seancorfield 2025-03-25T23:53:06.436349Z

@alexmiller I'm curious, this means tools.build requires Clojure 1.12, yes? How long has it required 1.12, vs 1.11 or earlier?

Alex Miller (Clojure team) 2025-03-26T00:15:33.905169Z

Since 1.12 came out

👍🏻 1
seancorfield 2025-03-10T18:11:45.396269Z

The former works fine for me in a fresh REPL started with clj -A:build in my next.jdbc project. How big is the git log for your project (from the apply sh)?

seancorfield 2025-03-10T18:12:15.979079Z

Also, what version of tools.build? what version of Clojure? what O/S environment?

roklenarcic 2025-03-10T18:13:14.902859Z

121kb, tools.build 0.10.7 version, Clojure 1.12.0, MacOS

seancorfield 2025-03-10T18:14:43.033349Z

121Kb seems big but not outrageously. macOS vs Ubuntu shouldn't make a difference. How are you starting your REPL / running that code?

roklenarcic 2025-03-10T18:15:44.584699Z

I’ve started the REPL in IntelliJ. Let me try that from cmd

roklenarcic 2025-03-10T18:17:49.471729Z

yeah that blocks too

roklenarcic 2025-03-10T18:19:01.951699Z

so I run:

clj -T:build get-history
and I got this:
:build {:deps {io.github.clojure/tools.build {:git/url ""
                                                :tag "v0.9.0"
                                                :sha "8c93e0c"}}
          :extra-deps {babashka/fs {:mvn/version "0.4.19"}
                       babashka/process {:mvn/version "0.5.21"}}
          :paths ["scripts"]
          :ns-default build}
And the build.clj file has this:
(defn get-history [_]
  (let [delimiter "===COMMIT_DELIMITER==="
        ;; Added --after to filter commits after 2025-01-01
        output (b/git-process {:git-args ["log" "--after=2025-01-01" (str "--pretty=format:%D%n%B" delimiter)]})]
    (if (str/blank? output)
      []
      (str/split output (re-pattern (str delimiter "\n"))))))

roklenarcic 2025-03-10T18:19:48.472549Z

If I simplify function to:

(defn get-history [_]
  (b/git-process {:git-args ["log" "--after=2025-01-01" "--pretty=format:%D%n%B"]}))

roklenarcic 2025-03-10T18:19:50.052999Z

same result

roklenarcic 2025-03-10T18:22:16.961929Z

debugger shows the thread is waiting on ProcessImpl.waitFor

seancorfield 2025-03-10T18:24:51.703919Z

I just tried that via build.clj in a much bigger project and it works fine -- doesn't show any output (unless I add println into get-history). Maybe it's something about your git version/install?

seancorfield 2025-03-10T18:25:07.511429Z

> git --version
git version 2.48.1

roklenarcic 2025-03-10T18:25:10.176189Z

I think its about pipe size

roklenarcic 2025-03-10T18:25:20.343839Z

If I add `

:capture nil

roklenarcic 2025-03-10T18:25:23.245869Z

then it works

seancorfield 2025-03-10T18:25:23.831119Z

Hmm, maybe.

roklenarcic 2025-03-10T18:25:47.982969Z

this code is wrong:

(let [proc (.start pb)
          exit (.waitFor proc)
          out-str (when (= out :capture) (copy-stream (.getInputStream proc)))
          err-str (when (= err :capture) (copy-stream (.getErrorStream proc)))]
      (cond-> {:exit exit}
        out-str (assoc :out out-str)
        err-str (assoc :err err-str)))

roklenarcic 2025-03-10T18:25:55.060409Z

in clojure.tools.build.tasks.process

roklenarcic 2025-03-10T18:26:19.412049Z

you cannot await for process exit before setting up something that will drain the streams

roklenarcic 2025-03-10T18:26:31.315059Z

that will cause process to block if the output is big enough

roklenarcic 2025-03-10T18:26:38.094749Z

I guess my pipe is small

seancorfield 2025-03-10T18:27:21.818839Z

Ah, winding the date back a year, I've managed to repro. Put it up on http://ask.clojure.org and Alex will make a Jira issue about it.

roklenarcic 2025-03-10T18:27:54.794429Z

and git-process doesn’t even let me redirect to file, I only have option to capture out OR capture err OR inherit (so it spills into my own process stdout

roklenarcic 2025-03-10T18:28:13.356159Z

I think we had this same conversation multiple times

roklenarcic 2025-03-10T18:28:24.923639Z

for now I’ll avoid using this library for running processes

seancorfield 2025-03-10T18:29:13.789489Z

@alexmiller FYI point_up::skin-tone-2 I can repro locally with a large enough output.

seancorfield 2025-03-10T18:35:03.660269Z

Possibly related to https://ask.clojure.org/index.php/11510/clojure-tools-build-process-ignore-hangs-process-large-output ?

👍 1
roklenarcic 2025-03-10T18:36:00.466679Z

that is just one of the modes and yes, he is right, if you’re going for ignore, you need to use discard mode otherwise it will block if there’s too much data in pipe

Alex Miller (Clojure team) 2025-03-10T19:09:30.847389Z

this process stuff (which was the precursor of the new 1.12 clojure.java.process api) definitely needs some clean up in this area. I actually thought I had done that but must have confused it with the work there

Alex Miller (Clojure team) 2025-03-10T19:10:01.911239Z

probably best to add it to the existing ask question if there is new info/repro

seancorfield 2025-03-10T19:23:03.427979Z

I added it as a comment on your answer there (where you linked to TBUILD-1)

👍 1