Skip to content

Commit

Permalink
[GR-50844] [GR-50853] Create additional artifacts only on successful …
Browse files Browse the repository at this point in the history
…build

PullRequest: graal/16375
  • Loading branch information
petalex committed Dec 21, 2023
2 parents bddd695 + 765f062 commit 195a916
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,15 @@ private int buildImage(ImageClassLoader classLoader) {
vmError = e;
return ExitStatus.BUILDER_ERROR.getValue();
} finally {
reportEpilog(imageName, reporter, classLoader, vmError, parsedHostedOptions);
reportEpilog(imageName, reporter, classLoader, wasSuccessfulBuild, vmError, parsedHostedOptions);
NativeImageGenerator.clearSystemPropertiesForImage();
ImageSingletonsSupportImpl.HostedManagement.clear();
}
return ExitStatus.OK.getValue();
}

protected void reportEpilog(String imageName, ProgressReporter reporter, ImageClassLoader classLoader, Throwable vmError, OptionValues parsedHostedOptions) {
reporter.printEpilog(Optional.ofNullable(imageName), Optional.ofNullable(generator), classLoader, Optional.ofNullable(vmError), parsedHostedOptions);
protected void reportEpilog(String imageName, ProgressReporter reporter, ImageClassLoader classLoader, boolean wasSuccessfulBuild, Throwable vmError, OptionValues parsedHostedOptions) {
reporter.printEpilog(Optional.ofNullable(imageName), Optional.ofNullable(generator), classLoader, wasSuccessfulBuild, Optional.ofNullable(vmError), parsedHostedOptions);
}

protected NativeImageGenerator createImageGenerator(ImageClassLoader classLoader, HostedOptionParser optionParser, Pair<Method, CEntryPointData> mainEntryPointData, ProgressReporter reporter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ private void printRecommendations() {
}
}

public void printEpilog(Optional<String> optionalImageName, Optional<NativeImageGenerator> optionalGenerator, ImageClassLoader classLoader, Optional<Throwable> optionalError,
OptionValues parsedHostedOptions) {
public void printEpilog(Optional<String> optionalImageName, Optional<NativeImageGenerator> optionalGenerator, ImageClassLoader classLoader, boolean wasSuccessfulBuild,
Optional<Throwable> optionalError, OptionValues parsedHostedOptions) {
executor.shutdown();

if (optionalError.isPresent()) {
Expand All @@ -712,7 +712,7 @@ public void printEpilog(Optional<String> optionalImageName, Optional<NativeImage
double totalSeconds = Utils.millisToSeconds(getTimer(TimerCollection.Registry.TOTAL).getTotalTime());
recordJsonMetric(ResourceUsageKey.TOTAL_SECS, totalSeconds);

createAdditionalArtifacts(imageName, generator, optionalError, parsedHostedOptions);
createAdditionalArtifacts(imageName, generator, wasSuccessfulBuild, parsedHostedOptions);
printArtifacts(generator.getBuildArtifacts());

l().printHeadlineSeparator();
Expand Down Expand Up @@ -753,19 +753,23 @@ private void printErrorMessage(Optional<Throwable> optionalError, OptionValues p
}
}

private void createAdditionalArtifacts(String imageName, NativeImageGenerator generator, Optional<Throwable> error, OptionValues parsedHostedOptions) {
private void createAdditionalArtifacts(String imageName, NativeImageGenerator generator, boolean wasSuccessfulBuild, OptionValues parsedHostedOptions) {
BuildArtifacts artifacts = BuildArtifacts.singleton();
if (wasSuccessfulBuild) {
createAdditionalArtifactsOnSuccess(artifacts, generator, parsedHostedOptions);
}
BuildArtifactsExporter.run(imageName, artifacts, generator.getBuildArtifacts());
}

private void createAdditionalArtifactsOnSuccess(BuildArtifacts artifacts, NativeImageGenerator generator, OptionValues parsedHostedOptions) {
Optional<Path> buildOutputJSONFile = SubstrateOptions.BuildOutputJSONFile.getValue(parsedHostedOptions).lastValue();
if (error.isEmpty() && buildOutputJSONFile.isPresent()) {
if (buildOutputJSONFile.isPresent()) {
artifacts.add(ArtifactType.BUILD_INFO, reportBuildOutput(buildOutputJSONFile.get()));
}
if (generator.getBigbang() != null && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(parsedHostedOptions)) {
artifacts.add(ArtifactType.BUILD_INFO, reportImageBuildStatistics());
}
if (error.isEmpty()) {
ImageSingletons.lookup(ProgressReporterFeature.class).createAdditionalArtifacts(artifacts);
}
BuildArtifactsExporter.run(imageName, artifacts, generator.getBuildArtifacts());
ImageSingletons.lookup(ProgressReporterFeature.class).createAdditionalArtifactsOnSuccess(artifacts);
}

private void printArtifacts(Map<ArtifactType, List<Path>> artifacts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void afterBreakdowns() {
}
}

public void createAdditionalArtifacts(@SuppressWarnings("unused") BuildArtifacts artifacts) {
public void createAdditionalArtifactsOnSuccess(@SuppressWarnings("unused") BuildArtifacts artifacts) {
}

protected List<UserRecommendation> getRecommendations() {
Expand Down

0 comments on commit 195a916

Please sign in to comment.