Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 674a5bb

Browse filesBrowse files
committed
Bazel installer: Retry ripunzip step.
Ripunzip is great, but occasionally bugs out due to a parallelism issue. As we don't want this to fail CI, retry the entire ripunzip/installation step up to 3 times. We need to clean up the working directory as ripunzip doesn't support overwriting files. I've not been able to test this with the original issue (it doesn't seem to reproduce locally for me), but I injected another error and got 3 retries of installation.
1 parent 31f68d2 commit 674a5bb
Copy full SHA for 674a5bb

File tree

Expand file treeCollapse file tree

1 file changed

+68
-30
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+68
-30
lines changed

‎misc/bazel/internal/install.py

Copy file name to clipboardExpand all lines: misc/bazel/internal/install.py
+68-30Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,41 @@
1313
import subprocess
1414
import platform
1515
import time
16+
import sys
1617
from python.runfiles import runfiles
1718

1819
runfiles = runfiles.Create()
1920
assert runfiles, "Installer should be run with `bazel run`"
2021

2122
parser = argparse.ArgumentParser(description=__doc__)
22-
parser.add_argument("--destdir", type=pathlib.Path, required=True,
23-
help="Desination directory, relative to `--build-file`")
24-
parser.add_argument("--pkg-install-script", required=True,
25-
help="The wrapped `pkg_install` installation script rlocation")
26-
parser.add_argument("--build-file",
27-
help="BUILD.bazel rlocation relative to which the installation should take place")
28-
parser.add_argument("--ripunzip",
29-
help="ripunzip executable rlocation. Must be provided if `--zip-manifest` is.")
30-
parser.add_argument("--zip-manifest",
31-
help="The rlocation of a file containing newline-separated `prefix:zip_file` entries")
32-
parser.add_argument("--cleanup", action=argparse.BooleanOptionalAction, default=True,
33-
help="Whether to wipe the destination directory before installing (true by default)")
23+
parser.add_argument(
24+
"--destdir",
25+
type=pathlib.Path,
26+
required=True,
27+
help="Desination directory, relative to `--build-file`",
28+
)
29+
parser.add_argument(
30+
"--pkg-install-script",
31+
required=True,
32+
help="The wrapped `pkg_install` installation script rlocation",
33+
)
34+
parser.add_argument(
35+
"--build-file",
36+
help="BUILD.bazel rlocation relative to which the installation should take place",
37+
)
38+
parser.add_argument(
39+
"--ripunzip", help="ripunzip executable rlocation. Must be provided if `--zip-manifest` is."
40+
)
41+
parser.add_argument(
42+
"--zip-manifest",
43+
help="The rlocation of a file containing newline-separated `prefix:zip_file` entries",
44+
)
45+
parser.add_argument(
46+
"--cleanup",
47+
action=argparse.BooleanOptionalAction,
48+
default=True,
49+
help="Whether to wipe the destination directory before installing (true by default)",
50+
)
3451
opts = parser.parse_args()
3552
if opts.zip_manifest and not opts.ripunzip:
3653
parser.error("Provide `--ripunzip` when specifying `--zip-manifest`")
@@ -45,35 +62,56 @@
4562

4663
_WIN_FILE_IN_USE_ERROR_CODE = 32
4764

48-
if destdir.exists() and opts.cleanup:
49-
if platform.system() == 'Windows':
65+
66+
def rmdir(dir: pathlib.Path):
67+
if platform.system() == "Windows":
5068
# On Windows we might have virus scanner still looking at the path so
5169
# attempt removal a couple of times sleeping between each attempt.
5270
for retry_delay in [1, 2, 2]:
5371
try:
54-
shutil.rmtree(destdir)
72+
shutil.rmtree(dir)
5573
break
5674
except OSError as e:
5775
if e.winerror == _WIN_FILE_IN_USE_ERROR_CODE:
5876
time.sleep(retry_delay)
5977
else:
6078
raise
6179
else:
62-
shutil.rmtree(destdir)
80+
shutil.rmtree(dir)
6381
else:
64-
shutil.rmtree(destdir)
82+
shutil.rmtree(dir)
83+
84+
85+
if destdir.exists() and opts.cleanup:
86+
rmdir(destdir)
87+
88+
class RetryException(Exception):
89+
pass
90+
91+
attempts = 0
92+
success = False
93+
while attempts < 3 and success is False:
94+
destdir.mkdir(parents=True, exist_ok=True)
95+
subprocess.run([script, "--destdir", destdir], check=True)
6596

66-
destdir.mkdir(parents=True, exist_ok=True)
67-
subprocess.run([script, "--destdir", destdir], check=True)
97+
if opts.zip_manifest:
98+
ripunzip = runfiles.Rlocation(opts.ripunzip)
99+
zip_manifest = runfiles.Rlocation(opts.zip_manifest)
100+
with open(zip_manifest) as manifest:
101+
for line in manifest:
102+
prefix, _, zip = line.partition(":")
103+
assert zip, f"missing prefix for {prefix}, you should use prefix:zip format"
104+
zip = zip.strip()
105+
dest = destdir / prefix
106+
dest.mkdir(parents=True, exist_ok=True)
107+
command = [ripunzip, "unzip-file", zip, "-d", dest]
108+
print(f"Running ", *command)
109+
ret = subprocess.run(command)
110+
success = ret.returncode == 0
111+
if not success:
112+
print(f"Failed to unzip {zip} to {dest}, retrying installation...")
113+
attempts += 1
114+
rmdir(destdir)
115+
break
68116

69-
if opts.zip_manifest:
70-
ripunzip = runfiles.Rlocation(opts.ripunzip)
71-
zip_manifest = runfiles.Rlocation(opts.zip_manifest)
72-
with open(zip_manifest) as manifest:
73-
for line in manifest:
74-
prefix, _, zip = line.partition(":")
75-
assert zip, f"missing prefix for {prefix}, you should use prefix:zip format"
76-
zip = zip.strip()
77-
dest = destdir / prefix
78-
dest.mkdir(parents=True, exist_ok=True)
79-
subprocess.run([ripunzip, "unzip-file", zip, "-d", dest], check=True)
117+
sys.exit(ret.returncode)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.