mirror of https://github.com/aminya/setup-cpp
fix: make execaSudo and setupAptPack synchronous
apt is not thread-safe
This commit is contained in:
parent
9ce1b85f0d
commit
18f813f0d6
|
@ -199,7 +199,7 @@ ENTRYPOINT [ "/bin/bash" ]
|
|||
FROM base AS builder
|
||||
ADD ./dev/cpp_vcpkg_project /home/app
|
||||
WORKDIR /home/app
|
||||
RUN bash -c 'source ~/.cpprc \
|
||||
RUN bash -c 'source ~/.cpprc \
|
||||
&& make build'
|
||||
|
||||
### Running environment
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -48,7 +48,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
|
||||
} catch (err) {
|
||||
info(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
|
||||
installationInfo = await setupAptPack("doxygen", undefined)
|
||||
installationInfo = setupAptPack("doxygen", undefined)
|
||||
}
|
||||
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
|
||||
return installationInfo
|
||||
|
|
|
@ -37,20 +37,20 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
|
|||
}
|
||||
case "linux": {
|
||||
if (arch === "x64") {
|
||||
await setupAptPack("gcc", version, [
|
||||
setupAptPack("gcc", version, [
|
||||
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
|
||||
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
|
||||
"ppa:ubuntu-toolchain-r/test",
|
||||
])
|
||||
binDir = (await setupAptPack("g++", version, [])).binDir
|
||||
binDir = setupAptPack("g++", version, []).binDir
|
||||
} else {
|
||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||
await setupAptPack("gcc-multilib", version, [
|
||||
setupAptPack("gcc-multilib", version, [
|
||||
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
|
||||
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
|
||||
"ppa:ubuntu-toolchain-r/test",
|
||||
])
|
||||
binDir = (await setupAptPack("g++-multilib", version, [])).binDir
|
||||
binDir = setupAptPack("g++-multilib", version, []).binDir
|
||||
}
|
||||
break
|
||||
}
|
||||
|
|
|
@ -42,12 +42,12 @@ async function buildKcov(file: string, dest: string) {
|
|||
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
await setupAptPack("libdw-dev")
|
||||
await setupAptPack("libcurl4-openssl-dev")
|
||||
setupAptPack("libdw-dev")
|
||||
setupAptPack("libcurl4-openssl-dev")
|
||||
}
|
||||
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
|
||||
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
|
||||
await execSudo("cmake", ["--install", "./build"], out)
|
||||
execSudo("cmake", ["--install", "./build"], out)
|
||||
return out
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ export async function setupKcov(version: string, setupDir: string, arch: string)
|
|||
switch (process.platform) {
|
||||
case "linux": {
|
||||
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
|
||||
await setupAptPack("libbinutils")
|
||||
setupAptPack("libbinutils")
|
||||
return installationInfo
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -268,7 +268,7 @@ async function _setupLLVM(version: string, setupDir: string, arch: string) {
|
|||
if (process.platform === "linux") {
|
||||
// install llvm build dependencies
|
||||
await setupGcc(getVersion("gcc", undefined), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
|
||||
await setupAptPack("libtinfo-dev")
|
||||
setupAptPack("libtinfo-dev")
|
||||
}
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
didInit = true
|
||||
|
|
|
@ -21,7 +21,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
|
|||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
|
||||
export function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
if (setupDir) {
|
||||
|
@ -39,8 +39,8 @@ export async function setupPythonViaSystem(version: string, setupDir: string, _a
|
|||
return setupBrewPack("python3", version)
|
||||
}
|
||||
case "linux": {
|
||||
const installInfo = await setupAptPack("python3", version)
|
||||
await setupAptPack("python3-pip")
|
||||
const installInfo = setupAptPack("python3", version)
|
||||
setupAptPack("python3-pip")
|
||||
return installInfo
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -3,12 +3,12 @@ import { isRoot } from "../env/sudo"
|
|||
|
||||
export function execSudo(file: string, args: string[], cwd?: string) {
|
||||
if (isRoot()) {
|
||||
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
|
||||
return execa.commandSync(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
|
||||
shell: true,
|
||||
cwd,
|
||||
stdio: "inherit",
|
||||
})
|
||||
} else {
|
||||
return execa(file, args, { stdio: "inherit" })
|
||||
return execa.sync(file, args, { stdio: "inherit" })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ let didUpdate: boolean = false
|
|||
let didInit: boolean = false
|
||||
|
||||
/** A function that installs a package using apt */
|
||||
export async function setupAptPack(
|
||||
export function setupAptPack(
|
||||
name: string,
|
||||
version?: string,
|
||||
repositories: boolean | string[] = true
|
||||
): Promise<InstallationInfo> {
|
||||
): InstallationInfo {
|
||||
info(`Installing ${name} ${version ?? ""} via apt`)
|
||||
|
||||
const apt = "apt-get"
|
||||
|
@ -23,7 +23,7 @@ export async function setupAptPack(
|
|||
process.env.DEBIAN_FRONTEND = "noninteractive"
|
||||
|
||||
if (!didUpdate) {
|
||||
await execSudo(apt, ["update", "-y"])
|
||||
execSudo(apt, ["update", "-y"])
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ export async function setupAptPack(
|
|||
// set time - zone
|
||||
// TZ = Canada / Pacific
|
||||
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
|
||||
await execSudo(apt, [
|
||||
execSudo(apt, [
|
||||
"install",
|
||||
"--fix-broken",
|
||||
"-y",
|
||||
|
@ -42,9 +42,9 @@ export async function setupAptPack(
|
|||
"gnupg",
|
||||
])
|
||||
try {
|
||||
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "3B4FE6ACC0B21F32"])
|
||||
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "40976EAF437D05B5"])
|
||||
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "1E9377A2BA9EF27F"])
|
||||
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "3B4FE6ACC0B21F32"])
|
||||
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "40976EAF437D05B5"])
|
||||
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "1E9377A2BA9EF27F"])
|
||||
} catch (err) {
|
||||
warning(`Failed to add keys: ${err}`)
|
||||
}
|
||||
|
@ -54,19 +54,19 @@ export async function setupAptPack(
|
|||
if (Array.isArray(repositories)) {
|
||||
for (const repo of repositories) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await execSudo("add-apt-repository", ["--update", "-y", repo])
|
||||
execSudo("add-apt-repository", ["--update", "-y", repo])
|
||||
}
|
||||
await execSudo(apt, ["update", "-y"])
|
||||
execSudo(apt, ["update", "-y"])
|
||||
}
|
||||
|
||||
if (version !== undefined && version !== "") {
|
||||
try {
|
||||
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
|
||||
execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
|
||||
} catch {
|
||||
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
|
||||
execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
|
||||
}
|
||||
} else {
|
||||
await execSudo(apt, ["install", "--fix-broken", "-y", name])
|
||||
execSudo(apt, ["install", "--fix-broken", "-y", name])
|
||||
}
|
||||
|
||||
return { binDir: "/usr/bin/" }
|
||||
|
|
|
@ -88,9 +88,9 @@ export async function setupBin(
|
|||
if (!didInit) {
|
||||
if (process.platform === "linux") {
|
||||
// extraction dependencies
|
||||
await setupAptPack("unzip")
|
||||
await setupAptPack("tar")
|
||||
await setupAptPack("xz-utils")
|
||||
setupAptPack("unzip")
|
||||
setupAptPack("tar")
|
||||
setupAptPack("xz-utils")
|
||||
}
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
didInit = true
|
||||
|
|
|
@ -42,7 +42,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
|
|||
execa.sync(python, ["-m", "pip", "install", "-U", "pip==21.3.1"], { stdio: "inherit" })
|
||||
} else if (process.platform === "linux") {
|
||||
// ensure that pip is installed on Linux (happens when python is found but pip not installed)
|
||||
await setupAptPack("python3-pip")
|
||||
setupAptPack("python3-pip")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ import { InstallationInfo } from "../utils/setup/setupBin"
|
|||
let hasVCPKG = false
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupVcpkg(_version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
|
||||
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
|
||||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||
if (process.platform === "linux") {
|
||||
// vcpkg download and extraction dependencies
|
||||
await setupAptPack("curl")
|
||||
await setupAptPack("zip")
|
||||
await setupAptPack("unzip")
|
||||
await setupAptPack("tar")
|
||||
await setupAptPack("git")
|
||||
await setupAptPack("pkg-config")
|
||||
setupAptPack("curl")
|
||||
setupAptPack("zip")
|
||||
setupAptPack("unzip")
|
||||
setupAptPack("tar")
|
||||
setupAptPack("git")
|
||||
setupAptPack("pkg-config")
|
||||
}
|
||||
|
||||
if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
|
||||
|
@ -38,7 +38,7 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
|
|||
isRoot() &&
|
||||
process.env.SUDO_USER !== undefined
|
||||
) {
|
||||
await execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
|
||||
execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
|
||||
}
|
||||
|
||||
addPath(setupDir)
|
||||
|
|
Loading…
Reference in New Issue