tools-build 2022-10-21

anyone using codox with tools.build? seems like it would need a way to inject the basis into it or just shell out from tools.build and run the deps.edn -X:codox alias. o/w it complains it can't find any of the project's namespaces on the classpath. anyone figured out anything better for that or similar libs?

Alex Miller (Clojure team) 2022-10-21T16:26:29.942829Z

You should be able to make a basis to do whatever you need?

Alex Miller (Clojure team) 2022-10-21T16:27:09.011719Z

I guess you’re trying to run it in the builds process?

Yeah, I tried calling codox/generate-docs from my build.clj. I hadn’t tried adding the paths to the build alias. I’ll give it a shot.

Alex Miller (Clojure team) 2022-10-21T16:50:27.337589Z

there's no magic here - you're just running a Clojure program with a classpath. If you need something additional on the classpath, just add it. :)

Yeah. I just would have thought it inherited the top-level paths if I didn’t override them in the alias

Alex Miller (Clojure team) 2022-10-21T16:52:12.245629Z

yeah, it intentionally does not

👍 1
Alex Miller (Clojure team) 2022-10-21T16:53:18.224399Z

there's some extended info on this at https://clojure.org/guides/tools_build#_setup

Alex Miller (Clojure team) 2022-10-21T16:54:03.150899Z

"Tools executed with -T:an-alias remove all project deps and paths, add "." as a path, and include any other deps or paths as defined in :an-alias."

Alex Miller (Clojure team) 2022-10-21T16:54:43.988829Z

In general, tool execution (-T) means "run a separate tool" and thus your project deps/paths are not included

gotcha. makes sense. thanks!

then it complains about not being able to find the top-level :deps referenced in macros when codox tries to generate the docs

codox might just be a hard one to tool-ify w/o some modifications huh?

Alex Miller (Clojure team) 2022-10-21T17:31:13.829619Z

I’m not understanding that

Alex Miller (Clojure team) 2022-10-21T17:31:57.547729Z

You might need to add the :deps too

Yeah, me neither really. Just throwing macro expansion errors about not finding any libs I’m pulling in via top-level deps

Alex Miller (Clojure team) 2022-10-21T17:33:05.545219Z

As I said above, you don’t have your :deps when running a tool, unless you pull them in

Yeah I’ll just leave it as a process invocation for now

Maybe open an issue about accepting a basis in codox and see what they think

(Maybe I will, that is)

You could also give #quickdoc a "quick" try, it doesn't load the code but uses clj-kondo analysis (for better or worse!)

ah, cool. I'll check it out, thanks!

Alex Miller (Clojure team) 2022-10-21T16:28:08.248499Z

You could add the :paths to the build process alias but maybe you would want to shell out for isolation, not sure

Is accepting a tools.deps.alpha basis value the idiomatic way for libraries to work with tools.build programs? Or is there a better way to integrate? I've seen some that do accept that as an optional arg, but wondering if it's the best approach or not.

Alex Miller (Clojure team) 2022-10-21T19:58:43.758979Z

I think unhelpfully I will say it depends :)

Alex Miller (Clojure team) 2022-10-21T19:59:22.490319Z

for things that expect to be run in some classpath context, then probably no - you should define the context in which you're expecting to be run

I assume you mean something broader here than just "put everything you'll need into the build alias"?

makes me wonder if there'd be any benefit to a tools.build.api fn along the lines of clojure-command or exec-alias? perhaps there's not much to be gained beyond what you get with (b/process {:command-args ["clojure" "-X:foo" ...]})

Alex Miller (Clojure team) 2022-10-21T20:10:41.703149Z

we have a ticket for that already and eventually I'll get to it

oh, ok. great!

Alex Miller (Clojure team) 2022-10-21T20:12:26.453479Z

the issues outlined by Sean in the comments are tied up with other things and that's the main reason this doesn't exist yet

@cap10morgan We have a variant of the code from TBUILD-6 in our build.clj at work and it's pretty nasty so I would say, for now, using the -M style invocation for subprocesses is just so much easier.

👍 1

I haven't looked at Codox but I get the impression it expects to be run in the project's context (classpath etc) rather than as a separate tool? Codox would need to accept args to specify deps.edn files and aliases etc and then use t.d.a itself to build the basis and then walk all the code...

(which is why it's hard to run directly in-process in build.clj right?)

yeah exactly

It's also possible to start a clojure process using deps.clj

which works as Clojure dependency as well, although it doesn't really have a nice Clojure API:

(borkdude.deps/-main "-Sdeps" <deps-map>" "-M" "-e" ...)

👍 1
Alex Miller (Clojure team) 2022-10-21T20:00:19.771109Z

for things that plan to shell out or manipulate basis information, then probably yes (or accept the same basis modifying parameters used throughout the :deps programs and pass those along to create-basis)