diff options
author | Salud Lemus <saludlemus@google.com> | 2019-09-04 18:15:35 -0700 |
---|---|---|
committer | Salud Lemus <saludlemus@google.com> | 2019-09-09 20:23:50 +0000 |
commit | 6270cccfcd886478a9c1b20acf9e8cd50a673a19 (patch) | |
tree | f9b5938b388f0be67333882113a2e66e1a969860 /llvm_tools/get_llvm_hash.py | |
parent | 2ad170bf822e26b07b4ed69f500be2ca9a5c3df1 (diff) | |
download | toolchain-utils-6270cccfcd886478a9c1b20acf9e8cd50a673a19.tar.gz |
LLVM tools: Migrated all scripts to python3
This CL includes changes such as replacements of `\'` with `"` and
adding extra debugging output to some scripts.
Currently, the scripts are in python2, so migrating them to python3 so
they are more maintainable.
BUG=None
TEST=Ran each script by itself with various input (e.g. different
google3, tot, etc.).
Change-Id: Ib72b7744c6f7c13711c2db427f6524ff3cbc6205
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1787738
Tested-by: Salud Lemus <saludlemus@google.com>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'llvm_tools/get_llvm_hash.py')
-rwxr-xr-x | llvm_tools/get_llvm_hash.py | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/llvm_tools/get_llvm_hash.py b/llvm_tools/get_llvm_hash.py index c4a72bba..e08c30f8 100755 --- a/llvm_tools/get_llvm_hash.py +++ b/llvm_tools/get_llvm_hash.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -14,7 +14,10 @@ import re import shutil import subprocess import tempfile + from contextlib import contextmanager +from subprocess_helpers import CheckCommand +from subprocess_helpers import check_output import requests @@ -22,19 +25,6 @@ _LLVM_GIT_URL = ('https://chromium.googlesource.com/external/github.com/llvm' '/llvm-project') -def CheckCommand(cmd): - """Executes the command using Popen().""" - - cmd_obj = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - stdout, _ = cmd_obj.communicate() - - if cmd_obj.returncode: - print(stdout) - raise subprocess.CalledProcessError(cmd_obj.returncode, cmd) - - @contextmanager def CreateTempLLVMRepo(temp_dir): """Adds a LLVM worktree to 'temp_dir'. @@ -70,7 +60,7 @@ def CreateTempLLVMRepo(temp_dir): yield temp_dir finally: if os.path.isdir(temp_dir): - subprocess.check_output([ + check_output([ 'git', '-C', abs_path_to_llvm_project_dir, 'worktree', 'remove', '-f', temp_dir ]) @@ -106,7 +96,7 @@ def GetAndUpdateLLVMProjectInLLVMTools(): # `git status` has a '-s'/'--short' option that shortens the output. # With the '-s' option, if no changes were made to the LLVM repo, then the # output (assigned to 'repo_status') would be empty. - repo_status = subprocess.check_output( + repo_status = check_output( ['git', '-C', abs_path_to_llvm_project_dir, 'status', '-s']) if repo_status.rstrip(): @@ -145,7 +135,7 @@ def GetGoogle3LLVMVersion(): cat_cmd = ['cat', path_to_google3_llvm_version] # Get latest version. - g3_version = subprocess.check_output(cat_cmd) + g3_version = check_output(cat_cmd) # Change type to an integer return int(g3_version.rstrip()) @@ -323,7 +313,7 @@ class LLVMHash(object): 'git', '-C', subdir, 'log', '--format=%B', '-n', '1', cur_hash ] - out = subprocess.check_output(find_llvm_cmd) + out = check_output(find_llvm_cmd) commit_svn_version = self.GetSVNVersionFromCommitMessage(out.rstrip()) @@ -356,7 +346,7 @@ class LLVMHash(object): 'llvm-svn: %d' % llvm_version ] - hash_vals = subprocess.check_output(hash_cmd) + hash_vals = check_output(hash_cmd) return self._ParseCommitMessages(llvm_git_dir, hash_vals.rstrip(), llvm_version) @@ -390,7 +380,7 @@ class LLVMHash(object): 'git', 'ls-remote', _LLVM_GIT_URL, path_to_master_branch ] - llvm_tot_git_hash = subprocess.check_output(llvm_tot_git_hash_cmd) + llvm_tot_git_hash = check_output(llvm_tot_git_hash_cmd) return llvm_tot_git_hash.rstrip().split()[0] |