feat: support passing arch from CLI to setupBin

This commit is contained in:
Amin Yahyaabadi 2022-01-30 15:33:22 -08:00
parent 0fe9b461ac
commit a062ce6962
7 changed files with 24 additions and 36 deletions

2
dist/setup_cpp.js vendored

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,16 +1,13 @@
import { extractZip, extractTar } from "@actions/tool-cache"
import { getInput } from "@actions/core"
import semverLte from "semver/functions/lte"
import semverCoerce from "semver/functions/coerce"
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
import { addBinExtension } from "../utils/extension/extension"
/** Get the platform data for cmake */
function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo {
function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
const semVersion = semverCoerce(version) ?? version
const platformStr = platform ?? process.platform
const arch = getInput("architecture") || process.arch
switch (platformStr) {
switch (platform) {
case "win32": {
const isOld = semverLte(semVersion, "v3.19.6")
let osArchStr: string
@ -58,12 +55,11 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
}
}
default:
throw new Error(`Unsupported platform '${platformStr}'`)
throw new Error(`Unsupported platform '${platform}'`)
}
}
/** Setup cmake */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCmake(version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("cmake", version, getCmakePackageInfo, setupDir)
export function setupCmake(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("cmake", version, getCmakePackageInfo, setupDir, arch)
}

View File

@ -48,7 +48,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
export async function setupKcov(version: string, setupDir: string, arch: string) {
switch (process.platform) {
case "linux": {
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir)
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
return installationInfo
}
default: {

View File

@ -222,8 +222,8 @@ export function getUrl(platform: string, version: string): string | null | Promi
//================================================
// Exports
//================================================
async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise<PackageInfo> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): Promise<PackageInfo> {
const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, platform, version, getUrl)
setOutput("version", specificVersion)
return {
@ -235,13 +235,8 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
}
}
export async function setupLLVM(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
const installationInfo = await setupBin("llvm", version, getLLVMPackageInfo, setupDir)
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installationInfo = await setupBin("llvm", version, getLLVMPackageInfo, setupDir, arch)
await activateLLVM(installationInfo.installDir ?? setupDir, version)
return installationInfo
}
@ -284,11 +279,6 @@ export async function activateLLVM(directory: string, versionGiven: string) {
}
/** Setup llvm tools (clang tidy, clang format, etc) without activating llvm and using it as the compiler */
export function setupClangTools(
version: string,
setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
return setupBin("llvm", version, getLLVMPackageInfo, setupDir)
export function setupClangTools(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("llvm", version, getLLVMPackageInfo, setupDir, arch)
}

View File

@ -17,7 +17,8 @@ function getNinjaPlatform(platform: NodeJS.Platform) {
}
/** Get the platform data for ninja */
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): PackageInfo {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): PackageInfo {
const ninjaPlatform = getNinjaPlatform(platform)
return {
binRelativeDir: "",
@ -28,7 +29,6 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupNinja(version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
return setupBin("ninja", version, getNinjaPackageInfo, setupDir)
export function setupNinja(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("ninja", version, getNinjaPackageInfo, setupDir, arch)
}

View File

@ -41,15 +41,17 @@ export type InstallationInfo = {
export async function setupBin(
name: string,
version: string,
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo | Promise<PackageInfo>,
setupDir: string
getPackageInfo: (version: string, platform: NodeJS.Platform, arch: string) => PackageInfo | Promise<PackageInfo>,
setupDir: string,
arch: string
): Promise<InstallationInfo> {
process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup-cpp", "ToolCache")
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACHE ?? join(tmpdir(), "setup-cpp", "ToolCache")
const { url, binRelativeDir, binFileName, extractedFolderName, extractFunction } = await getPackageInfo(
version,
process.platform
process.platform,
arch
)
// Restore from cache (if found).