Bug 1384396 - Detect Watchman Mercurial integration in configure; r?nalexander
authorGregory Szorc <gps@mozilla.com>
Tue, 25 Jul 2017 21:24:45 -0700
changeset 1196693 6b8b8180c1414f336b480302024e43d05e58932a
parent 1196692 fab38f2d2fc7238e523dda71d7630beb6590a7d0
child 1196694 87722634000bed56c93cec036e97aab8f14ddfc8
push id207991
push usergszorc@mozilla.com
push dateWed, 26 Jul 2017 04:29:53 +0000
treeherdertry@87722634000b [default view] [failures only]
reviewersnalexander
bugs1384396
milestone56.0a1
Bug 1384396 - Detect Watchman Mercurial integration in configure; r?nalexander Configure now detects VCS info. Configure now detects Watchman. We can combine the two so configure can detect if Mercurial is configured with Watchman enabled. This commit does two things: 1) collects the Mercurial config so it is available to downstream checks 2) examines the config for presence and state of the fsmonitor extension We don't yet do anything with the fsmonitor state. But it should be useful soon. MozReview-Commit-ID: HyHZ2X8VI0h
build/moz.configure/init.configure
moz.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -350,16 +350,35 @@ def hg_version(hg):
     if not match:
         raise FatalCheckError('unable to determine Mercurial version: %s' % out)
 
     # The version string may be "unknown" for Mercurial run out of its own
     # source checkout or for bad builds. But LooseVersion handles it.
 
     return Version(match.group(1))
 
+# Resolve Mercurial config items so other checks have easy access.
+# Do NOT set this in the config because it may contain sensitive data
+# like API keys.
+@depends_if(check_build_environment, hg)
+@imports('os')
+def hg_config(build_env, hg):
+    env = dict(os.environ)
+    env['HGPLAIN'] = '1'
+
+    out = check_cmd_output(hg, 'config', env=env, cwd=build_env.topsrcdir)
+
+    config = {}
+
+    for line in out.strip().splitlines():
+        key, value = [s.strip() for s in line.split('=', 1)]
+        config[key] = value
+
+    return config
+
 @depends_if(git)
 @checking('for Git version')
 @imports('re')
 def git_version(git):
     out = check_cmd_output(git, '--version').rstrip()
 
     match = re.search('git version (.*)$', out)
 
--- a/moz.configure
+++ b/moz.configure
@@ -373,16 +373,39 @@ watchman = check_prog('WATCHMAN', ('watc
 @depends(watchman)
 @checking('for Watchman version')
 @imports('json')
 def watchman_version(watchman):
     out = check_cmd_output(watchman, 'version')
     res = json.loads(out)
     return Version(res['version'])
 
+@depends_if(hg_version, hg_config, watchman)
+@checking('for Watchman Mercurial integration')
+@imports('os')
+def watchman_hg(hg_version, hg_config, watchman):
+    if hg_version < Version('3.8'):
+        return 'no (Mercurial 3.8+ required)'
+
+    ext_enabled = False
+    mode_disabled = False
+
+    for k in ('extensions.fsmonitor', 'extensions.hgext.fsmonitor'):
+        if k in hg_config and hg_config[k] != '!':
+            ext_enabled = True
+
+    mode_disabled = hg_config.get('fsmonitor.mode', 'irrelevant') == 'off'
+
+    if not ext_enabled:
+        return 'no (fsmonitor extension not enabled)'
+    if mode_disabled:
+        return 'no (fsmonitor.mode=off disables fsmonitor)'
+
+    return True
+
 # Miscellaneous programs
 # ==============================================================
 check_prog('DOXYGEN', ('doxygen',), allow_missing=True)
 check_prog('XARGS', ('xargs',))
 
 @depends(target)
 def extra_programs(target):
     if target.kernel == 'Darwin':