Skip to content

Commit

Permalink
out: Calculate cache path based on workspace path hash
Browse files Browse the repository at this point in the history
Signed-off-by: Eryk Szpotanski <[email protected]>
  • Loading branch information
eszpotanski authored and oharboe committed Apr 15, 2024
1 parent 96801c6 commit 51326a2
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit 51326a2

Please sign in to comment.