From a1ee297bf237fa55982245fad02f87da7e208b12 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 3 Jan 2022 08:53:37 +0100 Subject: [PATCH] Set up Windows environment with build tools. --- src/main.ts | 5 +++++ src/msvc.ts | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/msvc.ts diff --git a/src/main.ts b/src/main.ts index 637a4bb..0ed2ece 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import * as graalvm from './graalvm' import {join} from 'path' import {mkdirP} from '@actions/io' import {setUpGraalVMTrunk} from './graalvm-trunk' +import {setUpWindowsEnvironment} from './msvc' async function run(): Promise { try { @@ -14,6 +15,10 @@ async function run(): Promise { componentsString.length > 0 ? componentsString.split(',') : [] const setJavaHome = core.getInput('set-java-home') === 'true' + if (c.IS_WINDOWS) { + setUpWindowsEnvironment() + } + await mkdirP(c.GRAALVM_BASE) // Download or build GraalVM diff --git a/src/msvc.ts b/src/msvc.ts new file mode 100644 index 0000000..9ad9339 --- /dev/null +++ b/src/msvc.ts @@ -0,0 +1,60 @@ +import * as core from '@actions/core' +import {execSync} from 'child_process' +import {existsSync} from 'fs' + +// Keep in sync with https://github.com/actions/virtual-environments +const KNOWN_VISUAL_STUDIO_INSTALLATIONS = [ + 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise', // 'windows-2016' + 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise', // 'windows-2019' and 'windows-latest' + 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise' // 'windows-2022' +] +const VCVARSALL_SUBPATH = '\\VC\\Auxiliary\\Build\\vcvarsall.bat' + +function findVcvarsallPath(): string { + for (const installation of KNOWN_VISUAL_STUDIO_INSTALLATIONS) { + const candidate = `${installation}${VCVARSALL_SUBPATH}` + if (existsSync(candidate)) { + return candidate + } + } + throw new Error('Failed to find vcvarsall.bat') +} + +export function setUpWindowsEnvironment(): void { + core.startGroup('Updating Windows environment...') + + const vcvarsallPath = findVcvarsallPath() + core.debug(`Calling "${vcvarsallPath}"...`) + const [originalEnv, vcvarsallOutput, updatedEnv] = execSync( + `set && cls && "${vcvarsallPath}" x64 && cls && set`, + {shell: 'cmd'} + ) + .toString() + .split('\f') // form feed page break (printed by `cls`) + core.debug(vcvarsallOutput) + + const originalEnvMap = new Map() + for (const line of originalEnv.split('\r\n')) { + if (line.includes('=')) { + const [name, value] = line.split('=') + originalEnvMap.set(name, value) + } else if (line) { + core.debug(`Skipping ${line} (does not include '=')...`) + } + } + + for (const line of updatedEnv.split('\r\n')) { + if (line.includes('=')) { + const [name, value] = line.split('=') + const originalValue = originalEnvMap.get(name) + if (value !== originalValue) { + core.exportVariable(name, value) + core.debug(`"${name}" set to "${value}"`) + } + } else if (line) { + core.debug(`Skipping ${line} (does not include '=')...`) + } + } + + core.endGroup() +}