mirror of https://github.com/aminya/setup-cpp
feat: support only installing clang-format on Ubuntu
This commit is contained in:
parent
4ca8d58635
commit
734bc14554
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
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
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
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
|
@ -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"
|
||||
|
@ -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)
|
||||
|
|
|
@ -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> {
|
||||
|
@ -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}`)
|
||||
|
|
|
@ -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"], {
|
||||
await execRoot(
|
||||
"bash",
|
||||
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
|
||||
{
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
timeout: DEFAULT_TIMEOUT,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await addPath(`${installationFolder}/bin`)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -48,7 +48,7 @@ export const setups = {
|
|||
graphviz: setupGraphviz,
|
||||
cppcheck: setupCppcheck,
|
||||
clangtidy: setupClangTools,
|
||||
clangformat: setupClangTools,
|
||||
clangformat: setupClangFormat,
|
||||
msvc: setupMSVC,
|
||||
vcvarsall: setupVCVarsall,
|
||||
kcov: setupKcov,
|
||||
|
|
Loading…
Reference in New Issue