Use NATIVE_IMAGE_OPTIONS if possible.

This commit is contained in:
Fabio Niephaus 2024-03-21 08:37:34 +01:00
parent 3e1010f34c
commit ee8b81f45c
No known key found for this signature in database
GPG Key ID: F21CF5275F31DFD6
4 changed files with 97 additions and 39 deletions

42
dist/cleanup/index.js generated vendored
View File

@ -90553,10 +90553,10 @@ const c = __importStar(__nccwpck_require__(9042));
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147)); const fs = __importStar(__nccwpck_require__(7147));
const github = __importStar(__nccwpck_require__(5438)); const github = __importStar(__nccwpck_require__(5438));
const semver = __importStar(__nccwpck_require__(1383));
const path_1 = __nccwpck_require__(1017); const path_1 = __nccwpck_require__(1017);
const os_1 = __nccwpck_require__(2037); const os_1 = __nccwpck_require__(2037);
const utils_1 = __nccwpck_require__(1314); const utils_1 = __nccwpck_require__(1314);
const semver_1 = __nccwpck_require__(1383);
const BUILD_OUTPUT_JSON_PATH = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-build-output.json'); const BUILD_OUTPUT_JSON_PATH = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-build-output.json');
const BYTES_TO_KiB = 1024; const BYTES_TO_KiB = 1024;
const BYTES_TO_MiB = 1024 * 1024; const BYTES_TO_MiB = 1024 * 1024;
@ -90565,8 +90565,9 @@ const DOCS_BASE = 'https://github.com/oracle/graal/blob/master/docs/reference-ma
const INPUT_NI_JOB_REPORTS = 'native-image-job-reports'; const INPUT_NI_JOB_REPORTS = 'native-image-job-reports';
const INPUT_NI_PR_REPORTS = 'native-image-pr-reports'; const INPUT_NI_PR_REPORTS = 'native-image-pr-reports';
const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties'); const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties');
const NATIVE_IMAGE_OPTIONS_ENV = 'NATIVE_IMAGE_OPTIONS';
const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'; const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE';
function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion) { function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, javaVersionOrDev, graalVMVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const isRequired = areJobReportsEnabled() || arePRReportsEnabled(); const isRequired = areJobReportsEnabled() || arePRReportsEnabled();
if (!isRequired) { if (!isRequired) {
@ -90576,12 +90577,12 @@ function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion)
graalVMVersion === c.VERSION_LATEST || graalVMVersion === c.VERSION_LATEST ||
graalVMVersion === c.VERSION_DEV || graalVMVersion === c.VERSION_DEV ||
(!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) && (!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) &&
(0, semver_1.gte)((0, utils_1.toSemVer)(graalVMVersion), '22.2.0')); semver.gte((0, utils_1.toSemVer)(graalVMVersion), '22.2.0'));
if (!isSupported) { if (!isSupported) {
core.warning(`Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.`); core.warning(`Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.`);
return; return;
} }
setNativeImageOption(`-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`); // Escape backslashes for Windows setNativeImageOption(javaVersionOrDev, `-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`); // Escape backslashes for Windows
}); });
} }
exports.setUpNativeImageBuildReports = setUpNativeImageBuildReports; exports.setUpNativeImageBuildReports = setUpNativeImageBuildReports;
@ -90611,6 +90612,30 @@ function areJobReportsEnabled() {
function arePRReportsEnabled() { function arePRReportsEnabled() {
return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true'; return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true';
} }
function setNativeImageOption(javaVersionOrDev, optionValue) {
const coercedJavaVersionOrDev = semver.coerce(javaVersionOrDev);
if ((coercedJavaVersionOrDev &&
semver.gte(coercedJavaVersionOrDev, '22.0.0')) ||
javaVersionOrDev === c.VERSION_DEV ||
javaVersionOrDev.endsWith('-ea')) {
/* NATIVE_IMAGE_OPTIONS was introduced in GraalVM for JDK 22 (so were EA builds). */
let newOptionValue = optionValue;
const existingOptions = process.env[NATIVE_IMAGE_OPTIONS_ENV];
if (existingOptions) {
newOptionValue = `${existingOptions} ${newOptionValue}`;
}
core.exportVariable(NATIVE_IMAGE_OPTIONS_ENV, newOptionValue);
}
else {
const optionsFile = getNativeImageOptionsFile();
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${optionValue}`);
}
else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${optionValue}`);
}
}
}
function getNativeImageOptionsFile() { function getNativeImageOptionsFile() {
let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV]; let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV];
if (optionsFile === undefined) { if (optionsFile === undefined) {
@ -90619,15 +90644,6 @@ function getNativeImageOptionsFile() {
} }
return optionsFile; return optionsFile;
} }
function setNativeImageOption(value) {
const optionsFile = getNativeImageOptionsFile();
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${value}`);
}
else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${value}`);
}
}
function createReport(data) { function createReport(data) {
const context = github.context; const context = github.context;
const info = data.general_info; const info = data.general_info;

44
dist/main/index.js generated vendored
View File

@ -91333,10 +91333,10 @@ const c = __importStar(__nccwpck_require__(9042));
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147)); const fs = __importStar(__nccwpck_require__(7147));
const github = __importStar(__nccwpck_require__(5438)); const github = __importStar(__nccwpck_require__(5438));
const semver = __importStar(__nccwpck_require__(1383));
const path_1 = __nccwpck_require__(1017); const path_1 = __nccwpck_require__(1017);
const os_1 = __nccwpck_require__(2037); const os_1 = __nccwpck_require__(2037);
const utils_1 = __nccwpck_require__(1314); const utils_1 = __nccwpck_require__(1314);
const semver_1 = __nccwpck_require__(1383);
const BUILD_OUTPUT_JSON_PATH = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-build-output.json'); const BUILD_OUTPUT_JSON_PATH = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-build-output.json');
const BYTES_TO_KiB = 1024; const BYTES_TO_KiB = 1024;
const BYTES_TO_MiB = 1024 * 1024; const BYTES_TO_MiB = 1024 * 1024;
@ -91345,8 +91345,9 @@ const DOCS_BASE = 'https://github.com/oracle/graal/blob/master/docs/reference-ma
const INPUT_NI_JOB_REPORTS = 'native-image-job-reports'; const INPUT_NI_JOB_REPORTS = 'native-image-job-reports';
const INPUT_NI_PR_REPORTS = 'native-image-pr-reports'; const INPUT_NI_PR_REPORTS = 'native-image-pr-reports';
const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties'); const NATIVE_IMAGE_CONFIG_FILE = (0, path_1.join)((0, os_1.tmpdir)(), 'native-image-options.properties');
const NATIVE_IMAGE_OPTIONS_ENV = 'NATIVE_IMAGE_OPTIONS';
const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'; const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE';
function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion) { function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, javaVersionOrDev, graalVMVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const isRequired = areJobReportsEnabled() || arePRReportsEnabled(); const isRequired = areJobReportsEnabled() || arePRReportsEnabled();
if (!isRequired) { if (!isRequired) {
@ -91356,12 +91357,12 @@ function setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion)
graalVMVersion === c.VERSION_LATEST || graalVMVersion === c.VERSION_LATEST ||
graalVMVersion === c.VERSION_DEV || graalVMVersion === c.VERSION_DEV ||
(!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) && (!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) &&
(0, semver_1.gte)((0, utils_1.toSemVer)(graalVMVersion), '22.2.0')); semver.gte((0, utils_1.toSemVer)(graalVMVersion), '22.2.0'));
if (!isSupported) { if (!isSupported) {
core.warning(`Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.`); core.warning(`Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.`);
return; return;
} }
setNativeImageOption(`-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`); // Escape backslashes for Windows setNativeImageOption(javaVersionOrDev, `-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`); // Escape backslashes for Windows
}); });
} }
exports.setUpNativeImageBuildReports = setUpNativeImageBuildReports; exports.setUpNativeImageBuildReports = setUpNativeImageBuildReports;
@ -91391,6 +91392,30 @@ function areJobReportsEnabled() {
function arePRReportsEnabled() { function arePRReportsEnabled() {
return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true'; return (0, utils_1.isPREvent)() && core.getInput(INPUT_NI_PR_REPORTS) === 'true';
} }
function setNativeImageOption(javaVersionOrDev, optionValue) {
const coercedJavaVersionOrDev = semver.coerce(javaVersionOrDev);
if ((coercedJavaVersionOrDev &&
semver.gte(coercedJavaVersionOrDev, '22.0.0')) ||
javaVersionOrDev === c.VERSION_DEV ||
javaVersionOrDev.endsWith('-ea')) {
/* NATIVE_IMAGE_OPTIONS was introduced in GraalVM for JDK 22 (so were EA builds). */
let newOptionValue = optionValue;
const existingOptions = process.env[NATIVE_IMAGE_OPTIONS_ENV];
if (existingOptions) {
newOptionValue = `${existingOptions} ${newOptionValue}`;
}
core.exportVariable(NATIVE_IMAGE_OPTIONS_ENV, newOptionValue);
}
else {
const optionsFile = getNativeImageOptionsFile();
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${optionValue}`);
}
else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${optionValue}`);
}
}
}
function getNativeImageOptionsFile() { function getNativeImageOptionsFile() {
let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV]; let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV];
if (optionsFile === undefined) { if (optionsFile === undefined) {
@ -91399,15 +91424,6 @@ function getNativeImageOptionsFile() {
} }
return optionsFile; return optionsFile;
} }
function setNativeImageOption(value) {
const optionsFile = getNativeImageOptionsFile();
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${value}`);
}
else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${value}`);
}
}
function createReport(data) { function createReport(data) {
const context = github.context; const context = github.context;
const info = data.general_info; const info = data.general_info;
@ -92524,7 +92540,7 @@ function run() {
if (cache && (0, cache_1.isFeatureAvailable)()) { if (cache && (0, cache_1.isFeatureAvailable)()) {
yield (0, cache_2.restore)(cache); yield (0, cache_2.restore)(cache);
} }
(0, reports_1.setUpNativeImageBuildReports)(isGraalVMforJDK17OrLater, graalVMVersion); (0, reports_1.setUpNativeImageBuildReports)(isGraalVMforJDK17OrLater, javaVersion, graalVMVersion);
core.startGroup(`Successfully set up '${(0, path_1.basename)(graalVMHome)}'`); core.startGroup(`Successfully set up '${(0, path_1.basename)(graalVMHome)}'`);
yield (0, exec_1.exec)((0, path_1.join)(graalVMHome, 'bin', `java${c.EXECUTABLE_SUFFIX}`), [ yield (0, exec_1.exec)((0, path_1.join)(graalVMHome, 'bin', `java${c.EXECUTABLE_SUFFIX}`), [
javaVersion.startsWith('8') ? '-version' : '--version' javaVersion.startsWith('8') ? '-version' : '--version'

View File

@ -2,10 +2,10 @@ import * as c from '../constants'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as fs from 'fs' import * as fs from 'fs'
import * as github from '@actions/github' import * as github from '@actions/github'
import * as semver from 'semver'
import {join} from 'path' import {join} from 'path'
import {tmpdir} from 'os' import {tmpdir} from 'os'
import {createPRComment, isPREvent, toSemVer} from '../utils' import {createPRComment, isPREvent, toSemVer} from '../utils'
import {gte} from 'semver'
const BUILD_OUTPUT_JSON_PATH = join(tmpdir(), 'native-image-build-output.json') const BUILD_OUTPUT_JSON_PATH = join(tmpdir(), 'native-image-build-output.json')
const BYTES_TO_KiB = 1024 const BYTES_TO_KiB = 1024
@ -19,6 +19,7 @@ const NATIVE_IMAGE_CONFIG_FILE = join(
tmpdir(), tmpdir(),
'native-image-options.properties' 'native-image-options.properties'
) )
const NATIVE_IMAGE_OPTIONS_ENV = 'NATIVE_IMAGE_OPTIONS'
const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE' const NATIVE_IMAGE_CONFIG_FILE_ENV = 'NATIVE_IMAGE_CONFIG_FILE'
interface AnalysisResult { interface AnalysisResult {
@ -91,6 +92,7 @@ interface BuildOutput {
export async function setUpNativeImageBuildReports( export async function setUpNativeImageBuildReports(
isGraalVMforJDK17OrLater: boolean, isGraalVMforJDK17OrLater: boolean,
javaVersionOrDev: string,
graalVMVersion: string graalVMVersion: string
): Promise<void> { ): Promise<void> {
const isRequired = areJobReportsEnabled() || arePRReportsEnabled() const isRequired = areJobReportsEnabled() || arePRReportsEnabled()
@ -102,7 +104,7 @@ export async function setUpNativeImageBuildReports(
graalVMVersion === c.VERSION_LATEST || graalVMVersion === c.VERSION_LATEST ||
graalVMVersion === c.VERSION_DEV || graalVMVersion === c.VERSION_DEV ||
(!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) && (!graalVMVersion.startsWith(c.MANDREL_NAMESPACE) &&
gte(toSemVer(graalVMVersion), '22.2.0')) semver.gte(toSemVer(graalVMVersion), '22.2.0'))
if (!isSupported) { if (!isSupported) {
core.warning( core.warning(
`Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.` `Build reports for PRs and job summaries are only available in GraalVM 22.2.0 or later. This build job uses GraalVM ${graalVMVersion}.`
@ -110,6 +112,7 @@ export async function setUpNativeImageBuildReports(
return return
} }
setNativeImageOption( setNativeImageOption(
javaVersionOrDev,
`-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}` `-H:BuildOutputJSONFile=${BUILD_OUTPUT_JSON_PATH.replace(/\\/g, '\\\\')}`
) // Escape backslashes for Windows ) // Escape backslashes for Windows
} }
@ -144,6 +147,34 @@ function arePRReportsEnabled(): boolean {
return isPREvent() && core.getInput(INPUT_NI_PR_REPORTS) === 'true' return isPREvent() && core.getInput(INPUT_NI_PR_REPORTS) === 'true'
} }
function setNativeImageOption(
javaVersionOrDev: string,
optionValue: string
): void {
const coercedJavaVersionOrDev = semver.coerce(javaVersionOrDev)
if (
(coercedJavaVersionOrDev &&
semver.gte(coercedJavaVersionOrDev, '22.0.0')) ||
javaVersionOrDev === c.VERSION_DEV ||
javaVersionOrDev.endsWith('-ea')
) {
/* NATIVE_IMAGE_OPTIONS was introduced in GraalVM for JDK 22 (so were EA builds). */
let newOptionValue = optionValue
const existingOptions = process.env[NATIVE_IMAGE_OPTIONS_ENV]
if (existingOptions) {
newOptionValue = `${existingOptions} ${newOptionValue}`
}
core.exportVariable(NATIVE_IMAGE_OPTIONS_ENV, newOptionValue)
} else {
const optionsFile = getNativeImageOptionsFile()
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${optionValue}`)
} else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${optionValue}`)
}
}
}
function getNativeImageOptionsFile(): string { function getNativeImageOptionsFile(): string {
let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV] let optionsFile = process.env[NATIVE_IMAGE_CONFIG_FILE_ENV]
if (optionsFile === undefined) { if (optionsFile === undefined) {
@ -153,15 +184,6 @@ function getNativeImageOptionsFile(): string {
return optionsFile return optionsFile
} }
function setNativeImageOption(value: string): void {
const optionsFile = getNativeImageOptionsFile()
if (fs.existsSync(optionsFile)) {
fs.appendFileSync(optionsFile, ` ${value}`)
} else {
fs.writeFileSync(optionsFile, `NativeImageArgs = ${value}`)
}
}
function createReport(data: BuildOutput): string { function createReport(data: BuildOutput): string {
const context = github.context const context = github.context
const info = data.general_info const info = data.general_info

View File

@ -160,7 +160,11 @@ async function run(): Promise<void> {
if (cache && isCacheAvailable()) { if (cache && isCacheAvailable()) {
await restore(cache) await restore(cache)
} }
setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion) setUpNativeImageBuildReports(
isGraalVMforJDK17OrLater,
javaVersion,
graalVMVersion
)
core.startGroup(`Successfully set up '${basename(graalVMHome)}'`) core.startGroup(`Successfully set up '${basename(graalVMHome)}'`)
await exec(join(graalVMHome, 'bin', `java${c.EXECUTABLE_SUFFIX}`), [ await exec(join(graalVMHome, 'bin', `java${c.EXECUTABLE_SUFFIX}`), [