implements PLN-0010 builder pipeline entrypoints
This commit is contained in:
+3
-1
@@ -1,6 +1,7 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.compiler.messages.BuilderPipelineConfig;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.workspaces.BuilderPipelineService;
|
||||
import p.studio.utilities.PConstants;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
@@ -9,6 +10,7 @@ public class Compile {
|
||||
public static void main(String[] args) {
|
||||
final var logAggregator = LogAggregator.stdout();
|
||||
final var config = new BuilderPipelineConfig(false, "test-projects/%s".formatted(PConstants.PROJECT));
|
||||
BuilderPipelineService.INSTANCE.run(config, logAggregator);
|
||||
final var context = BuilderPipelineContext.fromConfig(config);
|
||||
BuilderPipelineService.INSTANCE.build(context, logAggregator);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -1,17 +1,28 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
|
||||
public record BuilderPipelineConfig(
|
||||
boolean explain,
|
||||
String rootProjectPath,
|
||||
String vmProfile) {
|
||||
String vmProfile,
|
||||
SourceProviderFactory sourceProviderFactory) {
|
||||
|
||||
public BuilderPipelineConfig(
|
||||
final boolean explain,
|
||||
final String rootProjectPath) {
|
||||
this(explain, rootProjectPath, "core-v1");
|
||||
this(explain, rootProjectPath, "core-v1", SourceProviderFactory.filesystem());
|
||||
}
|
||||
|
||||
public BuilderPipelineConfig(
|
||||
final boolean explain,
|
||||
final String rootProjectPath,
|
||||
final String vmProfile) {
|
||||
this(explain, rootProjectPath, vmProfile, SourceProviderFactory.filesystem());
|
||||
}
|
||||
|
||||
public BuilderPipelineConfig {
|
||||
vmProfile = vmProfile == null || vmProfile.isBlank() ? "core-v1" : vmProfile;
|
||||
sourceProviderFactory = sourceProviderFactory == null ? SourceProviderFactory.filesystem() : sourceProviderFactory;
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.source.tables.FileTable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record AnalysisSnapshot(
|
||||
List<BuildingIssue> diagnostics,
|
||||
ResolvedWorkspace resolvedWorkspace,
|
||||
FileTable fileTable,
|
||||
IRBackend irBackend) {
|
||||
public AnalysisSnapshot {
|
||||
diagnostics = List.copyOf(diagnostics);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public record BuildResult(
|
||||
CompileResult compileResult,
|
||||
List<BuildingIssue> diagnostics,
|
||||
Path bytecodeArtifactPath) {
|
||||
public BuildResult {
|
||||
diagnostics = List.copyOf(diagnostics);
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -30,7 +30,11 @@ public class BuilderPipelineContext {
|
||||
this.sourceProviderFactory = factory;
|
||||
}
|
||||
|
||||
public static BuilderPipelineContext fromConfig(final BuilderPipelineConfig config) {
|
||||
return new BuilderPipelineContext(config, config.sourceProviderFactory());
|
||||
}
|
||||
|
||||
public static BuilderPipelineContext compilerContext(final BuilderPipelineConfig config) {
|
||||
return new BuilderPipelineContext(config, SourceProviderFactory.filesystem());
|
||||
return fromConfig(config);
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.backend.bytecode.BytecodeModule;
|
||||
import p.studio.compiler.backend.irvm.IRVMProgram;
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public record CompileResult(
|
||||
AnalysisSnapshot analysisSnapshot,
|
||||
List<BuildingIssue> diagnostics,
|
||||
IRVMProgram irvm,
|
||||
IRVMProgram optimizedIrvm,
|
||||
BytecodeModule bytecodeModule,
|
||||
byte[] bytecodeBytes) {
|
||||
public CompileResult {
|
||||
diagnostics = List.copyOf(diagnostics);
|
||||
bytecodeBytes = bytecodeBytes == null ? null : Arrays.copyOf(bytecodeBytes, bytecodeBytes.length);
|
||||
}
|
||||
}
|
||||
+82
-17
@@ -2,12 +2,16 @@ package p.studio.compiler.workspaces;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import p.studio.compiler.exceptions.BuildException;
|
||||
import p.studio.compiler.messages.BuilderPipelineConfig;
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.models.AnalysisSnapshot;
|
||||
import p.studio.compiler.models.BuildResult;
|
||||
import p.studio.compiler.models.CompileResult;
|
||||
import p.studio.compiler.workspaces.stages.*;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@@ -35,29 +39,90 @@ public class BuilderPipelineService {
|
||||
this.stages = stages;
|
||||
}
|
||||
|
||||
public void run(
|
||||
final BuilderPipelineConfig config,
|
||||
public AnalysisSnapshot analyze(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var ctx = BuilderPipelineContext.compilerContext(config);
|
||||
final var diagnostics = runToTerminal(ctx, logs, FrontendPhasePipelineStage.class);
|
||||
return new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
ctx.fileTable,
|
||||
ctx.irBackend);
|
||||
}
|
||||
|
||||
public CompileResult compile(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = runToTerminal(ctx, logs, VerifyBytecodePipelineStage.class);
|
||||
final var analysisSnapshot = new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
ctx.fileTable,
|
||||
ctx.irBackend);
|
||||
return new CompileResult(
|
||||
analysisSnapshot,
|
||||
diagnostics,
|
||||
ctx.irvm,
|
||||
ctx.optimizedIrvm,
|
||||
ctx.bytecodeModule,
|
||||
ctx.bytecodeBytes);
|
||||
}
|
||||
|
||||
public BuildResult build(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = runToTerminal(ctx, logs, WriteBytecodeArtifactPipelineStage.class);
|
||||
final var analysisSnapshot = new AnalysisSnapshot(
|
||||
diagnostics,
|
||||
ctx.resolvedWorkspace,
|
||||
ctx.fileTable,
|
||||
ctx.irBackend);
|
||||
final var compileResult = new CompileResult(
|
||||
analysisSnapshot,
|
||||
diagnostics,
|
||||
ctx.irvm,
|
||||
ctx.optimizedIrvm,
|
||||
ctx.bytecodeModule,
|
||||
ctx.bytecodeBytes);
|
||||
return new BuildResult(
|
||||
compileResult,
|
||||
diagnostics,
|
||||
ctx.bytecodeArtifactPath);
|
||||
}
|
||||
|
||||
private List<BuildingIssue> runToTerminal(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs,
|
||||
final Class<? extends PipelineStage> terminalStage) {
|
||||
final var diagnostics = new ArrayList<BuildingIssue>();
|
||||
var completed = false;
|
||||
for (final var builderPipelineStage : stages) {
|
||||
final var issues = builderPipelineStage.run(ctx, logs);
|
||||
var error = false;
|
||||
if (ReadOnlyCollection.isNotEmpty(issues)) {
|
||||
for (final var issue : issues) {
|
||||
if (issue.isError()) {
|
||||
error = true;
|
||||
logs.using(log).error(issue.getMessage(), issue.getException());
|
||||
continue;
|
||||
}
|
||||
logs.using(log).warn(issue.getMessage());
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
diagnostics.addAll(issues.asCollection());
|
||||
printIssues(issues, logs);
|
||||
if (issues.hasErrors()) {
|
||||
throw new BuildException("issues found on pipeline stage: " + builderPipelineStage.getClass().getSimpleName());
|
||||
}
|
||||
if (terminalStage.isInstance(builderPipelineStage)) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!completed) {
|
||||
throw new BuildException("terminal stage not found on builder pipeline: " + terminalStage.getSimpleName());
|
||||
}
|
||||
logs.using(log).info("builder pipeline completed successfully through " + terminalStage.getSimpleName());
|
||||
return List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
logs.using(log).info("builder pipeline completed successfully");
|
||||
private void printIssues(
|
||||
final ReadOnlyCollection<BuildingIssue> issues,
|
||||
final LogAggregator logs) {
|
||||
if (ReadOnlyCollection.isEmpty(issues)) {
|
||||
return;
|
||||
}
|
||||
for (final var issue : issues) {
|
||||
issue.print(logs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user