Skip to content

Commit ecc6c76

Browse files
committed
feat: add apt-fast as an installable tool
1 parent 00fe6df commit ecc6c76

File tree

10 files changed

+90
-7
lines changed

10 files changed

+90
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
3131
| --------------- | ----------------------------------------------------------------------------------------------------------- |
3232
| compiler | llvm, gcc, msvc, apple-clang, vcvarsall |
3333
| build system | cmake, ninja, meson, make, task, bazel |
34-
| package manager | vcpkg, conan, choco, brew, nala, git, setup-cpp |
34+
| package manager | vcpkg, conan, choco, brew, apt-fast, nala, git, setup-cpp |
3535
| analyzer/linter | clang-tidy, clang-format, cppcheck, cpplint, flawfinder, lizard, infer, cmakelang, cmake-format, cmake-lint |
3636
| cache | ccache, sccache |
3737
| documentation | doxygen, graphviz |

dev/docker/ci/ubuntu.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ COPY "./dist/modern" "/usr/lib/setup-cpp/"
2323

2424
# install the cpp tools
2525
RUN node --enable-source-maps /usr/lib/setup-cpp/setup-cpp.mjs \
26+
--apt-fast true \
2627
--cmake true \
2728
--ninja true \
2829
--task true \

dist/legacy/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/legacy/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.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.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.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { execRootSync } from "admina"
2+
import { hasAptGet } from "../../utils/env/hasAptGet.js"
3+
import { testBin } from "../../utils/tests/test-helpers.js"
4+
import { setupAptFast } from "../apt-fast.js"
5+
6+
jest.setTimeout(300000)
7+
describe("setup-apt-fast", () => {
8+
if (!hasAptGet()) {
9+
test.skip("should setup apt-fast", () => {})
10+
return
11+
}
12+
it("should setup apt-fast", async () => {
13+
const installInfo = await setupAptFast("", "", process.arch)
14+
await testBin("apt-fast", ["--version"], installInfo?.binDir)
15+
})
16+
17+
afterAll(() => {
18+
// remove apt-fast to run the rest of the tests with apt-get
19+
execRootSync("apt-get", ["remove", "-y", "apt-fast"])
20+
})
21+
})

src/apt-fast/apt-fast.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { tmpdir } from "os"
2+
import { dirname, join } from "path"
3+
import { execRootSync } from "admina"
4+
import { error } from "ci-log"
5+
import { readFile, writeFile } from "fs/promises"
6+
import { DownloaderHelper } from "node-downloader-helper"
7+
import which from "which"
8+
import { hasAptGet } from "../utils/env/hasAptGet.js"
9+
10+
let binDir: string | undefined
11+
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
export async function setupAptFast(_version: string, _setupDir: string, _arch: string) {
14+
if (!hasAptGet()) {
15+
return undefined
16+
}
17+
if (typeof binDir === "string") {
18+
return { binDir }
19+
}
20+
21+
const maybeBinDir = which.sync("apt-fast", { nothrow: true })
22+
if (maybeBinDir !== null) {
23+
binDir = dirname(maybeBinDir)
24+
return { binDir }
25+
}
26+
27+
binDir = "/usr/bin" // eslint-disable-line require-atomic-updates
28+
29+
// Install via the installer script
30+
await setupAptFastViaInstaller()
31+
32+
return { binDir }
33+
}
34+
35+
async function setupAptFastViaInstaller() {
36+
const installer = new DownloaderHelper(
37+
"https://git.io/vokNn",
38+
tmpdir(),
39+
{ fileName: "install-apt-fast.sh" },
40+
)
41+
installer.on("error", (err) => {
42+
throw new Error(`Failed to download install-apt-fast.sh: ${err}`)
43+
})
44+
await installer.start()
45+
46+
const installerPath = join(tmpdir(), "install-apt-fast.sh")
47+
48+
// Patch the installer script to not use sudo explicitly
49+
const script = await readFile(installerPath, "utf8")
50+
await writeFile(installerPath, script.replace(/sudo/g, ""))
51+
52+
try {
53+
execRootSync("bash", [installerPath])
54+
} catch (err) {
55+
error(`Failed to install apt-fast via installer: ${err}`)
56+
execRootSync("apt", ["install", "-y", "-t", "apt-fast", "apt-fast"])
57+
}
58+
}

src/setup-cpp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ All the available tools:
126126
"build system": {
127127
tools: "--cmake, --ninja, --meson, --make, --task, --bazel",
128128
},
129-
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala, --git, --setup-cpp" },
129+
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --apt-fast, --nala, --git, --setup-cpp" },
130130
"analyzer/linter": {
131131
tools:
132132
"--clang-tidy, --clang-format, --cppcheck, --cpplint, --flawfinder, --lizard, --infer, , --cmakelang, --cmake-lint, --cmake-format",

src/tool.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { setupBrew } from "setup-brew"
2+
import { setupAptFast } from "./apt-fast/apt-fast.js"
23
import { setupBazel } from "./bazel/bazel.js"
34
import { setupCcache } from "./ccache/ccache.js"
45
import { setupChocolatey } from "./chocolatey/chocolatey.js"
@@ -61,8 +62,10 @@ export const llvmTools = ["llvm", "clang", "clang++", "clang-tidy", "clang-forma
6162

6263
/** The setup functions */
6364
export const setups = {
64-
git: setupGit,
65+
"apt-fast": setupAptFast,
66+
aptfast: setupAptFast,
6567
nala: setupNala,
68+
git: setupGit,
6669
brew: setupBrew,
6770
choco: setupChocolatey,
6871
python: setupPython,

0 commit comments

Comments
 (0)