diff --git a/src/cmake/cmake.ts b/src/cmake/cmake.ts index 743195d3..1a5771bc 100644 --- a/src/cmake/cmake.ts +++ b/src/cmake/cmake.ts @@ -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 { - return setupBin("cmake", version, getCmakePackageInfo, setupCppDir) + return setupPackage("cmake", version, getCmakePackageInfo, setupCppDir) } diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index d0c9e17b..704df349 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -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 { - const platform = process.platform +async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise { 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 { +export async function setupLLVM(version: string, directoryGiven?: string): Promise { 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 ?? "" diff --git a/src/ninja/ninja.ts b/src/ninja/ninja.ts index 49f67794..fdc8e033 100644 --- a/src/ninja/ninja.ts +++ b/src/ninja/ninja.ts @@ -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 { - return setupBin("ninja", version, getNinjaPackageInfo, setupCppDir) + return setupPackage("ninja", version, getNinjaPackageInfo, setupCppDir) } diff --git a/src/utils/setup/setupBin.ts b/src/utils/setup/setupBin.ts index 6456207f..0b2d05a0 100644 --- a/src/utils/setup/setupBin.ts +++ b/src/utils/setup/setupBin.ts @@ -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,