tools-build

Apple 2022-11-11T17:27:33.177339Z

I have a question. Why compile fails when the copy part is skipped?

(b/copy-dir {:src-dirs ["src/clj" "src/cljc" "env/prod/clj"]
               :target-dir class-dir})
  (b/compile-clj {:basis basis
                  :src-dirs ["src/clj" "src/cljc" "env/prod/clj"]
                  :class-dir class-dir})

Apple 2022-11-12T20:23:47.706679Z

This doesn't compile. deps.edn

{:paths
 ["src"]

 :aliases
 {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
          :ns-default build}}}
build.clj
(ns build
  (:require [clojure.string :as string]
            [clojure.tools.build.api :as b]))

(def basis (b/create-basis {:project "deps.edn"}))

(defn alt [_]
  (b/compile-clj {:basis basis
                  :src-dirs ["env"]
                  :class-dir "target"}))
env/core.clj
(ns core)

(defn testfn []
  (println "hello"))

Apple 2022-11-12T20:25:08.978659Z

Using :build :paths doesn't help either

{:paths
 ["src"]

 :aliases
 {:build {:paths ["env"]
          :deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
          :ns-default build}}}

Apple 2022-11-12T20:26:25.833219Z

{:paths
 ["env"]

 :aliases
 {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
          :ns-default build}}}
or
{:paths
 ["env"]

 :aliases
 {:build {:paths ["env"]
          :deps {io.github.clojure/tools.build {:git/tag "v0.8.4" :git/sha "8c3cd69"}}
          :ns-default build}}}
works.

Apple 2022-11-12T20:28:23.022749Z

So :build :paths is ignored. Only top level :paths is used. Is there a problem with tools.build or tools.dep.alpha?

Alex Miller (Clojure team) 2022-11-12T20:38:27.120309Z

your :build alias describes the execution environment for the build program. :paths there is not ignored, but it's affecting the classpath of the build program.

Alex Miller (Clojure team) 2022-11-12T20:39:17.587989Z

when you are compiling, that is a separate program, forked by the build program and using (by default) the basis of your main deps.edn (not the :build alias), but really the basis it uses is up to you

Alex Miller (Clojure team) 2022-11-12T20:40:33.505169Z

this line:

