mirror of https://github.com/aminya/setup-cpp
fix: make execPowershell async
This commit is contained in:
parent
8fdba4c150
commit
7e3e265a8a
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -23,7 +23,7 @@ describe("getCompilerInfo", () => {
|
|||
})
|
||||
|
||||
describe("syncVersion", () => {
|
||||
it("Syncs llvm tools versions", async () => {
|
||||
it("Syncs llvm tools versions", () => {
|
||||
const llvmTools = ["llvm", "clangtidy", "clangformat"] as Inputs[]
|
||||
expect(syncVersions(parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
|
||||
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
|
||||
|
|
|
@ -8,14 +8,14 @@ import { InstallationInfo } from "../utils/setup/setupBin"
|
|||
|
||||
let binDir: string | undefined
|
||||
|
||||
export function setupChocolatey(
|
||||
export async function setupChocolatey(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_version: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_setupDir: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_arch: string
|
||||
): InstallationInfo | undefined {
|
||||
): Promise<InstallationInfo | undefined> {
|
||||
if (process.platform !== "win32") {
|
||||
return undefined
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ export function setupChocolatey(
|
|||
)
|
||||
|
||||
const chocoPath = `${process.env.ALLUSERSPROFILE}\\chocolatey\\bin`
|
||||
addPath(chocoPath)
|
||||
await addPath(chocoPath)
|
||||
|
||||
const maybeChoco = which.sync("choco", { nothrow: true })
|
||||
if (maybeChoco !== null) {
|
||||
|
|
|
@ -8,7 +8,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
|||
switch (process.platform) {
|
||||
case "win32": {
|
||||
await setupChocoPack("cppcheck", version)
|
||||
const binDir = activateWinCppcheck()
|
||||
const binDir = await activateWinCppcheck()
|
||||
return { binDir }
|
||||
}
|
||||
case "darwin": {
|
||||
|
@ -23,8 +23,8 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
|
|||
}
|
||||
}
|
||||
|
||||
function activateWinCppcheck() {
|
||||
async function activateWinCppcheck() {
|
||||
const binDir = "C:/Program Files/Cppcheck"
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
return binDir
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
switch (process.platform) {
|
||||
case "win32": {
|
||||
await setupChocoPack("doxygen.install", version)
|
||||
const binDir = activateWinDoxygen()
|
||||
const binDir = await activateWinDoxygen()
|
||||
const installationInfo = { binDir }
|
||||
await setupGraphviz(getVersion("graphviz", undefined), "", arch)
|
||||
return installationInfo
|
||||
|
@ -72,7 +72,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
|
|||
}
|
||||
}
|
||||
|
||||
function activateWinDoxygen() {
|
||||
async function activateWinDoxygen() {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
for (const binDir of [
|
||||
|
@ -81,7 +81,8 @@ function activateWinDoxygen() {
|
|||
"C:/Program Files (x86)/doxygen",
|
||||
]) {
|
||||
if (existsSync(binDir)) {
|
||||
addPath(binDir)
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await addPath(binDir)
|
||||
return binDir
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
|
|||
await setupChocoPack("mingw", version)
|
||||
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
|
||||
binDir = "C:/tools/mingw64/bin"
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
|
||||
binDir = "C:/tools/mingw32/bin"
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
|
||||
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
|
||||
}
|
||||
|
@ -72,19 +72,19 @@ async function activateGcc(version: string, binDir: string) {
|
|||
// const ld = process.env.LD_LIBRARY_PATH ?? ""
|
||||
// const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
|
||||
// // Setup gcc as the compiler
|
||||
// addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
|
||||
// addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
|
||||
// addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
|
||||
// addEnv("LDFLAGS", `-L${installDir}/lib`)
|
||||
// addEnv("CPPFLAGS", `-I${installDir}/include`)
|
||||
// await addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
|
||||
// await addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
|
||||
// await addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
|
||||
// await addEnv("LDFLAGS", `-L${installDir}/lib`)
|
||||
// await addEnv("CPPFLAGS", `-I${installDir}/include`)
|
||||
if (process.platform === "win32") {
|
||||
addEnv("CC", `${binDir}/gcc`)
|
||||
addEnv("CXX", `${binDir}/g++`)
|
||||
await addEnv("CC", `${binDir}/gcc`)
|
||||
await addEnv("CXX", `${binDir}/g++`)
|
||||
} else {
|
||||
const majorVersion = semverMajor(semverCoerce(version) ?? version)
|
||||
if (majorVersion >= 5) {
|
||||
addEnv("CC", `${binDir}/gcc-${majorVersion}`)
|
||||
addEnv("CXX", `${binDir}/g++-${majorVersion}`)
|
||||
await addEnv("CC", `${binDir}/gcc-${majorVersion}`)
|
||||
await addEnv("CXX", `${binDir}/g++-${majorVersion}`)
|
||||
|
||||
if (process.platform === "linux") {
|
||||
await updateAptAlternatives("cc", `${binDir}/gcc-${majorVersion}`)
|
||||
|
@ -93,8 +93,8 @@ async function activateGcc(version: string, binDir: string) {
|
|||
await updateAptAlternatives("g++", `${binDir}/g++-${majorVersion}`)
|
||||
}
|
||||
} else {
|
||||
addEnv("CC", `${binDir}/gcc-${version}`)
|
||||
addEnv("CXX", `${binDir}/g++-${version}`)
|
||||
await addEnv("CC", `${binDir}/gcc-${version}`)
|
||||
await addEnv("CXX", `${binDir}/g++-${version}`)
|
||||
|
||||
if (process.platform === "linux") {
|
||||
await updateAptAlternatives("cc", `${binDir}/gcc-${version}`)
|
||||
|
|
|
@ -5,10 +5,10 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupGraphviz(version: string, _setupDir: string, _arch: string) {
|
||||
export async function setupGraphviz(version: string, _setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
setupChocoPack("graphviz", version)
|
||||
await setupChocoPack("graphviz", version)
|
||||
return activateGraphviz()
|
||||
}
|
||||
case "darwin": {
|
||||
|
@ -23,11 +23,11 @@ export function setupGraphviz(version: string, _setupDir: string, _arch: string)
|
|||
}
|
||||
}
|
||||
|
||||
function activateGraphviz(): InstallationInfo {
|
||||
async function activateGraphviz(): Promise<InstallationInfo> {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
const binDir = "C:/Program Files/Graphviz/bin"
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
return { binDir }
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -301,29 +301,29 @@ export async function activateLLVM(directory: string, versionGiven: string) {
|
|||
const ld = process.env.LD_LIBRARY_PATH ?? ""
|
||||
const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
|
||||
|
||||
addEnv("LLVM_PATH", directory) // the output of this action
|
||||
await addEnv("LLVM_PATH", directory) // the output of this action
|
||||
|
||||
// Setup LLVM as the compiler
|
||||
addEnv("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
|
||||
addEnv("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
|
||||
await addEnv("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
|
||||
await addEnv("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
|
||||
|
||||
// windows builds fail with llvm's CPATH
|
||||
if (process.platform !== "win32") {
|
||||
const llvmMajor = semverMajor(version)
|
||||
if (existsSync(`${directory}/lib/clang/${version}/include`)) {
|
||||
addEnv("CPATH", `${directory}/lib/clang/${version}/include`)
|
||||
await addEnv("CPATH", `${directory}/lib/clang/${version}/include`)
|
||||
} else if (existsSync(`${directory}/lib/clang/${llvmMajor}/include`)) {
|
||||
addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`)
|
||||
await addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`)
|
||||
}
|
||||
}
|
||||
|
||||
addEnv("LDFLAGS", `-L"${directory}/lib"`)
|
||||
addEnv("CPPFLAGS", `-I"${directory}/include"`)
|
||||
await addEnv("LDFLAGS", `-L"${directory}/lib"`)
|
||||
await addEnv("CPPFLAGS", `-I"${directory}/include"`)
|
||||
|
||||
addEnv("CC", `${directory}/bin/clang`)
|
||||
addEnv("CXX", `${directory}/bin/clang++`)
|
||||
await addEnv("CC", `${directory}/bin/clang`)
|
||||
await addEnv("CXX", `${directory}/bin/clang++`)
|
||||
|
||||
addEnv("LIBRARY_PATH", `${directory}/lib`)
|
||||
await addEnv("LIBRARY_PATH", `${directory}/lib`)
|
||||
|
||||
await setupMacOSSDK()
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ export async function setupMacOSSDK() {
|
|||
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
|
||||
const sdkroot = xcrun.stdout || xcrun.stderr
|
||||
if (sdkroot) {
|
||||
addEnv("SDKROOT", sdkroot.trim())
|
||||
await addEnv("SDKROOT", sdkroot.trim())
|
||||
} else {
|
||||
error(`SDKROOT not set`)
|
||||
}
|
||||
|
|
21
src/main.ts
21
src/main.ts
|
@ -164,7 +164,16 @@ export async function main(args: string[]): Promise<number> {
|
|||
try {
|
||||
let installationInfo: InstallationInfo | undefined | void
|
||||
if (tool === "vcvarsall") {
|
||||
setupVCVarsall(getVersion(tool, version, osVersion), undefined, arch, undefined, undefined, false, false)
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await setupVCVarsall(
|
||||
getVersion(tool, version, osVersion),
|
||||
undefined,
|
||||
arch,
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
false
|
||||
)
|
||||
} else {
|
||||
// get the setup function
|
||||
const setupFunction = setups[tool]
|
||||
|
@ -224,15 +233,19 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "visualstudio":
|
||||
case "visualcpp":
|
||||
case "visualc++": {
|
||||
const installationInfo = setupMSVC(getVersion("msvc", version, osVersion), join(setupCppDir, "msvc"), arch)
|
||||
const installationInfo = await setupMSVC(
|
||||
getVersion("msvc", version, osVersion),
|
||||
join(setupCppDir, "msvc"),
|
||||
arch
|
||||
)
|
||||
successMessages.push(getSuccessMessage("msvc", installationInfo))
|
||||
break
|
||||
}
|
||||
case "appleclang":
|
||||
case "applellvm": {
|
||||
notice("Assuming apple-clang is already installed")
|
||||
addEnv("CC", "clang")
|
||||
addEnv("CXX", "clang++")
|
||||
await addEnv("CC", "clang")
|
||||
await addEnv("CXX", "clang++")
|
||||
successMessages.push(getSuccessMessage("apple-clang", undefined))
|
||||
break
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupMake(version: string, _setupDir: string, _arch: string) {
|
||||
export async function setupMake(version: string, _setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
return setupChocoPack("make", version)
|
||||
}
|
||||
case "darwin": {
|
||||
setupBrewPack("make", version)
|
||||
addPath("/usr/local/opt/make/libexec/gnubin")
|
||||
await addPath("/usr/local/opt/make/libexec/gnubin")
|
||||
return { binDir: "/usr/local/opt/make/libexec/gnubin" }
|
||||
}
|
||||
case "linux": {
|
||||
|
|
|
@ -3,12 +3,12 @@ import { setupMSVC } from "../msvc"
|
|||
|
||||
jest.setTimeout(300000)
|
||||
describe("setup-msvc", () => {
|
||||
it("should setup the pre-installed msvc", () => {
|
||||
it("should setup the pre-installed msvc", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
setupMSVC("", "", process.arch)
|
||||
await setupMSVC("", "", process.arch)
|
||||
console.log(which.sync("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
|
@ -16,12 +16,12 @@ describe("setup-msvc", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("should setup msvc 2022", () => {
|
||||
it("should setup msvc 2022", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
setupMSVC("2022", "", process.arch)
|
||||
await setupMSVC("2022", "", process.arch)
|
||||
console.log(which.sync("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
|
@ -29,12 +29,12 @@ describe("setup-msvc", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("should setup msvc 2019", () => {
|
||||
it("should setup msvc 2019", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
setupMSVC("2019", "", process.arch)
|
||||
await setupMSVC("2019", "", process.arch)
|
||||
console.log(which.sync("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
|
@ -42,12 +42,12 @@ describe("setup-msvc", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("should setup msvc 2017", () => {
|
||||
it("should setup msvc 2017", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
setupMSVC("2017", "", process.arch)
|
||||
await setupMSVC("2017", "", process.arch)
|
||||
console.log(which.sync("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
|
@ -55,12 +55,12 @@ describe("setup-msvc", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("should setup msvc 2015", () => {
|
||||
it("should setup msvc 2015", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
setupMSVC("2015", "", process.arch)
|
||||
await setupMSVC("2015", "", process.arch)
|
||||
console.log(which.sync("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
|
|
|
@ -10,7 +10,7 @@ import { error, info, warning } from "../utils/io/io"
|
|||
|
||||
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
|
||||
|
||||
export function setupMSVC(
|
||||
export async function setupMSVC(
|
||||
versionGiven: MSVCVersion,
|
||||
_setupDir: string,
|
||||
arch: string,
|
||||
|
@ -41,19 +41,19 @@ export function setupMSVC(
|
|||
try {
|
||||
if (version === "14.0") {
|
||||
toolset = "14.0"
|
||||
setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
|
||||
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
|
||||
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
|
||||
} else if (version === "15.0") {
|
||||
toolset = "14.16"
|
||||
setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
|
||||
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
|
||||
} else if (version === "16.0") {
|
||||
toolset = "14.29"
|
||||
setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
|
||||
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
|
||||
} else if (version === "17.0") {
|
||||
toolset = undefined
|
||||
setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
|
||||
await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
|
||||
VCTargetsPath = undefined
|
||||
} else {
|
||||
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
|
||||
|
@ -63,7 +63,7 @@ export function setupMSVC(
|
|||
}
|
||||
}
|
||||
// run vcvarsall.bat environment variables
|
||||
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
|
||||
await setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
|
||||
|
||||
if (isGitHubCI()) {
|
||||
addMSVCLoggingMatcher()
|
||||
|
|
|
@ -7,12 +7,12 @@ export async function setupOpencppcoverage(version: string | undefined, _setupDi
|
|||
return
|
||||
}
|
||||
await setupChocoPack("opencppcoverage", version)
|
||||
const binDir = activateOpencppcoverage()
|
||||
const binDir = await activateOpencppcoverage()
|
||||
return { binDir }
|
||||
}
|
||||
|
||||
function activateOpencppcoverage() {
|
||||
async function activateOpencppcoverage() {
|
||||
const binDir = "C:/Program Files/OpenCppCoverage"
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
return binDir
|
||||
}
|
||||
|
|
|
@ -20,18 +20,18 @@ export async function setupPython(version: string, setupDir: string, arch: strin
|
|||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
|
||||
export async function setupPythonViaSystem(version: string, setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
if (setupDir) {
|
||||
setupChocoPack("python3", version, [`--params=/InstallDir:${setupDir}`])
|
||||
await setupChocoPack("python3", version, [`--params=/InstallDir:${setupDir}`])
|
||||
} else {
|
||||
setupChocoPack("python3", version)
|
||||
await setupChocoPack("python3", version)
|
||||
}
|
||||
|
||||
// Adding the bin dir to the path
|
||||
/** The directory which the tool is installed to */
|
||||
activateWinPython(setupDir)
|
||||
await activateWinPython(setupDir)
|
||||
return { installDir: setupDir, binDir: setupDir }
|
||||
}
|
||||
case "darwin": {
|
||||
|
@ -48,7 +48,7 @@ export function setupPythonViaSystem(version: string, setupDir: string, _arch: s
|
|||
}
|
||||
}
|
||||
|
||||
function activateWinPython(binDir: string) {
|
||||
async function activateWinPython(binDir: string) {
|
||||
info(`Add ${binDir} to PATH`)
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ import { delimiter } from "path"
|
|||
import { escapeSpace } from "../path/escape_space"
|
||||
|
||||
/** An add path function that works locally or inside GitHub Actions */
|
||||
export function addEnv(name: string, valGiven: string | undefined, shouldEscapeSpace: boolean = false) {
|
||||
export async function addEnv(name: string, valGiven: string | undefined, shouldEscapeSpace: boolean = false) {
|
||||
const val = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
||||
try {
|
||||
if (isGitHubCI()) {
|
||||
exportVariable(name, val)
|
||||
} else {
|
||||
addEnvSystem(name, val)
|
||||
await addEnvSystem(name, val)
|
||||
}
|
||||
} catch (err) {
|
||||
try {
|
||||
|
@ -28,13 +28,13 @@ export function addEnv(name: string, valGiven: string | undefined, shouldEscapeS
|
|||
}
|
||||
|
||||
/** An add path function that works locally or inside GitHub Actions */
|
||||
export function addPath(path: string) {
|
||||
export async function addPath(path: string) {
|
||||
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
|
||||
try {
|
||||
if (isGitHubCI()) {
|
||||
ghAddPath(path)
|
||||
} else {
|
||||
addPathSystem(path)
|
||||
await addPathSystem(path)
|
||||
}
|
||||
} catch (err) {
|
||||
try {
|
||||
|
@ -49,12 +49,12 @@ export function addPath(path: string) {
|
|||
|
||||
export const cpprc_path = untildify(".cpprc")
|
||||
|
||||
function addEnvSystem(name: string, valGiven: string | undefined) {
|
||||
async function addEnvSystem(name: string, valGiven: string | undefined) {
|
||||
const val = valGiven ?? ""
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
// We do not use `execa.sync(`setx PATH "${path};%PATH%"`)` because of its character limit
|
||||
execPowershell(`[Environment]::SetEnvironmentVariable("${name}", "${val}", "User")`)
|
||||
await execPowershell(`[Environment]::SetEnvironmentVariable("${name}", "${val}", "User")`)
|
||||
info(`${name}="${val} was set in the environment."`)
|
||||
return
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ function addEnvSystem(name: string, valGiven: string | undefined) {
|
|||
process.env[name] = val
|
||||
}
|
||||
|
||||
function addPathSystem(path: string) {
|
||||
async function addPathSystem(path: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
// We do not use `execa.sync(`setx PATH "${path};%PATH%"`)` because of its character limit and also because %PATH% is different for user and system
|
||||
execPowershell(
|
||||
await execPowershell(
|
||||
`$USER_PATH=([Environment]::GetEnvironmentVariable("PATH", "User")); [Environment]::SetEnvironmentVariable("PATH", "${path};$USER_PATH", "User")`
|
||||
)
|
||||
info(`${path} was added to the PATH.`)
|
||||
|
|
|
@ -4,6 +4,10 @@ import which from "which"
|
|||
let powershell: string | undefined
|
||||
|
||||
export function execPowershell(command: string, startupFlags: string[] = ["-NoProfile", "-NoLogo", "-NonInteractive"]) {
|
||||
return execa(getPowerShell(), [...startupFlags, "-c", command], { stdio: "inherit" })
|
||||
}
|
||||
|
||||
function getPowerShell() {
|
||||
if (powershell === undefined) {
|
||||
const maybePwsh = which.sync("pwsh", { nothrow: true })
|
||||
if (maybePwsh !== null) {
|
||||
|
@ -17,6 +21,5 @@ export function execPowershell(command: string, startupFlags: string[] = ["-NoPr
|
|||
if (powershell === undefined) {
|
||||
throw new Error("Could not find powershell")
|
||||
}
|
||||
|
||||
execa.sync(powershell, [...startupFlags, "-c", command], { stdio: "inherit" })
|
||||
return powershell
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ async function getSevenZip() {
|
|||
}
|
||||
|
||||
/// Extract Exe using 7z
|
||||
export async function extractExe(file: string, dest: string) {
|
||||
export function extractExe(file: string, dest: string) {
|
||||
return extract7Zip(file, dest)
|
||||
}
|
||||
|
||||
/// Extract Zip using 7z
|
||||
export async function extractZip(file: string, dest: string) {
|
||||
export function extractZip(file: string, dest: string) {
|
||||
return extract7Zip(file, dest)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ export async function setupBin(
|
|||
const binDir = join(installDir, binRelativeDir)
|
||||
if (existsSync(binDir) && existsSync(join(binDir, binFileName))) {
|
||||
info(`${name} ${version} was found in the cache at ${binDir}.`)
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
|
||||
return { installDir, binDir }
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ export async function setupBin(
|
|||
// Adding the bin dir to the path
|
||||
/** The directory which the tool is installed to */
|
||||
info(`Add ${binDir} to PATH`)
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
|
||||
// check if inside Github Actions. If so, cache the installation
|
||||
if (isGitHubCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
|
||||
|
|
|
@ -9,11 +9,11 @@ import { info } from "@actions/core"
|
|||
let hasChoco = false
|
||||
|
||||
/** A function that installs a package using choco */
|
||||
export function setupChocoPack(name: string, version?: string, args: string[] = []): InstallationInfo {
|
||||
export async function setupChocoPack(name: string, version?: string, args: string[] = []): Promise<InstallationInfo> {
|
||||
info(`Installing ${name} ${version ?? ""} via chocolatey`)
|
||||
|
||||
if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
|
||||
setupChocolatey("", "", process.arch)
|
||||
await setupChocolatey("", "", process.arch)
|
||||
hasChoco = true
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
|
|||
}
|
||||
|
||||
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
|
||||
return { binDir }
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
|
|||
}
|
||||
}
|
||||
info(`${binDir} to PATH`)
|
||||
addPath(binDir)
|
||||
await addPath(binDir)
|
||||
}
|
||||
|
||||
return { binDir }
|
||||
|
|
|
@ -13,7 +13,7 @@ import { InstallationInfo } from "../utils/setup/setupBin"
|
|||
let hasVCPKG = false
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
|
||||
export async function setupVcpkg(_version: string, setupDir: string, _arch: string): Promise<InstallationInfo> {
|
||||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||
if (process.platform === "linux") {
|
||||
// vcpkg download and extraction dependencies
|
||||
|
@ -42,7 +42,7 @@ export function setupVcpkg(_version: string, setupDir: string, _arch: string): I
|
|||
execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
|
||||
}
|
||||
|
||||
addPath(setupDir)
|
||||
await addPath(setupDir)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
hasVCPKG = true
|
||||
return { binDir: setupDir }
|
||||
|
|
|
@ -21,7 +21,7 @@ function getArch(arch: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
export function setupVCVarsall(
|
||||
export async function setupVCVarsall(
|
||||
vsversion: string,
|
||||
VCTargetsPath: string | undefined,
|
||||
arch: string,
|
||||
|
@ -32,7 +32,7 @@ export function setupVCVarsall(
|
|||
) {
|
||||
if (VCTargetsPath !== undefined && existsSync(VCTargetsPath)) {
|
||||
info(`Adding ${VCTargetsPath} to PATH`)
|
||||
addEnv("VCTargetsPath", VCTargetsPath)
|
||||
await addEnv("VCTargetsPath", VCTargetsPath)
|
||||
}
|
||||
|
||||
setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre, vsversion)
|
||||
|
|
Loading…
Reference in New Issue