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

View File

@ -1,5 +1,5 @@
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 */
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> {
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
*/
export async function setupBin(
export async function setupPackage(
name: string,
version: string,
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo | Promise<PackageInfo>,