Bug 1592855 - run mach vendor rust with python3 r=froydnj
authorEdwin Takahashi <egao@mozilla.com>
Tue, 05 Nov 2019 18:56:21 +0000
changeset 500649 0c306145f19e4c4ca0982afdb3513e83db7dfac7
parent 500648 0f875399e986934acd11a4418a5b8270060325d3
child 500650 e96c1ca93d2597b77def89d16f594c3e3b98787b
push id36768
push usershindli@mozilla.com
push dateTue, 05 Nov 2019 22:07:34 +0000
treeherdermozilla-central@e96c1ca93d25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1592855
milestone72.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 1592855 - run mach vendor rust with python3 r=froydnj Changes: - use regular strings instead of byte strings when matching - encode files in UTF-8 prior to hashing Depends on D51414 Differential Revision: https://phabricator.services.mozilla.com/D51728
python/mozbuild/mozbuild/vendor_rust.py
--- a/python/mozbuild/mozbuild/vendor_rust.py
+++ b/python/mozbuild/mozbuild/vendor_rust.py
@@ -72,20 +72,20 @@ class VendorRust(MozbuildObject):
                 raise OSError(errno.ENOENT, "Could not find 'cargo' on your $PATH.")
             return cargo
 
     def check_cargo_version(self, cargo):
         '''
         Ensure that cargo is new enough. cargo 1.37 added support
         for the vendor command.
         '''
-        out = subprocess.check_output([cargo, '--version']).splitlines()[0]
+        out = subprocess.check_output([cargo, '--version']).splitlines()[0].decode('UTF-8')
         if not out.startswith('cargo'):
             return False
-        return LooseVersion(out.split()[1]) >= b'1.37'
+        return LooseVersion(out.split()[1]) >= '1.37'
 
     def check_modified_files(self):
         '''
         Ensure that there aren't any uncommitted changes to files
         in the working copy, since we're going to change some state
         on the user. Allow changes to Cargo.{toml,lock} since that's
         likely to be a common use case.
         '''
@@ -277,17 +277,17 @@ Please commit or stash these changes bef
                      'Checking license for {}'.format(package))
 
             toml_file = os.path.join(vendor_dir, package, 'Cargo.toml')
 
             # pytoml is not sophisticated enough to parse Cargo.toml files
             # with [target.'cfg(...)'.dependencies sections, so we resort
             # to scanning individual lines.
             with open(toml_file, 'r') as f:
-                license_lines = [l for l in f if l.strip().startswith(b'license')]
+                license_lines = [l for l in f if l.strip().startswith('license')]
                 license_matches = list(
                     filter(lambda x: x, [LICENSE_LINE_RE.match(l) for l in license_lines]))
                 license_file_matches = list(
                     filter(lambda x: x, [LICENSE_FILE_LINE_RE.match(l) for l in license_lines]))
 
                 # License information is optional for crates to provide, but
                 # we require it.
                 if not license_matches and not license_file_matches:
@@ -319,17 +319,17 @@ Please commit or stash these changes bef
 Please request review on the provided license; if approved, the package can be added
 to the whitelist of packages whose licenses are suitable.
 '''.format(package, license_file))
                         return False
 
                     approved_hash = self.RUNTIME_LICENSE_FILE_PACKAGE_WHITELIST[package]
                     license_contents = open(os.path.join(
                         vendor_dir, package, license_file), 'r').read()
-                    current_hash = hashlib.sha256(license_contents).hexdigest()
+                    current_hash = hashlib.sha256(license_contents.encode('UTF-8')).hexdigest()
                     if current_hash != approved_hash:
                         self.log(logging.ERROR, 'package_license_file_mismatch', {},
                                  '''Package {} has changed its license file: {} (hash {}).
 
 Please request review on the provided license; if approved, please update the
 license file's hash.
 '''.format(package, license_file, current_hash))
                         return False
@@ -359,17 +359,17 @@ license file's hash.
 
         # We use check_call instead of mozprocess to ensure errors are displayed.
         # We do an |update -p| here to regenerate the Cargo.lock file with minimal
         # changes. See bug 1324462
         subprocess.check_call([cargo, 'update', '-p', 'gkrust'], cwd=self.topsrcdir)
 
         output = subprocess.check_output([cargo, 'vendor', vendor_dir],
                                          stderr=subprocess.STDOUT,
-                                         cwd=self.topsrcdir)
+                                         cwd=self.topsrcdir).decode('UTF-8')
 
         # Get the snippet of configuration that cargo vendor outputs, and
         # update .cargo/config with it.
         # XXX(bug 1576765): Hopefully do something better after
         # https://github.com/rust-lang/cargo/issues/7280 is addressed.
         config = '\n'.join(dropwhile(lambda l: not l.startswith('['),
                                      output.splitlines()))