Use decode('utf-8') for all subprocess calls

Bug: 221778256
Change-Id: Ib2029e5061193a62f3712baba99a395f4340ba86
diff --git a/tools/archive.py b/tools/archive.py
index 6eada3d..d3aa196 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -35,9 +35,9 @@
 
 def GetToolVersion(jar_path):
   # TODO(mkroghj) This would not work for r8-lib, maybe use utils.getR8Version.
-  output = str(subprocess.check_output([
+  output = subprocess.check_output([
     jdk.GetJavaExecutable(), '-jar', jar_path, '--version'
-  ]))
+  ]).decode('utf-8')
   return output.splitlines()[0].strip()
 
 def GetVersion():
@@ -54,11 +54,11 @@
   return subprocess.check_output(['git', 'show', '-s', '--pretty=%d', 'HEAD'])
 
 def GetGitHash():
-  return str(subprocess.check_output(['git', 'rev-parse', 'HEAD'])).strip()
+  return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()
 
 def IsMain(version):
-  branches = str(subprocess.check_output(['git', 'branch', '-r', '--contains',
-                                      'HEAD']))
+  branches = subprocess.check_output(['git', 'branch', '-r', '--contains',
+                                      'HEAD']).decode('utf-8')
   # CL runs from gerrit does not have a branch, we always treat them as main
   # commits to archive these to the hash based location
   if len(branches) == 0:
diff --git a/tools/gradle.py b/tools/gradle.py
index bd3aa3c..19fa773 100755
--- a/tools/gradle.py
+++ b/tools/gradle.py
@@ -96,7 +96,7 @@
   cmd.extend(args)
   utils.PrintCmd(cmd)
   with utils.ChangedWorkingDirectory(cwd):
-    return str(subprocess.check_output(cmd, env=GetJavaEnv(env)))
+    return subprocess.check_output(cmd, env=GetJavaEnv(env)).decode('utf-8')
 
 def RunGradleWrapperInGetOutput(args, cwd, env=None):
   return RunGradleInGetOutput('./gradlew', args, cwd, env=env)
diff --git a/tools/internal_test.py b/tools/internal_test.py
index 1ec2a19..0d591ad 100755
--- a/tools/internal_test.py
+++ b/tools/internal_test.py
@@ -166,7 +166,7 @@
 
 def ensure_git_clean():
   # Ensure clean git repo.
-  diff = str(subprocess.check_output(['git', 'diff']))
+  diff = subprocess.check_output(['git', 'diff']).decode('utf-8')
   if len(diff) > 0:
     log('Local modifications to the git repo, exiting')
     sys.exit(1)
diff --git a/tools/utils.py b/tools/utils.py
index 79efd9c..d616707 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -137,12 +137,12 @@
     return options.commit_hash or options.version
 
 def find_hash_or_version_from_tag(tag_or_hash):
-  info = str(subprocess.check_output([
+  info = subprocess.check_output([
       'git',
       'show',
       tag_or_hash,
       '-s',
-      '--format=oneline'])).splitlines()[-1].split()
+      '--format=oneline']).decode('utf-8').splitlines()[-1].split()
   # The info should be on the following form [hash,"Version",version]
   if len(info) == 3 and len(info[0]) == 40 and info[1] == "Version":
     return info[2]
@@ -309,8 +309,8 @@
   return sha1.hexdigest()
 
 def is_main():
-  remotes = str(subprocess.check_output(['git', 'branch', '-r', '--contains',
-                                     'HEAD']))
+  remotes = subprocess.check_output(['git', 'branch', '-r', '--contains',
+                                     'HEAD']).decode('utf-8')
   return 'origin/main' in remotes
 
 def get_HEAD_sha1():
@@ -359,7 +359,7 @@
 def ls_files_on_cloud_storage(destination):
   cmd = [get_gsutil(), 'ls', destination]
   PrintCmd(cmd)
-  return str(subprocess.check_output(cmd))
+  return subprocess.check_output(cmd).decode('utf-8')
 
 def cat_file_on_cloud_storage(destination, ignore_errors=False):
   cmd = [get_gsutil(), 'cat', destination]
@@ -535,7 +535,7 @@
          'com.android.tools.r8.cf_segments.MeasureLib',
          cfFile]
   PrintCmd(cmd)
-  output = str(subprocess.check_output(cmd))
+  output = subprocess.check_output(cmd).decode('utf-8')
 
   matches = DEX_SEGMENTS_RESULT_PATTERN.findall(output)
 
@@ -567,8 +567,8 @@
 # Ensure that we are not benchmarking with a google jvm.
 def check_java_version():
   cmd= [jdk.GetJavaExecutable(), '-version']
-  output = str(subprocess.check_output(cmd, stderr = subprocess.STDOUT))
-  m = re.search('openjdk version "([^"]*)"', output.decode('utf-8'))
+  output = subprocess.check_output(cmd, stderr = subprocess.STDOUT).decode('utf-8')
+  m = re.search('openjdk version "([^"]*)"', output)
   if m is None:
     raise Exception("Can't check java version: no version string in output"
         " of 'java -version': '{}'".format(output))
@@ -604,7 +604,7 @@
 def getR8Version(path):
   cmd = [jdk.GetJavaExecutable(), '-cp', path, 'com.android.tools.r8.R8',
         '--version']
-  output = str(subprocess.check_output(cmd, stderr = subprocess.STDOUT))
+  output = subprocess.check_output(cmd, stderr = subprocess.STDOUT).decode('utf-8')
   # output is of the form 'R8 <version> (with additional info)'
   # so we split on '('; clean up tailing spaces; and strip off 'R8 '.
   return output.split('(')[0].strip()[3:]