Skip to content

Commit f66aaf3

Browse files
gtrakalandipert
authored andcommitted
BOOT_WATCHERS_DISABLE - creates a --disable-watchers long-only flag and a (#564)
BOOT_WATCHERS_DISABLE env variable and property. Kills the directory recursion for adding watches based on the flag.
1 parent e0f3364 commit f66aaf3

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

boot/core/src/boot/main.clj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
(update-in %1 [%2] (fnil assoc {}) (keyword k) v))]
3333
["-i" "--init EXPR" "Evaluate EXPR in the boot.user context."
3434
:assoc-fn #(update-in %1 [%2] (fnil conj []) (read-string %3))]
35+
[nil "--disable-watchers" "Disable registering file watches (inotify/FSEvents) for constrained environments."]
3536
["-f" "--file PATH" "Evaluate PATH (implies -BP). Args and options passed to -main."]
3637
["-h" "--help" "Print basic usage and help info."]
3738
["-o" "--offline" "Don't attempt to access remote repositories." :id :offline?]
@@ -144,7 +145,10 @@
144145
boot? (and boot? (not (:file opts)))
145146
verbosity (if (:quiet opts)
146147
(* -1 @util/*verbosity*)
147-
(or (:verbose opts) 0))]
148+
(or (:verbose opts) 0))
149+
watchers? (if (:disable-watchers opts)
150+
false
151+
@util/*watchers?*)]
148152

149153
(when (seq errs)
150154
(util/exit-error
@@ -155,9 +159,12 @@
155159

156160
(swap! util/*verbosity* + verbosity)
157161

162+
(reset! util/*watchers?* watchers?)
163+
158164
(pod/with-eval-in worker-pod
159165
(require '[boot.util :as util])
160-
(swap! util/*verbosity* + ~verbosity))
166+
(swap! util/*verbosity* + ~verbosity)
167+
(reset! util/*watchers?* ~watchers?))
161168

162169
(binding [*out* (util/auto-flush *out*)
163170
*err* (util/auto-flush *err*)

boot/core/src/boot/task/built_in.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
["" "BOOT_FILE" "Build script name (build.boot)."]
4646
["" "BOOT_GPG_COMMAND" "System gpg command (gpg)."]
4747
["" "BOOT_HOME" "Directory where boot stores global state (~/.boot)."]
48+
["" "BOOT_WATCHERS_DISABLE" "Set to 'yes' to turn off inotify/FSEvents watches."]
4849
["" "BOOT_JAVA_COMMAND" "Specify the Java executable (java)."]
4950
["" "BOOT_JVM_OPTIONS" "Specify JVM options (Unix/Linux/OSX only)."]
5051
["" "BOOT_LOCAL_REPO" "The local Maven repo path (~/.m2/repository)."]

boot/pod/src/boot/util.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717

1818
(declare print-ex)
1919

20+
(defn watchers?-system-default
21+
"Return whether we should register file watches on this
22+
system. Constrained environments like clould build containers limit
23+
the number of inotify handles, and watchers are only necessary for
24+
interactive dev, not one-shot jobs. environment variable or
25+
configuration option BOOT_WATCHERS_DISABLE to either '1' or 'yes' to
26+
disable inotify; any other value keeps normal behavior."
27+
[]
28+
(let [value (boot.App/config "BOOT_WATCHERS_DISABLE")]
29+
(if (string/blank? value)
30+
true
31+
(not (#{"1" "yes"}
32+
(string/lower-case value))))))
33+
2034
(defn colorize?-system-default
2135
"Return whether we should colorize output on this system. The default
2236
console on Windows does not interprete ANSI escape codes, so colorized
@@ -50,6 +64,10 @@
5064
will be printed with boot output."
5165
(atom (colorize?-system-default)))
5266

67+
(def ^:dynamic *watchers?*
68+
"Atom containing the value that determines whether inotify watches are registered"
69+
(atom (watchers?-system-default)))
70+
5371
(defn- print*
5472
[verbosity color args]
5573
(when (>= @*verbosity* verbosity)

boot/worker/src/boot/watcher.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858

5959
(defn- register-recursive
6060
[service path events]
61-
(util/dbug* "registering %s %s\n" path events)
62-
(register service path events)
63-
(doseq [dir (.listFiles (io/file path))]
64-
(when (.isDirectory dir)
65-
(register-recursive service dir events))))
61+
(when @util/*watchers?*
62+
(util/dbug* "registering %s %s\n" path events)
63+
(register service path events)
64+
(doseq [dir (.listFiles (io/file path))]
65+
(when (.isDirectory dir)
66+
(register-recursive service dir events)))))
6667

6768
(defn- new-watch-service []
6869
(if (= "Mac OS X" (System/getProperty "os.name"))

0 commit comments

Comments
 (0)