mirror of
https://github.com/graalvm/setup-graalvm.git
synced 2025-01-31 19:26:36 +08:00
7652cc43b3
Fixes #32.
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import * as core from '@actions/core'
|
|
import * as semver from 'semver'
|
|
import {execSync} from 'child_process'
|
|
import {existsSync} from 'fs'
|
|
import {VERSION_DEV} from './constants'
|
|
|
|
// Keep in sync with https://github.com/actions/virtual-environments
|
|
const KNOWN_VISUAL_STUDIO_INSTALLATIONS = [
|
|
'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise', // 'windows-2022' and 'windows-latest'
|
|
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise', // 'windows-2019'
|
|
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise' // 'windows-2016' (deprecated and removed)
|
|
]
|
|
if (process.env['VSINSTALLDIR']) {
|
|
// if VSINSTALLDIR is set, make it the first known installation
|
|
KNOWN_VISUAL_STUDIO_INSTALLATIONS.unshift(
|
|
process.env['VSINSTALLDIR'].replace(/\\$/, '')
|
|
)
|
|
}
|
|
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(
|
|
javaVersion: string,
|
|
graalVMVersion: string
|
|
): void {
|
|
if (javaVersion === javaVersion || graalVMVersion === VERSION_DEV) {
|
|
return // no longer required in dev builds
|
|
}
|
|
const javaVersionSemVer = semver.coerce(javaVersion)
|
|
if (
|
|
javaVersionSemVer &&
|
|
semver.valid(javaVersionSemVer) &&
|
|
semver.gte(javaVersionSemVer, '18.0.0')
|
|
) {
|
|
return // no longer required in GraalVM for JDK 17 and later. JDK 17 builds from 22.3 still need this, so skip 17.X.X
|
|
}
|
|
|
|
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<string, string>()
|
|
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()
|
|
}
|