Skip to content

Commit 44b1c5d

Browse files
committed
stop using get_staging_dir in main
1 parent 83b76c6 commit 44b1c5d

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

backends/qualcomm/scripts/download_qnn_sdk.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def is_linux_x86() -> bool:
4444
APP_NAMESPACE = ["executorch", "qnn"]
4545

4646

47-
def get_staging_dir(*parts: str) -> pathlib.Path:
47+
def _get_staging_dir(*parts: str) -> pathlib.Path:
4848
"""
4949
Return a cross-platform staging directory for staging SDKs/libraries.
5050
@@ -237,17 +237,18 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
237237
####################
238238

239239
GLIBC_VERSION = "2.34"
240-
GLIBC_ROOT = get_staging_dir(f"glibc-{GLIBC_VERSION}")
241-
GLIBC_LIBDIR = GLIBC_ROOT / "lib"
242240
GLIBC_REEXEC_GUARD = "QNN_GLIBC_REEXEC"
243241
MINIMUM_LIBC_VERSION = GLIBC_VERSION
244242

245243
RPM_URL = (
246244
"https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/35/"
247245
"Everything/x86_64/os/Packages/g/glibc-2.34-7.fc35.x86_64.rpm"
248246
)
249-
RPM_PATH = get_staging_dir("glibc") / "glibc.rpm"
250-
WORKDIR = get_staging_dir("glibc") / "extracted"
247+
248+
249+
def _get_glibc_libdir() -> pathlib.Path:
250+
glibc_root = _get_staging_dir(f"glibc-{GLIBC_VERSION}")
251+
return glibc_root / "lib"
251252

252253

253254
def _parse_version(v: str) -> tuple[int, int]:
@@ -270,8 +271,8 @@ def _current_glibc_version() -> str:
270271
def _resolve_glibc_loader() -> pathlib.Path | None:
271272
"""Return staged ld.so path if available."""
272273
for p in [
273-
GLIBC_LIBDIR / f"ld-{GLIBC_VERSION}.so",
274-
GLIBC_LIBDIR / "ld-linux-x86-64.so.2",
274+
_get_glibc_libdir() / f"ld-{GLIBC_VERSION}.so",
275+
_get_glibc_libdir() / "ld-linux-x86-64.so.2",
275276
]:
276277
if p.exists():
277278
return p
@@ -281,16 +282,18 @@ def _resolve_glibc_loader() -> pathlib.Path | None:
281282
def _stage_prebuilt_glibc():
282283
"""Download + extract Fedora 35 glibc RPM into /tmp."""
283284
logger.info(">>> Staging prebuilt glibc-%s from Fedora 35 RPM", GLIBC_VERSION)
284-
GLIBC_LIBDIR.mkdir(parents=True, exist_ok=True)
285+
_get_glibc_libdir().mkdir(parents=True, exist_ok=True)
286+
rpm_path = _get_staging_dir("glibc") / "glibc.rpm"
287+
work_dir = _get_staging_dir("glibc") / "extracted"
285288

286289
# Download
287-
subprocess.check_call(["curl", "-fsSL", RPM_URL, "-o", str(RPM_PATH)])
290+
subprocess.check_call(["curl", "-fsSL", RPM_URL, "-o", str(rpm_path)])
288291

289292
# Extract
290-
if WORKDIR.exists():
291-
shutil.rmtree(WORKDIR)
292-
WORKDIR.mkdir(parents=True)
293-
subprocess.check_call(["bsdtar", "-C", str(WORKDIR), "-xf", str(RPM_PATH)])
293+
if work_dir.exists():
294+
shutil.rmtree(work_dir)
295+
work_dir.mkdir(parents=True)
296+
subprocess.check_call(["bsdtar", "-C", str(work_dir), "-xf", str(rpm_path)])
294297

295298
# Copy runtime libs
296299
staged = [
@@ -303,9 +306,9 @@ def _stage_prebuilt_glibc():
303306
"libutil.so.1",
304307
]
305308
for lib in staged:
306-
src = WORKDIR / "lib64" / lib
309+
src = work_dir / "lib64" / lib
307310
if src.exists():
308-
shutil.copy2(src, GLIBC_LIBDIR / lib)
311+
shutil.copy2(src, _get_glibc_libdir() / lib)
309312
logger.info("[glibc] Staged %s", lib)
310313
else:
311314
logger.warning("[glibc] Missing %s in RPM", lib)
@@ -332,21 +335,22 @@ def ensure_glibc_minimum(min_version: str = GLIBC_VERSION):
332335
return
333336

334337
# Stage prebuilt if not already staged
335-
if not (GLIBC_LIBDIR / "libc.so.6").exists():
338+
if not (_get_glibc_libdir() / "libc.so.6").exists():
336339
_stage_prebuilt_glibc()
337340

338341
loader = _resolve_glibc_loader()
339342
if not loader:
340-
logger.error("[glibc] Loader not found in %s", GLIBC_LIBDIR)
343+
logger.error("[glibc] Loader not found in %s", _get_glibc_libdir())
341344
return
342345

343346
logger.info(
344-
"[glibc] Re-execing under loader %s with libdir %s", loader, GLIBC_LIBDIR
347+
"[glibc] Re-execing under loader %s with libdir %s", loader, _get_glibc_libdir()
345348
)
346349
os.environ[GLIBC_REEXEC_GUARD] = "1"
347350
os.execv(
348351
str(loader),
349-
[str(loader), "--library-path", str(GLIBC_LIBDIR), sys.executable] + sys.argv,
352+
[str(loader), "--library-path", str(_get_glibc_libdir()), sys.executable]
353+
+ sys.argv,
350354
)
351355

352356

@@ -371,7 +375,7 @@ def _stage_libcxx(target_dir: pathlib.Path):
371375
logger.info("[libcxx] Already staged at %s, skipping download", target_dir)
372376
return
373377

374-
libcxx_stage = get_staging_dir(f"libcxx-{LLVM_VERSION}")
378+
libcxx_stage = _get_staging_dir(f"libcxx-{LLVM_VERSION}")
375379
temp_tar = libcxx_stage / f"{LIBCXX_BASE_NAME}.tar.xz"
376380
temp_extract = libcxx_stage / LIBCXX_BASE_NAME
377381

0 commit comments

Comments
 (0)