fix: return default installation directory for apt and brew

This commit is contained in:
Amin Yahyaabadi 2021-09-16 10:54:27 -05:00
parent 596c9438b5
commit 8e56d264af
11 changed files with 29 additions and 15 deletions

View File

@ -1,11 +1,12 @@
import { setupCcache } from "../ccache"
import { testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
jest.setTimeout(200000)
describe("setup-ccache", () => {
it("should setup ccache", async () => {
await setupCcache("", "", "")
const installInfo = await setupCcache("", "", "")
await testBin("ccache")
await testBin("ccache", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
})
})

View File

@ -1,11 +1,12 @@
import { setupCppcheck } from "../cppcheck"
import { testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
jest.setTimeout(200000)
describe("setup-cppcheck", () => {
it("should setup cppcheck", async () => {
await setupCppcheck("", "", "")
const installInfo = await setupCppcheck("", "", "")
await testBin("cppcheck")
await testBin("cppcheck", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
})
})

View File

@ -9,7 +9,7 @@ export async function setupCppcheck(version: string | undefined, _setupCppDir: s
case "win32": {
await setupChocoPack("cppcheck", version)
addPath("C:\\Program Files\\Cppcheck")
break
return undefined
}
case "darwin": {
return setupBrewPack("cppcheck", version)

View File

@ -1,11 +1,12 @@
import { setupDoxygen } from "../doxygen"
import { testBin } from "../../utils/tests/test-helpers"
import { InstallationInfo } from "../../utils/setup/setupBin"
jest.setTimeout(200000)
describe("setup-doxygen", () => {
it("should setup doxygen", async () => {
await setupDoxygen("", "", "")
const installInfo = await setupDoxygen("", "", "")
await testBin("doxygen")
await testBin("doxygen", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
})
})

View File

@ -11,7 +11,7 @@ export async function setupDoxygen(version: string | undefined, _setupCppDir: st
await setupChocoPack("doxygen.install", version)
addPath("C:\\Program Files\\Graphviz\\bin")
addPath("C:\\Program Files\\doxygen\\bin")
break
return undefined
}
case "darwin": {
setupBrewPack("graphviz", version)

View File

@ -1,11 +1,12 @@
import { InstallationInfo } from "../../utils/setup/setupBin"
import { testBin } from "../../utils/tests/test-helpers"
import { setupGcc } from "../gcc"
jest.setTimeout(200000)
describe("setup-gcc", () => {
it("should setup gcc", async () => {
await setupGcc("", "", "")
const installInfo = await setupGcc("", "", "")
await testBin("g++")
await testBin("g++", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
})
})

View File

@ -16,7 +16,7 @@ export async function setupGcc(version: string, _setupCppDir: string, arch: stri
} else if (arch === "ia32") {
addPath("C:\\tools\\mingw32\\bin")
}
break
return undefined
}
case "darwin": {
return setupBrewPack("gcc", version)

View File

@ -1,11 +1,16 @@
/* eslint-disable require-atomic-updates */
import { exec } from "@actions/exec"
import { InstallationInfo } from "./setupBin"
import { mightSudo } from "./sudo"
let didUpdate: boolean = false
/** A function that installs a package using apt */
export async function setupAptPack(name: string, version?: string, repository: boolean | string = true) {
export async function setupAptPack(
name: string,
version?: string,
repository: boolean | string = true
): Promise<InstallationInfo> {
const apt = mightSudo("apt-get")
let exit = 0
@ -22,4 +27,6 @@ export async function setupAptPack(name: string, version?: string, repository: b
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)
}
return { binDir: "/usr/bin/" }
}

View File

@ -21,7 +21,7 @@ export type PackageInfo = {
export type InstallationInfo = {
/** The top install dir */
installDir: string
installDir?: string
binDir: string
}

View File

@ -2,11 +2,12 @@
import { execFileSync } from "child_process"
import which from "which"
import { setupBrew } from "../../brew/brew"
import { InstallationInfo } from "./setupBin"
let hasBrew = false
/** A function that installs a package using brew */
export function setupBrewPack(name: string, version?: string) {
export function setupBrewPack(name: string, version?: string): InstallationInfo {
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
setupBrew("", "", "")
hasBrew = true
@ -16,4 +17,6 @@ export function setupBrewPack(name: string, version?: string) {
execFileSync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], {
stdio: "inherit",
})
return { binDir: "/usr/local/bin/" }
}

View File

@ -35,7 +35,7 @@ export async function cleanupTmpDir(testName: string) {
export async function testBin(name: string, args: string[] = ["--version"], binDir: string | undefined = undefined) {
let bin = name
if (binDir !== undefined) {
if (typeof binDir === "string") {
expect(binDir).toBeDefined()
expect(binDir).not.toHaveLength(0)
bin = join(binDir, addBinExtension(name))