diff options
author | George Burgess IV <gbiv@google.com> | 2020-04-25 15:04:21 -0700 |
---|---|---|
committer | George Burgess <gbiv@chromium.org> | 2020-04-28 19:02:01 +0000 |
commit | b999ceb903e3f163818e045d8710d6fe487157e0 (patch) | |
tree | d9cd1c4b1746c6f22f57bc6822fe4c4b6df6b762 /llvm_tools/git_llvm_rev_test.py | |
parent | 738a6668fc6caebfa6003d81f525d25feea4d5a7 (diff) | |
download | toolchain-utils-b999ceb903e3f163818e045d8710d6fe487157e0.tar.gz |
llvm_tools: make an llvm_project module for tests
I'd like to reuse these functions in an upcoming revert checker. This
refactors them into their own module, so we don't have tests relying on
tests.
BUG=chromium:1046988
TEST=unittests
Change-Id: I8766f03b3ee8b0cf5b0c128df0d0531aee5c0339
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2165512
Reviewed-by: Luis Lozano <llozano@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'llvm_tools/git_llvm_rev_test.py')
-rwxr-xr-x | llvm_tools/git_llvm_rev_test.py | 54 |
1 files changed, 4 insertions, 50 deletions
diff --git a/llvm_tools/git_llvm_rev_test.py b/llvm_tools/git_llvm_rev_test.py index c7d59b27..1e38f589 100755 --- a/llvm_tools/git_llvm_rev_test.py +++ b/llvm_tools/git_llvm_rev_test.py @@ -8,61 +8,15 @@ from __future__ import print_function -import datetime -import os -import subprocess -import sys import unittest -import get_llvm_hash import git_llvm_rev - - -def get_llvm_checkout() -> str: - my_dir = os.path.dirname(os.path.abspath(__file__)) - return os.path.join(my_dir, 'llvm-project-copy') - - -def ensure_llvm_project_up_to_date(): - checkout = get_llvm_checkout() - if not os.path.isdir(checkout): - print( - 'No llvm-project exists locally; syncing it. This takes a while.', - file=sys.stderr) - actual_checkout = get_llvm_hash.GetAndUpdateLLVMProjectInLLVMTools() - assert checkout == actual_checkout, '%s != %s' % (actual_checkout, checkout) - - commit_timestamp = git_llvm_rev.check_output( - ['git', 'log', '-n1', '--format=%ct', 'origin/master'], cwd=checkout) - - commit_time = datetime.datetime.fromtimestamp(int(commit_timestamp.strip())) - now = datetime.datetime.now() - - time_since_last_commit = now - commit_time - - # Arbitrary, but if it's been more than 2d since we've seen a commit, it's - # probably best to bring us up-to-date. - if time_since_last_commit <= datetime.timedelta(days=2): - return - - print( - '%d days have elapsed since the last commit to %s; auto-syncing' % - (time_since_last_commit.days, checkout), - file=sys.stderr) - - result = subprocess.run( - ['git', 'fetch', 'origin'], - cwd=checkout, - check=True, - ) - if result.returncode: - print( - 'Sync failed somehow; hoping that things are fresh enough, then...', - file=sys.stderr) +import llvm_project def get_llvm_config() -> git_llvm_rev.LLVMConfig: - return git_llvm_rev.LLVMConfig(dir=get_llvm_checkout(), remote='origin') + return git_llvm_rev.LLVMConfig( + dir=llvm_project.get_location(), remote='origin') class Test(unittest.TestCase): @@ -172,5 +126,5 @@ class Test(unittest.TestCase): # back to the base commit for. if __name__ == '__main__': - ensure_llvm_project_up_to_date() + llvm_project.ensure_up_to_date() unittest.main() |