Bug 1339670 - Use cargo --version --verbose output when available. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 15 Feb 2017 11:22:34 +0900
changeset 484258 206ce5634b948b44a0b8f6315bd819e2525b2dc6
parent 484245 4899a861d2869b33b0401a19b67ed6f0ed63ebfd
child 545750 02f3d43a5c1bf9951eb071c72269a456ecc20fb7
push id45434
push userbmo:mh+mozilla@glandium.org
push dateWed, 15 Feb 2017 03:06:36 +0000
reviewersfroydnj
bugs1339670
milestone54.0a1
Bug 1339670 - Use cargo --version --verbose output when available. r?froydnj Fallback to regexp on older versions of cargo.
build/moz.configure/rust.configure
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -18,28 +18,34 @@ def rustc_info(rustc):
         version=Version(info.get('release', '0')),
         commit=info.get('commit-hash', 'unknown'),
     )
 
 @depends_if(cargo)
 @checking('cargo version', lambda info: info.version)
 @imports('re')
 def cargo_info(cargo):
-    # |cargo --version| doesn't have pleasant-to-parse output like rustc
-    # does. So we have to resort to regexes.
-    out = check_cmd_output(cargo, '--version').splitlines()[0]
-    VERSION_FORMAT = r'^cargo (\d\.\d+\.\d+).*'
+    out = check_cmd_output(cargo, '--version', '--verbose').splitlines()
+    info = dict((s.strip() for s in line.split(':', 1)) for line in out[1:])
+    version = info.get('release')
+    # Older versions of cargo didn't support --verbose, in which case, they
+    # only output a not-really-pleasant-to-parse output. Fortunately, they
+    # don't error out, so we can just try some regexp matching on the output
+    # we already got.
+    if version is None:
+        VERSION_FORMAT = r'^cargo (\d\.\d+\.\d+).*'
 
-    m = re.search(VERSION_FORMAT, out)
-    # Fail fast if cargo changes its output on us.
-    if not m:
-        die('Could not determine cargo version from output: %s', out)
+        m = re.search(VERSION_FORMAT, out[0])
+        # Fail fast if cargo changes its output on us.
+        if not m:
+            die('Could not determine cargo version from output: %s', out)
+        version = m.group(1)
 
     return namespace(
-        version=Version(m.group(1)),
+        version=Version(version),
     )
 
 @depends_if(cargo)
 @checking('cargo support for --frozen')
 @imports('subprocess')
 @imports('os')
 def cargo_supports_frozen(cargo):
     try: