mirror of https://github.com/aminya/setup-cpp
fix: fix setupBin
This commit is contained in:
parent
c6eb5ca89b
commit
ec22e0200a
|
@ -6,7 +6,7 @@ jest.setTimeout(300000)
|
||||||
describe("setup-cmake", () => {
|
describe("setup-cmake", () => {
|
||||||
let directory: string
|
let directory: string
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
directory = await setupTmpDir("setup-cmake")
|
directory = await setupTmpDir("cmake")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should setup CMake", async () => {
|
it("should setup CMake", async () => {
|
||||||
|
@ -21,6 +21,6 @@ describe("setup-cmake", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await cleanupTmpDir("setup-cmake")
|
await cleanupTmpDir("cmake")
|
||||||
}, 100000)
|
}, 100000)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,7 @@ 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, InstallationInfo } from "../utils/setup/setupBin"
|
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
|
||||||
|
import { addBinExtension } from "../utils/extension/extension"
|
||||||
|
|
||||||
/** 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 {
|
||||||
|
@ -21,6 +22,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
|
||||||
const folderName = `cmake-${version}-${osArchStr}`
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "bin/",
|
binRelativeDir: "bin/",
|
||||||
|
binFileName: addBinExtension("cmake"),
|
||||||
extractedFolderName: folderName,
|
extractedFolderName: folderName,
|
||||||
extractFunction: extractZip,
|
extractFunction: extractZip,
|
||||||
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.zip`,
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.zip`,
|
||||||
|
@ -32,6 +34,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
|
||||||
const folderName = `cmake-${version}-${osArchStr}`
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "CMake.app/Contents/bin/",
|
binRelativeDir: "CMake.app/Contents/bin/",
|
||||||
|
binFileName: addBinExtension("cmake"),
|
||||||
extractedFolderName: folderName,
|
extractedFolderName: folderName,
|
||||||
extractFunction: extractTar,
|
extractFunction: extractTar,
|
||||||
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
|
||||||
|
@ -48,6 +51,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
|
||||||
const folderName = `cmake-${version}-${osArchStr}`
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "bin/",
|
binRelativeDir: "bin/",
|
||||||
|
binFileName: addBinExtension("cmake"),
|
||||||
extractedFolderName: folderName,
|
extractedFolderName: folderName,
|
||||||
extractFunction: extractTar,
|
extractFunction: extractTar,
|
||||||
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
|
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
|
||||||
|
|
|
@ -15,7 +15,7 @@ async function testUrl(version: string) {
|
||||||
describe("setup-llvm", () => {
|
describe("setup-llvm", () => {
|
||||||
let directory: string
|
let directory: string
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
directory = await setupTmpDir("setup-llvm")
|
directory = await setupTmpDir("llvm")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Finds valid LLVM URLs", async () => {
|
it("Finds valid LLVM URLs", async () => {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin
|
||||||
import { extractExe, extractTarByExe } from "../utils/setup/extract"
|
import { extractExe, extractTarByExe } from "../utils/setup/extract"
|
||||||
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version"
|
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version"
|
||||||
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
|
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
|
||||||
|
import { addBinExtension } from "../utils/extension/extension"
|
||||||
|
|
||||||
//================================================
|
//================================================
|
||||||
// Version
|
// Version
|
||||||
|
@ -227,6 +228,7 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
|
||||||
url,
|
url,
|
||||||
extractedFolderName: "",
|
extractedFolderName: "",
|
||||||
binRelativeDir: "bin",
|
binRelativeDir: "bin",
|
||||||
|
binFileName: addBinExtension("clang"),
|
||||||
extractFunction: platform === "win32" ? extractExe : extractTarByExe,
|
extractFunction: platform === "win32" ? extractExe : extractTarByExe,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ async function testNinja(directory: string) {
|
||||||
describe("setup-ninja", () => {
|
describe("setup-ninja", () => {
|
||||||
let directory: string
|
let directory: string
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
directory = await setupTmpDir("setup-ninja")
|
directory = await setupTmpDir("ninja")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should setup Ninja", async () => {
|
it("should setup Ninja", async () => {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { extractZip } from "@actions/tool-cache"
|
import { extractZip } from "@actions/tool-cache"
|
||||||
|
import { addBinExtension } from "../utils/extension/extension"
|
||||||
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
|
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
|
||||||
|
|
||||||
/** Get the platform name Ninja uses in their download links */
|
/** Get the platform name Ninja uses in their download links */
|
||||||
|
@ -20,6 +21,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
|
||||||
const ninjaPlatform = getNinjaPlatform(platform)
|
const ninjaPlatform = getNinjaPlatform(platform)
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "",
|
binRelativeDir: "",
|
||||||
|
binFileName: addBinExtension("ninja"),
|
||||||
extractedFolderName: "",
|
extractedFolderName: "",
|
||||||
extractFunction: extractZip,
|
extractFunction: extractZip,
|
||||||
url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`,
|
url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`,
|
||||||
|
|
|
@ -14,6 +14,8 @@ export type PackageInfo = {
|
||||||
extractedFolderName: string
|
extractedFolderName: string
|
||||||
/** The relative directory in which the binary is located. It can be `""` if the exe is in the top folder */
|
/** The relative directory in which the binary is located. It can be `""` if the exe is in the top folder */
|
||||||
binRelativeDir: string
|
binRelativeDir: string
|
||||||
|
/** The main binary file. */
|
||||||
|
binFileName: string
|
||||||
/** The function to extract the downloaded archive. It can be `undefined`, if the binary itself is downloaded directly. */
|
/** The function to extract the downloaded archive. It can be `undefined`, if the binary itself is downloaded directly. */
|
||||||
extractFunction?: {
|
extractFunction?: {
|
||||||
(file: string, dest: string): Promise<string> | Promise<void>
|
(file: string, dest: string): Promise<string> | Promise<void>
|
||||||
|
@ -42,36 +44,42 @@ export async function setupBin(
|
||||||
setupDir: string
|
setupDir: string
|
||||||
): Promise<InstallationInfo> {
|
): Promise<InstallationInfo> {
|
||||||
process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
|
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_CACH ?? join(tmpdir(), "setup-cpp", "ToolCache")
|
||||||
|
|
||||||
const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform)
|
const { url, binRelativeDir, binFileName, extractedFolderName, extractFunction } = await getPackageInfo(
|
||||||
|
version,
|
||||||
|
process.platform
|
||||||
|
)
|
||||||
|
|
||||||
// Restore from cache (if found).
|
// Restore from cache (if found).
|
||||||
if (isCI()) {
|
if (isCI()) {
|
||||||
try {
|
try {
|
||||||
const dir = find(name, version)
|
const dir = find(name, version)
|
||||||
if (dir) {
|
if (dir) {
|
||||||
info(`${name} ${version} was found in the cache.`)
|
|
||||||
const installDir = join(dir, extractedFolderName)
|
const installDir = join(dir, extractedFolderName)
|
||||||
const binDir = join(installDir, binRelativeDir)
|
const binDir = join(installDir, binRelativeDir)
|
||||||
|
if (existsSync(binDir) && existsSync(join(binRelativeDir, binFileName))) {
|
||||||
|
info(`${name} ${version} was found in the cache.`)
|
||||||
addPath(binDir)
|
addPath(binDir)
|
||||||
return { installDir, binDir }
|
return { installDir, binDir }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// fails on a local machine?
|
// fails on a local machine?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const installDir = join(setupDir, extractedFolderName)
|
||||||
|
const binDir = join(installDir, binRelativeDir)
|
||||||
|
const binFile = join(binDir, binFileName)
|
||||||
|
|
||||||
// download ane extract the package into the installation directory.
|
// download ane extract the package into the installation directory.
|
||||||
if (!existsSync(setupDir)) {
|
if (!existsSync(binDir) || !existsSync(binFile)) {
|
||||||
info(`Download and extract ${name} ${version}`)
|
info(`Download and extract ${name} ${version}`)
|
||||||
const downloaded = await downloadTool(url)
|
const downloaded = await downloadTool(url)
|
||||||
await extractFunction?.(downloaded, setupDir)
|
await extractFunction?.(downloaded, setupDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
const installDir = join(setupDir, extractedFolderName)
|
|
||||||
const binDir = join(installDir, binRelativeDir)
|
|
||||||
|
|
||||||
// Adding the bin dir to the path
|
// Adding the bin dir to the path
|
||||||
/** The directory which the tool is installed to */
|
/** The directory which the tool is installed to */
|
||||||
info(`Add ${binDir} to PATH`)
|
info(`Add ${binDir} to PATH`)
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
import { setupVcpkg } from "../vcpkg"
|
import { setupVcpkg } from "../vcpkg"
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { testBin, setupTmpDir } from "../../utils/tests/test-helpers"
|
||||||
|
|
||||||
jest.setTimeout(300000)
|
jest.setTimeout(300000)
|
||||||
async function testvcpkg() {
|
async function testvcpkg(directory: string) {
|
||||||
const { binDir } = await setupVcpkg("", "", "")
|
const { binDir } = await setupVcpkg("", directory, "")
|
||||||
await testBin("vcpkg", ["--version"], binDir)
|
await testBin("vcpkg", ["--version"], binDir)
|
||||||
return binDir
|
return binDir
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("setup-vcpkg", () => {
|
describe("setup-vcpkg", () => {
|
||||||
|
let directory: string
|
||||||
|
beforeAll(async () => {
|
||||||
|
directory = await setupTmpDir("vcpkg")
|
||||||
|
})
|
||||||
|
|
||||||
it("should setup vcpkg", async () => {
|
it("should setup vcpkg", async () => {
|
||||||
await testvcpkg()
|
await testvcpkg(directory)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { addPath } from "@actions/core"
|
import { addPath, warning } from "@actions/core"
|
||||||
import execa from "execa"
|
import execa from "execa"
|
||||||
import path, { dirname } from "path"
|
import { existsSync } from "fs"
|
||||||
|
import { dirname, join } from "path"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { addShellExtension, addShellHere } from "../utils/extension/extension"
|
import { addShellExtension, addShellHere } from "../utils/extension/extension"
|
||||||
import { InstallationInfo } from "../utils/setup/setupBin"
|
import { InstallationInfo } from "../utils/setup/setupBin"
|
||||||
|
@ -10,12 +11,16 @@ let hasVCPKG = false
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
|
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
|
||||||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||||
|
if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
|
||||||
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
|
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
|
||||||
|
} else {
|
||||||
|
warning(`Vcpkg folder already exists at ${setupDir}`)
|
||||||
|
}
|
||||||
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
|
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
|
||||||
addPath(setupDir)
|
addPath(setupDir)
|
||||||
hasVCPKG = true
|
hasVCPKG = true
|
||||||
return { binDir: setupDir }
|
return { binDir: setupDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
return { binDir: path.dirname(which.sync("vcpkg")) }
|
return { binDir: dirname(which.sync("vcpkg")) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue