diff --git a/__tests__/msvc.test.ts b/__tests__/msvc.test.ts new file mode 100644 index 0000000..871244d --- /dev/null +++ b/__tests__/msvc.test.ts @@ -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) + } +}) diff --git a/dist/main/index.js b/dist/main/index.js index ddb18e6..58d1dd1 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -94570,7 +94570,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.setUpWindowsEnvironment = void 0; +exports.setUpWindowsEnvironment = exports.needsWindowsEnvironmentSetup = void 0; const core = __importStar(__nccwpck_require__(2186)); const child_process_1 = __nccwpck_require__(2081); const fs_1 = __nccwpck_require__(7147); @@ -94595,12 +94595,19 @@ function findVcvarsallPath() { } throw new Error('Failed to find vcvarsall.bat'); } -function setUpWindowsEnvironment(javaVersion, graalVMVersion, isGraalVMforJDK17OrLater) { - if (javaVersion === javaVersion || graalVMVersion === constants_1.VERSION_DEV) { - return; // no longer required in dev builds +function needsWindowsEnvironmentSetup(javaVersion, graalVMVersion, isGraalVMforJDK17OrLater) { + if (javaVersion === constants_1.VERSION_DEV || graalVMVersion === constants_1.VERSION_DEV) { + return false; // no longer required in dev builds } else if (isGraalVMforJDK17OrLater) { - return; // no longer required in GraalVM for JDK 17 and later. + return false; // no longer required in GraalVM for JDK 17 and later. + } + return true; +} +exports.needsWindowsEnvironmentSetup = needsWindowsEnvironmentSetup; +function setUpWindowsEnvironment(javaVersion, graalVMVersion, isGraalVMforJDK17OrLater) { + if (!needsWindowsEnvironmentSetup(javaVersion, graalVMVersion, isGraalVMforJDK17OrLater)) { + return; } core.startGroup('Updating Windows environment...'); const vcvarsallPath = findVcvarsallPath(); diff --git a/src/msvc.ts b/src/msvc.ts index 18aff3e..5e5658c 100644 --- a/src/msvc.ts +++ b/src/msvc.ts @@ -28,15 +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, isGraalVMforJDK17OrLater: boolean ): void { - if (javaVersion === javaVersion || graalVMVersion === VERSION_DEV) { - return // no longer required in dev builds - } else if (isGraalVMforJDK17OrLater) { - return // no longer required in GraalVM for JDK 17 and later. + if ( + !needsWindowsEnvironmentSetup( + javaVersion, + graalVMVersion, + isGraalVMforJDK17OrLater + ) + ) { + return } core.startGroup('Updating Windows environment...')