Skip to content

Commit daaa4d9

Browse files
r-barnesmeta-codesync[bot]
authored andcommitted
fbcode_builder: skip 'sudo' in install-system-deps when unavailable
Summary: Containers that don't ship sudo (e.g. the manylinux CI image) run as root, so prepending 'sudo' to dnf/apt-get just fails with "command not found". Probe shutil.which("sudo") and only prepend when it's on PATH; also drop --preserve-env=http_proxy in the no-sudo path since that flag is sudo-specific. Reviewed By: bigfootjon Differential Revision: D104428968 fbshipit-source-id: 1684a3bf6ffa4e13e045619d0ac48e4f244cfe63
1 parent 5b17449 commit daaa4d9

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

build/fbcode_builder/getdeps.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,23 @@ def run_project_cmd(self, args, loader, manifest):
445445
all_packages[k] = merged
446446

447447
cmd_argss = []
448+
# Containers (e.g. manylinux) run as root and don't ship sudo. Only
449+
# prepend "sudo" if it's actually on PATH; otherwise invoke the
450+
# package manager directly.
451+
sudo_cmd = ["sudo"] if shutil.which("sudo") else []
448452
if manager == "rpm":
449453
packages = sorted(set(all_packages["rpm"]))
450454
if packages:
451455
cmd_argss.append(
452-
["sudo", "dnf", "install", "-y", "--skip-broken"] + packages
456+
sudo_cmd + ["dnf", "install", "-y", "--skip-broken"] + packages
453457
)
454458
elif manager == "deb":
455459
packages = sorted(set(all_packages["deb"]))
456460
if packages:
457461
cmd_argss.append(
458-
[
459-
"sudo",
460-
"--preserve-env=http_proxy",
462+
sudo_cmd
463+
+ (["--preserve-env=http_proxy"] if sudo_cmd else [])
464+
+ [
461465
"apt-get",
462466
"install",
463467
"-y",

0 commit comments

Comments
 (0)