Merge pull request #147 from aminya/sccache [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-11-20 22:16:09 -08:00 committed by GitHub
commit 740f226722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 107 additions and 22 deletions

View File

@ -51,6 +51,9 @@ inputs:
ccache: ccache:
description: "The ccache version to install." description: "The ccache version to install."
required: false required: false
sccache:
description: "The sccache version to install."
required: false
doxygen: doxygen:
description: "The doxygen version to install." description: "The doxygen version to install."
required: false required: false

View File

@ -67,6 +67,7 @@ words:
- pwsh - pwsh
- pygments - pygments
- pypy - pypy
- Sccache
- setupcpp - setupcpp
- setx - setx
- Syuu - 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

View File

@ -7,7 +7,7 @@ describe("setup-brew", () => {
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
return return
} }
const installInfo = setupBrew("", "", process.arch) const installInfo = await setupBrew("", "", process.arch)
await testBin("brew", ["--version"], installInfo?.binDir) await testBin("brew", ["--version"], installInfo?.binDir)
}) })
}) })

View File

@ -1,11 +1,16 @@
import { execFileSync } from "child_process" import execa from "execa"
import { dirname } from "patha" import { dirname } from "patha"
import which from "which" 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 let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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)) { if (!["darwin", "linux"].includes(process.platform)) {
return undefined return undefined
} }
@ -20,10 +25,37 @@ export function setupBrew(_version: string, _setupDir: string, _arch: string) {
} }
// brew is not thread-safe // brew is not thread-safe
execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, { const brewTempDirectory = path.join(tmpdir(), "setup_cpp", "brew")
stdio: "inherit", 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 } return { binDir }
} }
export function getBrewPath() {
if (process.platform === "linux") {
return "/home/linuxbrew/.linuxbrew/bin/"
} else {
return "/usr/local/bin/"
}
}

View File

@ -54,7 +54,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
return installationInfo return installationInfo
} }
case "darwin": { case "darwin": {
const installationInfo = setupBrewPack("doxygen", undefined) const installationInfo = await setupBrewPack("doxygen", undefined)
await setupGraphviz(getVersion("graphviz", undefined), "", arch) await setupGraphviz(getVersion("graphviz", undefined), "", arch)
return installationInfo return installationInfo
} }

View File

@ -83,7 +83,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
break break
} }
case "darwin": { case "darwin": {
installationInfo = setupBrewPack("gcc", version) installationInfo = await setupBrewPack("gcc", version)
break break
} }
case "linux": { case "linux": {

View File

@ -47,6 +47,7 @@ import { setupBazel } from "./bazel/bazel"
import { setupPowershell } from "./powershell/powershell" import { setupPowershell } from "./powershell/powershell"
import { isArch } from "./utils/env/isArch" import { isArch } from "./utils/env/isArch"
import { setupPacmanPack } from "./utils/setup/setupPacmanPack" import { setupPacmanPack } from "./utils/setup/setupPacmanPack"
import { setupSccache } from "./sccache/sccache"
/** The setup functions */ /** The setup functions */
const setups = { const setups = {
@ -66,6 +67,7 @@ const setups = {
brew: setupBrew, brew: setupBrew,
powershell: setupPowershell, powershell: setupPowershell,
ccache: setupCcache, ccache: setupCcache,
sccache: setupSccache,
doxygen: setupDoxygen, doxygen: setupDoxygen,
graphviz: setupGraphviz, graphviz: setupGraphviz,
cppcheck: setupCppcheck, cppcheck: setupCppcheck,
@ -366,6 +368,7 @@ All the available tools:
--make --make
--task --task
--ccache --ccache
--sccache
--cppcheck --cppcheck
--clangformat --clangformat
--clangtidy --clangtidy
@ -373,13 +376,13 @@ All the available tools:
--gcovr --gcovr
--opencppcoverage --opencppcoverage
--kcov --kcov
--python --python
--choco --choco
--brew --brew
--nala --nala
--sevenzip --sevenzip
--graphviz --graphviz
--powershell
`) `)
} }

View File

@ -15,7 +15,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
return setupChocoPack("make", version) return setupChocoPack("make", version)
} }
case "darwin": { case "darwin": {
setupBrewPack("make", version) await setupBrewPack("make", version)
await addPath("/usr/local/opt/make/libexec/gnubin") await addPath("/usr/local/opt/make/libexec/gnubin")
return { binDir: "/usr/local/opt/make/libexec/gnubin" } return { binDir: "/usr/local/opt/make/libexec/gnubin" }
} }

View File

@ -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)
})
})

18
src/sccache/sccache.ts Normal file
View File

@ -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`)
}
}
}

View File

@ -6,6 +6,7 @@ import { error, warning } from "ci-log"
import { execPowershell } from "exec-powershell" import { execPowershell } from "exec-powershell"
import { delimiter } from "path" import { delimiter } from "path"
import escapeSpace from "escape-path-with-spaces" import escapeSpace from "escape-path-with-spaces"
import { giveUserAccess } from "user-access"
/** /**
* Add an environment variable. * Add an environment variable.
@ -125,6 +126,10 @@ export function setupCppInProfile() {
appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`) appendFileSync(cpprc_path, `\n${source_cpprc_str}\n`)
info(`Added ${source_cpprc_str} to ${cpprc_path}`) 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` 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 { try {

View File

@ -1,25 +1,36 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { info } from "@actions/core" import { info } from "@actions/core"
import execa from "execa" import execa from "execa"
import { join } from "patha"
import which from "which" import which from "which"
import { setupBrew } from "../../brew/brew" import { getBrewPath, setupBrew } from "../../brew/brew"
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
let hasBrew = false let hasBrew = false
/** A function that installs a package using brew */ /** 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`) info(`Installing ${name} ${version ?? ""} via brew`)
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) { if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
setupBrew("", "", process.arch) await setupBrew("", "", process.arch)
hasBrew = true hasBrew = true
} }
// brew is not thread-safe const binDir = getBrewPath()
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs], {
stdio: "inherit",
})
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 }
} }