diff options
author | Jian Cai <jiancai@google.com> | 2020-04-10 12:01:26 -0700 |
---|---|---|
committer | Jian Cai <jiancai@google.com> | 2020-04-10 21:11:12 +0000 |
commit | b70c3c1c7371b572ff3f0b2c1a42e89838bcd689 (patch) | |
tree | 94778480b7c77a65fd5e8d026b6dc441a16fa99c /llvm_tools | |
parent | 0ca78c6a8dd0e86ce19ae4fd2858a15b1d974950 (diff) | |
download | toolchain-utils-b70c3c1c7371b572ff3f0b2c1a42e89838bcd689.tar.gz |
llvm_tools: fix the naming of ebuilds for LLVM rolls
Use LLVM SVN version in the name ebuilds in LLVM roll CLs.
BUG=chromium:1041590
TEST=local tests.
Change-Id: I61d45b166968d4081f11dd9838b6774d2502250b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2145671
Tested-by: Jian Cai <jiancai@google.com>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-x | llvm_tools/update_chromeos_llvm_hash.py | 13 | ||||
-rwxr-xr-x | llvm_tools/update_chromeos_llvm_hash_unittest.py | 54 |
2 files changed, 52 insertions, 15 deletions
diff --git a/llvm_tools/update_chromeos_llvm_hash.py b/llvm_tools/update_chromeos_llvm_hash.py index 4f55a5db..c44e8e14 100755 --- a/llvm_tools/update_chromeos_llvm_hash.py +++ b/llvm_tools/update_chromeos_llvm_hash.py @@ -378,18 +378,15 @@ def UprevEbuildToVersion(symlink, svn_version): # any other package else: new_ebuild, is_changed = re.subn( - r'pre([0-9]+)', - 'pre%s' % (datetime.today().strftime('%Y%m%d')), - ebuild, - count=1) + r'pre([0-9]+)', 'pre%s' % svn_version, ebuild, count=1) if not is_changed: # failed to increment the revision number raise ValueError('Failed to uprev the ebuild.') - symlink_dirname = os.path.dirname(symlink) + symlink_dir = os.path.dirname(symlink) # Rename the ebuild - cmd = ['git', '-C', symlink_dirname, 'mv', ebuild, new_ebuild] + cmd = ['git', '-C', symlink_dir, 'mv', ebuild, new_ebuild] ExecCommandAndCaptureOutput(cmd, verbose=verbose) # Create a symlink of the renamed ebuild @@ -400,11 +397,11 @@ def UprevEbuildToVersion(symlink, svn_version): if not os.path.islink(new_symlink): raise ValueError('Invalid symlink name: %s' % new_ebuild[:-len('.ebuild')]) - cmd = ['git', '-C', symlink_dirname, 'add', new_symlink] + cmd = ['git', '-C', symlink_dir, 'add', new_symlink] ExecCommandAndCaptureOutput(cmd, verbose=verbose) # Remove the old symlink - cmd = ['git', '-C', symlink_dirname, 'rm', symlink] + cmd = ['git', '-C', symlink_dir, 'rm', symlink] ExecCommandAndCaptureOutput(cmd, verbose=verbose) diff --git a/llvm_tools/update_chromeos_llvm_hash_unittest.py b/llvm_tools/update_chromeos_llvm_hash_unittest.py index a9f1841f..2ea483b6 100755 --- a/llvm_tools/update_chromeos_llvm_hash_unittest.py +++ b/llvm_tools/update_chromeos_llvm_hash_unittest.py @@ -323,19 +323,16 @@ class UpdateLLVMHashTest(unittest.TestCase): mock_islink.assert_called_once_with(symlink_path) - # Simulate 'os.path.islink' when a valid symbolic link is passed in. @mock.patch.object(os.path, 'islink', return_value=True) @mock.patch.object(os.path, 'realpath') - # Simulate 'RunCommandWOutput' when successfully added the upreved symlink - # for commit. @mock.patch.object( update_chromeos_llvm_hash, 'ExecCommandAndCaptureOutput', return_value=None) - def testSuccessfullyUprevEbuildToVersion(self, mock_command_output, - mock_realpath, mock_islink): - symlink = '/symlink/to/llvm/llvm_pre3_p2-r10.ebuild' - ebuild = '/abs/path/to/llvm_pre3_p2.ebuild' + def testSuccessfullyUprevEbuildToVersionLLVM(self, mock_command_output, + mock_realpath, mock_islink): + symlink = '/path/to/llvm/llvm_pre3_p2-r10.ebuild' + ebuild = '/abs/path/to/llvm/llvm_pre3_p2.ebuild' mock_realpath.return_value = ebuild svn_version = 1000 @@ -373,6 +370,49 @@ class UpdateLLVMHashTest(unittest.TestCase): self.assertEqual(mock_command_output.call_args_list[3], mock.call(expected_cmd, verbose=False)) + @mock.patch.object(os.path, 'islink', return_value=True) + @mock.patch.object(os.path, 'realpath') + @mock.patch.object( + update_chromeos_llvm_hash, + 'ExecCommandAndCaptureOutput', + return_value=None) + def testSuccessfullyUprevEbuildToVersionNonLLVM(self, mock_command_output, + mock_realpath, mock_islink): + symlink = '/path/to/compiler-rt/compiler-rt_pre3_p2-r10.ebuild' + ebuild = '/abs/path/to/compiler-rt/compiler-rt_pre3_p2.ebuild' + mock_realpath.return_value = ebuild + svn_version = 1000 + + update_chromeos_llvm_hash.UprevEbuildToVersion(symlink, svn_version) + + mock_islink.assert_called() + + mock_realpath.assert_called_once_with(symlink) + + mock_command_output.assert_called() + + # Verify commands + symlink_dir = os.path.dirname(symlink) + new_ebuild, _is_changed = re.subn( + r'pre([0-9]+)', 'pre%s' % svn_version, ebuild, count=1) + new_symlink = new_ebuild[:-len('.ebuild')] + '-r1.ebuild' + + expected_cmd = ['git', '-C', symlink_dir, 'mv', ebuild, new_ebuild] + self.assertEqual(mock_command_output.call_args_list[0], + mock.call(expected_cmd, verbose=False)) + + expected_cmd = ['ln', '-s', '-r', new_ebuild, new_symlink] + self.assertEqual(mock_command_output.call_args_list[1], + mock.call(expected_cmd, verbose=False)) + + expected_cmd = ['git', '-C', symlink_dir, 'add', new_symlink] + self.assertEqual(mock_command_output.call_args_list[2], + mock.call(expected_cmd, verbose=False)) + + expected_cmd = ['git', '-C', symlink_dir, 'rm', symlink] + self.assertEqual(mock_command_output.call_args_list[3], + mock.call(expected_cmd, verbose=False)) + # Simulate 'os.path.islink' when a valid symbolic link is passed in. @mock.patch.object(os.path, 'islink', return_value=True) # Simulate 'RunCommandWOutput' when successfully added the upreved symlink |