Merge pull request #188 from aminya/llvm [skip ci]

This commit is contained in:
Amin Yahyaabadi 2023-08-21 22:09:42 -07:00 committed by GitHub
commit c99df211c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 222 additions and 143 deletions

View File

@ -84,6 +84,10 @@ inputs:
powershell:
description: "The powershell version to install."
required: false
timeout:
description: "The timeout for installation of one tool (in minutes)."
default: "20"
required: false
runs:
using: "node16"

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

View File

@ -112,6 +112,7 @@
"npm-check-updates": "^16.10.17",
"npm-run-all2": "^6.0.6",
"numerous": "1.0.3",
"p-timeout": "^6.1.2",
"parcel": "2.9.3",
"path-exists": "^5.0.0",
"patha": "^0.4.1",

View File

@ -134,6 +134,9 @@ importers:
numerous:
specifier: 1.0.3
version: 1.0.3
p-timeout:
specifier: ^6.1.2
version: 6.1.2
parcel:
specifier: 2.9.3
version: 2.9.3
@ -8780,6 +8783,11 @@ packages:
aggregate-error: 3.1.0
dev: true
/p-timeout@6.1.2:
resolution: {integrity: sha512-UbD77BuZ9Bc9aABo74gfXhNvzC9Tx7SxtHSh1fxvx3jTLLYvmVhiQZZrJzqqU0jKbN32kb5VOKiLEQI/3bIjgQ==}
engines: {node: '>=14.16'}
dev: true
/p-try@2.2.0:
resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==}
engines: {node: '>=6'}

View File

