Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GraalVM for JDK 17+ detection in MSVC feature. #89

Merged
merged 2 commits into from
Mar 12, 2024
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
36 changes: 36 additions & 0 deletions __tests__/msvc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as path from 'path'
import {expect, test} from '@jest/globals'
import {needsWindowsEnvironmentSetup} from '../src/msvc'
import {VERSION_DEV, VERSION_LATEST} from '../src/constants'

process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')

test('decide whether Window env must be set up for GraalVM for JDK', async () => {
for (var javaVersion of [
'17',
'17.0.8',
'17.0',
'21',
'22',
'22-ea',
'23-ea',
VERSION_DEV
]) {
expect(needsWindowsEnvironmentSetup(javaVersion, '', true)).toBe(false)
}
})

test('decide whether Window env must be set up for legacy GraalVM', async () => {
for (var combination of [
['7', '22.3.0'],
['17', '22.3'],
['7', '22.3'],
['7', VERSION_DEV],
['17', VERSION_LATEST]
]) {
expect(
needsWindowsEnvironmentSetup(combination[0], combination[1], false)
).toBe(combination[1] !== VERSION_DEV)
}
})
27 changes: 15 additions & 12 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ async function run(): Promise<void> {
const enableCheckForUpdates =
core.getInput(c.INPUT_CHECK_FOR_UPDATES) === 'true'
const enableNativeImageMusl = core.getInput(c.INPUT_NI_MUSL) === 'true'
const isGraalVMforJDK17OrLater =
distribution.length > 0 || graalVMVersion.length == 0

if (c.IS_WINDOWS) {
setUpWindowsEnvironment(javaVersion, graalVMVersion)
setUpWindowsEnvironment(
javaVersion,
graalVMVersion,
isGraalVMforJDK17OrLater
)
}
await setUpDependencies(components)
if (enableNativeImageMusl) {
await setUpNativeImageMusl()
}

// Download GraalVM JDK
const isGraalVMforJDK17OrLater =
distribution.length > 0 || graalVMVersion.length == 0
let graalVMHome
if (isGraalVMforJDK17OrLater) {
if (
Expand Down
30 changes: 21 additions & 9 deletions src/msvc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,32 @@ function findVcvarsallPath(): string {
throw new Error('Failed to find vcvarsall.bat')
}

export function needsWindowsEnvironmentSetup(
javaVersion: string,
graalVMVersion: string,
isGraalVMforJDK17OrLater: boolean
): boolean {
if (javaVersion === VERSION_DEV || graalVMVersion === VERSION_DEV) {
return false // no longer required in dev builds
} else if (isGraalVMforJDK17OrLater) {
return false // no longer required in GraalVM for JDK 17 and later.
}
return true
}

export function setUpWindowsEnvironment(
javaVersion: string,
graalVMVersion: string
graalVMVersion: string,
isGraalVMforJDK17OrLater: boolean
): 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')
!needsWindowsEnvironmentSetup(
javaVersion,
graalVMVersion,
isGraalVMforJDK17OrLater
)
) {
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
return
}

core.startGroup('Updating Windows environment...')
Expand Down
Loading