diff options
author | Ryan Beltran <ryanbeltran@chromium.org> | 2021-05-21 17:17:32 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-25 19:53:55 +0000 |
commit | 09e2dac8f0faa19ba223020482253e9d6a508cfe (patch) | |
tree | 5cc6f37fcb214aa090fa42b0a71ea78f36fa5ea3 /llvm_tools | |
parent | a8142b16788dcc0ab5ef03f6d15d15f524715cfa (diff) | |
download | toolchain-utils-09e2dac8f0faa19ba223020482253e9d6a508cfe.tar.gz |
llvm_tools: detect cros checkout for default chroot_path
This CL improves the assumptions made when selecting the default chroot
path in update_chromeos_llvm_hash.py. Previously, it assumed the chrome
source tree was installed to ~/chromiumos which didn't work for people
with multiple chroots or with different naming. Now we detect whether
or not we are inside of the cros source tree and use that cros checkout
if so (otherwise defaulting back to old logic).
BUG=None
TEST=./update_chromeos_llvm_hash.py produced CL:2912507 without
specifiying chroot_path manually
Change-Id: Idb6dfc18a6f7a95c36eba4209dc43e08e373d6e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2912956
Commit-Queue: Ryan Beltran <ryanbeltran@chromium.org>
Tested-by: Ryan Beltran <ryanbeltran@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-x | llvm_tools/update_chromeos_llvm_hash.py | 21 | ||||
-rwxr-xr-x | llvm_tools/update_chromeos_llvm_hash_unittest.py | 13 |
2 files changed, 29 insertions, 5 deletions
diff --git a/llvm_tools/update_chromeos_llvm_hash.py b/llvm_tools/update_chromeos_llvm_hash.py index 8d8030b9..afc63f3c 100755 --- a/llvm_tools/update_chromeos_llvm_hash.py +++ b/llvm_tools/update_chromeos_llvm_hash.py @@ -39,6 +39,21 @@ class LLVMVariant(enum.Enum): verbose = False +def defaultCrosRoot(): + """Get default location of chroot_path. + + The logic assumes that the cros_root is ~/chromiumos, unless llvm_tools is + inside of a CrOS checkout, in which case that checkout should be used. + + Returns: + The best guess location for the cros checkout. + """ + llvm_tools_path = os.path.realpath(os.path.dirname(__file__)) + if llvm_tools_path.endswith('src/third_party/toolchain-utils/llvm_tools'): + return os.path.join(llvm_tools_path, '../../../../') + return '~/chromiumos' + + def GetCommandLineArgs(): """Parses the command line for the optional command line arguments. @@ -49,10 +64,6 @@ def GetCommandLineArgs(): and the LLVM version to use when retrieving the LLVM hash. """ - # Default path to the chroot if a path is not specified. - cros_root = os.path.expanduser('~') - cros_root = os.path.join(cros_root, 'chromiumos') - # Create parser and add optional command-line arguments. parser = argparse.ArgumentParser( description="Updates the build's hash for llvm-next.") @@ -60,7 +71,7 @@ def GetCommandLineArgs(): # Add argument for a specific chroot path. parser.add_argument( '--chroot_path', - default=cros_root, + default=defaultCrosRoot(), help='the path to the chroot (default: %(default)s)') # Add argument for specific builds to uprev and update their llvm-next hash. diff --git a/llvm_tools/update_chromeos_llvm_hash_unittest.py b/llvm_tools/update_chromeos_llvm_hash_unittest.py index 744a1aae..01306ad6 100755 --- a/llvm_tools/update_chromeos_llvm_hash_unittest.py +++ b/llvm_tools/update_chromeos_llvm_hash_unittest.py @@ -31,6 +31,19 @@ import update_chromeos_llvm_hash class UpdateLLVMHashTest(unittest.TestCase): """Test class for updating LLVM hashes of packages.""" + @mock.patch.object(os.path, 'realpath') + def testDefaultCrosRootFromCrOSCheckout(self, mock_llvm_tools): + llvm_tools_path = '/path/to/cros/src/third_party/toolchain-utils/llvm_tools' + mock_llvm_tools.return_value = llvm_tools_path + self.assertEqual(update_chromeos_llvm_hash.defaultCrosRoot(), + '%s/../../../../' % llvm_tools_path) + + @mock.patch.object(os.path, 'realpath') + def testDefaultCrosRootFromOutsideCrOSCheckout(self, mock_llvm_tools): + mock_llvm_tools.return_value = '~/toolchain-utils/llvm_tools' + self.assertEqual(update_chromeos_llvm_hash.defaultCrosRoot(), + '~/chromiumos') + # 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) |