Skip to content

Commit 2443ae4

Browse files
committed
use persistent cache path
1 parent 89d8237 commit 2443ae4

File tree

1 file changed

+56
-5
lines changed

1 file changed

+56
-5
lines changed

backends/qualcomm/scripts/download_qnn_sdk.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,56 @@ def is_linux_x86() -> bool:
3737
)
3838

3939

40+
#########################
41+
# Cache directory helper
42+
#########################
43+
44+
APP_NAMESPACE = ["executorch", "qnn"]
45+
46+
47+
def get_staging_dir(*parts: str) -> pathlib.Path:
48+
"""
49+
Return a cross-platform staging directory for staging SDKs/libraries.
50+
51+
- On Linux:
52+
~/.cache/executorch/qnn/<parts...>
53+
(falls back to $HOME/.cache if $XDG_CACHE_HOME is unset)
54+
55+
- On Windows:
56+
%LOCALAPPDATA%\executorch\qnn\<parts...>
57+
(falls back to $HOME/AppData/Local if %LOCALAPPDATA% is unset)
58+
59+
- Override:
60+
If QNN_STAGING_DIR is set in the environment, that path is used instead.
61+
62+
Args:
63+
parts (str): Subdirectories to append under the root staging dir.
64+
65+
Returns:
66+
pathlib.Path: Fully qualified staging path.
67+
"""
68+
# Environment override wins
69+
base = os.environ.get("QNN_STAGING_DIR")
70+
if base:
71+
return pathlib.Path(base).joinpath(*parts)
72+
73+
system = platform.system().lower()
74+
if system == "windows":
75+
# On Windows, prefer %LOCALAPPDATA%, fallback to ~/AppData/Local
76+
base = pathlib.Path(
77+
os.environ.get("LOCALAPPDATA", pathlib.Path.home() / "AppData" / "Local")
78+
)
79+
elif is_linux_x86():
80+
# On Linux/Unix, prefer $XDG_CACHE_HOME, fallback to ~/.cache
81+
base = pathlib.Path(
82+
os.environ.get("XDG_CACHE_HOME", pathlib.Path.home() / ".cache")
83+
)
84+
else:
85+
raise ValueError(f"Unsupported platform: {system}")
86+
87+
return base.joinpath(*APP_NAMESPACE, *parts)
88+
89+
4090
####################
4191
# qnn sdk download management
4292
####################
@@ -187,7 +237,7 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
187237
####################
188238

189239
GLIBC_VERSION = "2.34"
190-
GLIBC_ROOT = pathlib.Path(f"/tmp/glibc-install-{GLIBC_VERSION}")
240+
GLIBC_ROOT = get_staging_dir(f"glibc-{GLIBC_VERSION}")
191241
GLIBC_LIBDIR = GLIBC_ROOT / "lib"
192242
GLIBC_REEXEC_GUARD = "QNN_GLIBC_REEXEC"
193243
MINIMUM_LIBC_VERSION = GLIBC_VERSION
@@ -196,8 +246,8 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
196246
"https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/35/"
197247
"Everything/x86_64/os/Packages/g/glibc-2.34-7.fc35.x86_64.rpm"
198248
)
199-
RPM_PATH = pathlib.Path("/tmp/glibc.rpm")
200-
WORKDIR = pathlib.Path("/tmp/glibc-extracted")
249+
RPM_PATH = get_staging_dir("glibc") / "glibc.rpm"
250+
WORKDIR = get_staging_dir("glibc") / "extracted"
201251

202252

203253
def _parse_version(v: str) -> tuple[int, int]:
@@ -321,8 +371,9 @@ def _stage_libcxx(target_dir: pathlib.Path):
321371
logger.info("[libcxx] Already staged at %s, skipping download", target_dir)
322372
return
323373

324-
temp_tar = pathlib.Path("/tmp") / f"{LIBCXX_BASE_NAME}.tar.xz"
325-
temp_extract = pathlib.Path("/tmp") / LIBCXX_BASE_NAME
374+
libcxx_stage = get_staging_dir(f"libcxx-{LLVM_VERSION}")
375+
temp_tar = libcxx_stage / f"{LIBCXX_BASE_NAME}.tar.xz"
376+
temp_extract = libcxx_stage / LIBCXX_BASE_NAME
326377

327378
if not temp_tar.exists():
328379
logger.info("[libcxx] Downloading %s", LLVM_URL)

0 commit comments

Comments
 (0)