mirror of https://github.com/aminya/setup-cpp
Merge pull request #147 from aminya/sccache [skip ci]
This commit is contained in:
commit
740f226722
|
@ -51,6 +51,9 @@ inputs:
|
|||
ccache:
|
||||
description: "The ccache version to install."
|
||||
required: false
|
||||
sccache:
|
||||
description: "The sccache version to install."
|
||||
required: false
|
||||
doxygen:
|
||||
description: "The doxygen version to install."
|
||||
required: false
|
||||
|
|
|
@ -67,6 +67,7 @@ words:
|
|||
- pwsh
|
||||
- pygments
|
||||
- pypy
|
||||
- Sccache
|
||||
- setupcpp
|
||||
- setx
|
||||
- Syuu
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -7,7 +7,7 @@ describe("setup-brew", () => {
|
|||
if (process.platform !== "darwin") {
|
||||
return
|
||||
}
|
||||
const installInfo = setupBrew("", "", process.arch)
|
||||
const installInfo = await setupBrew("", "", process.arch)
|
||||
await testBin("brew", ["--version"], installInfo?.binDir)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
import { execFileSync } from "child_process"
|
||||
import execa from "execa"
|
||||
import { dirname } from "patha"
|
||||
import which from "which"
|
||||
import { tmpdir } from "os"
|
||||
import path, { join } from "path"
|
||||
import { mkdirP } from "@actions/io"
|
||||
import { readFileSync } from "fs"
|
||||
import { addPath } from "../utils/env/addEnv"
|
||||
|
||||
let binDir: string | undefined
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupBrew(_version: string, _setupDir: string, _arch: string) {
|
||||
export async function setupBrew(_version: string, _setupDir: string, _arch: string) {
|
||||
if (!["darwin", "linux"].includes(process.platform)) {
|
||||
return undefined
|
||||
}
|
||||
|
@ -20,10 +25,37 @@ export function setupBrew(_version: string, _setupDir: string, _arch: string) {
|
|||
}
|
||||
|
||||
// brew is not thread-safe
|
||||
execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, {
|
||||
stdio: "inherit",
|
||||
const brewTempDirectory = path.join(tmpdir(), "setup_cpp", "brew")
|
||||
await mkdirP(brewTempDirectory)
|
||||
|
||||
execa.sync("curl", ["-LJO", "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"], {
|
||||
cwd: brewTempDirectory,
|
||||
})
|
||||
binDir = "/usr/local/bin/"
|
||||
const installSh = join(brewTempDirectory, "install.sh")
|
||||
|
||||
if (process.platform === "linux") {
|
||||
const installShContent = readFileSync(installSh, "utf-8")
|
||||
|
||||
installShContent.replace("#!/bin/bash", "")
|
||||
}
|
||||
|
||||
execa.sync("/bin/bash", [installSh], {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
NONINTERACTIVE: "1",
|
||||
},
|
||||
})
|
||||
|
||||
binDir = getBrewPath()
|
||||
await addPath(binDir)
|
||||
|
||||
return { binDir }
|
||||
}
|
||||
|
||||
export function getBrewPath() {
|
||||
if (process.platform === "linux") {
|
||||
return "/home/linuxbrew/.linuxbrew/bin/"
|
||||
} else {
|
||||
return "/usr/local/bin/"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
return installationInfo
|
||||
}
|
||||
case "darwin": {
|
||||
const installationInfo = setupBrewPack("doxygen", undefined)
|
||||
const installationInfo = await setupBrewPack("doxygen", undefined)
|
||||
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
|
||||
return installationInfo
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
|
|||
break
|
||||
}
|
||||
case "darwin": {
|
||||
installationInfo = setupBrewPack("gcc", version)
|
||||
installationInfo = await setupBrewPack("gcc", version)
|
||||
break
|
||||
}
|
||||
case "linux": {
|
||||
|
|
|
@ -47,6 +47,7 @@ import { setupBazel } from "./bazel/bazel"
|
|||
import { setupPowershell } from "./powershell/powershell"
|
||||
import { isArch } from "./utils/env/isArch"
|
||||
import { setupPacmanPack } from "./utils/setup/setupPacmanPack"
|
||||
import { setupSccache } from "./sccache/sccache"
|
||||
|
||||
/** The setup functions */
|
||||
const setups = {
|
||||
|
@ -66,6 +67,7 @@ const setups = {
|
|||
brew: setupBrew,
|
||||
powershell: setupPowershell,
|
||||
ccache: setupCcache,
|
||||
sccache: setupSccache,
|
||||
doxygen: setupDoxygen,
|
||||
graphviz: setupGraphviz,
|
||||
cppcheck: setupCppcheck,
|
||||
|
@ -366,6 +368,7 @@ All the available tools:
|
|||
--make
|
||||
--task
|
||||
--ccache
|
||||
--sccache
|
||||
--cppcheck
|
||||
--clangformat
|
||||
--clangtidy
|
||||
|
@ -373,13 +376,13 @@ All the available tools:
|
|||
--gcovr
|
||||
--opencppcoverage
|
||||
--kcov
|
||||
|
||||
--python
|
||||
--choco
|
||||
--brew
|
||||
--nala
|
||||
--sevenzip
|
||||
--graphviz
|
||||
--powershell
|
||||
`)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
|
|||
return setupChocoPack("make", version)
|
||||
}
|
||||
case "darwin": {
|
||||
setupBrewPack("make", version)
|
||||
await setupBrewPack("make", version)
|
||||
await addPath("/usr/local/opt/make/libexec/gnubin")
|
||||
return { binDir: "/usr/local/opt/make/libexec/gnubin" }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { setupSccache } from "../sccache"
|
||||
import { testBin } from "../../utils/tests/test-helpers"
|
||||
import { InstallationInfo } from "../../utils/setup/setupBin"
|
||||
|
||||
jest.setTimeout(300000)
|
||||
describe("setup-sccache", () => {
|
||||
it("should setup sccache", async () => {
|
||||
const installInfo = await setupSccache("", "", process.arch)
|
||||
|
||||
await testBin("sccache", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,18 @@
|
|||
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupSccache(version: string, _setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
return setupChocoPack("sccache", version)
|
||||
}
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
return setupBrewPack("sccache", version)
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unsupported platform`)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import { error, warning } from "ci-log"
|
|||
import { execPowershell } from "exec-powershell"
|
||||
import { delimiter } from "path"
|
||||
import escapeSpace from "escape-path-with-spaces"
|
||||
import { giveUserAccess } from "user-access"
|
||||
|
||||
/**
|
||||
* Add an environment variable.
|
||||
|
@ -125,6 +126,10 @@ export function setupCppInProfile() {
|
|||
appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`)
|
||||
info(`Added ${source_cpprc_str} to ${cpprc_path}`)
|
||||
|
||||
giveUserAccess(cpprc_path)
|
||||
|
||||
// source cpprc in bashrc/profile
|
||||
|
||||
const source_cpprc_string = `\n# source .cpprc if SOURCE_CPPRC is not set to 0\nif [[ "$SOURCE_CPPRC" != 0 && -f "${cpprc_path}" ]]; then source "${cpprc_path}"; fi\n`
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,25 +1,36 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { info } from "@actions/core"
|
||||
import execa from "execa"
|
||||
import { join } from "patha"
|
||||
import which from "which"
|
||||
import { setupBrew } from "../../brew/brew"
|
||||
import { getBrewPath, 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, extraArgs: string[] = []): InstallationInfo {
|
||||
export async function setupBrewPack(
|
||||
name: string,
|
||||
version?: string,
|
||||
extraArgs: string[] = []
|
||||
): Promise<InstallationInfo> {
|
||||
info(`Installing ${name} ${version ?? ""} via brew`)
|
||||
|
||||
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
||||
setupBrew("", "", process.arch)
|
||||
await setupBrew("", "", process.arch)
|
||||
hasBrew = true
|
||||
}
|
||||
|
||||
// brew is not thread-safe
|
||||
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs], {
|
||||
stdio: "inherit",
|
||||
})
|
||||
const binDir = getBrewPath()
|
||||
|
||||
return { binDir: "/usr/local/bin/" }
|
||||
// brew is not thread-safe
|
||||
execa.sync(
|
||||
join(binDir, "brew"),
|
||||
["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs],
|
||||
{
|
||||
stdio: "inherit",
|
||||
}
|
||||
)
|
||||
|
||||
return { binDir }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue