aboutsummaryrefslogtreecommitdiff
path: root/llvm_tools
diff options
context:
space:
mode:
authorJian Cai <jiancai@google.com>2020-03-19 21:24:59 -0700
committerJian Cai <jiancai@google.com>2020-03-25 22:45:38 +0000
commit58c49f6faa951fdf0bb51e97f4ad3c77528b07c4 (patch)
tree87cad43a0889f432e88a1c4aa2afb3b376da5492 /llvm_tools
parenteb6e55f2b6f0f99aae9a4dbccf9970b1dfb5d1ca (diff)
downloadtoolchain-utils-58c49f6faa951fdf0bb51e97f4ad3c77528b07c4.tar.gz
llvm_tools: parameterize update_chromeos_llvm_next_hash.py
Currently update_chromeos_llvm_next_hash.py can only be used to create CLs that update LLVM_NEXT_HASH in toolchain-related ebuild files, as it hardcoded which git hash to update. This change allows users to choose betwen LLVM_HASH and LLVM_NEXT_HASH, and therefore can be used to create LLVM roll CLs automatically. BUG=chromium:1057428 TEST=local tests Change-Id: Ifc0cadb7b618d4780aceb92dcc8891941c612ecb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2112250 Reviewed-by: Bob Haarman <inglorion@chromium.org> Reviewed-by: Manoj Gupta <manojgupta@chromium.org> Tested-by: Jian Cai <jiancai@google.com>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-xllvm_tools/modify_a_tryjob.py3
-rwxr-xr-xllvm_tools/update_chromeos_llvm_next_hash.py154
-rwxr-xr-xllvm_tools/update_chromeos_llvm_next_hash_unittest.py248
-rwxr-xr-xllvm_tools/update_packages_and_run_tryjobs.py9
4 files changed, 249 insertions, 165 deletions
diff --git a/llvm_tools/modify_a_tryjob.py b/llvm_tools/modify_a_tryjob.py
index 20ba3541..6ea5e893 100755
--- a/llvm_tools/modify_a_tryjob.py
+++ b/llvm_tools/modify_a_tryjob.py
@@ -118,7 +118,8 @@ def GetCLAfterUpdatingPackages(packages, git_hash, svn_version, chroot_path,
"""Updates the packages' LLVM_NEXT."""
change_list = update_chromeos_llvm_next_hash.UpdatePackages(
- packages, git_hash, svn_version, chroot_path, patch_metadata_file,
+ packages, update_chromeos_llvm_next_hash.LLVMVariant.next, git_hash,
+ svn_version, chroot_path, patch_metadata_file,
FailureModes.DISABLE_PATCHES, svn_option)
print('\nSuccessfully updated packages to %d' % svn_version)
diff --git a/llvm_tools/update_chromeos_llvm_next_hash.py b/llvm_tools/update_chromeos_llvm_next_hash.py
index 955ebff7..ce87db94 100755
--- a/llvm_tools/update_chromeos_llvm_next_hash.py
+++ b/llvm_tools/update_chromeos_llvm_next_hash.py
@@ -4,26 +4,38 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Updates LLVM_NEXT_HASH and uprevs the build of a package or packages.
+"""Updates the LLVM hash and uprevs the build of the specified
+
+packages.
For each package, a temporary repo is created and the changes are uploaded
for review.
"""
from __future__ import print_function
+from collections import namedtuple
+from enum import Enum
import argparse
import os
import re
import subprocess
-from collections import namedtuple
from assert_not_in_chroot import VerifyOutsideChroot
from failure_modes import FailureModes
+from subprocess_helpers import ChrootRunCommand, ExecCommandAndCaptureOutput
from get_llvm_hash import GetLLVMHashAndVersionFromSVNOption, is_svn_option
import get_llvm_hash
import llvm_patch_management
-from subprocess_helpers import ChrootRunCommand, ExecCommandAndCaptureOutput
+
+
+# Specify which LLVM hash to update
+class LLVMVariant(Enum):
+ """Represent the LLVM hash in an ebuild file to update."""
+
+ current = 'LLVM_HASH'
+ next = 'LLVM_NEXT_HASH'
+
# If set to `True`, then the contents of `stdout` after executing a command will
# be displayed to the terminal.
@@ -72,12 +84,21 @@ def GetCommandLineArgs():
help='display contents of a command to the terminal '
'(default: %(default)s)')
+ # Add argument for the LLVM hash to update
+ parser.add_argument(
+ '--is_llvm_next',
+ action='store_true',
+ help=
+ 'which llvm hash to update. Update LLVM_NEXT_HASH specified. ' \
+ 'Otherwise, update LLVM_HASH'
+ )
+
# Add argument for the LLVM version to use.
parser.add_argument(
'--llvm_version',
type=is_svn_option,
required=True,
- help='which git hash of LLVM to find. Either a svn revision, or one '
+ help='which git hash to use. Either a svn revision, or one '
'of %s' % sorted(get_llvm_hash.KNOWN_HASH_SOURCES))
# Add argument for the mode of the patch management when handling patches.
@@ -218,15 +239,16 @@ def GetEbuildPathsFromSymLinkPaths(symlinks):
return resolved_paths
-def UpdateBuildLLVMNextHash(ebuild_path, llvm_hash, llvm_version):
- """Updates the build's LLVM_NEXT_HASH.
+def UpdateEbuildLLVMHash(ebuild_path, llvm_variant, git_hash, svn_version):
+ """Updates the LLVM hash in the ebuild.
The build changes are staged for commit in the temporary repo.
Args:
ebuild_path: The absolute path to the ebuild.
- llvm_hash: The new LLVM hash to use for LLVM_NEXT_HASH.
- llvm_version: The revision number of 'llvm_hash'.
+ llvm_variant: Which LLVM hash to update.
+ git_hash: The new git hash.
+ svn_version: The SVN-style revision number of git_hash.
Raises:
ValueError: Invalid ebuild path provided or failed to stage the commit
@@ -244,19 +266,13 @@ def UpdateBuildLLVMNextHash(ebuild_path, llvm_hash, llvm_version):
if not os.path.isfile(ebuild_path):
raise ValueError('Invalid ebuild path provided: %s' % ebuild_path)
- # Create regex that finds 'LLVM_NEXT_HASH'.
- llvm_regex = re.compile('^LLVM_NEXT_HASH=\"[a-z0-9]+\"')
-
temp_ebuild_file = '%s.temp' % ebuild_path
- # A flag for whether 'LLVM_NEXT_HASH=...' was updated.
- is_updated = False
-
with open(ebuild_path) as ebuild_file:
# write updates to a temporary file in case of interrupts
with open(temp_ebuild_file, 'w') as temp_file:
- for cur_line in ReplaceLLVMNextHash(ebuild_file, is_updated, llvm_regex,
- llvm_hash, llvm_version):
+ for cur_line in ReplaceLLVMHash(ebuild_file, llvm_variant, git_hash,
+ svn_version):
temp_file.write(cur_line)
os.rename(temp_ebuild_file, ebuild_path)
@@ -270,30 +286,30 @@ def UpdateBuildLLVMNextHash(ebuild_path, llvm_hash, llvm_version):
ExecCommandAndCaptureOutput(stage_changes_cmd, verbose=verbose)
-def ReplaceLLVMNextHash(ebuild_lines, is_updated, llvm_regex, llvm_hash,
- llvm_version):
- """Iterates through the ebuild file and updates the 'LLVM_NEXT_HASH'.
+def ReplaceLLVMHash(ebuild_lines, llvm_variant, git_hash, svn_version):
+ """Updates the LLVM git hash.
Args:
ebuild_lines: The contents of the ebuild file.
- is_updated: A flag for whether 'LLVM_NEXT_HASH' was updated.
- llvm_regex: The regex object for finding 'LLVM_NEXT_HASH=...' when
- iterating through the contents of the file.
- llvm_hash: The new LLVM hash to use for LLVM_NEXT_HASH.
- llvm_version: The revision number of 'llvm_hash'.
+ llvm_variant: The LLVM hash to update.
+ git_hash: The new git hash.
+ svn_version: The SVN-style revision number of git_hash.
"""
-
+ is_updated = False
+ llvm_regex = re.compile('^' + re.escape(llvm_variant.value) +
+ '=\"[a-z0-9]+\"')
for cur_line in ebuild_lines:
if not is_updated and llvm_regex.search(cur_line):
- # Update the LLVM next hash and revision number.
- cur_line = 'LLVM_NEXT_HASH=\"%s\" # r%d\n' % (llvm_hash, llvm_version)
+ # Update the git hash and revision number.
+ cur_line = '%s=\"%s\" # r%d\n' % (llvm_variant.value, git_hash,
+ svn_version)
is_updated = True
yield cur_line
- if not is_updated: # failed to update 'LLVM_NEXT_HASH'
- raise ValueError('Failed to update the LLVM hash.')
+ if not is_updated:
+ raise ValueError('Failed to update %s' % llvm_variant.value)
def UprevEbuild(symlink):
@@ -333,12 +349,14 @@ def UprevEbuild(symlink):
ExecCommandAndCaptureOutput(stage_symlink_cmd, verbose=verbose)
-def _CreateRepo(path_to_repo_dir, llvm_hash):
+def _CreateRepo(path_to_repo_dir, branch):
"""Creates a temporary repo for the changes.
Args:
path_to_repo_dir: The absolute path to the repo.
- llvm_hash: The LLVM hash to use for the name of the repo.
+ branch: The name of the branch to create.
+ llvm_variant: The LLVM hash to update.
+ git_hash: The new git hash.
Raises:
ValueError: Failed to create a repo in that directory.
@@ -358,18 +376,18 @@ def _CreateRepo(path_to_repo_dir, llvm_hash):
ExecCommandAndCaptureOutput(reset_changes_cmd, verbose=verbose)
- create_repo_cmd = ['repo', 'start', 'llvm-next-update-%s' % llvm_hash]
+ create_repo_cmd = ['repo', 'start', branch]
ExecCommandAndCaptureOutput(
create_repo_cmd, cwd=path_to_repo_dir, verbose=verbose)
-def _DeleteRepo(path_to_repo_dir, llvm_hash):
+def _DeleteRepo(path_to_repo_dir, branch):
"""Deletes the temporary repo.
Args:
path_to_repo_dir: The absolute path of the repo.
- llvm_hash: The LLVM hash used for the name of the repo.
+ branch: The name of the branch to delete.
Raises:
ValueError: Failed to delete the repo in that directory.
@@ -388,10 +406,7 @@ def _DeleteRepo(path_to_repo_dir, llvm_hash):
ExecCommandAndCaptureOutput(reset_head_cmd, verbose=verbose)
- delete_repo_cmd = [
- 'git', '-C', path_to_repo_dir, 'branch', '-D',
- 'llvm-next-update-%s' % llvm_hash
- ]
+ delete_repo_cmd = ['git', '-C', path_to_repo_dir, 'branch', '-D', branch]
ExecCommandAndCaptureOutput(delete_repo_cmd, verbose=verbose)
@@ -424,12 +439,12 @@ def GetGerritRepoUploadContents(repo_upload_contents):
return CommitContents(url=found_url.group(0), cl_number=cl_number)
-def UploadChanges(path_to_repo_dir, llvm_hash, commit_messages):
+def UploadChanges(path_to_repo_dir, branch, commit_messages):
"""Uploads the changes (updating LLVM next hash and uprev symlink) for review.
Args:
path_to_repo_dir: The absolute path to the repo where changes were made.
- llvm_hash: The LLVM hash used for the name of the repo.
+ branch: The name of the branch to upload.
commit_messages: A string of commit message(s) (i.e. '-m [message]'
of the changes made.
@@ -455,8 +470,7 @@ def UploadChanges(path_to_repo_dir, llvm_hash, commit_messages):
# Upload the changes for review.
upload_change_cmd = (
- 'yes | repo upload --wip --ne --br=llvm-next-update-%s --no-verify' %
- llvm_hash)
+ 'yes | repo upload --wip --ne --br=%s --no-verify' % branch)
# Pylint currently doesn't lint things in py3 mode, and py2 didn't allow
# users to specify `encoding`s for Popen. Hence, pylint is "wrong" here.
@@ -598,25 +612,26 @@ def StagePackagesPatchResultsForCommit(package_info_dict, commit_messages):
return commit_messages
-def UpdatePackages(packages, llvm_hash, llvm_version, chroot_path,
- patch_metadata_file, mode, svn_option):
- """Updates the package's LLVM_NEXT_HASH and uprevs the ebuild.
+def UpdatePackages(packages, llvm_variant, git_hash, svn_version, chroot_path,
+ patch_metadata_file, mode, git_hash_source):
+ """Updates an LLVM hash and uprevs the ebuild of the packages.
A temporary repo is created for the changes. The changes are
then uploaded for review.
Args:
packages: A list of all the packages that are going to be updated.
- llvm_hash: The LLVM hash to use for 'LLVM_NEXT_HASH'.
- llvm_version: The LLVM version of the 'llvm_hash'.
+ llvm_variant: The LLVM hash to update.
+ git_hash: The new git hash.
+ svn_version: The SVN-style revision number of git_hash.
chroot_path: The absolute path to the chroot.
patch_metadata_file: The name of the .json file in '$FILESDIR/' that has
the patches and its metadata.
mode: The mode of the patch manager when handling an applicable patch
that failed to apply.
Ex: 'FailureModes.FAIL'
- svn_option: The git hash to use based off of the svn option.
- Ex: 'google3', 'tot', or <svn_version> such as 365123
+ git_hash_source: The source of which git hash to use based off of.
+ Ex: 'google3', 'tot', or <version> such as 365123
Returns:
A nametuple that has two (key, value) pairs, where the first pair is the
@@ -632,15 +647,20 @@ def UpdatePackages(packages, llvm_hash, llvm_version, chroot_path,
repo_path = os.path.dirname(next(iter(paths_dict.values())))
- _CreateRepo(repo_path, llvm_hash)
+ branch = 'update-' + llvm_variant.value + '-' + git_hash
+
+ _CreateRepo(repo_path, branch)
try:
- if svn_option in get_llvm_hash.KNOWN_HASH_SOURCES:
- commit_message_header = ('llvm-next/%s: upgrade to %s (r%d)' %
- (svn_option, llvm_hash, llvm_version))
+ commit_message_header = 'llvm'
+ if llvm_variant == LLVMVariant.next:
+ commit_message_header = 'llvm-next'
+ if git_hash_source in get_llvm_hash.KNOWN_HASH_SOURCES:
+ commit_message_header += (
+ '/%s: upgrade to %s (r%d)' % (git_hash_source, git_hash, svn_version))
else:
- commit_message_header = (
- 'llvm-next: upgrade to %s (r%d)' % (llvm_hash, llvm_version))
+ commit_message_header += (
+ ': upgrade to %s (r%d)' % (git_hash, svn_version))
commit_messages = ['-m %s' % commit_message_header]
@@ -652,13 +672,13 @@ def UpdatePackages(packages, llvm_hash, llvm_version, chroot_path,
# Iterate through the dictionary.
#
# For each iteration:
- # 1) Update the ebuild's LLVM_NEXT_HASH.
+ # 1) Update the ebuild's LLVM hash.
# 2) Uprev the ebuild (symlink).
# 3) Add the modified package to the commit message.
for symlink_path, ebuild_path in paths_dict.items():
path_to_ebuild_dir = os.path.dirname(ebuild_path)
- UpdateBuildLLVMNextHash(ebuild_path, llvm_hash, llvm_version)
+ UpdateEbuildLLVMHash(ebuild_path, llvm_variant, git_hash, svn_version)
UprevEbuild(symlink_path)
@@ -673,16 +693,16 @@ def UpdatePackages(packages, llvm_hash, llvm_version, chroot_path,
# Handle the patches for each package.
package_info_dict = llvm_patch_management.UpdatePackagesPatchMetadataFile(
- chroot_path, llvm_version, patch_metadata_file, packages, mode)
+ chroot_path, svn_version, patch_metadata_file, packages, mode)
# Update the commit message if changes were made to a package's patches.
commit_messages = StagePackagesPatchResultsForCommit(
package_info_dict, commit_messages)
- change_list = UploadChanges(repo_path, llvm_hash, commit_messages)
+ change_list = UploadChanges(repo_path, branch, commit_messages)
finally:
- _DeleteRepo(repo_path, llvm_hash)
+ _DeleteRepo(repo_path, branch)
return change_list
@@ -698,16 +718,20 @@ def main():
args_output = GetCommandLineArgs()
- svn_option = args_output.llvm_version
+ llvm_variant = LLVMVariant.current
+ if args_output.is_llvm_next:
+ llvm_variant = LLVMVariant.next
+
+ git_hash_source = args_output.llvm_version
- llvm_hash, llvm_version = GetLLVMHashAndVersionFromSVNOption(svn_option)
+ git_hash, svn_version = GetLLVMHashAndVersionFromSVNOption(git_hash_source)
change_list = UpdatePackages(
- args_output.update_packages, llvm_hash, llvm_version,
+ args_output.update_packages, llvm_variant, git_hash, svn_version,
args_output.chroot_path, args_output.patch_metadata_file,
- FailureModes(args_output.failure_mode), svn_option)
+ FailureModes(args_output.failure_mode), git_hash_source)
- print('Successfully updated packages to %d' % llvm_version)
+ print('Successfully updated packages to %s (%d)' % (git_hash, svn_version))
print('Gerrit URL: %s' % change_list.url)
print('Change list number: %d' % change_list.cl_number)
diff --git a/llvm_tools/update_chromeos_llvm_next_hash_unittest.py b/llvm_tools/update_chromeos_llvm_next_hash_unittest.py
index 4e39bafa..033d602e 100755
--- a/llvm_tools/update_chromeos_llvm_next_hash_unittest.py
+++ b/llvm_tools/update_chromeos_llvm_next_hash_unittest.py
@@ -4,7 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Unit tests for updating the LLVM next hash."""
+"""Unit tests for updating LLVM hashes."""
from __future__ import print_function
@@ -23,8 +23,8 @@ import update_chromeos_llvm_next_hash
# pylint: disable=protected-access
-class UpdateLLVMNextHashTest(unittest.TestCase):
- """Test class for updating 'LLVM_NEXT_HASH' of packages."""
+class UpdateLLVMHashTest(unittest.TestCase):
+ """Test class for updating LLVM hashes of packages."""
@mock.patch.object(update_chromeos_llvm_next_hash, 'ChrootRunCommand')
def testSucceedsToGetChrootPathForPackage(self, mock_chroot_command):
@@ -108,16 +108,16 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Simulate behavior of 'os.path.isfile()' when the ebuild path to a package
# does not exist.
@mock.patch.object(os.path, 'isfile', return_value=False)
- def testFailedToUpdateLLVMNextHashForInvalidEbuildPath(self, mock_isfile):
+ def testFailedToUpdateLLVMHashForInvalidEbuildPath(self, mock_isfile):
ebuild_path = '/some/path/to/package.ebuild'
-
- llvm_hash = 'a123testhash1'
- llvm_revision = 1000
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.current
+ git_hash = 'a123testhash1'
+ svn_version = 1000
# Verify the exception is raised when the ebuild path does not exist.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash.UpdateBuildLLVMNextHash(
- ebuild_path, llvm_hash, llvm_revision)
+ update_chromeos_llvm_next_hash.UpdateEbuildLLVMHash(
+ ebuild_path, llvm_variant, git_hash, svn_version)
self.assertEqual(
str(err.exception), 'Invalid ebuild path provided: %s' % ebuild_path)
@@ -126,6 +126,34 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Simulate 'os.path.isfile' behavior on a valid ebuild path.
@mock.patch.object(os.path, 'isfile', return_value=True)
+ def testFailedToUpdateLLVMHash(self, mock_isfile):
+ # Create a temporary file to simulate an ebuild file of a package.
+ with CreateTemporaryJsonFile() as ebuild_file:
+ with open(ebuild_file, 'w') as f:
+ f.write('\n'.join([
+ 'First line in the ebuild', 'Second line in the ebuild',
+ 'Last line in the ebuild'
+ ]))
+
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.current
+ git_hash = 'a123testhash1'
+ svn_version = 1000
+
+ # Verify the exception is raised when the ebuild file does not have
+ # 'LLVM_HASH'.
+ with self.assertRaises(ValueError) as err:
+ update_chromeos_llvm_next_hash.UpdateEbuildLLVMHash(
+ ebuild_file, llvm_variant, git_hash, svn_version)
+
+ self.assertEqual(
+ str(err.exception), ('Failed to update %s.', 'LLVM_HASH'))
+
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.next
+
+ self.assertEqual(mock_isfile.call_count, 2)
+
+ # Simulate 'os.path.isfile' behavior on a valid ebuild path.
+ @mock.patch.object(os.path, 'isfile', return_value=True)
def testFailedToUpdateLLVMNextHash(self, mock_isfile):
# Create a temporary file to simulate an ebuild file of a package.
with CreateTemporaryJsonFile() as ebuild_file:
@@ -135,19 +163,64 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
'Last line in the ebuild'
]))
- llvm_hash = 'a123testhash1'
- llvm_revision = 1000
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.next
+ git_hash = 'a123testhash1'
+ svn_version = 1000
# Verify the exception is raised when the ebuild file does not have
# 'LLVM_NEXT_HASH'.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash.UpdateBuildLLVMNextHash(
- ebuild_file, llvm_hash, llvm_revision)
+ update_chromeos_llvm_next_hash.UpdateEbuildLLVMHash(
+ ebuild_file, llvm_variant, git_hash, svn_version)
+
+ self.assertEqual(
+ str(err.exception), ('Failed to update %s.', 'LLVM_NEXT_HASH'))
+
+ self.assertEqual(mock_isfile.call_count, 2)
+
+ # Simulate 'os.path.isfile' behavior on a valid ebuild path.
+ @mock.patch.object(os.path, 'isfile', return_value=True)
+ # Simulate 'ExecCommandAndCaptureOutput()' when successfully staged the
+ # ebuild file for commit.
+ @mock.patch.object(
+ update_chromeos_llvm_next_hash,
+ 'ExecCommandAndCaptureOutput',
+ return_value=None)
+ def testSuccessfullyStageTheEbuildForCommitForLLVMHashUpdate(
+ self, mock_stage_commit_command, mock_isfile):
+
+ # Create a temporary file to simulate an ebuild file of a package.
+ with CreateTemporaryJsonFile() as ebuild_file:
+ # Updates LLVM_HASH to 'git_hash' and revision to
+ # 'svn_version'.
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.current
+ git_hash = 'a123testhash1'
+ svn_version = 1000
- self.assertEqual(str(err.exception), 'Failed to update the LLVM hash.')
+ with open(ebuild_file, 'w') as f:
+ f.write('\n'.join([
+ 'First line in the ebuild', 'Second line in the ebuild',
+ 'LLVM_HASH=\"a12b34c56d78e90\" # r500', 'Last line in the ebuild'
+ ]))
+
+ update_chromeos_llvm_next_hash.UpdateEbuildLLVMHash(
+ ebuild_file, llvm_variant, git_hash, svn_version)
+
+ expected_file_contents = [
+ 'First line in the ebuild\n', 'Second line in the ebuild\n',
+ 'LLVM_HASH=\"a123testhash1\" # r1000\n', 'Last line in the ebuild'
+ ]
+
+ # Verify the new file contents of the ebuild file match the expected file
+ # contents.
+ with open(ebuild_file) as new_file:
+ file_contents_as_a_list = [cur_line for cur_line in new_file]
+ self.assertListEqual(file_contents_as_a_list, expected_file_contents)
self.assertEqual(mock_isfile.call_count, 2)
+ mock_stage_commit_command.assert_called_once()
+
# Simulate 'os.path.isfile' behavior on a valid ebuild path.
@mock.patch.object(os.path, 'isfile', return_value=True)
# Simulate 'ExecCommandAndCaptureOutput()' when successfully staged the
@@ -161,6 +234,12 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Create a temporary file to simulate an ebuild file of a package.
with CreateTemporaryJsonFile() as ebuild_file:
+ # Updates LLVM_NEXT_HASH to 'git_hash' and revision to
+ # 'svn_version'.
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.next
+ git_hash = 'a123testhash1'
+ svn_version = 1000
+
with open(ebuild_file, 'w') as f:
f.write('\n'.join([
'First line in the ebuild', 'Second line in the ebuild',
@@ -168,13 +247,8 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
'Last line in the ebuild'
]))
- # Updates the ebuild's git hash to 'llvm_hash' and revision to
- # 'llvm_revision'.
- llvm_hash = 'a123testhash1'
- llvm_revision = 1000
-
- update_chromeos_llvm_next_hash.UpdateBuildLLVMNextHash(
- ebuild_file, llvm_hash, llvm_revision)
+ update_chromeos_llvm_next_hash.UpdateEbuildLLVMHash(
+ ebuild_file, llvm_variant, git_hash, svn_version)
expected_file_contents = [
'First line in the ebuild\n', 'Second line in the ebuild\n',
@@ -250,13 +324,11 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
@mock.patch.object(os.path, 'isdir', return_value=False)
def testFailedToCreateRepoForInvalidDirectoryPath(self, mock_isdir):
path_to_repo = '/path/to/repo'
-
- # The name to use for the repo name.
- llvm_hash = 'a123testhash1'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash1'
# Verify the exception is raised when provided an invalid directory path.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash._CreateRepo(path_to_repo, llvm_hash)
+ update_chromeos_llvm_next_hash._CreateRepo(path_to_repo, branch)
self.assertEqual(
str(err.exception),
@@ -274,11 +346,9 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
return_value=None)
def testSuccessfullyCreatedRepo(self, mock_command_output, mock_isdir):
path_to_repo = '/path/to/repo'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash1'
- # The name to use for the repo name.
- llvm_hash = 'a123testhash1'
-
- update_chromeos_llvm_next_hash._CreateRepo(path_to_repo, llvm_hash)
+ update_chromeos_llvm_next_hash._CreateRepo(path_to_repo, branch)
mock_isdir.assert_called_once_with(path_to_repo)
@@ -289,13 +359,11 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
@mock.patch.object(os.path, 'isdir', return_value=False)
def testFailedToDeleteRepoForInvalidDirectoryPath(self, mock_isdir):
path_to_repo = '/some/path/to/repo'
-
- # The name to use for the repo name.
- llvm_hash = 'a123testhash2'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash2'
# Verify the exception is raised on an invalid repo path.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash._DeleteRepo(path_to_repo, llvm_hash)
+ update_chromeos_llvm_next_hash._DeleteRepo(path_to_repo, branch)
self.assertEqual(
str(err.exception),
@@ -313,11 +381,9 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
return_value=None)
def testSuccessfullyDeletedRepo(self, mock_command_output, mock_isdir):
path_to_repo = '/some/path/to/repo'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash2'
- # The name of the repo to be deleted.
- llvm_hash = 'a123testhash2'
-
- update_chromeos_llvm_next_hash._DeleteRepo(path_to_repo, llvm_hash)
+ update_chromeos_llvm_next_hash._DeleteRepo(path_to_repo, branch)
mock_isdir.assert_called_once_with(path_to_repo)
@@ -354,16 +420,12 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
@mock.patch.object(os.path, 'isdir', return_value=False)
def testFailedToUploadChangesForInvalidPathDirectory(self, mock_isdir):
path_to_repo = '/some/path/to/repo'
-
- # The name of repo to upload for review.
- llvm_hash = 'a123testhash3'
-
- # Commit messages to add to the CL.
+ branch = 'update-LLVM_NEXT_HASH-a123testhash3'
commit_messages = ['-m Test message']
# Verify exception is raised when on an invalid repo path.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash.UploadChanges(path_to_repo, llvm_hash,
+ update_chromeos_llvm_next_hash.UploadChanges(path_to_repo, branch,
commit_messages)
self.assertEqual(
@@ -395,16 +457,12 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
mock_repo_upload.return_value.returncode = 1
path_to_repo = '/some/path/to/repo'
-
- # The name of repo to upload for review.
- llvm_hash = 'a123testhash3'
-
- # Commit messages to add to the CL.
+ branch = 'update-LLVM_NEXT_HASH-a123testhash3'
commit_messages = ['-m Test message']
# Verify exception is raised when failed to upload the changes for review.
with self.assertRaises(ValueError) as err:
- update_chromeos_llvm_next_hash.UploadChanges(path_to_repo, llvm_hash,
+ update_chromeos_llvm_next_hash.UploadChanges(path_to_repo, branch,
commit_messages)
self.assertEqual(str(err.exception), 'Failed to upload changes for review')
@@ -443,15 +501,11 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
mock_repo_upload.return_value.returncode = 0
path_to_repo = '/some/path/to/repo'
-
- # The name of the hash to upload for review.
- llvm_hash = 'a123testhash3'
-
- # Commit messages to add to the CL.
+ branch = 'update-LLVM_NEXT_HASH-a123testhash3'
commit_messages = ['-m Test message']
change_list = update_chromeos_llvm_next_hash.UploadChanges(
- path_to_repo, llvm_hash, commit_messages)
+ path_to_repo, branch, commit_messages)
self.assertEqual(
change_list.url,
@@ -701,7 +755,7 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
@mock.patch.object(update_chromeos_llvm_next_hash,
'CreatePathDictionaryFromPackages')
@mock.patch.object(update_chromeos_llvm_next_hash, '_CreateRepo')
- @mock.patch.object(update_chromeos_llvm_next_hash, 'UpdateBuildLLVMNextHash')
+ @mock.patch.object(update_chromeos_llvm_next_hash, 'UpdateEbuildLLVMHash')
@mock.patch.object(update_chromeos_llvm_next_hash, 'UprevEbuild')
@mock.patch.object(update_chromeos_llvm_next_hash, 'UploadChanges')
@mock.patch.object(update_chromeos_llvm_next_hash, '_DeleteRepo')
@@ -718,16 +772,16 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Test function to simulate '_CreateRepo' when successfully created the
# repo on a valid repo path.
- def SuccessfullyCreateRepoForChanges(_repo_path, llvm_hash):
- self.assertEqual(llvm_hash, 'a123testhash4')
+ def SuccessfullyCreateRepoForChanges(_repo_path, branch):
+ self.assertEqual(branch, 'update-LLVM_NEXT_HASH-a123testhash4')
return
- # Test function to simulate 'UpdateBuildLLVMNextHash' when successfully
+ # Test function to simulate 'UpdateEbuildLLVMHash' when successfully
# updated the ebuild's 'LLVM_NEXT_HASH'.
- def SuccessfullyUpdatedLLVMNextHash(ebuild_path, llvm_hash, llvm_version):
+ def SuccessfullyUpdatedLLVMHash(ebuild_path, _, git_hash, svn_version):
self.assertEqual(ebuild_path, abs_path_to_package)
- self.assertEqual(llvm_hash, 'a123testhash4')
- self.assertEqual(llvm_version, 1000)
+ self.assertEqual(git_hash, 'a123testhash4')
+ self.assertEqual(svn_version, 1000)
return
# Test function to simulate 'UprevEbuild' when the symlink to the ebuild
@@ -739,7 +793,7 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Test function to fail on 'UploadChanges' if the function gets called
# when an exception is raised.
- def ShouldNotExecuteUploadChanges(_repo_path, _llvm_hash, _commit_messages):
+ def ShouldNotExecuteUploadChanges(_repo_path, _git_hash, _commit_messages):
# Test function should not be called (i.e. execution should resume in the
# 'finally' block) because 'UprevEbuild()' raised an
# exception.
@@ -756,44 +810,46 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Use test function to simulate behavior.
mock_create_repo.side_effect = SuccessfullyCreateRepoForChanges
- mock_update_llvm_next.side_effect = SuccessfullyUpdatedLLVMNextHash
+ mock_update_llvm_next.side_effect = SuccessfullyUpdatedLLVMHash
mock_uprev_ebuild.side_effect = FailedToUprevEbuild
mock_upload_changes.side_effect = ShouldNotExecuteUploadChanges
packages_to_update = ['test-packages/package1']
- patch_metadata_file = 'PATCHES.json'
- llvm_hash = 'a123testhash4'
- llvm_version = 1000
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.next
+ git_hash = 'a123testhash4'
+ svn_version = 1000
chroot_path = '/some/path/to/chroot'
- svn_option = 'google3'
+ patch_metadata_file = 'PATCHES.json'
+ git_hash_source = 'google3'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash4'
# Verify exception is raised when an exception is thrown within
# the 'try' block by UprevEbuild function.
with self.assertRaises(ValueError) as err:
update_chromeos_llvm_next_hash.UpdatePackages(
- packages_to_update, llvm_hash, llvm_version, chroot_path,
- patch_metadata_file, FailureModes.FAIL, svn_option)
+ packages_to_update, llvm_variant, git_hash, svn_version, chroot_path,
+ patch_metadata_file, FailureModes.FAIL, git_hash_source)
self.assertEqual(str(err.exception), 'Failed to uprev the ebuild.')
mock_create_path_dict.assert_called_once_with(chroot_path,
packages_to_update)
- mock_create_repo.assert_called_once_with(path_to_package_dir, llvm_hash)
+ mock_create_repo.assert_called_once_with(path_to_package_dir, branch)
- mock_update_llvm_next.assert_called_once_with(abs_path_to_package,
- llvm_hash, llvm_version)
+ mock_update_llvm_next.assert_called_once_with(
+ abs_path_to_package, llvm_variant, git_hash, svn_version)
mock_uprev_ebuild.assert_called_once_with(symlink_path_to_package)
mock_upload_changes.assert_not_called()
- mock_delete_repo.assert_called_once_with(path_to_package_dir, llvm_hash)
+ mock_delete_repo.assert_called_once_with(path_to_package_dir, branch)
@mock.patch.object(update_chromeos_llvm_next_hash,
'CreatePathDictionaryFromPackages')
@mock.patch.object(update_chromeos_llvm_next_hash, '_CreateRepo')
- @mock.patch.object(update_chromeos_llvm_next_hash, 'UpdateBuildLLVMNextHash')
+ @mock.patch.object(update_chromeos_llvm_next_hash, 'UpdateEbuildLLVMHash')
@mock.patch.object(update_chromeos_llvm_next_hash, 'UprevEbuild')
@mock.patch.object(update_chromeos_llvm_next_hash, 'UploadChanges')
@mock.patch.object(update_chromeos_llvm_next_hash, '_DeleteRepo')
@@ -814,17 +870,17 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Test function to simulate '_CreateRepo' when successfully created the repo
# for the changes to be made to the ebuild files.
- def SuccessfullyCreateRepoForChanges(_repo_path, llvm_hash):
- self.assertEqual(llvm_hash, 'a123testhash5')
+ def SuccessfullyCreateRepoForChanges(_repo_path, branch):
+ self.assertEqual(branch, 'update-LLVM_NEXT_HASH-a123testhash5')
return
# Test function to simulate 'UploadChanges' after a successfull update of
# 'LLVM_NEXT_HASH" of the ebuild file.
- def SuccessfullyUpdatedLLVMNextHash(ebuild_path, llvm_hash, llvm_version):
+ def SuccessfullyUpdatedLLVMHash(ebuild_path, _, git_hash, svn_version):
self.assertEqual(ebuild_path,
'/some/path/to/chroot/src/path/to/package.ebuild')
- self.assertEqual(llvm_hash, 'a123testhash5')
- self.assertEqual(llvm_version, 1000)
+ self.assertEqual(git_hash, 'a123testhash5')
+ self.assertEqual(svn_version, 1000)
return
# Test function to simulate 'UprevEbuild' when successfully incremented
@@ -837,11 +893,11 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Test function to simulate 'UpdatePackagesPatchMetadataFile()' when the
# patch results contains a disabled patch in 'disable_patches' mode.
- def RetrievedPatchResults(chroot_path, llvm_version, patch_metadata_file,
+ def RetrievedPatchResults(chroot_path, svn_version, patch_metadata_file,
packages, mode):
self.assertEqual(chroot_path, '/some/path/to/chroot')
- self.assertEqual(llvm_version, 1000)
+ self.assertEqual(svn_version, 1000)
self.assertEqual(patch_metadata_file, 'PATCHES.json')
self.assertListEqual(packages, ['path/to'])
self.assertEqual(mode, FailureModes.DISABLE_PATCHES)
@@ -869,7 +925,7 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Test function to simulate 'UploadChanges()' when successfully created a
# commit for the changes made to the packages and their patches and
# retrieved the change list of the commit.
- def SuccessfullyUploadedChanges(_repo_path, _llvm_hash, _commit_messages):
+ def SuccessfullyUploadedChanges(_repo_path, _branch, _commit_messages):
commit_url = 'https://some_name/path/to/commit/+/12345'
return update_chromeos_llvm_next_hash.CommitContents(
@@ -885,21 +941,23 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
# Use test function to simulate behavior.
mock_create_repo.side_effect = SuccessfullyCreateRepoForChanges
- mock_update_llvm_next.side_effect = SuccessfullyUpdatedLLVMNextHash
+ mock_update_llvm_next.side_effect = SuccessfullyUpdatedLLVMHash
mock_uprev_ebuild.side_effect = SuccessfullyUprevedEbuild
mock_update_package_metadata_file.side_effect = RetrievedPatchResults
mock_upload_changes.side_effect = SuccessfullyUploadedChanges
packages_to_update = ['test-packages/package1']
- patch_metadata_file = 'PATCHES.json'
- llvm_hash = 'a123testhash5'
- llvm_version = 1000
+ llvm_variant = update_chromeos_llvm_next_hash.LLVMVariant.next
+ git_hash = 'a123testhash5'
+ svn_version = 1000
chroot_path = '/some/path/to/chroot'
- svn_option = 'tot'
+ patch_metadata_file = 'PATCHES.json'
+ git_hash_source = 'tot'
+ branch = 'update-LLVM_NEXT_HASH-a123testhash5'
change_list = update_chromeos_llvm_next_hash.UpdatePackages(
- packages_to_update, llvm_hash, llvm_version, chroot_path,
- patch_metadata_file, FailureModes.DISABLE_PATCHES, svn_option)
+ packages_to_update, llvm_variant, git_hash, svn_version, chroot_path,
+ patch_metadata_file, FailureModes.DISABLE_PATCHES, git_hash_source)
self.assertEqual(change_list.url,
'https://some_name/path/to/commit/+/12345')
@@ -909,10 +967,10 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
mock_create_path_dict.assert_called_once_with(chroot_path,
packages_to_update)
- mock_create_repo.assert_called_once_with(path_to_package_dir, llvm_hash)
+ mock_create_repo.assert_called_once_with(path_to_package_dir, branch)
- mock_update_llvm_next.assert_called_once_with(abs_path_to_package,
- llvm_hash, llvm_version)
+ mock_update_llvm_next.assert_called_once_with(
+ abs_path_to_package, llvm_variant, git_hash, svn_version)
mock_uprev_ebuild.assert_called_once_with(symlink_path_to_package)
@@ -931,10 +989,10 @@ class UpdateLLVMNextHashTest(unittest.TestCase):
mock_stage_patch_file.assert_called_once_with(
'/abs/path/to/filesdir/PATCHES.json')
- mock_upload_changes.assert_called_once_with(path_to_package_dir, llvm_hash,
+ mock_upload_changes.assert_called_once_with(path_to_package_dir, branch,
expected_commit_messages)
- mock_delete_repo.assert_called_once_with(path_to_package_dir, llvm_hash)
+ mock_delete_repo.assert_called_once_with(path_to_package_dir, branch)
if __name__ == '__main__':
diff --git a/llvm_tools/update_packages_and_run_tryjobs.py b/llvm_tools/update_packages_and_run_tryjobs.py
index fac93db3..30e8b356 100755
--- a/llvm_tools/update_packages_and_run_tryjobs.py
+++ b/llvm_tools/update_packages_and_run_tryjobs.py
@@ -38,8 +38,8 @@ def GetCommandLineArgs():
# Create parser and add optional command-line arguments.
parser = argparse.ArgumentParser(
- description='Runs a tryjob if successfully updated packages\''
- '"LLVM_NEXT_HASH".')
+ description=
+ 'Runs a tryjob if successfully updated LLVM_NEXT_HASH of packages.')
# Add argument for the absolute path to the file that contains information on
# the previous tested svn version.
@@ -287,8 +287,9 @@ def main():
update_chromeos_llvm_next_hash.verbose = args_output.verbose
change_list = update_chromeos_llvm_next_hash.UpdatePackages(
- update_packages, git_hash, svn_version, args_output.chroot_path,
- patch_metadata_file, FailureModes.DISABLE_PATCHES, svn_option)
+ update_packages, update_chromeos_llvm_next_hash.LLVMVariant.next,
+ git_hash, svn_version, args_output.chroot_path, patch_metadata_file,
+ FailureModes.DISABLE_PATCHES, svn_option)
print('Successfully updated packages to %d' % svn_version)
print('Gerrit URL: %s' % change_list.url)