Merge branch 'master' into pr/164

This commit is contained in:
Amin Yahyaabadi 2023-07-15 14:33:06 -07:00
commit f7f2d14ebb
51 changed files with 3106 additions and 2185 deletions

View File

@ -1,4 +1,16 @@
{
"extends": "eslint-config-atomic",
"ignorePatterns": ["dist/", "node_modules/", "dev/cpp_vcpkg_project"]
"ignorePatterns": ["dist/", "node_modules/", "dev/cpp_vcpkg_project"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}
]
}
}

View File

@ -7,4 +7,3 @@ stats.html
src/python/setup-python/
src/msvc/msvc-dev-cmd/
dev/cpp_vcpkg_project
package.json

View File

@ -1,22 +0,0 @@
const terserConfig = require("terser-config-atomic")
const compress =
typeof terserConfig.compress !== "boolean"
? {
...terserConfig.compress,
global_defs: {
...terserConfig.compress.global_defs,
"process.env.NODE_DEBUG": false,
"process.env.RUNNER_DEBUG": "0",
},
}
: terserConfig.compress
module.exports = {
...terserConfig,
compress,
format: {
...terserConfig.format,
comments: false,
},
}

View File

@ -24,7 +24,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
| coverage | gcovr, opencppcoverage, kcov |
| other | python, powershell, sevenzip |
`setup-cpp` automatically installs the dependencies above tools if needed for the selected tool (e.g., `python` is required for `conan`).
`setup-cpp` automatically handles the dependencies of the selected tool (e.g., `python` is required for `conan`).
## Usage
@ -32,24 +32,18 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
#### With npm and Nodejs
Install setup-cpp with npm:
Run `setup-cpp` with the available options.
```shell
npm install -g setup-cpp
```
Then run `setup-cpp` with the available options.
```shell
# windows example (open PowerShell as admin)
setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
# Windows example (open PowerShell as admin)
npx setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
RefreshEnv.cmd # activate the environment
```
```shell
# linux/macos example
sudo setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
# Linux/Macos example
sudo npx setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
source ~/.cpprc
```
@ -62,13 +56,13 @@ NOTE: On Unix systems, if you are already a root user (e.g., in a GitLab runner
#### With executable
Download the executable for your platform from [here](https://github.com/aminya/setup-cpp/releases/tag/v0.26.2), and run it with the available options. You can also automate downloading using `wget`, `curl`, or other similar tools.
Download the executable for your platform from [here](https://github.com/aminya/setup-cpp/releases/tag/v0.30.1), and run it with the available options. You can also automate downloading using `wget`, `curl`, or other similar tools.
An example that installs llvm, cmake, ninja, ccache, and vcpkg:
```shell
# windows example (open PowerShell as admin)
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.26.2/setup-cpp-x64-windows.exe"
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.30.1/setup-cpp-x64-windows.exe"
./setup-cpp-x64-windows --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
RefreshEnv.cmd # activate cpp environment variables
@ -76,7 +70,7 @@ RefreshEnv.cmd # activate cpp environment variables
```shell
# linux example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.26.2/setup-cpp-x64-linux"
wget "https://github.com/aminya/setup-cpp/releases/download/v0.30.1/setup-cpp-x64-linux"
chmod +x ./setup-cpp-x64-linux
sudo ./setup-cpp-x64-linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
@ -85,7 +79,7 @@ source ~/.cpprc # activate cpp environment variables
```shell
# macos example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.26.2/setup-cpp-x64-macos"
wget "https://github.com/aminya/setup-cpp/releases/download/v0.30.1/setup-cpp-x64-macos"
chmod +x ./setup-cpp-x64-macos
sudo ./setup-cpp-x64-macos --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
@ -255,7 +249,7 @@ stages:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F
.setup-cpp: &setup-cpp |
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.26.2/setup-cpp-x64-linux"
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.30.1/setup-cpp-x64-linux"
chmod +x setup-cpp-x64-linux
./setup-cpp-x64-linux --compiler $compiler --cmake true --ninja true --ccache true --vcpkg true
source ~/.cpprc

View File

@ -11,6 +11,10 @@ ignorePaths:
- "**/node_modules/"
words:
- aarch
- clangd
- Trofimovich
- cobertura
- whatwg
- aminya
- applellvm
- bazel

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

@ -1,12 +1,26 @@
module.exports = {
/** @typedef {import("jest")} jestConfig */
const jestConfig = {
preset: "ts-jest/presets/js-with-ts-esm",
extensionsToTreatAsEsm: [".ts"],
transformIgnorePatterns: [], // transform everything
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
testPathIgnorePatterns: ["<rootDir>/src/python/setup-python/"],
// tsconfig
transform: {
"^.+\\.tsx?$": [
"ts-jest",
/** @type {import("ts-jest")} */
{
importHelpers: true,
useESM: true,
},
],
},
// coverage
collectCoverageFrom: ["src/**/*.{ts,tsx}"],
coveragePathIgnorePatterns: ["assets", ".css.d.ts"],
verbose: true,
}
export default jestConfig

4
package-version.json Normal file
View File

@ -0,0 +1,4 @@
{
"name": "setup-cpp",
"version": "0.30.1"
}

View File

@ -1,6 +1,6 @@
{
"name": "setup-cpp",
"version": "0.26.2",
"version": "0.30.1",
"description": "Install all the tools required for building and testing C++/C projects.",
"repository": "https://github.com/aminya/setup-cpp",
"license": "Apache-2.0",
@ -9,19 +9,26 @@
"import": "./dist/node16/setup-cpp.mjs",
"require": "./dist/node16/setup-cpp.js"
},
"main": "dist/node16/setup-cpp.js",
"main.legacy": "./dist/node12/setup-cpp.js",
"main.actions": "./dist/node18/setup-cpp.js",
"source": "./src/main.ts",
"bin": {
"setup-cpp": "./dist/node16/setup-cpp.js"
"setup-cpp": "dist/node16/setup-cpp.js"
},
"files": [
"action.yml",
".dockerignore",
"dist",
"src",
"packages",
"dev",
"dev/docker",
"dev/container-tests",
"README.md",
"LICENSE.txt",
"LICENSE.dependencies.txt",
"package.json",
"package-version.json",
"tsconfig.json"
],
"scripts": {
@ -45,8 +52,8 @@
"lint.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/ --fix",
"lint.prettier": "prettier --list-different --write .",
"lint.tsc": "tsc --noEmit",
"pack.exe": "shx rm -rf ./dist/tsconfig.tsbuildinfo && ts-node --esm ./dev/scripts/pack-exe.ts",
"prepare": "pnpm run -r build && pnpm run -w build",
"pack.exe": "shx rm -rf ./dist/tsconfig.tsbuildinfo && node ./dev/scripts/pack-exe.mjs",
"prepare": "pnpm run -r build && pnpm run -w build && rm ./dist/tsconfig.tsbuildinfo",
"start.docker": "docker run -t setup-cpp .",
"start.docker.arch": "docker run -t setup-cpp:arch .",
"start.docker.fedora": "docker run -t setup-cpp:fedora .",
@ -66,15 +73,15 @@
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"@babel/cli": "^7.21.0",
"@babel/cli": "^7.22.5",
"@types/cross-spawn": "^6.0.2",
"@types/eslint": "^8.37.0",
"@types/jest": "^29.5.1",
"@types/eslint": "^8.40.2",
"@types/jest": "^29.5.2",
"@types/mri": "^1.1.1",
"@types/node": "^18.16.0",
"@types/node": "^20.3.2",
"@types/npmcli__ci-detect": "^2.0.0",
"@types/prettier": "2.7.2",
"@types/semver": "^7.3.13",
"@types/prettier": "2.7.3",
"@types/semver": "^7.5.0",
"@types/which": "^3.0.0",
"@upleveled/babel-plugin-remove-node-prefix": "github:aminya/babel-plugin-remove-node-prefix#95fcbd92405b99a6eece48c493548996f12e6519",
"admina": "^0.1.3",
@ -87,20 +94,22 @@
"escape-path-with-spaces": "^1.0.2",
"escape-quotes": "^1.0.2",
"escape-string-regexp": "^5.0.0",
"eslint": "^8.39.0",
"eslint-config-atomic": "^1.18.3",
"eslint": "^8.43.0",
"eslint-config-atomic": "^1.19.3",
"exec-powershell": "workspace:*",
"execa": "^7.1.1",
"fast-glob": "^3.2.12",
"find-up": "^6.3.0",
"gen-readme": "^1.6.0",
"is-url-online": "^1.5.0",
"jest": "^29.5.0",
"micro-memoize": "^4.1.2",
"mri": "^1.2.0",
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"npm-check-updates": "^16.10.9",
"npm-check-updates": "^16.10.13",
"npm-run-all2": "^6.0.5",
"numerous": "1.0.3",
"parcel": "2.8.3",
"parcel": "2.9.3",
"path-exists": "^5.0.0",
"patha": "^0.4.1",
"prettier": "2.8.8",
@ -108,19 +117,19 @@
"quote-unquote": "^1.0.0",
"readme-md-generator": "^1.0.0",
"retry-as-promised": "^7.0.4",
"semver": "7.5.0",
"setup-python": "github:actions/setup-python#v4.6.0",
"semver": "7.5.3",
"setup-python": "github:actions/setup-python#v4.6.1",
"shx": "0.3.4",
"terser-config-atomic": "^0.1.1",
"simple-update-notifier": "^2.0.0",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"ts-readme": "^1.1.3",
"typescript": "^5.0.4",
"typescript": "^5.1.5",
"ubuntu-version": "^2.0.0",
"untildify-user": "workspace:*",
"user-access": "workspace:*",
"which": "^3.0.0"
"which": "^3.0.1"
},
"engines": {
"node": ">=12.x"
@ -148,16 +157,20 @@
"electron": false,
"patha": "patha/dist/index.node.mjs"
},
"main": "./dist/node16/setup-cpp.js",
"main.legacy": "./dist/node12/setup-cpp.js",
"main.actions": "./dist/node18/setup-cpp.js",
"pnpm": {
"overrides": {
"whatwg-url": "^12"
}
},
"targets": {
"main.legacy": {
"context": "node",
"engines": {
"node": ">=12.x"
},
"includeNodeModules": true,
"includeNodeModules": {
"update-notifier": false
},
"optimize": true,
"outputFormat": "commonjs"
},
@ -166,7 +179,9 @@
"engines": {
"node": ">=16.x"
},
"includeNodeModules": true,
"includeNodeModules": {
"update-notifier": false
},
"optimize": true,
"outputFormat": "commonjs"
},

View File

@ -12,7 +12,7 @@
},
"dependencies": {
"@actions/core": "^1.9.1",
"@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d"
"ci-info": "^3.8.0"
},
"keywords": [
"log",

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -7,6 +7,7 @@ import { mkdirP } from "@actions/io"
import { readFileSync } from "fs"
import { addPath } from "../utils/env/addEnv"
/* eslint-disable require-atomic-updates */
let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars

12
src/check-updates.ts Normal file
View File

@ -0,0 +1,12 @@
import { warning } from "ci-log"
import updateNotifier from "simple-update-notifier"
import packageJson from "../package-version.json"
// auto self update notifier
export async function checkUpdates() {
try {
await updateNotifier({ pkg: packageJson })
} catch (err) {
warning(`Failed to check for updates: ${err instanceof Error ? err.message + err.stack : err}`)
}
}

72
src/cli-options.ts Normal file
View File

@ -0,0 +1,72 @@
import { getInput } from "@actions/core"
import { info } from "ci-log"
import mri from "mri"
import { InstallationInfo } from "./utils/setup/setupBin"
import { Inputs, inputs } from "./tool"
export function parseArgs(args: string[]): Opts {
return mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
string: inputs,
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
alias: { h: "help" },
boolean: "help",
})
}
export function printHelp() {
info(`
setup-cpp [options]
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.
--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:
`)
console.table(
{
"compiler and analyzer": { tools: `--llvm, --gcc, --msvc, --vcvarsall, --cppcheck, --clangtidy, --clangformat` },
"build system": { tools: `--cmake, --ninja, --meson, --make, --task, --bazel` },
"package manager": { tools: `--vcpkg, --conan, --choco, --brew, --nala` },
cache: { tools: `--cppcache, --sccache` },
documentation: { tools: `--doxygen, --graphviz` },
coverage: { tools: `--gcovr, --opencppcoverage, --kcov` },
other: { tools: `--python, --powershell, --sevenzip` },
},
["tools"]
)
}
/** Get an object from github actions */
export function maybeGetInput(key: string) {
const value = getInput(key.toLowerCase())
if (value !== "false" && value !== "") {
return value
}
return undefined // skip installation
}
export type Opts = mri.Argv<
Record<Inputs, string | undefined> & {
help: boolean
}
>
export function getSuccessMessage(tool: string, installationInfo: InstallationInfo | undefined | void) {
let msg = `${tool} was installed successfully:`
if (installationInfo === undefined) {
return msg
}
if ("installDir" in installationInfo) {
msg += `\n- The installation directory is ${installationInfo.installDir}`
}
if (installationInfo.binDir !== "") {
msg += `\n- The binary directory is ${installationInfo.binDir}`
}
return msg
}

114
src/compilers.ts Normal file
View File

@ -0,0 +1,114 @@
import { endGroup, notice, startGroup } from "@actions/core"
import { error, info } from "ci-log"
import { join } from "path"
import semverValid from "semver/functions/valid"
import { getSuccessMessage } from "./cli-options"
import { setupGcc } from "./gcc/gcc"
import { activateGcovGCC, activateGcovLLVM } from "./gcovr/gcovr"
import { setupLLVM } from "./llvm/llvm"
import { setupMSVC } from "./msvc/msvc"
import { addEnv } from "./utils/env/addEnv"
import { getVersion } from "./versions/versions"
/** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
export function getCompilerInfo(compilerAndVersion: string) {
const compilerAndMaybeVersion = compilerAndVersion.split("-")
const compiler = compilerAndMaybeVersion[0]
if (1 in compilerAndMaybeVersion) {
const maybeVersion = compilerAndMaybeVersion[1]
if (semverValid(maybeVersion) !== null) {
return { compiler, version: maybeVersion }
} else {
info(`Invalid semver version ${maybeVersion} used for the compiler.`)
return { compiler, version: maybeVersion }
}
}
return { compiler, version: undefined }
}
/** Installing the specified compiler */
export async function installCompiler(
compilerAndVersion: string,
osVersion: number[] | null,
setupCppDir: string,
arch: string,
successMessages: string[],
hasLLVM: boolean,
errorMessages: string[]
) {
try {
const { compiler, version } = getCompilerInfo(compilerAndVersion)
// install the compiler. We allow some aliases for the compiler name
startGroup(`Installing ${compiler} ${version ?? ""}`)
switch (compiler) {
case "llvm":
case "clang":
case "clang++": {
const installationInfo = await setupLLVM(
getVersion("llvm", version, osVersion),
join(setupCppDir, "llvm"),
arch
)
await activateGcovLLVM()
successMessages.push(getSuccessMessage("llvm", installationInfo))
break
}
case "gcc":
case "mingw":
case "cygwin":
case "msys": {
const gccVersion = getVersion("gcc", version, osVersion)
const installationInfo = await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch)
if (hasLLVM) {
// remove back the added CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "")
}
await activateGcovGCC(gccVersion)
successMessages.push(getSuccessMessage("gcc", installationInfo))
break
}
case "cl":
case "msvc":
case "msbuild":
case "vs":
case "visualstudio":
case "visualcpp":
case "visualc++": {
const installationInfo = await setupMSVC(
getVersion("msvc", version, osVersion),
join(setupCppDir, "msvc"),
arch
)
if (hasLLVM) {
// remove the CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "")
}
successMessages.push(getSuccessMessage("msvc", installationInfo))
break
}
case "appleclang":
case "applellvm": {
notice("Assuming apple-clang is already installed")
await Promise.all([addEnv("CC", "clang"), addEnv("CXX", "clang++")])
successMessages.push(getSuccessMessage("apple-clang", undefined))
break
}
default: {
errorMessages.push(`Unsupported compiler ${compiler}`)
}
}
} catch (err) {
error(err as string | Error)
errorMessages.push(`Failed to install the ${compilerAndVersion}`)
}
endGroup()
}

View File

@ -16,6 +16,7 @@ import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
import { pathExists } from "path-exists"
import retry from "retry-as-promised"
import { ubuntuVersion } from "../utils/env/ubuntu_version"
/** Get the platform data for cmake */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -70,7 +71,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
let installationInfo: InstallationInfo
if (version === "" || isArch() || hasDnf()) {
if (isArch()) {
installationInfo = setupPacmanPack("doxygen", version)
installationInfo = await setupPacmanPack("doxygen", version)
} else if (hasDnf()) {
return setupDnfPack("doxygen", version)
} else if (isUbuntu()) {
@ -90,7 +91,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
} else {
throw new Error(`Unsupported linux distributions`)
}
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
await setupGraphviz(getVersion("graphviz", undefined, await ubuntuVersion()), "", arch)
return installationInfo
}
default: {

View File

@ -17,6 +17,7 @@ import { isUbuntu } from "../utils/env/isUbuntu"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { pathExists } from "path-exists"
import { ExecaReturnValue } from "execa"
interface MingwInfo {
releaseName: string
@ -25,7 +26,12 @@ interface MingwInfo {
// https://github.com/brechtsanders/winlibs_mingw/releases
const GccToMingwInfo = {
"12": { releaseName: "12.2.0-14.0.6-10.0.0-ucrt-r2", fileSuffix: "12.2.0-mingw-w64ucrt-10.0.0-r2" },
"13": { releaseName: "13.1.0posix-16.0.3-11.0.0-ucrt-r1", fileSuffix: "13.1.0-mingw-w64ucrt-11.0.0-r1" },
"13.1-ucrt": { releaseName: "13.1.0posix-16.0.3-11.0.0-ucrt-r1", fileSuffix: "13.1.0-mingw-w64ucrt-11.0.0-r1" },
"13.1-msvcrt": { releaseName: "13.1.0posix-16.0.3-11.0.0-msvcrt-r1", fileSuffix: "13.1.0-mingw-w64msvcrt-11.0.0-r1" },
"12": { releaseName: "12.3.0-16.0.4-11.0.0-ucrt-r1", fileSuffix: "12.3.0-mingw-w64ucrt-11.0.0-r1" },
"12.3.0-ucrt": { releaseName: "12.3.0-16.0.4-11.0.0-ucrt-r1", fileSuffix: "12.3.0-mingw-w64ucrt-11.0.0-r1" },
"12.3.0-msvcrt": { releaseName: "12.3.0-16.0.4-11.0.0-msvcrt-r1", fileSuffix: "12.3.0-mingw-w64msvcrt-11.0.0-r1" },
"12.2.0-ucrt": { releaseName: "12.2.0-14.0.6-10.0.0-ucrt-r2", fileSuffix: "12.2.0-mingw-w64ucrt-10.0.0-r2" },
"12.2.0-msvcrt": { releaseName: "12.2.0-14.0.6-10.0.0-msvcrt-r2", fileSuffix: "12.2.0-mingw-w64msvcrt-10.0.0-r2" },
"12.1.0-ucrt": { releaseName: "12.1.0-14.0.4-10.0.0-ucrt-r2", fileSuffix: "12.1.0-mingw-w64ucrt-10.0.0-r2" },
@ -90,7 +96,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
case "linux": {
if (arch === "x64") {
if (isArch()) {
installationInfo = setupPacmanPack("gcc", version)
installationInfo = await setupPacmanPack("gcc", version)
} else if (hasDnf()) {
installationInfo = setupDnfPack("gcc", version)
setupDnfPack("gcc-c++", version)
@ -104,7 +110,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
} else {
info(`Install g++-multilib because gcc for ${arch} was requested`)
if (isArch()) {
setupPacmanPack("gcc-multilib", version)
await setupPacmanPack("gcc-multilib", version)
} else if (isUbuntu()) {
await setupAptPack([{ name: "gcc-multilib", version, repositories: ["ppa:ubuntu-toolchain-r/test"] }])
}
@ -152,7 +158,7 @@ async function setupChocoMingw(version: string, arch: string): Promise<Installat
}
async function activateGcc(version: string, binDir: string) {
const promises: Promise<any>[] = []
const promises: Promise<void | ExecaReturnValue<string>>[] = []
// Setup gcc as the compiler
// TODO

View File

@ -2,6 +2,7 @@ import { setupGraphviz } from "../graphviz"
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
import { getVersion } from "../../versions/versions"
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
jest.setTimeout(300000)
describe("setup-graphviz", () => {
@ -11,7 +12,11 @@ describe("setup-graphviz", () => {
})
it("should setup graphviz", async () => {
const installInfo = await setupGraphviz(getVersion("graphviz", undefined), directory, process.arch)
const installInfo = await setupGraphviz(
getVersion("graphviz", undefined, await ubuntuVersion()),
directory,
process.arch
)
await testBin("dot", ["-V"], (installInfo as InstallationInfo | undefined)?.binDir)
})

View File

@ -11,6 +11,18 @@ describe("setup-Kcov", () => {
return
}
it("should build and setup kcov-41", async () => {
const directory = await setupTmpDir("kcov-v41")
const { binDir } = (await setupKcov("41", directory, "")) as InstallationInfo
// the prebuild binary only works on ubuntu 20.04
try {
await testBin("kcov", ["--version"], binDir)
} catch (err) {
info((err as Error).message)
}
await cleanupTmpDir("kcov-v41")
})
it("should setup Kcov v40 via downloading the binaries", async () => {
const directory = await setupTmpDir("kcov-v40")
const { binDir } = (await setupKcov("40-binary", directory, "")) as InstallationInfo

54
src/kcov/gcc13.patch Normal file
View File

@ -0,0 +1,54 @@
From b63754b53b3a7cf43e13ec56bd0be76cb6175437 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyich@gmail.com>
Date: Thu, 15 Sep 2022 19:55:21 +0100
Subject: [PATCH] Fix build on gcc-13: add missing <stdint.h> include
[ 15%] Building CXX object src/CMakeFiles/kcov.dir/writers/cobertura-writer.cc.o
In file included from kcov/src/writers/cobertura-writer.cc:6:
kcov/src/include/reporter.hh:24:90: error: 'uint64_t' has not been declared
24 | LineExecutionCount(unsigned int hits, unsigned int possibleHits, uint64_t order) :
| ^~~~~~~~
---
src/include/collector.hh | 2 ++
src/include/reporter.hh | 1 +
src/include/source-file-cache.hh | 2 ++
3 files changed, 5 insertions(+)
diff --git a/src/include/collector.hh b/src/include/collector.hh
index 79e5d5f2..1369a416 100644
--- a/src/include/collector.hh
+++ b/src/include/collector.hh
@@ -2,6 +2,8 @@
#include <string>
+#include <stdint.h>
+
namespace kcov
{
class IFileParser;
diff --git a/src/include/reporter.hh b/src/include/reporter.hh
index bc058e69..98d8e56b 100644
--- a/src/include/reporter.hh
+++ b/src/include/reporter.hh
@@ -3,6 +3,7 @@
#include <string>
#include <stddef.h>
+#include <stdint.h>
namespace kcov
{
diff --git a/src/include/source-file-cache.hh b/src/include/source-file-cache.hh
index c0cb00ee..cfc73b81 100644
--- a/src/include/source-file-cache.hh
+++ b/src/include/source-file-cache.hh
@@ -3,6 +3,8 @@
#include <vector>
#include <string>
+#include <stdint.h>
+
namespace kcov
{
/**

View File

@ -15,6 +15,7 @@ import { addVPrefix, removeVPrefix } from "../utils/setup/version"
import { info } from "ci-log"
import { untildifyUser } from "untildify-user"
import { setupNinja } from "../ninja/ninja"
import { ubuntuVersion } from "../utils/env/ubuntu_version"
function getDownloadKcovPackageInfo(version: string): PackageInfo {
return {
@ -44,8 +45,7 @@ async function buildKcov(file: string, dest: string) {
if (process.platform === "linux") {
if (isArch()) {
setupPacmanPack("libdwarf")
setupPacmanPack("libcurl-openssl")
await Promise.all([setupPacmanPack("libdwarf"), setupPacmanPack("libcurl-openssl")])
} else if (hasDnf()) {
setupDnfPack("libdwarf-devel")
setupDnfPack("libcurl-devel")
@ -53,6 +53,19 @@ async function buildKcov(file: string, dest: string) {
await setupAptPack([{ name: "libdw-dev" }, { name: "libcurl4-openssl-dev" }])
}
}
// apply gcc13.patch
try {
if (which.sync("patch", { nothrow: true }) !== null) {
const patch = join(__dirname, "gcc13.patch")
await execa("patch", ["-N", "-p1", "-i", patch], { cwd: out, stdio: "inherit" })
} else {
info("`patch` not found, skipping gcc13.patch, kcov may not build on gcc 13")
}
} catch {
// ignore
}
const buildDir = join(out, "build")
await execa(cmake, ["-S", out, "-B", buildDir, "-DCMAKE_BUILD_TYPE=Release", "-G", "Ninja"], {
cwd: out,
@ -67,12 +80,16 @@ async function buildKcov(file: string, dest: string) {
async function getCmake() {
let cmake = which.sync("cmake", { nothrow: true })
if (cmake === null) {
const { binDir } = await setupCmake(getVersion("cmake", undefined), join(untildifyUser(""), "cmake"), "")
const { binDir } = await setupCmake(
getVersion("cmake", undefined, await ubuntuVersion()),
join(untildifyUser(""), "cmake"),
""
)
cmake = join(binDir, "cmake")
}
const ninja = which.sync("ninja", { nothrow: true })
if (ninja === null) {
await setupNinja(getVersion("ninja", undefined), join(untildifyUser(""), "ninja"), "")
await setupNinja(getVersion("ninja", undefined, await ubuntuVersion()), join(untildifyUser(""), "ninja"), "")
}
return cmake
}
@ -97,7 +114,7 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
if (installMethod === "binary" && version_number >= 39) {
installationInfo = await setupBin("kcov", version, getDownloadKcovPackageInfo, setupDir, arch)
if (isArch()) {
setupPacmanPack("binutils")
await setupPacmanPack("binutils")
} else if (hasDnf()) {
setupDnfPack("binutils")
} else if (isUbuntu()) {

View File

@ -1,6 +1,5 @@
import { join, addExeExt } from "patha"
import { delimiter } from "path"
import semverMajor from "semver/functions/major"
import { InstallationInfo, setupBin } from "../utils/setup/setupBin"
import { semverCoerceIfInvalid } from "../utils/setup/version"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
@ -47,8 +46,7 @@ async function setupLLVMWithoutActivation(version: string, setupDir: string, arc
async function setupLLVMDeps(arch: string, version: string) {
if (process.platform === "linux") {
// install llvm build dependencies
const osVersion = await ubuntuVersion()
await setupGcc(getVersion("gcc", undefined, osVersion), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
await setupGcc(getVersion("gcc", undefined, await ubuntuVersion()), "", arch) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
if (isUbuntu()) {
const majorVersion = parseInt(version.split(".")[0], 10)
@ -59,12 +57,12 @@ async function setupLLVMDeps(arch: string, version: string) {
}
}
// TODO: install libtinfo on other distros
// setupPacmanPack("ncurses")
// await setupPacmanPack("ncurses")
}
}
export async function activateLLVM(directory: string, versionGiven: string) {
const version = semverCoerceIfInvalid(versionGiven)
const _version = semverCoerceIfInvalid(versionGiven)
const lib = join(directory, "lib")
@ -93,15 +91,16 @@ export async function activateLLVM(directory: string, versionGiven: string) {
setupMacOSSDK(),
]
// windows builds fail with llvm's CPATH
if (process.platform !== "win32") {
const llvmMajor = semverMajor(version)
if (await pathExists(`${directory}/lib/clang/${version}/include`)) {
promises.push(addEnv("CPATH", `${directory}/lib/clang/${version}/include`))
} else if (await pathExists(`${directory}/lib/clang/${llvmMajor}/include`)) {
promises.push(addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`))
}
}
// TODO Causes issues with clangd
// TODO Windows builds fail with llvm's CPATH
// if (process.platform !== "win32") {
// const llvmMajor = semverMajor(version)
// if (await pathExists(`${directory}/lib/clang/${version}/include`)) {
// promises.push(addEnv("CPATH", `${directory}/lib/clang/${version}/include`))
// } else if (await pathExists(`${directory}/lib/clang/${llvmMajor}/include`)) {
// promises.push(addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`))
// }
// }
if (isUbuntu()) {
promises.push(

View File

@ -65,6 +65,8 @@ export const VERSIONS: Set<string> = getVersions([
"16.0.0",
"16.0.1",
"16.0.2",
"16.0.3",
"16.0.4",
])
/** The LLVM versions that were never released for the Windows platform. */
@ -93,6 +95,8 @@ const DARWIN_MISSING = new Set([
"16.0.0",
"16.0.1",
"16.0.2",
"16.0.3",
"16.0.4",
])
/**
@ -152,6 +156,8 @@ const UBUNTU_SUFFIX_MAP: { [key: string]: string } = {
"15.0.6": "-ubuntu-18.04",
"16.0.0": "-ubuntu-18.04",
"16.0.2": "-ubuntu-22.04",
"16.0.3": "-ubuntu-22.04",
"16.0.4": "-ubuntu-22.04",
}
/** The latest supported LLVM version for the Linux (Ubuntu) platform. */

View File

@ -1,95 +1,28 @@
#!/usr/bin/env node
/* eslint-disable node/shebang */
import { endGroup, getInput, notice, startGroup } from "@actions/core"
import { GITHUB_ACTIONS } from "ci-info"
import { error, info, success, warning } from "ci-log"
import mri from "mri"
import * as numerous from "numerous"
import numerousLocale from "numerous/locales/en.js"
import { join } from "patha"
import semverValid from "semver/functions/valid"
import * as timeDelta from "time-delta"
import timeDeltaLocale from "time-delta/locales/en.js"
import { untildifyUser } from "untildify-user"
import { setupBazel } from "./bazel/bazel"
import { setupBrew } from "./brew/brew"
import { setupCcache } from "./ccache/ccache"
import { setupChocolatey } from "./chocolatey/chocolatey"
import { setupCmake } from "./cmake/cmake"
import { setupConan } from "./conan/conan"
import { setupCppcheck } from "./cppcheck/cppcheck"
import { setupDoxygen } from "./doxygen/doxygen"
import { setupGcc } from "./gcc/gcc"
import { activateGcovGCC, activateGcovLLVM, setupGcovr } from "./gcovr/gcovr"
import { setupGraphviz } from "./graphviz/graphviz"
import { setupKcov } from "./kcov/kcov"
import { setupClangTools, setupLLVM } from "./llvm/llvm"
import { setupMake } from "./make/make"
import { setupMeson } from "./meson/meson"
import { setupMSVC } from "./msvc/msvc"
import { setupNala } from "./nala/nala"
import { setupNinja } from "./ninja/ninja"
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPowershell } from "./powershell/powershell"
import { setupPython } from "./python/python"
import { setupSccache } from "./sccache/sccache"
import { setupSevenZip } from "./sevenzip/sevenzip"
import { setupTask } from "./task/task"
import { addEnv, finalizeCpprc } from "./utils/env/addEnv"
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 { InstallationInfo } from "./utils/setup/setupBin"
import { setupPacmanPack } from "./utils/setup/setupPacmanPack"
import { setupVcpkg } from "./vcpkg/vcpkg"
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
import { getVersion, syncVersions } from "./versions/versions"
/** The setup functions */
const setups = {
nala: setupNala,
cmake: setupCmake,
ninja: setupNinja,
python: setupPython,
vcpkg: setupVcpkg,
bazel: setupBazel,
conan: setupConan,
meson: setupMeson,
gcovr: setupGcovr,
opencppcoverage: setupOpencppcoverage,
llvm: setupLLVM,
gcc: setupGcc,
choco: setupChocolatey,
brew: setupBrew,
powershell: setupPowershell,
ccache: setupCcache,
sccache: setupSccache,
doxygen: setupDoxygen,
graphviz: setupGraphviz,
cppcheck: setupCppcheck,
clangtidy: setupClangTools,
clangformat: setupClangTools,
msvc: setupMSVC,
vcvarsall: setupVCVarsall,
kcov: setupKcov,
make: setupMake,
task: setupTask,
sevenzip: setupSevenZip,
}
/** The tools that can be installed */
const tools = Object.keys(setups) as Array<keyof typeof setups>
/** The possible inputs to the program */
export type Inputs = keyof typeof setups | "compiler" | "architecture"
// an array of possible inputs
const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
import { syncVersions } from "./versions/versions"
/** The main entry function */
export async function main(args: string[]): Promise<number> {
async function main(args: string[]): Promise<number> {
let checkUpdatePromise = Promise.resolve()
if (!GITHUB_ACTIONS) {
checkUpdatePromise = checkUpdates()
process.env.ACTIONS_ALLOW_UNSECURE_COMMANDS = "true"
}
@ -127,13 +60,14 @@ export async function main(args: string[]): Promise<number> {
return 1
}
let hasLLVM = false // used to unset CPPFLAGS of LLVM when other compilers are used as the main compiler
if (isArch() && typeof opts.cppcheck === "string" && typeof opts.gcovr === "string") {
info("installing python-pygments to avoid conflicts with cppcheck and gcovr on Arch linux")
setupPacmanPack("python-pygments")
await setupPacmanPack("python-pygments")
}
/** Used to unset CPPFLAGS of LLVM when other compilers are used as the main compiler */
let hasLLVM = false
// loop over the tools and run their setup function
for (const tool of tools) {
// get the version or "true" or undefined for this tool from the options
@ -143,40 +77,8 @@ export async function main(args: string[]): Promise<number> {
if (version !== undefined) {
// running the setup function for this tool
time1 = Date.now()
startGroup(`Installing ${tool} ${version}`)
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()
// eslint-disable-next-line no-await-in-loop
hasLLVM = await installTool(tool, version, osVersion, arch, setupCppDir, successMessages, errorMessages)
time2 = Date.now()
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
}
@ -184,87 +86,11 @@ export async function main(args: string[]): Promise<number> {
// installing the specified compiler
const maybeCompiler = opts.compiler
time1 = Date.now()
try {
if (maybeCompiler !== undefined) {
const { compiler, version } = getCompilerInfo(maybeCompiler)
// install the compiler. We allow some aliases for the compiler name
startGroup(`Installing ${compiler} ${version ?? ""}`)
switch (compiler) {
case "llvm":
case "clang":
case "clang++": {
const installationInfo = await setupLLVM(
getVersion("llvm", version, osVersion),
join(setupCppDir, "llvm"),
arch
)
await activateGcovLLVM()
successMessages.push(getSuccessMessage("llvm", installationInfo))
break
}
case "gcc":
case "mingw":
case "cygwin":
case "msys": {
const gccVersion = getVersion("gcc", version, osVersion)
const installationInfo = await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch)
if (hasLLVM) {
// remove the CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "")
}
await activateGcovGCC(gccVersion)
successMessages.push(getSuccessMessage("gcc", installationInfo))
break
}
case "cl":
case "msvc":
case "msbuild":
case "vs":
case "visualstudio":
case "visualcpp":
case "visualc++": {
const installationInfo = await setupMSVC(
getVersion("msvc", version, osVersion),
join(setupCppDir, "msvc"),
arch
)
if (hasLLVM) {
// remove the CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "")
}
successMessages.push(getSuccessMessage("msvc", installationInfo))
break
}
case "appleclang":
case "applellvm": {
notice("Assuming apple-clang is already installed")
await Promise.all([addEnv("CC", "clang"), addEnv("CXX", "clang++")])
successMessages.push(getSuccessMessage("apple-clang", undefined))
break
}
default: {
errorMessages.push(`Unsupported compiler ${compiler}`)
}
}
endGroup()
time2 = Date.now()
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
}
} catch (e) {
error(e as string | Error)
errorMessages.push(`Failed to install the ${maybeCompiler}`)
endGroup()
time2 = Date.now()
info(`took ${timeFormatter.format(time1, time2) || "0 seconds"}`)
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()
@ -297,8 +123,11 @@ export async function main(args: string[]): Promise<number> {
}
}
await checkUpdatePromise
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
}
// Run main
main(process.argv)
.then((ret) => {
@ -309,101 +138,3 @@ main(process.argv)
error(err as string | Error)
process.exitCode = 1
})
export type Opts = mri.Argv<
Record<Inputs, string | undefined> & {
help: boolean
}
>
export function parseArgs(args: string[]): Opts {
return mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
string: inputs,
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
alias: { h: "help" },
boolean: "help",
})
}
/** Detecting the compiler version. Divide the given string by `-` and use the second element as the version */
export function getCompilerInfo(maybeCompiler: string) {
const compilerAndMaybeVersion = maybeCompiler.split("-")
const compiler = compilerAndMaybeVersion[0]
if (1 in compilerAndMaybeVersion) {
const maybeVersion = compilerAndMaybeVersion[1]
if (semverValid(maybeVersion) !== null) {
return { compiler, version: maybeVersion }
} else {
info(`Invalid semver version ${maybeVersion} used for the compiler.`)
return { compiler, version: maybeVersion }
}
}
return { compiler, version: undefined }
}
function printHelp() {
info(`
setup-cpp [options]
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.
--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:
--llvm
--gcc
--vcvarsall
--cmake
--ninja
--vcpkg
--bazel
--meson
--conan
--make
--task
--ccache
--sccache
--cppcheck
--clangformat
--clangtidy
--doxygen
--gcovr
--opencppcoverage
--kcov
--python
--choco
--brew
--nala
--sevenzip
--graphviz
--powershell
`)
}
/** Get an object from github actions */
function maybeGetInput(key: string) {
const value = getInput(key.toLowerCase())
if (value !== "false" && value !== "") {
return value
}
return undefined // skip installation
}
function getSuccessMessage(tool: string, installationInfo: InstallationInfo | undefined | void) {
let msg = `${tool} was installed successfully:`
if (installationInfo === undefined) {
return msg
}
if ("installDir" in installationInfo) {
msg += `\n- The installation directory is ${installationInfo.installDir}`
}
if (installationInfo.binDir !== "") {
msg += `\n- The binary directory is ${installationInfo.binDir}`
}
return msg
}

View File

@ -24,6 +24,7 @@ describe("setup-python", () => {
it("should setup python via system", async () => {
process.env.CI = "false"
process.env.GITHUB_ACTIONS = "false"
const installInfo = await setupPython(getVersion("python", "true", await ubuntuVersion()), directory, process.arch)

View File

@ -1,45 +1,89 @@
/* eslint-disable require-atomic-updates */
import { getExecOutput } from "@actions/exec"
import assert from "assert"
import { GITHUB_ACTIONS } from "ci-info"
import { info, warning } from "ci-log"
import { execa } from "execa"
import memoize from "micro-memoize"
import { addExeExt, dirname, join } from "patha"
import which from "which"
import { addPath } from "../utils/env/addEnv"
import { hasDnf } from "../utils/env/hasDnf"
import { isArch } from "../utils/env/isArch"
import { isUbuntu } from "../utils/env/isUbuntu"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { InstallationInfo } from "../utils/setup/setupBin"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { GITHUB_ACTIONS } from "ci-info"
import { warning, info } from "ci-log"
import { isArch } from "../utils/env/isArch"
import which from "which"
import { InstallationInfo } from "../utils/setup/setupBin"
import { dirname, join } from "patha"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
import { getExecOutput } from "@actions/exec"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { isBinUptoDate } from "../utils/setup/version"
import { getVersion } from "../versions/versions"
import assert from "assert"
import { execaSync } from "execa"
import { unique } from "../utils/std"
import { MinVersions } from "../versions/default_versions"
import { pathExists } from "path-exists"
import { setupPipPackWithPython } from "../utils/setup/setupPipPack"
export async function setupPython(version: string, setupDir: string, arch: string) {
if (!GITHUB_ACTIONS) {
// TODO parse version
return setupPythonViaSystem(version, setupDir, arch)
export async function setupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installInfo = await findOrSetupPython(version, setupDir, arch)
assert(installInfo.bin !== undefined)
const foundPython = installInfo.bin
// setup pip
const foundPip = await findOrSetupPip(foundPython)
if (foundPip === undefined) {
throw new Error("pip was not installed correctly")
}
// setup wheel and setuptools
try {
info("Installing python in GitHub Actions")
const { setupActionsPython } = await import("./actions_python")
return setupActionsPython(version, setupDir, arch)
await setupPipPackWithPython(foundPython, "setuptools", undefined, true)
await setupPipPackWithPython(foundPython, "wheel", undefined, true)
} catch (err) {
warning((err as Error).toString())
return setupPythonViaSystem(version, setupDir, arch)
warning(`Failed to install setuptools or wheel: ${(err as Error).toString()}. Ignoring...`)
}
return installInfo
}
export async function setupPythonViaSystem(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
async function findOrSetupPython(version: string, setupDir: string, arch: string) {
let installInfo: InstallationInfo | undefined
let foundPython = await findPython(setupDir)
if (foundPython !== undefined) {
const binDir = dirname(foundPython)
installInfo = { bin: foundPython, installDir: binDir, binDir }
} else {
// if python is not found, try to install it
if (GITHUB_ACTIONS) {
// install python in GitHub Actions
try {
info("Installing python in GitHub Actions")
const { setupActionsPython } = await import("./actions_python")
await setupActionsPython(version, setupDir, arch)
foundPython = (await findPython(setupDir))!
const binDir = dirname(foundPython)
installInfo = { bin: foundPython, installDir: binDir, binDir }
} catch (err) {
warning((err as Error).toString())
}
}
if (installInfo === undefined) {
// install python via system package manager
installInfo = await setupPythonSystem(setupDir, version)
}
}
if (foundPython === undefined || installInfo.bin === undefined) {
foundPython = (await findPython(setupDir))!
installInfo.bin = foundPython
}
return installInfo
}
async function setupPythonSystem(setupDir: string, version: string) {
let installInfo: InstallationInfo | undefined
switch (process.platform) {
case "win32": {
if (setupDir) {
@ -48,86 +92,157 @@ export async function setupPythonViaSystem(
await setupChocoPack("python3", version)
}
// Adding the bin dir to the path
const pythonBinPath =
which.sync("python3.exe", { nothrow: true }) ??
which.sync("python.exe", { nothrow: true }) ??
join(setupDir, "python.exe")
const pythonSetupDir = dirname(pythonBinPath)
const bin = (await findPython(setupDir))!
const binDir = dirname(bin)
/** The directory which the tool is installed to */
await addPath(pythonSetupDir)
return { installDir: pythonSetupDir, binDir: pythonSetupDir }
await addPath(binDir)
installInfo = { installDir: binDir, binDir, bin }
break
}
case "darwin": {
return setupBrewPack("python3", version)
installInfo = await setupBrewPack("python3", version)
// add the python and pip binaries to the path
const brewPythonPrefix = await execa("brew", ["--prefix", "python"], { stdio: "pipe" })
const brewPythonBin = join(brewPythonPrefix.stdout, "libexec", "bin")
await addPath(brewPythonBin)
break
}
case "linux": {
let installInfo: InstallationInfo
if (isArch()) {
installInfo = setupPacmanPack("python", version)
setupPacmanPack("python-pip")
installInfo = await setupPacmanPack("python", version)
} else if (hasDnf()) {
installInfo = setupDnfPack("python3", version)
setupDnfPack("python3-pip")
} else if (isUbuntu()) {
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python3-pip" }])
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python-is-python3" }])
} else {
throw new Error("Unsupported linux distributions")
}
return installInfo
break
}
default: {
throw new Error("Unsupported platform")
}
}
return installInfo
}
let setupPythonAndPipTried = false
/// setup python and pip if needed
export async function setupPythonAndPip(): Promise<string> {
let foundPython: string
// install python
if (which.sync("python3", { nothrow: true }) !== null) {
foundPython = "python3"
} else if (which.sync("python", { nothrow: true }) !== null && (await isBinUptoDate("python", "3.0.0"))) {
foundPython = "python"
} else {
info("python3 was not found. Installing python")
await setupPython(getVersion("python", undefined), "", process.arch)
// try again
if (setupPythonAndPipTried) {
throw new Error("Failed to install python")
async function findPython(binDir?: string) {
for (const pythonBin of ["python3", "python"]) {
// eslint-disable-next-line no-await-in-loop
const foundPython = await isPythonUpToDate(pythonBin, binDir)
if (foundPython !== undefined) {
return foundPython
}
setupPythonAndPipTried = true
return setupPythonAndPip() // recurse
}
return undefined
}
async function isPythonUpToDate(candidate: string, binDir?: string) {
try {
if (binDir !== undefined) {
const pythonBinPath = join(binDir, addExeExt(candidate))
if (await pathExists(pythonBinPath)) {
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
return pythonBinPath
}
}
}
const pythonBinPaths = (await which(candidate, { nothrow: true, all: true })) ?? []
for (const pythonBinPath of pythonBinPaths) {
// eslint-disable-next-line no-await-in-loop
if (await isBinUptoDate(pythonBinPath, MinVersions.python!)) {
return pythonBinPath
}
}
} catch {
// fall through
}
return undefined
}
async function findOrSetupPip(foundPython: string) {
const maybePip = await findPip()
if (maybePip === undefined) {
// install pip if not installed
info("pip was not found. Installing pip")
await setupPip(foundPython)
return findPip() // recurse to check if pip is on PATH and up-to-date
}
assert(typeof foundPython === "string")
return maybePip
}
// install pip
if (process.platform === "win32") {
// downgrade pip on Windows
// https://github.com/pypa/pip/issues/10875#issuecomment-1030293005
execaSync(foundPython, ["-m", "pip", "install", "-U", "pip==21.3.1"], { stdio: "inherit" })
} else if (process.platform === "linux") {
async function findPip() {
for (const pipCandidate of ["pip3", "pip"]) {
// eslint-disable-next-line no-await-in-loop
const maybePip = await isPipUptoDate(pipCandidate)
if (maybePip !== undefined) {
return maybePip
}
}
return undefined
}
async function isPipUptoDate(pip: string) {
try {
const pipPaths = (await which(pip, { nothrow: true, all: true })) ?? []
for (const pipPath of pipPaths) {
// eslint-disable-next-line no-await-in-loop
if (pipPath !== null && (await isBinUptoDate(pipPath, MinVersions.pip!))) {
return pipPath
}
}
} catch {
// fall through
}
return undefined
}
async function setupPip(foundPython: string) {
const upgraded = await ensurePipUpgrade(foundPython)
if (!upgraded) {
await setupPipSystem()
// upgrade pip
await ensurePipUpgrade(foundPython)
}
}
async function ensurePipUpgrade(foundPython: string) {
try {
await execa(foundPython, ["-m", "ensurepip", "-U", "--upgrade"], { stdio: "inherit" })
return true
} catch (err1) {
info((err1 as Error)?.toString?.())
try {
// ensure pip is disabled on Ubuntu
await execa(foundPython, ["-m", "pip", "install", "--upgrade", "pip"], { stdio: "inherit" })
return true
} catch (err2) {
info((err2 as Error)?.toString?.())
// pip module not found
}
}
// all methods failed
return false
}
function setupPipSystem() {
if (process.platform === "linux") {
// ensure that pip is installed on Linux (happens when python is found but pip not installed)
if (isArch()) {
setupPacmanPack("python-pip")
return setupPacmanPack("python-pip")
} else if (hasDnf()) {
setupDnfPack("python3-pip")
return setupDnfPack("python3-pip")
} else if (isUbuntu()) {
await setupAptPack([{ name: "python3-pip" }])
return setupAptPack([{ name: "python3-pip" }])
}
}
// install wheel (required for Conan, Meson, etc.)
execaSync(foundPython, ["-m", "pip", "install", "-U", "wheel"], { stdio: "inherit" })
return foundPython
throw new Error(`Could not install pip on ${process.platform}`)
}
export async function addPythonBaseExecPrefix(python: string) {
async function addPythonBaseExecPrefix_raw(python: string) {
const dirs: string[] = []
// detection based on the platform
@ -145,3 +260,10 @@ export async function addPythonBaseExecPrefix(python: string) {
// remove duplicates
return unique(dirs)
}
/**
* Add the base exec prefix to the PATH. This is required for Conan, Meson, etc. to work properly.
*
* The answer is cached for subsequent calls
*/
export const addPythonBaseExecPrefix = memoize(addPythonBaseExecPrefix_raw)

113
src/tool.ts Normal file
View File

@ -0,0 +1,113 @@
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"
import { setupDoxygen } from "./doxygen/doxygen"
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 { setupMake } from "./make/make"
import { setupMeson } from "./meson/meson"
import { setupMSVC } from "./msvc/msvc"
import { setupNala } from "./nala/nala"
import { setupNinja } from "./ninja/ninja"
import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPowershell } from "./powershell/powershell"
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 */
export const setups = {
nala: setupNala,
cmake: setupCmake,
ninja: setupNinja,
python: setupPython,
vcpkg: setupVcpkg,
bazel: setupBazel,
conan: setupConan,
meson: setupMeson,
gcovr: setupGcovr,
opencppcoverage: setupOpencppcoverage,
llvm: setupLLVM,
gcc: setupGcc,
choco: setupChocolatey,
brew: setupBrew,
powershell: setupPowershell,
ccache: setupCcache,
sccache: setupSccache,
doxygen: setupDoxygen,
graphviz: setupGraphviz,
cppcheck: setupCppcheck,
clangtidy: setupClangTools,
clangformat: setupClangTools,
msvc: setupMSVC,
vcvarsall: setupVCVarsall,
kcov: setupKcov,
make: setupMake,
task: setupTask,
sevenzip: setupSevenZip,
}
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"
/** an array of possible inputs */
export const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]

View File

@ -10,23 +10,45 @@ import { giveUserAccess } from "user-access"
import escapeQuote from "escape-quotes"
import { pathExists } from "path-exists"
type AddEnvOptions = {
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
shouldEscapeSpace?: boolean
/** If true, the variable will be only added if it is not defined */
shouldAddOnlyIfNotDefined?: boolean
}
const defaultAddEnvOptions: AddEnvOptions = {
shouldEscapeSpace: false,
shouldAddOnlyIfNotDefined: false,
}
/**
* Add an environment variable.
*
* This function is cross-platforms and works in all the local or CI systems.
*/
export async function addEnv(name: string, valGiven: string | undefined, shouldEscapeSpace: boolean = false) {
const val = escapeString(valGiven ?? "", shouldEscapeSpace)
export async function addEnv(
name: string,
valGiven: string | undefined,
options: AddEnvOptions = defaultAddEnvOptions
) {
const val = escapeString(valGiven ?? "", options.shouldEscapeSpace)
try {
if (GITHUB_ACTIONS) {
try {
if (options.shouldAddOnlyIfNotDefined) {
if (process.env[name] !== undefined) {
info(`Environment variable ${name} is already defined. Skipping.`)
return
}
}
exportVariable(name, val)
} catch (err) {
error(err as Error)
await addEnvSystem(name, val)
await addEnvSystem(name, val, options)
}
} else {
await addEnvSystem(name, val)
await addEnvSystem(name, val, options)
}
} catch (err) {
error(err as Error)
@ -65,10 +87,16 @@ export async function addPath(path: string) {
export const cpprc_path = untildifyUser(".cpprc")
async function addEnvSystem(name: string, valGiven: string | undefined) {
async function addEnvSystem(name: string, valGiven: string | undefined, options: AddEnvOptions) {
const val = valGiven ?? ""
switch (process.platform) {
case "win32": {
if (options.shouldAddOnlyIfNotDefined) {
if (process.env[name] !== undefined) {
info(`Environment variable ${name} is already defined. Skipping.`)
return
}
}
// We do not use `execaSync(`setx PATH "${path};%PATH%"`)` because of its character limit
await execPowershell(`[Environment]::SetEnvironmentVariable('${name}', '${val}', "User")`)
info(`${name}='${val}' was set in the environment.`)
@ -77,8 +105,13 @@ async function addEnvSystem(name: string, valGiven: string | undefined) {
case "linux":
case "darwin": {
await setupCppInProfile()
appendFileSync(cpprc_path, `\nexport ${name}="${val}"\n`)
info(`${name}="${val}" was added to "${cpprc_path}`)
if (options.shouldAddOnlyIfNotDefined) {
appendFileSync(cpprc_path, `\nif [ -z "\${${name}}" ]; then export ${name}="${val}"; fi\n`)
info(`if not defined ${name} then ${name}="${val}" was added to "${cpprc_path}`)
} else {
appendFileSync(cpprc_path, `\nexport ${name}="${val}"\n`)
info(`${name}="${val}" was added to "${cpprc_path}`)
}
return
}
default: {
@ -111,6 +144,7 @@ async function addPathSystem(path: string) {
}
}
/* eslint-disable require-atomic-updates */
let setupCppInProfile_called = false
/// handles adding conditions to source .cpprc file from .bashrc and .profile

View File

@ -3,18 +3,24 @@ import { getUbuntuVersion } from "ubuntu-version"
import which from "which"
import { setupAptPack } from "../setup/setupAptPack"
import { isUbuntu } from "./isUbuntu"
import os from "os"
import memoize from "micro-memoize"
export async function ubuntuVersion(): Promise<number[] | null> {
async function ubuntuVersion_raw(): Promise<number[] | null> {
try {
if (isUbuntu()) {
if (which.sync("lsb_release", { nothrow: true }) === null) {
await setupAptPack([{ name: "lsb-release" }])
try {
if (which.sync("lsb_release", { nothrow: true }) === null) {
await setupAptPack([{ name: "lsb-release" }])
}
} catch {
return detectUsingOsVersion()
}
const versionSplitted = await getUbuntuVersion()
if (versionSplitted.length === 0) {
warning("Failed to get the ubuntu major version.")
return null
return detectUsingOsVersion()
}
return versionSplitted
@ -26,3 +32,18 @@ export async function ubuntuVersion(): Promise<number[] | null> {
return null
}
}
/** Detect Ubuntu version */
export const ubuntuVersion = memoize(ubuntuVersion_raw)
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
function detectUsingOsVersion() {
// #46~22.04.1-Ubuntu SMP ...
const osVersion = os.version()
const versionSplitted = osVersion.split(".")
const majorVersion = parseInt(versionSplitted[0].replace("#", ""), 10)
const minorVersion = parseInt(versionSplitted[1].replace("~", ""), 10)
const patchVersion = parseInt(versionSplitted[2].split("-")[0], 10)
return [majorVersion, minorVersion, patchVersion]
}

View File

@ -1,7 +1,5 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRoot, execRootSync } from "admina"
import { info } from "@actions/core"
import { GITHUB_ACTIONS } from "ci-info"
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"
import which from "which"
@ -10,7 +8,9 @@ import { promises as fsPromises } from "fs"
const { appendFile } = fsPromises
import { execa } from "execa"
import escapeRegex from "escape-string-regexp"
import { warning, info } from "ci-log"
/* eslint-disable require-atomic-updates */
let didUpdate: boolean = false
let didInit: boolean = false
@ -62,16 +62,24 @@ async function getAptArg(name: string, version: string | undefined) {
const { stdout } = await execa("apt-cache", [
"search",
"--names-only",
`^${escapeRegex(name)}\-${escapeRegex(version)}$`,
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
])
if (stdout.trim() !== "") {
return `${name}-${version}`
} else {
return `${name}=${version}`
try {
// check if apt-get show can find the version
const { stdout: showStdout } = await execa("apt-cache", ["show", `${name}=${version}`])
if (showStdout.trim() === "") {
return `${name}=${version}`
}
} catch {
// ignore
}
warning(`Failed to install ${name} ${version} via apt, trying without version`)
}
} else {
return name
}
return name
}
function getApt() {
@ -99,13 +107,16 @@ async function initApt(apt: string) {
"ca-certificates",
"gnupg",
])
const promises: Promise<any>[] = [
const promises: Promise<string | void>[] = [
addAptKeyViaServer(["3B4FE6ACC0B21F32", "40976EAF437D05B5"], "setup-cpp-ubuntu-archive.gpg"),
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
]
if (apt === "nala") {
// enable utf8 otherwise it fails because of the usage of ASCII encoding
promises.push(addEnv("LANG", "C.UTF-8"), addEnv("LC_ALL", "C.UTF-8"))
promises.push(
addEnv("LANG", "C.UTF-8", { shouldAddOnlyIfNotDefined: true }),
addEnv("LC_ALL", "C.UTF-8", { shouldAddOnlyIfNotDefined: true })
)
}
await Promise.all(promises)
}
@ -115,26 +126,31 @@ function initGpg() {
}
export async function addAptKeyViaServer(keys: string[], name: string, server = "keyserver.ubuntu.com") {
const fileName = `/etc/apt/trusted.gpg.d/${name}`
if (!(await pathExists(fileName))) {
initGpg()
try {
const fileName = `/etc/apt/trusted.gpg.d/${name}`
if (!(await pathExists(fileName))) {
initGpg()
await Promise.all(
keys.map(async (key) => {
await execRoot("gpg", [
"--no-default-keyring",
"--keyring",
`gnupg-ring:${fileName}`,
"--keyserver",
server,
"--recv-keys",
key,
])
await execRoot("chmod", ["644", fileName])
})
)
await Promise.all(
keys.map(async (key) => {
await execRoot("gpg", [
"--no-default-keyring",
"--keyring",
`gnupg-ring:${fileName}`,
"--keyserver",
server,
"--recv-keys",
key,
])
await execRoot("chmod", ["644", fileName])
})
)
}
return fileName
} catch (err) {
warning(`Failed to add apt key via server ${server}: ${err}`)
return undefined
}
return fileName
}
export async function addAptKeyViaDownload(name: string, url: string) {

View File

@ -34,6 +34,7 @@ export type InstallationInfo = {
/** The top install dir */
installDir?: string
binDir: string
bin?: string
}
let didInit: boolean = false
@ -104,9 +105,7 @@ export async function setupBin(
info(`Installing extraction dependencies`)
if (process.platform === "linux") {
if (isArch()) {
setupPacmanPack("unzip")
setupPacmanPack("tar")
setupPacmanPack("xz")
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
} else if (hasDnf()) {
setupDnfPack("unzip")
setupDnfPack("tar")

View File

@ -1,13 +1,14 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRootSync } from "admina"
import { info } from "ci-log"
import { info, warning } from "ci-log"
import { execa } from "execa"
/* eslint-disable require-atomic-updates */
let didUpdate: boolean = false
let didInit: boolean = false
/** A function that installs a package using pacman */
export function setupPacmanPack(name: string, version?: string, aur?: string): InstallationInfo {
export async function setupPacmanPack(name: string, version?: string, aur?: string): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pacman`)
const pacman = "pacman"
@ -18,21 +19,52 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
didUpdate = true
}
// install base-devel
if (!didInit) {
// install base-devel
execRootSync(pacman, ["-S", "--noconfirm", "base-devel"])
didInit = true
}
const runInstall = (arg: string) => {
return execRootSync(aur ?? pacman, ["-S", "--noconfirm", arg])
}
if (version !== undefined && version !== "") {
try {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`])
} catch {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`])
// check if version is available
const availableVersions = await availablePacmanVersions(pacman, name)
if (availableVersions.includes(version)) {
// try different version formats
try {
runInstall(`${name}=${version}`)
} catch {
runInstall(`${name}${version}`)
}
} else {
// try without version
info(`Failed to install ${name} ${version} via pacman, trying without version`)
runInstall(name)
}
} else {
execRootSync(aur ?? pacman, ["-S", "--noconfirm", name])
// version not specified, install latest
runInstall(name)
}
return { binDir: "/usr/bin/" }
}
const pacmanSiVersionRegex = /Version\s*:\s*(.*)/g
/** Query pacman for available versions */
async function availablePacmanVersions(pacman: string, name: string) {
const availableVersions = []
try {
const { stdout } = await execa(pacman, ["-Si", name])
for (const match of stdout.matchAll(pacmanSiVersionRegex)) {
availableVersions.push(match[1])
}
} catch (err) {
warning(`Failed to get available versions for ${name}: ${err}`)
}
return availableVersions
}

View File

@ -1,45 +1,57 @@
/* eslint-disable require-atomic-updates */
import { info } from "@actions/core"
import { execaSync } from "execa"
import { pathExists } from "path-exists"
import { addExeExt, dirname, join } from "patha"
import which from "which"
import { addPythonBaseExecPrefix, setupPythonAndPip } from "../../python/python"
import { addPythonBaseExecPrefix, setupPython } from "../../python/python"
import { addPath } from "../env/addEnv"
import { InstallationInfo } from "./setupBin"
let python: string | undefined
let binDirs: string[] | undefined
import { getVersion } from "../../versions/versions"
import { ubuntuVersion } from "../env/ubuntu_version"
import memoize from "micro-memoize"
/** A function that installs a package using pip */
export async function setupPipPack(name: string, version?: string): Promise<InstallationInfo> {
export async function setupPipPack(name: string, version?: string, upgrade = false): Promise<InstallationInfo> {
return setupPipPackWithPython(await getPython(), name, version, upgrade)
}
export async function setupPipPackWithPython(
givenPython: string,
name: string,
version?: string,
upgrade = false
): Promise<InstallationInfo> {
info(`Installing ${name} ${version ?? ""} via pip`)
if (python === undefined) {
python = await setupPythonAndPip()
}
const nameAndVersion = version !== undefined && version !== "" ? `${name}==${version}` : name
const upgradeFlag = upgrade === true ? ["--upgrade"] : []
execaSync(python, ["-m", "pip", "install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
execaSync(givenPython, ["-m", "pip", "install", ...upgradeFlag, nameAndVersion], {
stdio: "inherit",
})
if (binDirs === undefined) {
binDirs = await addPythonBaseExecPrefix(python)
}
const binDir = await findBinDir(binDirs, name)
const execPaths = await addPythonBaseExecPrefix(givenPython)
const binDir = await findBinDir(execPaths, name)
await addPath(binDir)
return { binDir }
}
async function getPython_raw(): Promise<string> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
if (pythonBin === undefined) {
throw new Error("Python binary was not found")
}
return pythonBin
}
const getPython = memoize(getPython_raw)
async function findBinDir(dirs: string[], name: string) {
const exists = await Promise.all(dirs.map((dir) => pathExists(join(dir, addExeExt(name)))))
const dirIndex = exists.findIndex((exist) => exist)
const foundDir = dirs[dirIndex]
if (foundDir !== undefined) {
if (dirIndex !== -1) {
const foundDir = dirs[dirIndex]
return foundDir
}

View File

@ -12,7 +12,13 @@ import { info } from "ci-log"
export function getSpecificVersions(versions: Set<string>, semversion: string): string[] {
return Array.from(versions)
.filter((v) => /^\d+\.\d+\.\d+$/.test(v) && v.startsWith(semversion))
.sort()
.sort((a, b) => {
try {
return semverCompare(a, b)
} catch (err) {
return a.localeCompare(b)
}
})
.reverse()
}
@ -49,16 +55,21 @@ export async function getSpecificVersionAndUrl(
// if the given set doesn't include the version, throw an error
if (!versions.has(version)) {
throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`)
throw new Error(
`Unsupported target! (platform='${platform}', version='${version}'). Try one of the following: ${JSON.stringify(
versions
)}`
)
}
const offlineUrls: string[] = []
// TODO use Promise.any
for (const specificVersion of getSpecificVersions(versions, version)) {
// eslint-disable-next-line no-await-in-loop
const url = await getUrl(platform, specificVersion)
// eslint-disable-next-line no-await-in-loop
if (url !== null) {
// eslint-disable-next-line no-await-in-loop
if (await isUrlOnline(url)) {
return [specificVersion, url]
} else {
@ -68,8 +79,8 @@ export async function getSpecificVersionAndUrl(
}
throw new Error(
`Unsupported target! (platform='${platform}', version='${version}'). The offline urls tested:\n${offlineUrls.join(
"\n"
`Unsupported target! (platform='${platform}', version='${version}'). Try one of the following: ${JSON.stringify(
versions
)}`
)
}

View File

@ -21,12 +21,14 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
if (process.platform === "linux") {
// vcpkg download and extraction dependencies
if (isArch()) {
setupPacmanPack("curl")
setupPacmanPack("zip")
setupPacmanPack("unzip")
setupPacmanPack("tar")
setupPacmanPack("git")
setupPacmanPack("pkg-config")
await Promise.all([
setupPacmanPack("curl"),
setupPacmanPack("zip"),
setupPacmanPack("unzip"),
setupPacmanPack("tar"),
setupPacmanPack("git"),
setupPacmanPack("pkg-config"),
])
} else if (hasDnf()) {
setupDnfPack("curl")
setupDnfPack("zip")

View File

@ -15,27 +15,32 @@ function getLLVMDefault() {
}
}
export const DefaultVersions: Record<string, string> = {
export const DefaultVersions: Record<string, string | undefined> = {
llvm: getLLVMDefault(), // https://github.com/llvm/llvm-project/releases
clangtidy: getLLVMDefault(),
clangformat: getLLVMDefault(),
ninja: "1.11.1", // https://github.com/ninja-build/ninja/releases
cmake: "3.25.1", // https://github.com/Kitware/CMake/releases
cmake: "3.26.4", // https://github.com/Kitware/CMake/releases
gcovr: "5.2", // https://pypi.org/project/gcovr/
conan: "1.57.0", // https://github.com/conan-io/conan/releases
meson: "1.0.0", // https://github.com/mesonbuild/meson/releases
kcov: "40", // https://github.com/SimonKagstrom/kcov/releases
task: "3.20.0", // https://github.com/go-task/task/releases
doxygen: isArch() ? "1.9.6-1" : "1.9.6", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
gcc: isArch() ? "12.2.1-2" : "12", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
conan: "1.60.0", // https://github.com/conan-io/conan/releases
meson: "1.0.2", // https://github.com/mesonbuild/meson/releases
kcov: "41", // https://github.com/SimonKagstrom/kcov/releases
task: "3.25.0", // https://github.com/go-task/task/releases
doxygen: isArch() ? "1.9.6-1" : "1.9.7", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
gcc: isArch() ? "13.1.1-1" : "13", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
}
export const MinVersions: Record<string, string | undefined> = {
pip: "22.3.1",
python: "3.7.9",
}
/// If an ubuntu versions is not in this map:
// - the newer ubuntu versions use the first entry (e.g. v20),
// - the older ones use ""
export const DefaultLinuxVersion: Record<string, Record<number, string>> = {
export const DefaultLinuxVersion: Record<string, Record<number, string> | undefined> = {
gcc: {
22: "12",
22: "13",
20: "11",
18: "11",
16: "11",

View File

@ -1,32 +1,35 @@
import { Inputs, Opts } from "../main"
import { Opts } from "../cli-options"
import { Inputs } from "../tool"
import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
/** Get the default version if passed true or undefined, otherwise return the version itself */
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
if (isDefault(version, name)) {
if (process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
return getDefaultLinuxVersion(name, osVersion)
}
// anything else
return DefaultVersions[name]
} else {
return version ?? ""
console.log("isDefault", version, name, isVersionDefault(version))
if (isVersionDefault(version) && process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
return getDefaultLinuxVersion(osVersion, DefaultLinuxVersion[name]!)
} else if (isVersionDefault(version) && name in DefaultVersions) {
return DefaultVersions[name]!
} else if (version === "true") {
return ""
}
return version ?? ""
}
function isVersionDefault(version: string | undefined) {
return version === "true" || version === undefined
}
/// choose the default linux version based on ubuntu version
function getDefaultLinuxVersion(name: string, osVersion: number[]) {
function getDefaultLinuxVersion(osVersion: number[], toolLinuxVersions: Record<number, string>) {
const osVersionMaj = osVersion[0]
const newest = parseInt(Object.keys(DefaultLinuxVersion[name])[0], 10) // newest version with the default
if (osVersionMaj >= newest) {
return DefaultLinuxVersion[name][osVersionMaj]
} else {
return ""
}
}
export function isDefault(version: string | undefined, name: string) {
return version === "true" || (version === undefined && name in DefaultVersions)
// find which version block the os version is in
const satisfyingVersion = Object.keys(toolLinuxVersions)
.map((v) => parseInt(v, 10))
.sort((a, b) => b - a) // sort in descending order
.find((v) => osVersionMaj >= v)
return satisfyingVersion === undefined ? "" : toolLinuxVersions[satisfyingVersion]
}
/**
@ -36,7 +39,7 @@ export function isDefault(version: string | undefined, name: string) {
*/
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isVersionDefault(opts[tool]))
const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"

View File

@ -18,11 +18,11 @@
"removeComments": false,
"skipLibCheck": true,
"lib": ["ES2020", "dom"],
"target": "ES2020",
"target": "ESNext",
"allowJs": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"module": "esnext",
"module": "ESNext",
"moduleResolution": "node",
"importHelpers": false,
"outDir": "./dist"