@ -1,7 +1,7 @@
import { syncVersions, getVersion } from "../versions/versions"
import { parseArgs } from "../cli-options"
import { Inputs } from "../tool"
import { getCompilerInfo } from "../compilers"
import { Inputs } from "../tool"
jest.setTimeout(300000)
describe("getCompilerInfo", () => {

View File

@ -6,7 +6,7 @@ import { Inputs, inputs } from "./tool"
export function parseArgs(args: string[]): Opts {
return mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
string: inputs,
string: [...inputs, "timeout"],
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
alias: { h: "help" },
boolean: "help",
@ -21,9 +21,9 @@ setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
Install all the tools required for building and testing C++/C projects.
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
--timeout\t the timeout for the installation of each tool in minutes. By default it is 10 minutes.
--compiler\t the <compiler> to install.
\t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-13.0.0'
--$tool_name\t pass "true" or pass the <version> you would like to install for this tool. e.g. --conan true or --conan "1.42.1"
All the available tools:
@ -54,6 +54,7 @@ export function maybeGetInput(key: string) {
export type Opts = mri.Argv<
Record<Inputs, string | undefined> & {
help: boolean
timeout?: string
}
>

68
src/installTool.ts Normal file
View File

@ -0,0 +1,68 @@
import { endGroup, startGroup } from "@actions/core"
import { error } from "ci-log"
import { join } from "patha"
import { getSuccessMessage } from "./cli-options"
import { InstallationInfo } from "./utils/setup/setupBin"
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
import { getVersion } from "./versions/versions"
import pTimeout from "p-timeout"
import { ToolName, setups } from "./tool"
export const DEFAULT_TIMEOUT = 20 * 60 * 1000 // 20 minutes
export async function installTool(
tool: ToolName,
version: string,
osVersion: number[] | null,
arch: string,
setupCppDir: string,
successMessages: string[],
errorMessages: string[],
timeout: number = DEFAULT_TIMEOUT,
) {
startGroup(`Installing ${tool} ${version}`)
let hasLLVM = false
try {
hasLLVM = await pTimeout(installToolImpl(tool, version, osVersion, arch, hasLLVM, setupCppDir, successMessages), {
milliseconds: timeout,
message: `Timeout while installing ${tool} ${version}. You can increase the timeout from options`,
})
} catch (e) {
// push error message to the logger
error(e as string | Error)
errorMessages.push(`${tool} failed to install`)
}
endGroup()
return hasLLVM
}
async function installToolImpl(
tool: ToolName,
version: string,
osVersion: number[] | null,
arch: string,
hasLLVM: boolean,
setupCppDir: string,
successMessages: string[],
) {
let installationInfo: InstallationInfo | undefined | void
if (tool === "vcvarsall") {
// eslint-disable-next-line no-await-in-loop
await setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
} else {
// get the setup function
const setupFunction = setups[tool]
// eslint-disable-next-line no-param-reassign
hasLLVM = ["llvm", "clangformat", "clangtidy"].includes(tool)
// the tool installation directory (for the functions that ue it)
const setupDir = join(setupCppDir, hasLLVM ? "llvm" : tool)
// eslint-disable-next-line no-await-in-loop
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
}
// preparing a report string
successMessages.push(getSuccessMessage(tool, installationInfo))
return hasLLVM
}

View File

@ -35,7 +35,9 @@ 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 */
export const setupClangTools = setupLLVMWithoutActivation
export function setupClangTools(version: string, setupDir: string, arch: string) {
return setupLLVMOnly(version, setupDir, arch)
}
async function setupLLVMOnly(version: string, setupDir: string, arch: string) {
const coeredVersion = semverCoerceIfInvalid(version)

View File

@ -5,6 +5,7 @@ import { hasNala, isPackageInstalled, setupAptPack } from "../utils/setup/setupA
import { InstallationInfo } from "../utils/setup/setupBin"
import { promises } from "fs"
import { info } from "console"
import { DEFAULT_TIMEOUT } from "../installTool"
const { readFile, writeFile, chmod } = promises
export async function setupLLVMApt(majorVersion: number): Promise<InstallationInfo> {
@ -19,6 +20,7 @@ export async function setupLLVMApt(majorVersion: number): Promise<InstallationIn
await execRoot("bash", ["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, "all"], {
stdio: "inherit",
shell: true,
timeout: DEFAULT_TIMEOUT,
})
await addPath(`${installationFolder}/bin`)
@ -33,6 +35,7 @@ export async function setupLLVMApt(majorVersion: number): Promise<InstallationIn
async function patchAptLLVMScript(path: string, target_path: string) {
let script = await readFile(path, "utf-8")
script = debugScript(script)
script = nonInteractiveScript(script)
script = await removeConflictingPAckages(script)
script = useNalaScript(script)
@ -42,9 +45,17 @@ async function patchAptLLVMScript(path: string, target_path: string) {
// the packages needed by the script
return [{ name: "lsb-release" }, { name: "wget" }, { name: "software-properties-common" }, { name: "gnupg" }]
}
function nonInteractiveScript(givenScript: string) {
function debugScript(script: string) {
if (!process.env.NODE_DEBUG) {
return script.replace(/set -eux/g, "set -eu")
}
return script
}
function nonInteractiveScript(script: string) {
// make the scirpt non-interactive and fix broken packages
return givenScript.replace(
return script.replace(
/add-apt-repository "\${REPO_NAME}"/g,
// eslint-disable-next-line no-template-curly-in-string
'add-apt-repository -y "${REPO_NAME}"',

View File

@ -1,7 +1,7 @@
#!/usr/bin/env node
/* eslint-disable node/shebang */
import { GITHUB_ACTIONS } from "ci-info"
import { GITHUB_ACTIONS, isCI } from "ci-info"
import { error, info, success, warning } from "ci-log"
import * as numerous from "numerous"
import numerousLocale from "numerous/locales/en.js"
@ -11,12 +11,13 @@ import { untildifyUser } from "untildify-user"
import { checkUpdates } from "./check-updates"
import { parseArgs, printHelp } from "./cli-options"
import { installCompiler } from "./compilers"
import { installTool, tools } from "./tool"
import { finalizeCpprc } from "./utils/env/addEnv"
import { isArch } from "./utils/env/isArch"
import { ubuntuVersion } from "./utils/env/ubuntu_version"
import { setupPacmanPack } from "./utils/setup/setupPacmanPack"
import { syncVersions } from "./versions/versions"
import { installTool } from "./installTool"
import { tools } from "./tool"
/** The main entry function */
async function main(args: string[]): Promise<number> {
@ -69,7 +70,17 @@ async function main(args: string[]): Promise<number> {
let hasLLVM = false
// loop over the tools and run their setup function
let failedFast = false
for (const tool of tools) {
// fail fast inside CI when any tool fails
if (isCI) {
if (errorMessages.length !== 0) {
failedFast = true
break
}
}
// get the version or "true" or undefined for this tool from the options
const version = opts[tool]
@ -78,19 +89,30 @@ async function main(args: string[]): Promise<number> {
// running the setup function for this tool
time1 = Date.now()
// eslint-disable-next-line no-await-in-loop
hasLLVM = await installTool(tool, version, osVersion, arch, setupCppDir, successMessages, errorMessages)
hasLLVM = await installTool(
tool,
version,
osVersion,
arch,
setupCppDir,
successMessages,
errorMessages,
parseFloat(opts.timeout ?? "20") * 60 * 1000,
)
time2 = Date.now()
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
}
}
// installing the specified compiler
const maybeCompiler = opts.compiler
if (maybeCompiler !== undefined) {
const time1Compiler = Date.now()
await installCompiler(maybeCompiler, osVersion, setupCppDir, arch, successMessages, hasLLVM, errorMessages)
const time2Compiler = Date.now()
info(`took ${timeFormatter.format(time1Compiler, time2Compiler) || "0 seconds"}`)
if (!failedFast) {
// installing the specified compiler
const maybeCompiler = opts.compiler
if (maybeCompiler !== undefined) {
const time1Compiler = Date.now()
await installCompiler(maybeCompiler, osVersion, setupCppDir, arch, successMessages, hasLLVM, errorMessages)
const time2Compiler = Date.now()
info(`took ${timeFormatter.format(time1Compiler, time2Compiler) || "0 seconds"}`)
}
}
await finalizeCpprc()

View File

@ -1,11 +1,7 @@
import { endGroup, startGroup } from "@actions/core"
import { error } from "ci-log"
import { join } from "patha"
import { setupBazel } from "./bazel/bazel"
import { setupBrew } from "./brew/brew"
import { setupCcache } from "./ccache/ccache"
import { setupChocolatey } from "./chocolatey/chocolatey"
import { getSuccessMessage } from "./cli-options"
import { setupCmake } from "./cmake/cmake"
import { setupConan } from "./conan/conan"
import { setupCppcheck } from "./cppcheck/cppcheck"
@ -26,50 +22,10 @@ import { setupPython } from "./python/python"
import { setupSccache } from "./sccache/sccache"
import { setupSevenZip } from "./sevenzip/sevenzip"
import { setupTask } from "./task/task"
import { InstallationInfo } from "./utils/setup/setupBin"
import { setupVcpkg } from "./vcpkg/vcpkg"
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
import { getVersion } from "./versions/versions"
export async function installTool(
tool: ToolName,
version: string,
osVersion: number[] | null,
arch: string,
setupCppDir: string,
successMessages: string[],
errorMessages: string[],
) {
startGroup(`Installing ${tool} ${version}`)
let hasLLVM = false
try {
let installationInfo: InstallationInfo | undefined | void
if (tool === "vcvarsall") {
// eslint-disable-next-line no-await-in-loop
await setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
} else {
// get the setup function
const setupFunction = setups[tool]
hasLLVM = ["llvm", "clangformat", "clangtidy"].includes(tool)
// the tool installation directory (for the functions that ue it)
const setupDir = join(setupCppDir, hasLLVM ? "llvm" : tool)
// eslint-disable-next-line no-await-in-loop
installationInfo = await setupFunction(getVersion(tool, version, osVersion), setupDir, arch)
}
// preparing a report string
successMessages.push(getSuccessMessage(tool, installationInfo))
} catch (e) {
// push error message to the logger
error(e as string | Error)
errorMessages.push(`${tool} failed to install`)
}
endGroup()
return hasLLVM
} /** The setup functions */
/** The setup functions */
export const setups = {
nala: setupNala,
cmake: setupCmake,
@ -102,12 +58,12 @@ export const setups = {
}
export type ToolName = keyof typeof setups
/** The tools that can be installed */
export const tools = Object.keys(setups) as Array<ToolName>
/** The possible inputs to the program */
export type Inputs = keyof typeof setups | "compiler" | "architecture" | "timeout"
export type Inputs = keyof typeof setups | "compiler" | "architecture"
/** an array of possible inputs */
export const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
export const inputs: Array<Inputs> = ["compiler", "architecture", "timeout", ...tools]