mirror of https://github.com/aminya/setup-cpp
Merge pull request #201 from aminya/clang-format [skip ci]
This commit is contained in:
commit
9e5af3bc58
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 { getSpecificVersionAndUrl } from "../../utils/setup/version"
|
||||||
import { isUrlOnline } from "is-url-online"
|
import { isUrlOnline } from "is-url-online"
|
||||||
import { setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
|
@ -98,7 +98,13 @@ describe("setup-llvm", () => {
|
||||||
execaSync(main_exe, { cwd: __dirname, stdio: "inherit" })
|
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 osVersion = await ubuntuVersion()
|
||||||
const { binDir } = await setupClangTools(getVersion("llvm", "true", osVersion), directory, process.arch)
|
const { binDir } = await setupClangTools(getVersion("llvm", "true", osVersion), directory, process.arch)
|
||||||
await testBin("clang-tidy", ["--version"], binDir)
|
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 { InstallationInfo, setupBin } from "../utils/setup/setupBin"
|
||||||
import { semverCoerceIfInvalid } from "../utils/setup/version"
|
import { semverCoerceIfInvalid } from "../utils/setup/version"
|
||||||
import { getVersion } from "../versions/versions"
|
import { getVersion } from "../versions/versions"
|
||||||
import { setupLLVMApt } from "./llvm_installer"
|
import { LLVMPackages, setupLLVMApt } from "./llvm_installer"
|
||||||
import { getLLVMPackageInfo } from "./llvm_url"
|
import { getLLVMPackageInfo } from "./llvm_url"
|
||||||
|
|
||||||
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
|
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 })
|
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) {
|
export function setupClangTools(version: string, setupDir: string, arch: string) {
|
||||||
return setupLLVMOnly(version, setupDir, arch)
|
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 coeredVersion = semverCoerceIfInvalid(version)
|
||||||
const majorVersion = parseInt(coeredVersion.split(".")[0], 10)
|
const majorVersion = parseInt(coeredVersion.split(".")[0], 10)
|
||||||
try {
|
try {
|
||||||
if (isUbuntu()) {
|
if (isUbuntu()) {
|
||||||
return await setupLLVMApt(majorVersion)
|
return await setupLLVMApt(majorVersion, packages)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
info(`Failed to install llvm via system package manager ${err}`)
|
info(`Failed to install llvm via system package manager ${err}`)
|
||||||
|
|
|
@ -8,20 +8,33 @@ import { info } from "console"
|
||||||
import { DEFAULT_TIMEOUT } from "../installTool"
|
import { DEFAULT_TIMEOUT } from "../installTool"
|
||||||
const { readFile, writeFile, chmod } = promises
|
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
|
// TODO for older versions, this also includes the minor version
|
||||||
const installationFolder = `/usr/lib/llvm-${majorVersion}`
|
const installationFolder = `/usr/lib/llvm-${majorVersion}`
|
||||||
|
|
||||||
await setupAptPack([{ name: "curl" }])
|
await setupAptPack([{ name: "curl" }])
|
||||||
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
|
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 setupAptPack(neededPackages)
|
||||||
await chmod("/tmp/llvm-setup-cpp.sh", "755")
|
await chmod("/tmp/llvm-setup-cpp.sh", "755")
|
||||||
await execRoot("bash", ["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, "all"], {
|
await execRoot(
|
||||||
stdio: "inherit",
|
"bash",
|
||||||
shell: true,
|
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
|
||||||
timeout: DEFAULT_TIMEOUT,
|
{
|
||||||
})
|
stdio: "inherit",
|
||||||
|
shell: true,
|
||||||
|
timeout: DEFAULT_TIMEOUT,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
await addPath(`${installationFolder}/bin`)
|
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")
|
let script = await readFile(path, "utf-8")
|
||||||
|
|
||||||
script = debugScript(script)
|
script = debugScript(script)
|
||||||
script = nonInteractiveScript(script)
|
script = nonInteractiveScript(script)
|
||||||
script = await removeConflictingPAckages(script)
|
script = await removeConflictingPAckages(script)
|
||||||
script = useNalaScript(script)
|
script = useNalaScript(script)
|
||||||
|
script = choosePackages(packages, script)
|
||||||
|
|
||||||
await writeFile(target_path, script)
|
await writeFile(target_path, script)
|
||||||
|
|
||||||
|
@ -90,3 +104,10 @@ function useNalaScript(script: string) {
|
||||||
}
|
}
|
||||||
return script
|
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 { setupGcovr } from "./gcovr/gcovr"
|
||||||
import { setupGraphviz } from "./graphviz/graphviz"
|
import { setupGraphviz } from "./graphviz/graphviz"
|
||||||
import { setupKcov } from "./kcov/kcov"
|
import { setupKcov } from "./kcov/kcov"
|
||||||
import { setupClangTools, setupLLVM } from "./llvm/llvm"
|
import { setupClangTools, setupLLVM, setupClangFormat } from "./llvm/llvm"
|
||||||
import { setupMake } from "./make/make"
|
import { setupMake } from "./make/make"
|
||||||
import { setupMeson } from "./meson/meson"
|
import { setupMeson } from "./meson/meson"
|
||||||
import { setupMSVC } from "./msvc/msvc"
|
import { setupMSVC } from "./msvc/msvc"
|
||||||
|
@ -48,7 +48,7 @@ export const setups = {
|
||||||
graphviz: setupGraphviz,
|
graphviz: setupGraphviz,
|
||||||
cppcheck: setupCppcheck,
|
cppcheck: setupCppcheck,
|
||||||
clangtidy: setupClangTools,
|
clangtidy: setupClangTools,
|
||||||
clangformat: setupClangTools,
|
clangformat: setupClangFormat,
|
||||||
msvc: setupMSVC,
|
msvc: setupMSVC,
|
||||||
vcvarsall: setupVCVarsall,
|
vcvarsall: setupVCVarsall,
|
||||||
kcov: setupKcov,
|
kcov: setupKcov,
|
||||||
|
|
Loading…
Reference in New Issue