mirror of https://github.com/aminya/setup-cpp
Merge pull request #137 from aminya/refactor-version [skip ci]
This commit is contained in:
commit
73a098f0c6
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 { syncVersions, getVersion } from "../default_versions"
|
import { syncVersions, getVersion } from "../versions/versions"
|
||||||
import { getCompilerInfo, Inputs, parseArgs } from "../main"
|
import { getCompilerInfo, Inputs, parseArgs } from "../main"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { setupCmake } from "../cmake"
|
import { setupCmake } from "../cmake"
|
||||||
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupConan } from "../conan"
|
import { setupConan } from "../conan"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-conan", () => {
|
describe("setup-conan", () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupCppcheck } from "../cppcheck"
|
import { setupCppcheck } from "../cppcheck"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-cppcheck", () => {
|
describe("setup-cppcheck", () => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { setupDoxygen } from "../doxygen"
|
import { setupDoxygen } from "../doxygen"
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { InstallationInfo } from "../../utils/setup/setupBin"
|
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { addExeExt, join } from "patha"
|
||||||
import { extractTar, extractZip } from "../utils/setup/extract"
|
import { extractTar, extractZip } from "../utils/setup/extract"
|
||||||
import { notice } from "ci-log"
|
import { notice } from "ci-log"
|
||||||
import { setupGraphviz } from "../graphviz/graphviz"
|
import { setupGraphviz } from "../graphviz/graphviz"
|
||||||
import { getVersion } from "../default_versions"
|
import { getVersion } from "../versions/versions"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import { isArch } from "../utils/env/isArch"
|
import { isArch } from "../utils/env/isArch"
|
||||||
import { hasDnf } from "../utils/env/hasDnf"
|
import { hasDnf } from "../utils/env/hasDnf"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { setupGcc } from "../gcc"
|
import { setupGcc } from "../gcc"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { join, addExeExt } from "patha"
|
import { join, addExeExt } from "patha"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import { chmodSync } from "fs"
|
import { chmodSync } from "fs"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupGcovr } from "../gcovr"
|
import { setupGcovr } from "../gcovr"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { setupGraphviz } from "../graphviz"
|
import { setupGraphviz } from "../graphviz"
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { InstallationInfo } from "../../utils/setup/setupBin"
|
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-graphviz", () => {
|
describe("setup-graphviz", () => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import execa from "execa"
|
||||||
import { join, addExeExt } from "patha"
|
import { join, addExeExt } from "patha"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { setupCmake } from "../cmake/cmake"
|
import { setupCmake } from "../cmake/cmake"
|
||||||
import { getVersion } from "../default_versions"
|
import { getVersion } from "../versions/versions"
|
||||||
import { extractTarByExe } from "../utils/setup/extract"
|
import { extractTarByExe } from "../utils/setup/extract"
|
||||||
import { setupAptPack } from "../utils/setup/setupAptPack"
|
import { setupAptPack } from "../utils/setup/setupAptPack"
|
||||||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import ciDetect from "@npmcli/ci-detect"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import path, { addExeExt } from "patha"
|
import path, { addExeExt } from "patha"
|
||||||
import { chmodSync } from "fs"
|
import { chmodSync } from "fs"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
import * as io from "@actions/io"
|
import * as io from "@actions/io"
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { info, warning } from "ci-log"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { setupGcc } from "../gcc/gcc"
|
import { setupGcc } from "../gcc/gcc"
|
||||||
import { getVersion } from "../default_versions"
|
import { getVersion } from "../versions/versions"
|
||||||
import { isArch } from "../utils/env/isArch"
|
import { isArch } from "../utils/env/isArch"
|
||||||
import { isUbuntu } from "../utils/env/isUbuntu"
|
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||||
|
|
||||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -31,7 +31,7 @@ import numerousLocale from "numerous/locales/en.js"
|
||||||
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
import { ubuntuVersion } from "./utils/env/ubuntu_version"
|
||||||
|
|
||||||
import semverValid from "semver/functions/valid"
|
import semverValid from "semver/functions/valid"
|
||||||
import { getVersion, syncVersions } from "./default_versions"
|
import { getVersion, syncVersions } from "./versions/versions"
|
||||||
import { setupGcc } from "./gcc/gcc"
|
import { setupGcc } from "./gcc/gcc"
|
||||||
import { InstallationInfo } from "./utils/setup/setupBin"
|
import { InstallationInfo } from "./utils/setup/setupBin"
|
||||||
import { error, info, success, warning } from "ci-log"
|
import { error, info, success, warning } from "ci-log"
|
||||||
|
@ -148,13 +148,7 @@ export async function main(args: string[]): Promise<number> {
|
||||||
|
|
||||||
// installing the specified tools
|
// installing the specified tools
|
||||||
|
|
||||||
let osVersion: number[] | null = null
|
const osVersion = await ubuntuVersion()
|
||||||
try {
|
|
||||||
// get the version if not already done
|
|
||||||
osVersion = await ubuntuVersion()
|
|
||||||
} catch (err) {
|
|
||||||
warning((err as Error).toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
// sync the version for the llvm tools
|
// sync the version for the llvm tools
|
||||||
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {
|
if (!syncVersions(opts, ["llvm", "clangtidy", "clangformat"])) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupMeson } from "../meson"
|
import { setupMeson } from "../meson"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { setupNinja } from "../ninja"
|
import { setupNinja } from "../ninja"
|
||||||
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
async function testNinja(directory: string) {
|
async function testNinja(directory: string) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupPowershell } from "../powershell"
|
import { setupPowershell } from "../powershell"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-powershell", () => {
|
describe("setup-powershell", () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { setupPython } from "../python"
|
import { setupPython } from "../python"
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { info } from "ci-log"
|
import { info } from "ci-log"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { setupTask } from "../task"
|
import { setupTask } from "../task"
|
||||||
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import ciDetect from "@npmcli/ci-detect"
|
import ciDetect from "@npmcli/ci-detect"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
describe("setup-task", () => {
|
describe("setup-task", () => {
|
||||||
|
|
|
@ -1,21 +1,28 @@
|
||||||
|
import { warning } from "ci-log"
|
||||||
import { getUbuntuVersion } from "ubuntu-version"
|
import { getUbuntuVersion } from "ubuntu-version"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { setupAptPack } from "../setup/setupAptPack"
|
import { setupAptPack } from "../setup/setupAptPack"
|
||||||
import { isUbuntu } from "./isUbuntu"
|
import { isUbuntu } from "./isUbuntu"
|
||||||
|
|
||||||
export async function ubuntuVersion(): Promise<number[] | null> {
|
export async function ubuntuVersion(): Promise<number[] | null> {
|
||||||
if (isUbuntu()) {
|
try {
|
||||||
if (which.sync("lsb_release", { nothrow: true }) === null) {
|
if (isUbuntu()) {
|
||||||
await setupAptPack("lsb-release")
|
if (which.sync("lsb_release", { nothrow: true }) === null) {
|
||||||
}
|
await setupAptPack("lsb-release")
|
||||||
const versionSplitted = await getUbuntuVersion()
|
}
|
||||||
|
const versionSplitted = await getUbuntuVersion()
|
||||||
|
|
||||||
if (versionSplitted.length === 0) {
|
if (versionSplitted.length === 0) {
|
||||||
throw new Error("Failed to get the ubuntu major version.")
|
warning("Failed to get the ubuntu major version.")
|
||||||
}
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return versionSplitted
|
return versionSplitted
|
||||||
} else {
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
warning((err as Error).toString())
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { addPath } from "../env/addEnv"
|
||||||
import { setupPython } from "../../python/python"
|
import { setupPython } from "../../python/python"
|
||||||
import { isBinUptoDate } from "./version"
|
import { isBinUptoDate } from "./version"
|
||||||
import { join } from "patha"
|
import { join } from "patha"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../versions/versions"
|
||||||
import { InstallationInfo } from "./setupBin"
|
import { InstallationInfo } from "./setupBin"
|
||||||
import { setupAptPack } from "./setupAptPack"
|
import { setupAptPack } from "./setupAptPack"
|
||||||
import { setupPacmanPack } from "./setupPacmanPack"
|
import { setupPacmanPack } from "./setupPacmanPack"
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { Inputs, Opts } from "./main"
|
import { isArch } from "../utils/env/isArch"
|
||||||
import { isArch } from "./utils/env/isArch"
|
|
||||||
|
|
||||||
// passing "" to a tool installed by a package manager (apt, brew, choco) will result in the default version of that package manager.
|
// passing "" to a tool installed by a package manager (apt, brew, choco) will result in the default version of that package manager.
|
||||||
// the directly downloaded tools require a given version ("" doesn't work).
|
// the directly downloaded tools require a given version ("" doesn't work).
|
||||||
|
|
||||||
const DefaultVersions: Record<string, string> = {
|
export const DefaultVersions: Record<string, string> = {
|
||||||
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
|
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
|
||||||
clangtidy: "13.0.0",
|
clangtidy: "13.0.0",
|
||||||
clangformat: "13.0.0",
|
clangformat: "13.0.0",
|
||||||
|
@ -22,7 +21,7 @@ const DefaultVersions: Record<string, string> = {
|
||||||
/// If an ubuntu versions is not in this map:
|
/// If an ubuntu versions is not in this map:
|
||||||
// - the newer ubuntu versions use the first entry (e.g. v20),
|
// - the newer ubuntu versions use the first entry (e.g. v20),
|
||||||
// - the older ones use ""
|
// - the older ones use ""
|
||||||
const DefaultUbuntuVersion: Record<string, Record<number, string>> = {
|
export const DefaultLinuxVersion: Record<string, Record<number, string>> = {
|
||||||
llvm: {
|
llvm: {
|
||||||
22: "13.0.0-ubuntu-20.04",
|
22: "13.0.0-ubuntu-20.04",
|
||||||
20: "13.0.0-ubuntu-20.04",
|
20: "13.0.0-ubuntu-20.04",
|
||||||
|
@ -69,51 +68,3 @@ const DefaultUbuntuVersion: Record<string, Record<number, string>> = {
|
||||||
14: "40",
|
14: "40",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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 (useDefault(version, name)) {
|
|
||||||
// choose the default linux version based on ubuntu version
|
|
||||||
if (process.platform === "linux" && osVersion !== null && name in DefaultUbuntuVersion) {
|
|
||||||
const osVersionMaj = osVersion[0]
|
|
||||||
const newest = parseInt(Object.keys(DefaultUbuntuVersion[name])[0], 10) // newest version with the default
|
|
||||||
if (osVersionMaj >= newest) {
|
|
||||||
return DefaultUbuntuVersion[name][osVersionMaj]
|
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// anything else
|
|
||||||
return DefaultVersions[name]
|
|
||||||
} else {
|
|
||||||
return version ?? ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function useDefault(version: string | undefined, name: string) {
|
|
||||||
return version === "true" || (version === undefined && name in DefaultVersions)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
|
|
||||||
for (let i = 0; i < tools.length; i++) {
|
|
||||||
// tools excluding i_tool
|
|
||||||
const otherTools = tools.slice(0, i).concat(tools.slice(i + 1))
|
|
||||||
|
|
||||||
const tool = tools[i]
|
|
||||||
|
|
||||||
if (!useDefault(opts[tool], tool)) {
|
|
||||||
for (let i_other = 0; i_other < otherTools.length; i_other++) {
|
|
||||||
const otherTool = otherTools[i_other]
|
|
||||||
const useDefaultOtherTool = useDefault(opts[otherTool], otherTools[i_other])
|
|
||||||
if (useDefaultOtherTool) {
|
|
||||||
// use the same version if the other tool was requested with the default
|
|
||||||
opts[otherTool] = opts[tool]
|
|
||||||
} else if (opts[tool] !== opts[otherTools[i_other]]) {
|
|
||||||
// error if different from the other given versions
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { Inputs, Opts } from "../main"
|
||||||
|
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 ?? ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// choose the default linux version based on ubuntu version
|
||||||
|
function getDefaultLinuxVersion(name: string, osVersion: number[]) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
|
||||||
|
for (let i = 0; i < tools.length; i++) {
|
||||||
|
// tools excluding i_tool
|
||||||
|
const otherTools = tools.slice(0, i).concat(tools.slice(i + 1))
|
||||||
|
|
||||||
|
const tool = tools[i]
|
||||||
|
|
||||||
|
if (!isDefault(opts[tool], tool)) {
|
||||||
|
for (let i_other = 0; i_other < otherTools.length; i_other++) {
|
||||||
|
const otherTool = otherTools[i_other]
|
||||||
|
const useDefaultOtherTool = isDefault(opts[otherTool], otherTools[i_other])
|
||||||
|
if (useDefaultOtherTool) {
|
||||||
|
// use the same version if the other tool was requested with the default
|
||||||
|
opts[otherTool] = opts[tool]
|
||||||
|
} else if (opts[tool] !== opts[otherTools[i_other]]) {
|
||||||
|
// error if different from the other given versions
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Loading…
Reference in New Issue