Skip to content

Commit 57dd50f

Browse files
committed
Allow the download cache dir to be customized.
1 parent bdd45ed commit 57dd50f

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Android/android.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,20 @@ def make_build_python(context):
205205
#
206206
# If you're a member of the Python core team, and you'd like to be able to push
207207
# these tags yourself, please contact Malcolm Smith or Russell Keith-Magee.
208-
def unpack_deps(host, prefix_dir):
208+
def unpack_deps(host, prefix_dir, cache_dir):
209209
os.chdir(prefix_dir)
210210
deps_url = "https://github.com/beeware/cpython-android-source-deps/releases/download"
211211
for name_ver in ["bzip2-1.0.8-3", "libffi-3.4.4-3", "openssl-3.5.5-0",
212212
"sqlite-3.50.4-0", "xz-5.4.6-1", "zstd-1.5.7-1"]:
213213
filename = f"{name_ver}-{host}.tar.gz"
214-
download(f"{deps_url}/{name_ver}/{filename}")
214+
download(f"{deps_url}/{name_ver}/{filename}", cache_dir)
215215
shutil.unpack_archive(filename)
216216
os.remove(filename)
217217

218218

219-
def download(url, target_dir="."):
220-
out_path = f"{target_dir}/{basename(url)}"
221-
run(["curl", "-Lf", "--retry", "5", "--retry-all-errors", "-o", out_path, url])
219+
def download(url, cache_dir):
220+
out_path = cache_dir / basename(url)
221+
run(["curl", "-Lf", "--retry", "5", "--retry-all-errors", "-o", str(out_path), url])
222222
return out_path
223223

224224

@@ -230,7 +230,8 @@ def configure_host_python(context):
230230
prefix_dir = host_dir / "prefix"
231231
if not prefix_dir.exists():
232232
prefix_dir.mkdir()
233-
unpack_deps(context.host, prefix_dir)
233+
cache_dir = context.cache_dir or CROSS_BUILD_DIR / "downloads"
234+
unpack_deps(context.host, prefix_dir, cache_dir)
234235

235236
os.chdir(host_dir)
236237
command = [
@@ -890,6 +891,15 @@ def add_parser(*args, **kwargs):
890891
env = add_parser("env", help="Print environment variables")
891892

892893
# Common arguments
894+
# --cache-dir option
895+
for cmd in [configure_host, build, ci]:
896+
cmd.add_argument(
897+
"--cache-dir",
898+
default=os.environ.get("CACHE_DIR"),
899+
help="The directory to store cached downloads.",
900+
)
901+
902+
# --clean option
893903
for subcommand in [build, configure_build, configure_host, ci]:
894904
subcommand.add_argument(
895905
"--clean", action="store_true", default=False, dest="clean",

0 commit comments

Comments
 (0)