fix: install the packages needed for the llvm installer

This commit is contained in:
Amin Yahyaabadi 2023-07-17 11:01:22 -07:00
parent f1d59251fb
commit e7304e1143
8 changed files with 101 additions and 65 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -61,7 +61,8 @@ async function setupLLVMApt(majorVersion: number): Promise<InstallationInfo> {
await setupAptPack([{ name: "curl" }]) await setupAptPack([{ name: "curl" }])
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" }) await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh") const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh")
await setupAptPack(neededPackages)
await chmod("/tmp/llvm-setup-cpp.sh", "755") await chmod("/tmp/llvm-setup-cpp.sh", "755")
await execRoot("bash", ["/tmp/llvm-setup-cpp.sh"], { await execRoot("bash", ["/tmp/llvm-setup-cpp.sh"], {
stdio: "inherit", stdio: "inherit",
@ -90,6 +91,9 @@ async function patchAptLLVMScript(path: string, target_path: string) {
script = script.replace(/apt-get/g, "nala") script = script.replace(/apt-get/g, "nala")
} }
await writeFile(target_path, script) await writeFile(target_path, script)
// the packages needed by the script
return [{ name: "lsb-release" }, { name: "wget" }, { name: "software-properties-common" }, { name: "gnupg" }]
} }
async function llvmBinaryDeps_raw(majorVersion: number) { async function llvmBinaryDeps_raw(majorVersion: number) {

View File

@ -57,7 +57,14 @@ export async function setupAptPack(packages: AptPackage[], update = false): Prom
return { binDir: "/usr/bin/" } return { binDir: "/usr/bin/" }
} }
async function getAptArg(name: string, version: string | undefined) { export enum AptPackageType {
NameDashVersion,
NameEqualsVersion,
Name,
None,
}
export async function aptPackageType(name: string, version: string | undefined): Promise<AptPackageType> {
if (version !== undefined && version !== "") { if (version !== undefined && version !== "") {
const { stdout } = await execa("apt-cache", [ const { stdout } = await execa("apt-cache", [
"search", "search",
@ -65,21 +72,46 @@ async function getAptArg(name: string, version: string | undefined) {
`^${escapeRegex(name)}-${escapeRegex(version)}$`, `^${escapeRegex(name)}-${escapeRegex(version)}$`,
]) ])
if (stdout.trim() !== "") { if (stdout.trim() !== "") {
return `${name}-${version}` return AptPackageType.NameDashVersion
} else { }
try {
// check if apt-get show can find the version try {
const { stdout: showStdout } = await execa("apt-cache", ["show", `${name}=${version}`]) // check if apt-get show can find the version
if (showStdout.trim() === "") { // eslint-disable-next-line @typescript-eslint/no-shadow
return `${name}=${version}` const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`])
} if (stdout.trim() === "") {
} catch { return AptPackageType.NameEqualsVersion
// ignore
} }
warning(`Failed to install ${name} ${version} via apt, trying without version`) } catch {
// ignore
} }
} }
return name
try {
const { stdout: showStdout } = await execa("apt-cache", ["show", name])
if (showStdout.trim() !== "") {
return AptPackageType.Name
}
} catch {
// ignore
}
return AptPackageType.None
}
async function getAptArg(name: string, version: string | undefined) {
const package_type = await aptPackageType(name, version)
switch (package_type) {
case AptPackageType.NameDashVersion:
return `${name}-${version}`
case AptPackageType.NameEqualsVersion:
return `${name}=${version}`
case AptPackageType.Name:
return name
case AptPackageType.None:
default:
throw new Error(`Could not find package ${name} ${version ?? ""}`)
}
} }
export function hasNala() { export function hasNala() {