Skip to content

Commit

Permalink
feat: support only installing clang-format on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 11, 2023
1 parent 4ca8d58 commit 734bc14
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 99 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions dist/actions/cache-dependencies.a31532a6.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/actions/cache-dependencies.a31532a6.js.map

This file was deleted.

6 changes: 6 additions & 0 deletions dist/actions/cache-dependencies.cb06b881.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/actions/cache-dependencies.cb06b881.js.map

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/legacy/cache-dependencies.087b1350.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/legacy/cache-dependencies.087b1350.js.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions dist/legacy/cache-dependencies.348a592e.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/legacy/cache-dependencies.348a592e.js.map

This file was deleted.

32 changes: 15 additions & 17 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/modern/cache-dependencies.0e86bfa1.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/cache-dependencies.0e86bfa1.js.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions dist/modern/cache-dependencies.e0061047.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/modern/cache-dependencies.e0061047.js.map

This file was deleted.

32 changes: 15 additions & 17 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/llvm/__tests__/llvm.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupLLVM, setupClangTools } from "../llvm"
import { setupLLVM, setupClangTools, setupClangFormat } from "../llvm"
import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { isUrlOnline } from "is-url-online"
import { setupTmpDir, testBin } from "../../utils/tests/test-helpers"
Expand Down Expand Up @@ -98,7 +98,13 @@ describe("setup-llvm", () => {
execaSync(main_exe, { cwd: __dirname, stdio: "inherit" })
})

it("should setup clang-tidy and clang-format", async () => {
it("should setup clang-format", async () => {
const osVersion = await ubuntuVersion()
const { binDir } = await setupClangFormat(getVersion("llvm", "true", osVersion), directory, process.arch)
await testBin("clang-format", ["--version"], binDir)
})

it("should setup clang tools", async () => {
const osVersion = await ubuntuVersion()
const { binDir } = await setupClangTools(getVersion("llvm", "true", osVersion), directory, process.arch)
await testBin("clang-tidy", ["--version"], binDir)
Expand Down
22 changes: 18 additions & 4 deletions src/llvm/llvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack
import { InstallationInfo, setupBin } from "../utils/setup/setupBin"
import { semverCoerceIfInvalid } from "../utils/setup/version"
import { getVersion } from "../versions/versions"
import { setupLLVMApt } from "./llvm_installer"
import { LLVMPackages, setupLLVMApt } from "./llvm_installer"
import { getLLVMPackageInfo } from "./llvm_url"

export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
Expand All @@ -34,17 +34,31 @@ async function setupLLVMWithoutActivation_raw(version: string, setupDir: string,
}
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_raw, { isPromise: true })

/** Setup llvm tools (clang tidy, clang format, etc) without activating llvm and using it as the compiler */
/**
* Setup clang-format
*
* This uses the LLVM installer on Ubuntu, and the LLVM binaries on other platforms
*/
export function setupClangFormat(version: string, setupDir: string, arch: string) {
return setupLLVMOnly(version, setupDir, arch, LLVMPackages.ClangFormat)
}

/** Setup llvm tools (clang tidy, etc.) without activating llvm and using it as the compiler */
export function setupClangTools(version: string, setupDir: string, arch: string) {
return setupLLVMOnly(version, setupDir, arch)
}

async function setupLLVMOnly(version: string, setupDir: string, arch: string) {
async function setupLLVMOnly(
version: string,
setupDir: string,
arch: string,
packages: LLVMPackages = LLVMPackages.All,
) {
const coeredVersion = semverCoerceIfInvalid(version)
const majorVersion = parseInt(coeredVersion.split(".")[0], 10)
try {
if (isUbuntu()) {
return await setupLLVMApt(majorVersion)
return await setupLLVMApt(majorVersion, packages)
}
} catch (err) {
info(`Failed to install llvm via system package manager ${err}`)
Expand Down
37 changes: 29 additions & 8 deletions src/llvm/llvm_installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,33 @@ import { info } from "console"
import { DEFAULT_TIMEOUT } from "../installTool"
const { readFile, writeFile, chmod } = promises

export async function setupLLVMApt(majorVersion: number): Promise<InstallationInfo> {
export enum LLVMPackages {
All,
ClangFormat,
Core,
}

export async function setupLLVMApt(
majorVersion: number,
packages: LLVMPackages = LLVMPackages.All,
): Promise<InstallationInfo> {
// TODO for older versions, this also includes the minor version
const installationFolder = `/usr/lib/llvm-${majorVersion}`

await setupAptPack([{ name: "curl" }])
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh")
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh", packages)
await setupAptPack(neededPackages)
await chmod("/tmp/llvm-setup-cpp.sh", "755")
await execRoot("bash", ["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, "all"], {
stdio: "inherit",
shell: true,
timeout: DEFAULT_TIMEOUT,
})
await execRoot(
"bash",
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
{
stdio: "inherit",
shell: true,
timeout: DEFAULT_TIMEOUT,
},
)

await addPath(`${installationFolder}/bin`)

Expand All @@ -32,13 +45,14 @@ export async function setupLLVMApt(majorVersion: number): Promise<InstallationIn
}
}

async function patchAptLLVMScript(path: string, target_path: string) {
async function patchAptLLVMScript(path: string, target_path: string, packages: LLVMPackages) {
let script = await readFile(path, "utf-8")

script = debugScript(script)
script = nonInteractiveScript(script)
script = await removeConflictingPAckages(script)
script = useNalaScript(script)
script = choosePackages(packages, script)

await writeFile(target_path, script)

Expand Down Expand Up @@ -90,3 +104,10 @@ function useNalaScript(script: string) {
}
return script
}

function choosePackages(packages: LLVMPackages, script: string) {
if (packages === LLVMPackages.ClangFormat) {
return script.replace(/ -y \$PKG/g, " -y clang-format")
}
return script
}
4 changes: 2 additions & 2 deletions src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { setupGcc } from "./gcc/gcc"
import { setupGcovr } from "./gcovr/gcovr"
import { setupGraphviz } from "./graphviz/graphviz"
import { setupKcov } from "./kcov/kcov"
import { setupClangTools, setupLLVM } from "./llvm/llvm"
import { setupClangTools, setupLLVM, setupClangFormat } from "./llvm/llvm"
import { setupMake } from "./make/make"
import { setupMeson } from "./meson/meson"
import { setupMSVC } from "./msvc/msvc"
Expand Down Expand Up @@ -48,7 +48,7 @@ export const setups = {
graphviz: setupGraphviz,
cppcheck: setupCppcheck,
clangtidy: setupClangTools,
clangformat: setupClangTools,
clangformat: setupClangFormat,
msvc: setupMSVC,
vcvarsall: setupVCVarsall,
kcov: setupKcov,
Expand Down

0 comments on commit 734bc14

Please sign in to comment.