Merge pull request #79 from aminya/faster-pwsh [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-05-12 16:54:23 -07:00 committed by GitHub
commit c6a8977164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 111 additions and 94 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,7 +23,7 @@ describe("getCompilerInfo", () => {
}) })
describe("syncVersion", () => { describe("syncVersion", () => {
it("Syncs llvm tools versions", async () => { it("Syncs llvm tools versions", () => {
const llvmTools = ["llvm", "clangtidy", "clangformat"] as Inputs[] const llvmTools = ["llvm", "clangtidy", "clangformat"] as Inputs[]
expect(syncVersions(parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true) expect(syncVersions(parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true) expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)

View File

@ -8,14 +8,14 @@ import { InstallationInfo } from "../utils/setup/setupBin"
let binDir: string | undefined let binDir: string | undefined
export function setupChocolatey( export async function setupChocolatey(
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
_version: string, _version: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
_setupDir: string, _setupDir: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string _arch: string
): InstallationInfo | undefined { ): Promise<InstallationInfo | undefined> {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return undefined return undefined
} }
@ -54,7 +54,7 @@ export function setupChocolatey(
) )
const chocoPath = `${process.env.ALLUSERSPROFILE}\\chocolatey\\bin` const chocoPath = `${process.env.ALLUSERSPROFILE}\\chocolatey\\bin`
addPath(chocoPath) await addPath(chocoPath)
const maybeChoco = which.sync("choco", { nothrow: true }) const maybeChoco = which.sync("choco", { nothrow: true })
if (maybeChoco !== null) { if (maybeChoco !== null) {

View File

@ -8,7 +8,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
await setupChocoPack("cppcheck", version) await setupChocoPack("cppcheck", version)
const binDir = activateWinCppcheck() const binDir = await activateWinCppcheck()
return { binDir } return { binDir }
} }
case "darwin": { 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" const binDir = "C:/Program Files/Cppcheck"
addPath(binDir) await addPath(binDir)
return binDir return binDir
} }

View File

@ -43,7 +43,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
await setupChocoPack("doxygen.install", version) await setupChocoPack("doxygen.install", version)
const binDir = activateWinDoxygen() const binDir = await activateWinDoxygen()
const installationInfo = { binDir } const installationInfo = { binDir }
await setupGraphviz(getVersion("graphviz", undefined), "", arch) await setupGraphviz(getVersion("graphviz", undefined), "", arch)
return installationInfo return installationInfo
@ -72,7 +72,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
} }
} }
function activateWinDoxygen() { async function activateWinDoxygen() {
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
for (const binDir of [ for (const binDir of [
@ -81,7 +81,8 @@ function activateWinDoxygen() {
"C:/Program Files (x86)/doxygen", "C:/Program Files (x86)/doxygen",
]) { ]) {
if (existsSync(binDir)) { if (existsSync(binDir)) {
addPath(binDir) // eslint-disable-next-line no-await-in-loop
await addPath(binDir)
return binDir return binDir
} }
} }

View File

@ -21,10 +21,10 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
await setupChocoPack("mingw", version) await setupChocoPack("mingw", version)
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) { if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
binDir = "C:/tools/mingw64/bin" binDir = "C:/tools/mingw64/bin"
addPath(binDir) await addPath(binDir)
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) { } else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
binDir = "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`)) { } else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin` 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 ld = process.env.LD_LIBRARY_PATH ?? ""
// const dyld = process.env.DYLD_LIBRARY_PATH ?? "" // const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
// // Setup gcc as the compiler // // Setup gcc as the compiler
// addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`) // await addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
// addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`) // await addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
// addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`) // await addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
// addEnv("LDFLAGS", `-L${installDir}/lib`) // await addEnv("LDFLAGS", `-L${installDir}/lib`)
// addEnv("CPPFLAGS", `-I${installDir}/include`) // await addEnv("CPPFLAGS", `-I${installDir}/include`)
if (process.platform === "win32") { if (process.platform === "win32") {
addEnv("CC", `${binDir}/gcc`) await addEnv("CC", `${binDir}/gcc`)
addEnv("CXX", `${binDir}/g++`) await addEnv("CXX", `${binDir}/g++`)
} else { } else {
const majorVersion = semverMajor(semverCoerce(version) ?? version) const majorVersion = semverMajor(semverCoerce(version) ?? version)
if (majorVersion >= 5) { if (majorVersion >= 5) {
addEnv("CC", `${binDir}/gcc-${majorVersion}`) await addEnv("CC", `${binDir}/gcc-${majorVersion}`)
addEnv("CXX", `${binDir}/g++-${majorVersion}`) await addEnv("CXX", `${binDir}/g++-${majorVersion}`)
if (process.platform === "linux") { if (process.platform === "linux") {
await updateAptAlternatives("cc", `${binDir}/gcc-${majorVersion}`) await updateAptAlternatives("cc", `${binDir}/gcc-${majorVersion}`)
@ -93,8 +93,8 @@ async function activateGcc(version: string, binDir: string) {
await updateAptAlternatives("g++", `${binDir}/g++-${majorVersion}`) await updateAptAlternatives("g++", `${binDir}/g++-${majorVersion}`)
} }
} else { } else {
addEnv("CC", `${binDir}/gcc-${version}`) await addEnv("CC", `${binDir}/gcc-${version}`)
addEnv("CXX", `${binDir}/g++-${version}`) await addEnv("CXX", `${binDir}/g++-${version}`)
if (process.platform === "linux") { if (process.platform === "linux") {
await updateAptAlternatives("cc", `${binDir}/gcc-${version}`) await updateAptAlternatives("cc", `${binDir}/gcc-${version}`)

View File

@ -5,10 +5,10 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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) { switch (process.platform) {
case "win32": { case "win32": {
setupChocoPack("graphviz", version) await setupChocoPack("graphviz", version)
return activateGraphviz() return activateGraphviz()
} }
case "darwin": { 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) { switch (process.platform) {
case "win32": { case "win32": {
const binDir = "C:/Program Files/Graphviz/bin" const binDir = "C:/Program Files/Graphviz/bin"
addPath(binDir) await addPath(binDir)
return { binDir } return { binDir }
} }
default: { default: {

View File

@ -301,29 +301,29 @@ export async function activateLLVM(directory: string, versionGiven: string) {
const ld = process.env.LD_LIBRARY_PATH ?? "" const ld = process.env.LD_LIBRARY_PATH ?? ""
const dyld = process.env.DYLD_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 // Setup LLVM as the compiler
addEnv("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`) await addEnv("LD_LIBRARY_PATH", `${lib}${path.delimiter}${ld}`)
addEnv("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`) await addEnv("DYLD_LIBRARY_PATH", `${lib}${path.delimiter}${dyld}`)
// windows builds fail with llvm's CPATH // windows builds fail with llvm's CPATH
if (process.platform !== "win32") { if (process.platform !== "win32") {
const llvmMajor = semverMajor(version) const llvmMajor = semverMajor(version)
if (existsSync(`${directory}/lib/clang/${version}/include`)) { 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`)) { } 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"`) await addEnv("LDFLAGS", `-L"${directory}/lib"`)
addEnv("CPPFLAGS", `-I"${directory}/include"`) await addEnv("CPPFLAGS", `-I"${directory}/include"`)
addEnv("CC", `${directory}/bin/clang`) await addEnv("CC", `${directory}/bin/clang`)
addEnv("CXX", `${directory}/bin/clang++`) await addEnv("CXX", `${directory}/bin/clang++`)
addEnv("LIBRARY_PATH", `${directory}/lib`) await addEnv("LIBRARY_PATH", `${directory}/lib`)
await setupMacOSSDK() await setupMacOSSDK()

View File

@ -8,7 +8,7 @@ export async function setupMacOSSDK() {
const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path") const xcrun = await getExecOutput("xcrun --sdk macosx --show-sdk-path")
const sdkroot = xcrun.stdout || xcrun.stderr const sdkroot = xcrun.stdout || xcrun.stderr
if (sdkroot) { if (sdkroot) {
addEnv("SDKROOT", sdkroot.trim()) await addEnv("SDKROOT", sdkroot.trim())
} else { } else {
error(`SDKROOT not set`) error(`SDKROOT not set`)
} }

View File

@ -164,7 +164,16 @@ export async function main(args: string[]): Promise<number> {
try { try {
let installationInfo: InstallationInfo | undefined | void let installationInfo: InstallationInfo | undefined | void
if (tool === "vcvarsall") { 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 { } else {
// get the setup function // get the setup function
const setupFunction = setups[tool] const setupFunction = setups[tool]
@ -224,15 +233,19 @@ export async function main(args: string[]): Promise<number> {
case "visualstudio": case "visualstudio":
case "visualcpp": case "visualcpp":
case "visualc++": { 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)) successMessages.push(getSuccessMessage("msvc", installationInfo))
break break
} }
case "appleclang": case "appleclang":
case "applellvm": { case "applellvm": {
notice("Assuming apple-clang is already installed") notice("Assuming apple-clang is already installed")
addEnv("CC", "clang") await addEnv("CC", "clang")
addEnv("CXX", "clang++") await addEnv("CXX", "clang++")
successMessages.push(getSuccessMessage("apple-clang", undefined)) successMessages.push(getSuccessMessage("apple-clang", undefined))
break break
} }

View File

@ -4,14 +4,14 @@ import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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) { switch (process.platform) {
case "win32": { case "win32": {
return setupChocoPack("make", version) return setupChocoPack("make", version)
} }
case "darwin": { case "darwin": {
setupBrewPack("make", version) 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" } return { binDir: "/usr/local/opt/make/libexec/gnubin" }
} }
case "linux": { case "linux": {

View File

@ -3,12 +3,12 @@ import { setupMSVC } from "../msvc"
jest.setTimeout(300000) jest.setTimeout(300000)
describe("setup-msvc", () => { describe("setup-msvc", () => {
it("should setup the pre-installed msvc", () => { it("should setup the pre-installed msvc", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
setupMSVC("", "", process.arch) await setupMSVC("", "", process.arch)
console.log(which.sync("cl")) console.log(which.sync("cl"))
} catch (e) { } catch (e) {
// TODO // TODO
@ -16,12 +16,12 @@ describe("setup-msvc", () => {
} }
}) })
it("should setup msvc 2022", () => { it("should setup msvc 2022", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
setupMSVC("2022", "", process.arch) await setupMSVC("2022", "", process.arch)
console.log(which.sync("cl")) console.log(which.sync("cl"))
} catch (e) { } catch (e) {
// TODO // TODO
@ -29,12 +29,12 @@ describe("setup-msvc", () => {
} }
}) })
it("should setup msvc 2019", () => { it("should setup msvc 2019", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
setupMSVC("2019", "", process.arch) await setupMSVC("2019", "", process.arch)
console.log(which.sync("cl")) console.log(which.sync("cl"))
} catch (e) { } catch (e) {
// TODO // TODO
@ -42,12 +42,12 @@ describe("setup-msvc", () => {
} }
}) })
it("should setup msvc 2017", () => { it("should setup msvc 2017", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
setupMSVC("2017", "", process.arch) await setupMSVC("2017", "", process.arch)
console.log(which.sync("cl")) console.log(which.sync("cl"))
} catch (e) { } catch (e) {
// TODO // TODO
@ -55,12 +55,12 @@ describe("setup-msvc", () => {
} }
}) })
it("should setup msvc 2015", () => { it("should setup msvc 2015", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
setupMSVC("2015", "", process.arch) await setupMSVC("2015", "", process.arch)
console.log(which.sync("cl")) console.log(which.sync("cl"))
} catch (e) { } catch (e) {
// TODO // TODO

View File

@ -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 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, versionGiven: MSVCVersion,
_setupDir: string, _setupDir: string,
arch: string, arch: string,
@ -41,19 +41,19 @@ export function setupMSVC(
try { try {
if (version === "14.0") { if (version === "14.0") {
toolset = "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" VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
} else if (version === "15.0") { } else if (version === "15.0") {
toolset = "14.16" 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 VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
} else if (version === "16.0") { } else if (version === "16.0") {
toolset = "14.29" 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" VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
} else if (version === "17.0") { } else if (version === "17.0") {
toolset = undefined toolset = undefined
setupChocoPack("visualstudio2022buildtools", "117.0.5.0", []) await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
VCTargetsPath = undefined VCTargetsPath = undefined
} else { } else {
error(`The given MSVC versions ${versionGiven} is not supported yet.`) error(`The given MSVC versions ${versionGiven} is not supported yet.`)
@ -63,7 +63,7 @@ export function setupMSVC(
} }
} }
// run vcvarsall.bat environment variables // run vcvarsall.bat environment variables
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre) await setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
if (isGitHubCI()) { if (isGitHubCI()) {
addMSVCLoggingMatcher() addMSVCLoggingMatcher()

View File

@ -7,12 +7,12 @@ export async function setupOpencppcoverage(version: string | undefined, _setupDi
return return
} }
await setupChocoPack("opencppcoverage", version) await setupChocoPack("opencppcoverage", version)
const binDir = activateOpencppcoverage() const binDir = await activateOpencppcoverage()
return { binDir } return { binDir }
} }
function activateOpencppcoverage() { async function activateOpencppcoverage() {
const binDir = "C:/Program Files/OpenCppCoverage" const binDir = "C:/Program Files/OpenCppCoverage"
addPath(binDir) await addPath(binDir)
return binDir return binDir
} }

View File

@ -20,18 +20,18 @@ export async function setupPython(version: string, setupDir: string, arch: strin
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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) { switch (process.platform) {
case "win32": { case "win32": {
if (setupDir) { if (setupDir) {
setupChocoPack("python3", version, [`--params=/InstallDir:${setupDir}`]) await setupChocoPack("python3", version, [`--params=/InstallDir:${setupDir}`])
} else { } else {
setupChocoPack("python3", version) await setupChocoPack("python3", version)
} }
// Adding the bin dir to the path // Adding the bin dir to the path
/** The directory which the tool is installed to */ /** The directory which the tool is installed to */
activateWinPython(setupDir) await activateWinPython(setupDir)
return { installDir: setupDir, binDir: setupDir } return { installDir: setupDir, binDir: setupDir }
} }
case "darwin": { 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`) info(`Add ${binDir} to PATH`)
addPath(binDir) await addPath(binDir)
} }

View File

@ -8,13 +8,13 @@ import { delimiter } from "path"
import { escapeSpace } from "../path/escape_space" import { escapeSpace } from "../path/escape_space"
/** An add path function that works locally or inside GitHub Actions */ /** 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 const val = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
try { try {
if (isGitHubCI()) { if (isGitHubCI()) {
exportVariable(name, val) exportVariable(name, val)
} else { } else {
addEnvSystem(name, val) await addEnvSystem(name, val)
} }
} catch (err) { } catch (err) {
try { 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 */ /** 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}` process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try { try {
if (isGitHubCI()) { if (isGitHubCI()) {
ghAddPath(path) ghAddPath(path)
} else { } else {
addPathSystem(path) await addPathSystem(path)
} }
} catch (err) { } catch (err) {
try { try {
@ -49,12 +49,12 @@ export function addPath(path: string) {
export const cpprc_path = untildify(".cpprc") export const cpprc_path = untildify(".cpprc")
function addEnvSystem(name: string, valGiven: string | undefined) { async function addEnvSystem(name: string, valGiven: string | undefined) {
const val = valGiven ?? "" const val = valGiven ?? ""
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
// We do not use `execa.sync(`setx PATH "${path};%PATH%"`)` because of its character limit // 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."`) info(`${name}="${val} was set in the environment."`)
return return
} }
@ -72,11 +72,11 @@ function addEnvSystem(name: string, valGiven: string | undefined) {
process.env[name] = val process.env[name] = val
} }
function addPathSystem(path: string) { async function addPathSystem(path: string) {
switch (process.platform) { switch (process.platform) {
case "win32": { 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 // 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")` `$USER_PATH=([Environment]::GetEnvironmentVariable("PATH", "User")); [Environment]::SetEnvironmentVariable("PATH", "${path};$USER_PATH", "User")`
) )
info(`${path} was added to the PATH.`) info(`${path} was added to the PATH.`)

View File

@ -3,7 +3,11 @@ import which from "which"
let powershell: string | undefined let powershell: string | undefined
export function execPowershell(command: string) { export function execPowershell(command: string, startupFlags: string[] = ["-NoProfile", "-NoLogo", "-NonInteractive"]) {
return execa(getPowerShell(), [...startupFlags, "-c", command], { stdio: "inherit" })
}
function getPowerShell() {
if (powershell === undefined) { if (powershell === undefined) {
const maybePwsh = which.sync("pwsh", { nothrow: true }) const maybePwsh = which.sync("pwsh", { nothrow: true })
if (maybePwsh !== null) { if (maybePwsh !== null) {
@ -17,6 +21,5 @@ export function execPowershell(command: string) {
if (powershell === undefined) { if (powershell === undefined) {
throw new Error("Could not find powershell") throw new Error("Could not find powershell")
} }
return powershell
execa.sync(powershell, ["-c", command], { stdio: "inherit" })
} }

View File

@ -26,12 +26,12 @@ async function getSevenZip() {
} }
/// Extract Exe using 7z /// Extract Exe using 7z
export async function extractExe(file: string, dest: string) { export function extractExe(file: string, dest: string) {
return extract7Zip(file, dest) return extract7Zip(file, dest)
} }
/// Extract Zip using 7z /// Extract Zip using 7z
export async function extractZip(file: string, dest: string) { export function extractZip(file: string, dest: string) {
return extract7Zip(file, dest) return extract7Zip(file, dest)
} }

View File

@ -67,7 +67,7 @@ export async function setupBin(
const binDir = join(installDir, binRelativeDir) const binDir = join(installDir, binRelativeDir)
if (existsSync(binDir) && existsSync(join(binDir, binFileName))) { if (existsSync(binDir) && existsSync(join(binDir, binFileName))) {
info(`${name} ${version} was found in the cache at ${binDir}.`) info(`${name} ${version} was found in the cache at ${binDir}.`)
addPath(binDir) await addPath(binDir)
return { installDir, binDir } return { installDir, binDir }
} }
@ -107,7 +107,7 @@ export async function setupBin(
// Adding the bin dir to the path // Adding the bin dir to the path
/** The directory which the tool is installed to */ /** The directory which the tool is installed to */
info(`Add ${binDir} to PATH`) info(`Add ${binDir} to PATH`)
addPath(binDir) await addPath(binDir)
// check if inside Github Actions. If so, cache the installation // check if inside Github Actions. If so, cache the installation
if (isGitHubCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") { if (isGitHubCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {

View File

@ -9,11 +9,11 @@ import { info } from "@actions/core"
let hasChoco = false let hasChoco = false
/** A function that installs a package using choco */ /** 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`) info(`Installing ${name} ${version ?? ""} via chocolatey`)
if (!hasChoco || which.sync("choco", { nothrow: true }) === null) { if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
setupChocolatey("", "", process.arch) await setupChocolatey("", "", process.arch)
hasChoco = true hasChoco = true
} }
@ -36,7 +36,7 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
} }
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin` const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
addPath(binDir) await addPath(binDir)
return { binDir } return { binDir }
} }

View File

@ -70,7 +70,7 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
} }
} }
info(`${binDir} to PATH`) info(`${binDir} to PATH`)
addPath(binDir) await addPath(binDir)
} }
return { binDir } return { binDir }

View File

@ -13,7 +13,7 @@ import { InstallationInfo } from "../utils/setup/setupBin"
let hasVCPKG = false let hasVCPKG = false
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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 (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
if (process.platform === "linux") { if (process.platform === "linux") {
// vcpkg download and extraction dependencies // 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) execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
} }
addPath(setupDir) await addPath(setupDir)
// eslint-disable-next-line require-atomic-updates // eslint-disable-next-line require-atomic-updates
hasVCPKG = true hasVCPKG = true
return { binDir: setupDir } return { binDir: setupDir }

View File

@ -21,7 +21,7 @@ function getArch(arch: string): string {
} }
} }
export function setupVCVarsall( export async function setupVCVarsall(
vsversion: string, vsversion: string,
VCTargetsPath: string | undefined, VCTargetsPath: string | undefined,
arch: string, arch: string,
@ -32,7 +32,7 @@ export function setupVCVarsall(
) { ) {
if (VCTargetsPath !== undefined && existsSync(VCTargetsPath)) { if (VCTargetsPath !== undefined && existsSync(VCTargetsPath)) {
info(`Adding ${VCTargetsPath} to PATH`) info(`Adding ${VCTargetsPath} to PATH`)
addEnv("VCTargetsPath", VCTargetsPath) await addEnv("VCTargetsPath", VCTargetsPath)
} }
setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre, vsversion) setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre, vsversion)