Bug 1377216 - Discover version control info in configure; r=glandium
☠☠ backed out by b31c56eb6317 ☠ ☠
authorGregory Szorc <gps@mozilla.com>
Tue, 18 Jul 2017 18:07:29 -0700
changeset 418502 ded5328ba74cf66d45d97ccb9997d59853c42e12
parent 418501 6cb234539746e2d85c7bca3f808fed879ba0b676
child 418503 c8931588f674c86b6b1a749dcf419c8f959f7f1a
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1377216
milestone56.0a1
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 1377216 - Discover version control info in configure; r=glandium For reasons unknown to me, Windows CI is periodically failing to find the Mercurial binary. In addition, we've also reimplemented various VCS logic throughout the build system. There is room to cut down on code complexity by e.g. recording VCS info in configure instead of determining it at run-time. Also, for forensic purposes it is sometimes desirable to know which VCS tool is in use by a build and which version of that tool is being used. This commit adds VCS type detection, binary searching, and version resolution to configure. substs now contains VCS_CHECKOUT_TYPE, HG, and GIT, which can be consulted by downstream consumers. If the Mercurial or Git versions could not be resolved, all variables are not set. Otherwise, VCS_CHECKOUT_TYPE and one of HG or GIT is set. If MOZ_AUTOMATION is set, we require that the VCS info be resolved. This helps prevents weirdness in automation due to unexpected environment configuration. MozReview-Commit-ID: AMLy0Hfx5rD
build/moz.configure/init.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -304,16 +304,96 @@ def shell(value, mozillabuild):
     shell = 'sh'
     if mozillabuild:
         shell = mozillabuild[0] + '/msys/bin/sh'
     if sys.platform == 'win32':
         shell = shell + '.exe'
     return find_program(shell)
 
 
+# Source checkout and version control integration.
+# ================================================
+
+@depends(check_build_environment, 'MOZ_AUTOMATION')
+@checking('for vcs source checkout')
+@imports('os')
+def vcs_checkout_type(build_env, automation):
+    if os.path.exists(os.path.join(build_env.topsrcdir, '.hg')):
+        return 'hg'
+    elif os.path.exists(os.path.join(build_env.topsrcdir, '.git')):
+        return 'git'
+    elif automation:
+        raise FatalCheckError('unable to resolve VCS type; must run '
+                              'from a source checkout when MOZ_AUTOMATION '
+                              'is set')
+
+# Resolve VCS binary for detected repository type.
+hg = check_prog('HG', ('hg',), allow_missing=True,
+                when=depends(vcs_checkout_type)(lambda x: x == 'hg'))
+git = check_prog('GIT', ('git',), allow_missing=True,
+                 when=depends(vcs_checkout_type)(lambda x: x == 'git'))
+
+@depends_if(hg)
+@checking('for Mercurial version')
+@imports('os')
+@imports('re')
+def hg_version(hg):
+    # HGPLAIN in Mercurial 1.5+ forces stable output, regardless of set
+    # locale or encoding.
+    env = dict(os.environ)
+    env['HGPLAIN'] = '1'
+
+    out = check_cmd_output(hg, '--version', env=env)
+
+    match = re.search(r'Mercurial Distributed SCM \(version ([^\)]+)', out)
+
+    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))
+
+@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)
+
+    if not match:
+        raise FatalCheckError('unable to determine Git version: %s' % out)
+
+    return Version(match.group(1))
+
+# Only set VCS_CHECKOUT_TYPE if we resolved the VCS binary.
+# Require resolved VCS info when running in automation so automation's
+# environment is more well-defined.
+@depends(vcs_checkout_type, hg_version, git_version, 'MOZ_AUTOMATION')
+def exposed_vcs_checkout_type(vcs_checkout_type, hg, git, automation):
+    if vcs_checkout_type == 'hg':
+        if hg:
+            return 'hg'
+
+        if automation:
+            raise FatalCheckError('could not resolve Mercurial binary info')
+
+    elif vcs_checkout_type == 'git':
+        if git:
+            return 'git'
+
+        if automation:
+            raise FatalCheckError('could not resolve Git binary info')
+    elif vcs_checkout_type:
+        raise FatalCheckError('unhandled VCS type: %s' % vcs_checkout_type)
+
+set_config('VCS_CHECKOUT_TYPE', exposed_vcs_checkout_type)
+
 # Host and target systems
 # ==============================================================
 option('--host', nargs=1, help='Define the system type performing the build')
 
 option('--target', nargs=1,
        help='Define the system type where the resulting executables will be '
             'used')