From 6270cccfcd886478a9c1b20acf9e8cd50a673a19 Mon Sep 17 00:00:00 2001 From: Salud Lemus Date: Wed, 4 Sep 2019 18:15:35 -0700 Subject: 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 Reviewed-by: Manoj Gupta --- llvm_tools/llvm_patch_management.py | 50 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'llvm_tools/llvm_patch_management.py') diff --git a/llvm_tools/llvm_patch_management.py b/llvm_tools/llvm_patch_management.py index 90f82d30..522d4e34 100755 --- a/llvm_tools/llvm_patch_management.py +++ b/llvm_tools/llvm_patch_management.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 @@ -8,19 +8,21 @@ from __future__ import print_function -from pipes import quote import argparse import os import patch_manager from assert_not_in_chroot import VerifyOutsideChroot -from cros_utils import command_executer from failure_modes import FailureModes from get_llvm_hash import CreateTempLLVMRepo from get_llvm_hash import GetGoogle3LLVMVersion from get_llvm_hash import LLVMHash +from subprocess_helpers import ChrootRunCommand +from subprocess_helpers import ExecCommandAndCaptureOutput -ce = command_executer.GetCommandExecuter() +# If set to `True`, then the contents of `stdout` after executing a command will +# be displayed to the terminal. +verbose = False def GetCommandLineArgs(): @@ -52,12 +54,12 @@ def GetCommandLineArgs(): default=['sys-devel/llvm'], help='the packages to manage their patches (default: %(default)s)') - # Add argument for the log level. + # Add argument for whether to display command contents to `stdout`. parser.add_argument( - '--log_level', - default='none', - choices=['none', 'quiet', 'average', 'verbose'], - help='the level for the logs (default: %(default)s)') + '--verbose', + action='store_true', + help='display contents of a command to the terminal ' + '(default: %(default)s)') # Add argument for the LLVM version to use for patch management. parser.add_argument( @@ -86,8 +88,9 @@ def GetCommandLineArgs(): # Parse the command line. args_output = parser.parse_args() - # Set the log level for the command executer. - ce.SetLogLevel(log_level=args_output.log_level) + global verbose + + verbose = args_output.verbose unique_packages = list(set(args_output.packages)) @@ -119,15 +122,8 @@ def GetPathToFilesDirectory(chroot_path, package): raise ValueError('Invalid chroot provided: %s' % chroot_path) # Get the absolute chroot path to the ebuild. - ret, chroot_ebuild_path, err = ce.ChrootRunCommandWOutput( - chromeos_root=chroot_path, - command='equery w %s' % package, - print_to_console=ce.GetLogLevel() == 'verbose') - - if ret: # Failed to get the absolute chroot path to package's ebuild. - raise ValueError( - 'Failed to get the absolute chroot path of the package %s: %s' % - (package, err)) + chroot_ebuild_path = ChrootRunCommand( + chroot_path, ['equery', 'w', package], verbose=verbose) # Get the absolute chroot path to $FILESDIR's parent directory. filesdir_parent_path = os.path.dirname(chroot_ebuild_path.strip()) @@ -175,20 +171,15 @@ def _CheckPatchMetadataPath(patch_metadata_path): raise ValueError('Invalid file provided: %s' % patch_metadata_path) if not patch_metadata_path.endswith('.json'): - raise ValueError('File does not end in \'.json\': %s' % patch_metadata_path) + raise ValueError('File does not end in ".json": %s' % patch_metadata_path) def _MoveSrcTreeHEADToGitHash(src_path, git_hash): """Moves HEAD to 'git_hash'.""" - move_head_cmd = 'git -C %s checkout %s' % (quote(src_path), git_hash) + move_head_cmd = ['git', '-C', src_path, 'checkout', git_hash] - ret, _, err = ce.RunCommandWOutput( - move_head_cmd, print_to_console=ce.GetLogLevel() == 'verbose') - - if ret: # Failed to checkout to 'git_hash'. - raise ValueError('Failed to moved HEAD in %s to %s: %s' % (quote(src_path), - git_hash, err)) + ExecCommandAndCaptureOutput(move_head_cmd, verbose=verbose) def UpdatePackagesPatchMetadataFile(chroot_path, svn_version, @@ -275,6 +266,9 @@ def main(): print('The patch file %s has been modified for the packages:' % args_output.patch_metadata_file) print('\n'.join(args_output.packages)) + else: + print('Applicable patches in %s applied successfully.' % + args_output.patch_metadata_file) if __name__ == '__main__': -- cgit v1.2.3