Bug 1385380 - Detect watchman more resiliently; r=glandium
authorGregory Szorc <gps@mozilla.com>
Fri, 28 Jul 2017 16:11:22 -0700
changeset 423842 6cb26a4c377737cc905eef2cb5caf575f46c3c08
parent 423841 6dacffdd0ed1ea53f7e2a56d1f44e2c90b959144
child 423843 d033c0e7f61aaf0093c25a1bc2e1497e135cdf77
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385380 - Detect watchman more resiliently; r=glandium Before, a non-runnable watchman would result in configure error. A trivial refactor to ignore `watchman version` errors would still result in setting WATCHMAN and exposing its presence to downstream consumers. Since we want WATCHMAN tied to a working watchman install, we refactor the code so that binary location and its version test are in the same function. They are either both defined or none of them are. MozReview-Commit-ID: 7wvBvYuOlmJ
--- a/moz.configure
+++ b/moz.configure
@@ -363,25 +363,51 @@ def tup_progs(build_backends):
             return ['tup']
     return None
 tup = check_prog('TUP', tup_progs)
 # watchman detection
 # ==============================================================
-watchman = check_prog('WATCHMAN', ('watchman',), allow_missing=True)
+option(env='WATCHMAN', nargs=1, help='Path to the watchman program')
-@checking('for watchman version')
-def watchman_version(watchman):
-    out = check_cmd_output(watchman, 'version')
-    res = json.loads(out)
-    return Version(res['version'])
+def watchman_info(prog):
+    if not prog:
+        prog = find_program('watchman')
+    if not prog:
+        return
+    out = check_cmd_output(prog, 'version', onerror=lambda: None)
+    if out is None:
+        return
+    # Assume a process not emitting JSON is not watchman or is a
+    # broken watchman.
+    try:
+        res = json.loads(out)
+    except ValueError:
+        return
+    return namespace(path=prog, version=Version(res['version']))
+@checking('for watchman')
+def watchman(w):
+    return w.path
+@checking('for watchman version')
+def watchman_version(w):
+    return w.version
+set_config('WATCHMAN', watchman)
 @depends_all(hg_version, hg_config, watchman)
 @checking('for watchman Mercurial integration')
 def watchman_hg(hg_version, hg_config, watchman):
     if hg_version < Version('3.8'):
         return 'no (Mercurial 3.8+ required)'