implements PLN-0106
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.49% (17397/28294)
* Branch Coverage: 52.32% (6724/12852)
* Lines of Code: 28294
* Cyclomatic Complexity: 11339
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 608
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 61.49% (17397/28294)
* Branch Coverage: 52.32% (6724/12852)
* Lines of Code: 28294
* Cyclomatic Complexity: 11339
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 608
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
This commit is contained in:
+2
-8
@@ -17,13 +17,7 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
@Override
|
||||
public BuildingIssueSink run(final BuilderPipelineContext ctx, final LogAggregator logs) {
|
||||
final var frontedSpec = ctx.resolvedWorkspace.frontendSpec();
|
||||
final var service = FrontendRegistryService.getFrontendPhaseService(frontedSpec.getLanguageId());
|
||||
if (service.isEmpty()) {
|
||||
return BuildingIssueSink.empty()
|
||||
.report(builder -> builder
|
||||
.error(true)
|
||||
.message("[BUILD]: unable to find a service for frontend phase: " + frontedSpec.getLanguageId()));
|
||||
}
|
||||
final var provider = FrontendRegistryService.require(frontedSpec.getLanguageId());
|
||||
final var projectTable = ctx.resolvedWorkspace.graph().projectTable();
|
||||
final var fileTable = ctx.fileTable;
|
||||
final var frontendPhaseContext = new FrontendPhaseContext(
|
||||
@@ -36,7 +30,7 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
assetSurfaceContextLoader.load(ctx.resolvedWorkspace.mainProject().getRootPath()));
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
final var issues = BuildingIssueSink.empty();
|
||||
ctx.irBackend = service.get().compile(frontendPhaseContext, diagnostics, logs, issues);
|
||||
ctx.irBackend = provider.compiler().compile(frontendPhaseContext, diagnostics, logs, issues);
|
||||
logs.using(log).debug("Frontend phase completed successfully!");
|
||||
adaptDiagnostics(diagnostics, issues);
|
||||
return issues;
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package p.studio.compiler.specs;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
class FrontendProviderBoundaryTest {
|
||||
|
||||
@Test
|
||||
void commonModulesMustNotInstantiatePbsFrontendPhaseServiceDirectly() throws IOException {
|
||||
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
|
||||
final var commonSourceRoots = List.of(
|
||||
repoRoot.resolve("prometeu-compiler/prometeu-build-pipeline/src/main/java"),
|
||||
repoRoot.resolve("prometeu-compiler/prometeu-deps/src/main/java"),
|
||||
repoRoot.resolve("prometeu-studio/src/main/java"),
|
||||
repoRoot.resolve("prometeu-app/src/main/java"));
|
||||
|
||||
for (final var sourceRoot : commonSourceRoots) {
|
||||
if (!Files.exists(sourceRoot)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (final var files = Files.walk(sourceRoot)) {
|
||||
final var violations = files
|
||||
.filter(path -> path.toString().endsWith(".java"))
|
||||
.filter(path -> contains(path, "new PBSFrontendPhaseService("))
|
||||
.toList();
|
||||
if (!violations.isEmpty()) {
|
||||
fail("common modules must resolve frontend compiler behavior through FrontendProvider: " + violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contains(final Path path, final String needle) {
|
||||
try {
|
||||
return Files.readString(path).contains(needle);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("failed to read " + path, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Path findRepoRoot(final Path start) {
|
||||
var current = start;
|
||||
while (current != null) {
|
||||
if (Files.exists(current.resolve("settings.gradle.kts"))) {
|
||||
return current;
|
||||
}
|
||||
current = current.getParent();
|
||||
}
|
||||
fail("unable to locate repository root from " + start);
|
||||
return start;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -60,7 +60,7 @@ public final class PrometeuManifestUtils {
|
||||
.message("[DEPS]: invalid 'target' \"" + dto.target() + "\": " + manifestPathCanon));
|
||||
}
|
||||
final var language = StringUtils.isBlank(dto.language())
|
||||
? FrontendRegistryService.getDefaultFrontendSpec().getLanguageId()
|
||||
? FrontendRegistryService.getDefaultProvider().specification().getLanguageId()
|
||||
: dto.language();
|
||||
final var dependencies = DependencyResolver.resolveDependencies(mainProjectRootPathCanon, dto.dependencies(), issuesLocal);
|
||||
if (ReadOnlyCollection.isNotEmpty(issuesLocal)) {
|
||||
|
||||
+6
-5
@@ -55,23 +55,24 @@ public class DiscoverPhase implements DependencyPhase {
|
||||
ctx.rootStdlib = manifest.get().stdlib();
|
||||
ctx.target = manifest.get().target();
|
||||
}
|
||||
final var frontendSpec = FrontendRegistryService.getFrontendSpec(manifest.get().language());
|
||||
final var frontendProvider = FrontendRegistryService.getProvider(manifest.get().language());
|
||||
// Returns empty when language is unknown
|
||||
if (frontendSpec.isEmpty()) {
|
||||
if (frontendProvider.isEmpty()) {
|
||||
issues.report(builder -> builder
|
||||
.error(true)
|
||||
.message("[DEPS]: unknown language " + manifest.get().language() + " for project " + manifest.get().name()));
|
||||
return Optional.empty();
|
||||
}
|
||||
final var frontendSpec = frontendProvider.get().specification();
|
||||
// Enforces consistent language across projects
|
||||
if (Objects.isNull(ctx.frontendSpec)) {
|
||||
ctx.frontendSpec = frontendSpec.get();
|
||||
} else if (!ctx.frontendSpec.getLanguageId().equals(frontendSpec.get().getLanguageId())) {
|
||||
ctx.frontendSpec = frontendSpec;
|
||||
} else if (!ctx.frontendSpec.getLanguageId().equals(frontendSpec.getLanguageId())) {
|
||||
// Reports language inconsistency across projects
|
||||
issues.report(builder -> builder
|
||||
.error(true)
|
||||
.message(String.format("[DEPS]: inconsistent language: [ %s ] has \"%s\" but should be \"%s\"",
|
||||
manifest.get().name(), frontendSpec.get().getLanguageId(), ctx.frontendSpec.getLanguageId())));
|
||||
manifest.get().name(), frontendSpec.getLanguageId(), ctx.frontendSpec.getLanguageId())));
|
||||
return Optional.empty();
|
||||
}
|
||||
final var projectInfo = ProjectInfo
|
||||
|
||||
@@ -6,7 +6,7 @@ dependencies {
|
||||
implementation(project(":prometeu-infra"))
|
||||
implementation(project(":prometeu-compiler:prometeu-compiler-core"))
|
||||
|
||||
implementation(project(":prometeu-compiler:prometeu-frontend-api"))
|
||||
api(project(":prometeu-compiler:prometeu-frontend-api"))
|
||||
|
||||
implementation(project(":prometeu-compiler:frontends:prometeu-frontend-pbs"))
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -21,7 +21,11 @@ public class FrontendRegistryService {
|
||||
}
|
||||
|
||||
public static FrontendSpec getDefaultFrontendSpec() {
|
||||
return require(PBSDefinitions.PBS.getLanguageId()).specification();
|
||||
return getDefaultProvider().specification();
|
||||
}
|
||||
|
||||
public static FrontendProvider getDefaultProvider() {
|
||||
return require(PBSDefinitions.PBS.getLanguageId());
|
||||
}
|
||||
|
||||
public static Optional<FrontendSpec> getFrontendSpec(final String languageId) {
|
||||
|
||||
+8
@@ -33,4 +33,12 @@ class FrontendRegistryServiceTest {
|
||||
assertEquals(1, specs.size());
|
||||
assertEquals(PBSDefinitions.PBS.getLanguageId(), specs.getFirst().getLanguageId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void providerListingShouldExposeOnlyPbsByDefault() {
|
||||
final var providers = FrontendRegistryService.listProviders();
|
||||
|
||||
assertEquals(1, providers.size());
|
||||
assertEquals(PBSDefinitions.PBS.getLanguageId(), providers.getFirst().specification().getLanguageId());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user