boot-clj / boot

Build tooling for Clojure.
https://boot-clj.github.io/
Eclipse Public License 1.0
1.75k stars 180 forks source link

Running shell (make all) command after completion of (comp) task #593

Closed gamecubate closed 7 years ago

gamecubate commented 7 years ago

I have a Makefile and would like to invoke a make all shell command at the completion of my (boot) release task.

So I did this:

(deftask release []
  "Compile for release"
  (task-options! cljs {:optimizations :advanced})
  (comp
    (build)
    (sift :include #{#"index.html" #"css/*" #"js/app.js"})
    (target :dir #{"release"})
    (dosh "make" "all")))

That clearly fails as make seems to be invoked immediately, cutting off execution of the previous tasks, and is then followed by a java.lang.NullPointerException error.

I tried this with sh as well. In that case, the command fails immediately (no make execution) and is again followed by a java.lang.NullPointerException error.

arichiardi commented 7 years ago

Yep it makes sense because sh is not a task. In order to get what you want to achieve you have to wrap it into a with-pass-thru.

Hope it helps! -- Sent from my Android device with K-9 Mail. Please excuse my brevity.

gamecubate commented 7 years ago

Thanks @arichiardi.

arichiardi commented 7 years ago

No problem! Sample here.

gamecubate commented 7 years ago

Great. I was just about to ask for one. :)

gamecubate commented 7 years ago

Actually... getting errors of the type Cannot run program "/usr/bin/make all": error=2, No such file or directory. Here's my task:

(deftask release []
  "Compile for release"
  (task-options! cljs {:optimizations :advanced})
  (comp
    (build)
    (sift :include #{#"index.html" #"css/*" #"js/app.js"})
    (target :dir #{"release"})
    (with-pass-thru _
      (let [{:keys [exit out err]} (sh "/usr/bin/make all")]
        (println out)
        (when-not (zero? exit)
          (println err))))))

The Makefile is in the same directory as build.boot. Assuming that the task's cwd is not that from which `boot release``` was launched.

arichiardi commented 7 years ago

It should work, I am basically doing something similar (but with dosh) here too.

EDIT: add line

gamecubate commented 7 years ago

Great example. Will try it out immediately. Thanks!

gamecubate commented 7 years ago

Worked perfectly. Thanks again.

(require
 ...
 '[boot.util :as util])

(deftask release []
  "Compile for release"
  (task-options! cljs {:optimizations :advanced})
  (comp
    (build)
    (sift :include #{#"index.html" #"css/*" #"js/app.js"})
    (target :dir #{"release"})
    (with-pass-thru _
      (util/info "make all...\n")
      (util/dosh "make" "all"))))
gamecubate commented 7 years ago

This works very well. I later realized that same results could have been obtained by adding a boot release command to my Makefile target:

all:
  boot release
  scp ...