tools-build

Eugen 2021-09-08T08:55:29.099300Z

FYI, git-rev-count throws NPE if not in a git repo. I use the following to make build.clj work in a docker image build (where there is no git repo - since we have a multi project repo and we are not top level).

(defn git-count-revs-safe
  "Get version without git."
  (^String [^String fallback]
   (try
     (b/git-count-revs nil)
     (catch NullPointerException _
       fallback))))
(def version (format "0.1.%s" (git-count-revs-safe "NOGIT")))
Could we have something like that in git-count-revs ?

tvaughan 2021-09-08T11:02:34.100500Z

We have the same issue. I was thinking of taking the value from an environment variable

Eugen 2021-09-08T12:09:22.100700Z

you could pass the fallback as (System/getenv) and have both ?! wdyt?

Alex Miller (Clojure team) 2021-09-08T12:32:59.101800Z

Why are using this in a non-git project?

Alex Miller (Clojure team) 2021-09-08T12:33:41.102400Z

Oh sorry, didn’t read all above

Eugen 2021-09-08T12:33:44.102600Z

I build a docker image and I use a task in build.clj . The directory I copy is not the git root and no .git is copied over (multi project git )

Alex Miller (Clojure team) 2021-09-08T12:36:54.104200Z

This seems like a good approach in your build and that seems like the right place to handle it

Alex Miller (Clojure team) 2021-09-08T12:37:21.105200Z

But it would maybe be useful to have a predicate for whether you’re in a git repo?

tvaughan 2021-09-08T12:48:51.105400Z

Personally I'd prefer a consistent mechanism for building the version string. If I wanted to use a git revision count, I'd want things to blow up if I wasn't in a git repo. And if I wanted to use something else, like an environment variable, I'm not sure I'd want a fall back either

2021-09-08T13:42:20.105600Z

Throwing in my two bits, I think this is the sort of thing which would be good to include in build.clj by @seancorfield or a similar library, or manually in your project. It doesn't feel like part of what tools.build is trying to provide.

seancorfield 2021-09-08T15:14:47.105800Z

Like @tvaughan I would want my version to blow up if I accidentally ran the build in a non-git context. But anyone can wrap their call to git-rev-count in try/catch without needing a library function for it.

Alex Miller (Clojure team) 2021-09-08T16:12:29.106100Z

as I said above, I think handling this in your build (not in git-rev-count) is the right place

Alex Miller (Clojure team) 2021-09-08T16:12:59.106300Z

but it might be useful to have some way to proactively change behavior rather than reacting to an exception

2021-09-08T21:12:23.106500Z

That's what https://github.com/IGJoshua/farolero is for 😉

Alex Miller (Clojure team) 2021-09-08T21:17:24.106700Z

I think you're missing the point, which is to avoid having an exception in the first place. I think if technology is sufficient for that

1
2021-09-08T21:26:59.106900Z

Oh sure, I was just being cheeky.

seancorfield 2021-09-08T22:03:15.108Z

https://ask.clojure.org/index.php/11027/should-tools-build-functions-respect-with-from-tools-alpha -- not sure whether this would be considered a bug or not?

Alex Miller (Clojure team) 2021-09-08T22:22:13.108300Z

why are you doing it?

seancorfield 2021-09-08T23:17:19.109400Z

I explained in the ask post -- probably in more detail than you care to know since, of course, I'm doing something a bit weird 🙂