Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out: Calculate cache path based on workspace path hash #38

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions out
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
#
# Where:
# _bazel_user is a folder where "user" is the username
# 7e6ad621f3f951c3ee6f5b179289b54e is the most recent folder
# 7e6ad621f3f951c3ee6f5b179289b54e is the MD5 hash of the path name of workspace root
# (as described in https://bazel.build/remote/output-directories#layout)
#
# Then print out the path

import os
import sys
import re
import argparse
import hashlib
from pathlib import Path

PROJECT_DIR = Path(__file__).parent.resolve()


def find_path():
Expand All @@ -22,19 +27,14 @@ def find_path():
print("Path does not exist: " + path)
sys.exit(1)

dirs = os.listdir(path)
dirs.sort(key=lambda x: os.path.getmtime(os.path.join(path, x)), reverse=True)
dirs.reverse()

for d in dirs:
if not re.match(r'[a-z0-9]{32}', d):
continue
hash = hashlib.new("md5")
hash.update(str(PROJECT_DIR).encode())
d = hash.hexdigest()
if re.match(r'[a-z0-9]{32}', d):
path2 = os.path.join(path, d,
"execroot/_main/bazel-out/k8-fastbuild/bin")
if not os.path.exists(path2):
continue

return path2
if os.path.exists(path2):
return path2

print("Could not find path")
sys.exit(1)
Expand All @@ -45,7 +45,9 @@ def recurse(path):
files.sort(key=lambda x: os.lstat(os.path.join(path, x)).st_mtime, reverse=True)
for f in files:
if os.path.isdir(os.path.join(path, f)):
return recurse(os.path.join(path, f))
result = recurse(os.path.join(path, f))
if result is not None:
return result
elif f.endswith(".log"):
return os.path.join(path, f)
return None
Expand Down
Loading