Skip to content

Commit 18f813f

Browse files
committed
fix: make execaSudo and setupAptPack synchronous
apt is not thread-safe
1 parent 9ce1b85 commit 18f813f

File tree

13 files changed

+42
-42
lines changed

13 files changed

+42
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ ENTRYPOINT [ "/bin/bash" ]
199199
FROM base AS builder
200200
ADD ./dev/cpp_vcpkg_project /home/app
201201
WORKDIR /home/app
202-
RUN bash -c 'source ~/.cpprc \
202+
RUN bash -c 'source ~/.cpprc \
203203
&& make build'
204204

205205
### Running environment

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/doxygen/doxygen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
4848
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
4949
} catch (err) {
5050
info(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
51-
installationInfo = await setupAptPack("doxygen", undefined)
51+
installationInfo = setupAptPack("doxygen", undefined)
5252
}
5353
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
5454
return installationInfo

src/gcc/gcc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
3737
}
3838
case "linux": {
3939
if (arch === "x64") {
40-
await setupAptPack("gcc", version, [
40+
setupAptPack("gcc", version, [
4141
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
4242
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
4343
"ppa:ubuntu-toolchain-r/test",
4444
])
45-
binDir = (await setupAptPack("g++", version, [])).binDir
45+
binDir = setupAptPack("g++", version, []).binDir
4646
} else {
4747
info(`Install g++-multilib because gcc for ${arch} was requested`)
48-
await setupAptPack("gcc-multilib", version, [
48+
setupAptPack("gcc-multilib", version, [
4949
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
5050
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
5151
"ppa:ubuntu-toolchain-r/test",
5252
])
53-
binDir = (await setupAptPack("g++-multilib", version, [])).binDir
53+
binDir = setupAptPack("g++-multilib", version, []).binDir
5454
}
5555
break
5656
}

src/kcov/kcov.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ async function buildKcov(file: string, dest: string) {
4242
await setupCmake(getVersion("cmake", undefined), join(untildify(""), "cmake"), "")
4343
}
4444
if (process.platform === "linux") {
45-
await setupAptPack("libdw-dev")
46-
await setupAptPack("libcurl4-openssl-dev")
45+
setupAptPack("libdw-dev")
46+
setupAptPack("libcurl4-openssl-dev")
4747
}
4848
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out, stdio: "inherit" })
4949
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out, stdio: "inherit" })
50-
await execSudo("cmake", ["--install", "./build"], out)
50+
execSudo("cmake", ["--install", "./build"], out)
5151
return out
5252
}
5353

5454
export async function setupKcov(version: string, setupDir: string, arch: string) {
5555
switch (process.platform) {
5656
case "linux": {
5757
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
58-
await setupAptPack("libbinutils")
58+
setupAptPack("libbinutils")
5959
return installationInfo
6060
}
6161
default: {

src/llvm/llvm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ async function _setupLLVM(version: string, setupDir: string, arch: string) {
268268
if (process.platform === "linux") {
269269
// install llvm build dependencies
270270
await setupGcc(getVersion("gcc", undefined), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
271-
await setupAptPack("libtinfo-dev")
271+
setupAptPack("libtinfo-dev")
272272
}
273273
// eslint-disable-next-line require-atomic-updates
274274
didInit = true

src/python/python.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function setupPython(version: string, setupDir: string, arch: strin
2121
}
2222

2323
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24-
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
24+
export function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
2525
switch (process.platform) {
2626
case "win32": {
2727
if (setupDir) {
@@ -39,8 +39,8 @@ export async function setupPythonViaSystem(version: string, setupDir: string, _a
3939
return setupBrewPack("python3", version)
4040
}
4141
case "linux": {
42-
const installInfo = await setupAptPack("python3", version)
43-
await setupAptPack("python3-pip")
42+
const installInfo = setupAptPack("python3", version)
43+
setupAptPack("python3-pip")
4444
return installInfo
4545
}
4646
default: {

src/utils/exec/sudo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { isRoot } from "../env/sudo"
33

44
export function execSudo(file: string, args: string[], cwd?: string) {
55
if (isRoot()) {
6-
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
6+
return execa.commandSync(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
77
shell: true,
88
cwd,
99
stdio: "inherit",
1010
})
1111
} else {
12-
return execa(file, args, { stdio: "inherit" })
12+
return execa.sync(file, args, { stdio: "inherit" })
1313
}
1414
}

src/utils/setup/setupAptPack.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ let didUpdate: boolean = false
1111
let didInit: boolean = false
1212

1313
/** A function that installs a package using apt */
14-
export async function setupAptPack(
14+
export function setupAptPack(
1515
name: string,
1616
version?: string,
1717
repositories: boolean | string[] = true
18-
): Promise<InstallationInfo> {
18+
): InstallationInfo {
1919
info(`Installing ${name} ${version ?? ""} via apt`)
2020

2121
const apt = "apt-get"
2222

2323
process.env.DEBIAN_FRONTEND = "noninteractive"
2424

2525
if (!didUpdate) {
26-
await execSudo(apt, ["update", "-y"])
26+
execSudo(apt, ["update", "-y"])
2727
didUpdate = true
2828
}
2929

@@ -32,7 +32,7 @@ export async function setupAptPack(
3232
// set time - zone
3333
// TZ = Canada / Pacific
3434
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
35-
await execSudo(apt, [
35+
execSudo(apt, [
3636
"install",
3737
"--fix-broken",
3838
"-y",
@@ -42,9 +42,9 @@ export async function setupAptPack(
4242
"gnupg",
4343
])
4444
try {
45-
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "3B4FE6ACC0B21F32"])
46-
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "40976EAF437D05B5"])
47-
await execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "1E9377A2BA9EF27F"])
45+
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "3B4FE6ACC0B21F32"])
46+
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "40976EAF437D05B5"])
47+
execSudo("apt-key", ["adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "1E9377A2BA9EF27F"])
4848
} catch (err) {
4949
warning(`Failed to add keys: ${err}`)
5050
}
@@ -54,19 +54,19 @@ export async function setupAptPack(
5454
if (Array.isArray(repositories)) {
5555
for (const repo of repositories) {
5656
// eslint-disable-next-line no-await-in-loop
57-
await execSudo("add-apt-repository", ["--update", "-y", repo])
57+
execSudo("add-apt-repository", ["--update", "-y", repo])
5858
}
59-
await execSudo(apt, ["update", "-y"])
59+
execSudo(apt, ["update", "-y"])
6060
}
6161

6262
if (version !== undefined && version !== "") {
6363
try {
64-
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
64+
execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
6565
} catch {
66-
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
66+
execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
6767
}
6868
} else {
69-
await execSudo(apt, ["install", "--fix-broken", "-y", name])
69+
execSudo(apt, ["install", "--fix-broken", "-y", name])
7070
}
7171

7272
return { binDir: "/usr/bin/" }

0 commit comments

Comments
 (0)