(def basis (b/create-basis {:project "deps.edn"}))
is the one defining what is on the classpath during compilation (because you are passing that basis to compile-clj

Alex Miller (Clojure team) 2022-11-12T20:42:46.836989Z

there's so many things above I'm not sure what problem you're actually trying to solve at this point, but that's the important thing to know in getting it to do what you want. If you have optional things to put in the classpath of your compile, you can do that by supplying :aliases on the basis call (see the https://clojure.github.io/tools.build/clojure.tools.build.api.html#var-create-basis api for details)

Apple 2022-11-12T20:44:55.994419Z

Given the build.clj and env/core.clj above, how should I set deps.edn so that it compiles?

Apple 2022-11-12T20:48:27.544409Z

I checked /tmp/com*/compile.args the classpath matches what I set in :paths but not :build :paths

Apple 2022-11-12T20:58:54.314459Z

(ns build
  (:require [clojure.string :as string]
            [clojure.tools.build.api :as b]))

(defn alt [_]
  (b/compile-clj {:src-dirs ["env"]
                  :class-dir "target"}))
also fails

Apple 2022-11-12T21:00:21.299239Z

tools.build guide says top level :paths is replaced with "." plus extra :paths under :build alias. I am not able to validate that in my testing.

Apple 2022-11-12T21:01:13.203649Z

ok never mind i think i get you now

Apple 2022-11-12T21:22:44.070709Z

In kit-clj setup, there's the shared source code in src/, and dev code in env/dev/ and prod code in env/prod. What's the best way to configure deps.edn and/or :build alias to include only src/ and env/prod for compilation?

Apple 2022-11-12T21:41:43.749259Z

I guess that's why kit-clj opt to copy source code into target for prod build

Alex Miller (Clojure team) 2022-11-12T23:09:21.501309Z

You can create a separate alias pulling in env/prod and then use that when you make the basis to do compilation

Apple 2022-11-13T01:04:09.383769Z

Great. This is it. Tyvm! deps.edn

:aliases {:prod     {:extra-paths ["env/prod/clj"]}}
build.clj
(def basis      (b/create-basis {:project "deps.edn", :aliases [:prod]}))

Alex Miller (Clojure team) 2022-11-11T18:37:17.030749Z

is there kit/net/env.clj in the class-dir ?

Alex Miller (Clojure team) 2022-11-11T18:40:15.891939Z

I guess that shouldn't matter given the :src-dirs in compile-clj

Alex Miller (Clojure team) 2022-11-11T18:40:59.980939Z

re "Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779" - that directory is a temp dir that contains the results of the failed compile

Alex Miller (Clojure team) 2022-11-11T18:42:08.774159Z

you can inspect the compile.args and compile.clj files in that directory

Alex Miller (Clojure team) 2022-11-11T18:45:54.564779Z

it's basically running (in that directory) java with the args in compile.args, which should execute the compile.clj file (which shows what's being compiled)

Apple 2022-11-11T20:01:12.830409Z

compile.args reveals the problem: "env/prod/clj" has to go into deps.edn top level :paths not the build alias level :paths

ghadi 2022-11-11T17:28:47.630509Z

fail how? (stacktrace)

Apple 2022-11-11T17:30:51.638099Z

{:clojure.main/message
 "Execution error (ExceptionInfo) at clojure.tools.build.tasks.compile-clj/compile-clj (compile_clj.clj:112).\nClojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779\n",
 :clojure.main/triage
 {:clojure.error/class clojure.lang.ExceptionInfo,
  :clojure.error/line 112,
  :clojure.error/cause
  "Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
  :clojure.error/symbol
  clojure.tools.build.tasks.compile-clj/compile-clj,
  :clojure.error/source "compile_clj.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message
    "Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
    :data {},
    :at
    [clojure.tools.build.tasks.compile_clj$compile_clj
     invokeStatic
     "compile_clj.clj"
     112]}],
  :trace
  [[clojure.tools.build.tasks.compile_clj$compile_clj
    invokeStatic
    "compile_clj.clj"
    112]
   [clojure.tools.build.tasks.compile_clj$compile_clj
    invoke
    "compile_clj.clj"
    80]
   [clojure.lang.Var invoke "Var.java" 384]
   [clojure.tools.build.api$compile_clj invokeStatic "api.clj" 312]
   [clojure.tools.build.api$compile_clj invoke "api.clj" 272]
   [build$main invokeStatic "build.clj" 73]
   [build$main invoke "build.clj" 68]
   [clojure.lang.AFn applyToHelper "AFn.java" 154]
   [clojure.lang.AFn applyTo "AFn.java" 144]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$apply invoke "core.clj" 662]
   [clojure.run.exec$exec invokeStatic "exec.clj" 48]
   [clojure.run.exec$exec doInvoke "exec.clj" 39]
   [clojure.lang.RestFn invoke "RestFn.java" 423]
   [clojure.run.exec$_main$fn__205 invoke "exec.clj" 180]
   [clojure.run.exec$_main invokeStatic "exec.clj" 176]
   [clojure.run.exec$_main doInvoke "exec.clj" 139]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause
  "Clojure compilation failed, working dir preserved: /tmp/compile-clj2911297849938394779",
  :data {}}}

Apple 2022-11-11T17:33:44.315609Z

Cleaning target
Preparing main jar...
Execution error (FileNotFoundException) at kit.net.web.middleware.core/loading (core.clj:1).
Could not locate kit/net/env__init.class, kit/net/env.clj or kit/net/env.cljc on classpath.

Apple 2022-11-11T17:34:07.176179Z

$ find env/prod/
env/prod/
env/prod/resources
env/prod/resources/logback.xml
env/prod/clj
env/prod/clj/kit
env/prod/clj/kit/net
env/prod/clj/kit/net/env.clj

seancorfield 2022-11-11T18:21:40.222429Z

Threads, please. Don't post walls of text into the channels.

➕ 1