Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/gcc/gcc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addPath, addEnv } from "../utils/env/addEnv"
import { existsSync } from "fs"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import semverMajor from "semver/functions/major"
Expand Down Expand Up @@ -96,9 +96,19 @@ async function activateGcc(version: string, binDir: string) {
if (majorVersion >= 5) {
addEnv("CC", `${binDir}/gcc-${majorVersion}`)
addEnv("CXX", `${binDir}/g++-${majorVersion}`)

if (process.platform === "linux") {
await updateAptAlternatives("cc", `${binDir}/gcc-${majorVersion}`)
await updateAptAlternatives("cxx", `${binDir}/g++-${majorVersion}`)
}
} else {
addEnv("CC", `${binDir}/gcc-${version}`)
addEnv("CXX", `${binDir}/g++-${version}`)

if (process.platform === "linux") {
await updateAptAlternatives("cc", `${binDir}/gcc-${version}`)
await updateAptAlternatives("cxx", `${binDir}/g++-${version}`)
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/llvm/llvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
import { addBinExtension } from "../utils/extension/extension"
import { addEnv } from "../utils/env/addEnv"
import { info, setOutput } from "@actions/core"
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack"
import { warning } from "../utils/io/io"
import { existsSync } from "fs"
import { isGitHubCI } from "../utils/env/isci"
Expand Down Expand Up @@ -307,6 +307,16 @@ export async function activateLLVM(directory: string, versionGiven: string) {

await setupMacOSSDK()

if (process.platform === "linux") {
await updateAptAlternatives("cc", `${directory}/bin/clang`)
await updateAptAlternatives("cxx", `${directory}/bin/clang++`)
await updateAptAlternatives("clang", `${directory}/bin/clang`)
await updateAptAlternatives("clang++", `${directory}/bin/clang++`)
await updateAptAlternatives("lld", `${directory}/bin/lld`)
await updateAptAlternatives("ld.lld", `${directory}/bin/ld.lld`)
await updateAptAlternatives("llvm-ar", `${directory}/bin/llvm-ar`)
}

if (isGitHubCI()) {
addLLVMLoggingMatcher()
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/env/addEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function addPath(path: string) {
}
}

const cpprc_path = untildify(".cpprc")
export const cpprc_path = untildify(".cpprc")

function addEnvSystem(name: string, valGiven: string | undefined) {
const val = valGiven ?? ""
Expand Down Expand Up @@ -96,7 +96,7 @@ function addPathSystem(path: string) {
let setupCppInProfile_called = false

/// handles adding conditions to source .cpprc file from .bashrc and .profile
function setupCppInProfile() {
export function setupCppInProfile() {
if (setupCppInProfile_called) {
return
}
Expand Down
15 changes: 15 additions & 0 deletions src/utils/setup/setupAptPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo"
import { info } from "@actions/core"
import { warning } from "../io/io"
import { isGitHubCI } from "../env/isci"
import { cpprc_path, setupCppInProfile } from "../env/addEnv"
import { appendFileSync } from "fs"

let didUpdate: boolean = false
let didInit: boolean = false
Expand Down Expand Up @@ -68,3 +71,15 @@ export async function setupAptPack(

return { binDir: "/usr/bin/" }
}

export function updateAptAlternatives(name: string, path: string) {
if (isGitHubCI()) {
return execSudo("update-alternatives", ["--install", `/usr/bin/${name}`, name, path, "10"])
} else {
setupCppInProfile()
return appendFileSync(
cpprc_path,
`\nif [ $UID -eq 0 ]; then update-alternatives --install /usr/bin/${name} ${name} ${path} 10; fi\n`
)
}
}