Last active
April 10, 2024 13:47
-
-
Save srenatus/bbea51ca88ca93da7fa4414c4f749c1a to your computer and use it in GitHub Desktop.
babashkba make helper, to be called as `make`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(require '[babashka.fs :as :fs] | |
'[babashka.process :refer [shell]]) | |
(def make "/usr/bin/make") | |
(defn find-root | |
([] (find-root (fs/cwd))) | |
([wd] (cond | |
(fs/exists? (fs/path wd "Makefile")) {:dir wd} | |
(fs/same-file? (fs/home) wd) :not-found | |
(fs/exists? (fs/path wd ".git")) :not-found | |
:else (recur (fs/parent wd))))) | |
(defn run-make [wd & args] | |
(if (= :not-found wd) | |
(throw (ex-info "Makefile not found" {:babashka/exit 1})) | |
(-> (apply shell (assoc wd :continue true) make args) | |
:exit | |
System/exit))) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(apply run-make (find-root) *command-line-args*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment