fix: use setup bin for llvm installation

This commit is contained in:
Amin Yahyaabadi 2021-09-14 08:50:26 -05:00
parent 64f3cf193b
commit 9bf59efb6c
4 changed files with 20 additions and 36 deletions

View File

@ -2,7 +2,7 @@ import { extractZip, extractTar } from "@actions/tool-cache"
import { getInput } from "@actions/core" import { getInput } from "@actions/core"
import semverLte from "semver/functions/lte" import semverLte from "semver/functions/lte"
import semverCoerce from "semver/functions/coerce" import semverCoerce from "semver/functions/coerce"
import { setupBin, PackageInfo } from "../utils/setup/setupBin" import { setupPackage, PackageInfo } from "../utils/setup/setupBin"
/** Get the platform data for cmake */ /** Get the platform data for cmake */
function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo { function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo {
@ -60,5 +60,5 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
/** Setup cmake */ /** Setup cmake */
export function setupCmake(version: string, setupCppDir: string): Promise<string> { export function setupCmake(version: string, setupCppDir: string): Promise<string> {
return setupBin("cmake", version, getCmakePackageInfo, setupCppDir) return setupPackage("cmake", version, getCmakePackageInfo, setupCppDir)
} }

View File

@ -1,10 +1,9 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import * as exec from "@actions/exec"
import * as io from "@actions/io"
import * as tc from "@actions/tool-cache" import * as tc from "@actions/tool-cache"
import * as path from "path" import * as path from "path"
import semverLte from "semver/functions/lte" import semverLte from "semver/functions/lte"
import { isValidUrl } from "../utils/http/validate_url" import { isValidUrl } from "../utils/http/validate_url"
import { PackageInfo, setupPackage } from "../utils/setup/setupBin"
//================================================ //================================================
// Version // Version
@ -263,32 +262,23 @@ export async function getSpecificVersionAndUrl(platform: string, version: string
const DEFAULT_NIX_DIRECTORY = "./llvm" const DEFAULT_NIX_DIRECTORY = "./llvm"
const DEFAULT_WIN32_DIRECTORY = "C:/Program Files/LLVM" const DEFAULT_WIN32_DIRECTORY = "C:/Program Files/LLVM"
async function install(version: string, directory: string): Promise<void> { async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise<PackageInfo> {
const platform = process.platform
const [specificVersion, url] = await getSpecificVersionAndUrl(platform, version) const [specificVersion, url] = await getSpecificVersionAndUrl(platform, version)
core.setOutput("version", specificVersion) core.setOutput("version", specificVersion)
return {
core.info(`Installing LLVM and Clang ${version} (${specificVersion})...`) url,
core.info(`Downloading and extracting '${url}'...`) extractedFolderName: "",
const archive = await tc.downloadTool(url) binRelativeDir: "bin",
extractFunction:
let exit platform === "win32"
if (platform === "win32") { ? tc.extractZip
exit = await exec.exec("7z", ["x", archive, `-o${directory}`]) : (file: string, dest: string) => {
} else { return tc.extractTar(file, dest, "--strip-components=1")
await io.mkdirP(directory) },
exit = await exec.exec("tar", ["xf", archive, "-C", directory, "--strip-components=1"]) }
} }
if (exit !== 0) { export async function setupLLVM(version: string, directoryGiven?: string): Promise<void> {
throw new Error("Could not extract LLVM and Clang binaries.")
}
core.info(`Installed LLVM and Clang ${version} (${specificVersion})!`)
core.info(`Install location: ${directory}`)
}
export async function setupLLVM(version: string, directoryGiven?: string, cached: boolean = false): Promise<void> {
let directory = directoryGiven let directory = directoryGiven
if (directory === "" || directory === undefined) { if (directory === "" || directory === undefined) {
directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY directory = process.platform === "win32" ? DEFAULT_WIN32_DIRECTORY : DEFAULT_NIX_DIRECTORY
@ -296,17 +286,11 @@ export async function setupLLVM(version: string, directoryGiven?: string, cached
directory = path.resolve(directory) directory = path.resolve(directory)
if (cached) { await setupPackage("llvm", version, getLLVMPackageInfo, directory)
core.info(`Using cached LLVM and Clang ${version}...`)
} else {
await install(version, directory)
}
const bin = path.join(directory, "bin") // Adding environment variables
const lib = path.join(directory, "lib") const lib = path.join(directory, "lib")
core.addPath(bin)
const ld = process.env.LD_LIBRARY_PATH ?? "" const ld = process.env.LD_LIBRARY_PATH ?? ""
const dyld = process.env.DYLD_LIBRARY_PATH ?? "" const dyld = process.env.DYLD_LIBRARY_PATH ?? ""

View File

@ -1,5 +1,5 @@
import { extractZip } from "@actions/tool-cache" import { extractZip } from "@actions/tool-cache"
import { setupBin, PackageInfo } from "../utils/setup/setupBin" import { setupPackage, PackageInfo } from "../utils/setup/setupBin"
/** Get the platform name Ninja uses in their download links */ /** Get the platform name Ninja uses in their download links */
function getNinjaPlatform(platform: NodeJS.Platform) { function getNinjaPlatform(platform: NodeJS.Platform) {
@ -27,5 +27,5 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
} }
export function setupNinja(version: string, setupCppDir: string): Promise<string> { export function setupNinja(version: string, setupCppDir: string): Promise<string> {
return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir) return setupPackage("ninja", version, getNinjaPackageInfo, setupCppDir)
} }

View File

@ -28,7 +28,7 @@ export type PackageInfo = {
* *
* @returns The installation directory * @returns The installation directory
*/ */
export async function setupBin( export async function setupPackage(
name: string, name: string,
version: string, version: string,
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo | Promise<PackageInfo>, getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo | Promise<PackageInfo>,