add AppMode for best boundaries over stdlib
JaCoCo Coverage #### Project Overview No changes detected, that affect the code coverage. * Line Coverage: 61.98% (17344/27983) * Branch Coverage: 53.07% (6720/12663) * Lines of Code: 27983 * Cyclomatic Complexity: 11207 #### Quality Gates Summary Output truncated.
Test / Build skipped: 11, passed: 581
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

This commit is contained in:
2026-05-14 11:15:00 +01:00
parent 22887b56cd
commit 991863d086
54 changed files with 700 additions and 546 deletions
@@ -1,5 +1,6 @@
package p.studio.compiler;
import p.studio.AppMode;
import p.studio.compiler.models.FrontendSemanticToken;
import p.studio.compiler.models.FrontendSemanticTokenProvider;
import p.studio.compiler.pbs.ast.PbsAst;
@@ -26,6 +27,7 @@ import java.util.Set;
public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProvider {
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "float", "bool", "string", "i32", "i64", "f32", "f64");
private static final int DEFAULT_STDLIB_VERSION = 1;
private static final AppMode DEFAULT_TARGET = AppMode.Game;
private static final ResourceStdlibEnvironmentResolver STDLIB_RESOLVER = new ResourceStdlibEnvironmentResolver();
private static final Map<PbsTokenKind, PbsSemanticKind> DECLARATION_KINDS = declarationKinds();
@@ -210,7 +212,7 @@ public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProv
}
private Map<String, PbsSemanticKind> resolveStdlibExportKinds(final PbsAst.ModuleRef moduleRef) {
final var stdlibEnvironment = STDLIB_RESOLVER.resolve(DEFAULT_STDLIB_VERSION);
final var stdlibEnvironment = STDLIB_RESOLVER.resolve(DEFAULT_STDLIB_VERSION, DEFAULT_TARGET);
return stdlibEnvironment.resolveModule(moduleRef.project(), moduleRef.pathSegments())
.map(this::parseStdlibVisibleKinds)
.orElseGet(Map::of);
@@ -1,21 +1,14 @@
package p.studio.compiler.pbs.stdlib;
import p.studio.utilities.structures.ReadOnlyList;
import p.studio.AppMode;
import java.util.Optional;
public final class EmptyStdlibEnvironmentResolver implements StdlibEnvironmentResolver {
private static final StdlibEnvironment EMPTY = new StdlibEnvironment() {
@Override
public Optional<StdlibModuleSource> resolveModule(
final String project,
final ReadOnlyList<String> pathSegments) {
return Optional.empty();
}
};
private static final StdlibEnvironment EMPTY = (project, pathSegments) -> Optional.empty();
@Override
public StdlibEnvironment resolve(final int stdlibVersion) {
public StdlibEnvironment resolve(final int stdlibVersion, final AppMode target) {
return EMPTY;
}
}
@@ -1,26 +1,23 @@
package p.studio.compiler.pbs.stdlib;
import p.studio.AppMode;
import p.studio.utilities.structures.ReadOnlyList;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmentResolver {
private static final String STDLIB_ROOT = "stdlib";
@Override
public StdlibEnvironment resolve(final int stdlibVersion) {
return new ResourceStdlibEnvironment(stdlibVersion);
public StdlibEnvironment resolve(final int stdlibVersion, final AppMode target) {
return new ResourceStdlibEnvironment(stdlibVersion, target);
}
private static final class ResourceStdlibEnvironment implements StdlibEnvironment {
private final int stdlibVersion;
private ResourceStdlibEnvironment(final int stdlibVersion) {
this.stdlibVersion = stdlibVersion;
}
private record ResourceStdlibEnvironment(int stdlibVersion, AppMode target) implements StdlibEnvironment {
@Override
public Optional<StdlibModuleSource> resolveModule(
@@ -36,7 +33,7 @@ public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmen
return Optional.of(new StdlibModuleSource(
project,
pathSegments,
ReadOnlyList.wrap(java.util.List.of(new StdlibModuleSource.SourceFile("main.pbs", mainSource.get()))),
ReadOnlyList.wrap(List.of(new StdlibModuleSource.SourceFile("main.pbs", mainSource.get()))),
barrelSource.get()));
}
@@ -44,7 +41,10 @@ public final class ResourceStdlibEnvironmentResolver implements StdlibEnvironmen
final String project,
final ReadOnlyList<String> pathSegments) {
final var pathBuilder = new StringBuilder();
pathBuilder.append(STDLIB_ROOT)
pathBuilder
.append(target.exportReferenceName().toLowerCase())
.append('/')
.append(STDLIB_ROOT)
.append('/')
.append(stdlibVersion)
.append('/')
@@ -1,6 +1,8 @@
package p.studio.compiler.pbs.stdlib;
import p.studio.AppMode;
public interface StdlibEnvironmentResolver {
StdlibEnvironment resolve(int stdlibVersion);
StdlibEnvironment resolve(int stdlibVersion, AppMode target);
}
@@ -1,5 +1,6 @@
package p.studio.compiler.services;
import p.studio.AppMode;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRGlobalVisibility;
@@ -99,7 +100,8 @@ final class PbsModuleAssemblyService {
projectIdByName,
defaultSyntheticOwnerProjectId,
diagnostics,
ctx.stdlibVersion());
ctx.stdlibVersion(),
ctx.target());
final var modules = new ArrayList<PbsModuleVisibilityValidator.ModuleUnit>(modulesByCoordinates.size());
for (final var entry : modulesByCoordinates.entrySet()) {
@@ -206,28 +208,29 @@ final class PbsModuleAssemblyService {
final Map<String, ProjectId> projectIdByName,
final ProjectId defaultSyntheticOwnerProjectId,
final DiagnosticSink diagnostics,
final int stdlibVersion) {
final var stdlibEnvironment = stdlibEnvironmentResolver.resolve(stdlibVersion);
final int stdlibVersion,
final AppMode target) {
final var stdlibEnvironment = stdlibEnvironmentResolver.resolve(stdlibVersion, target);
final var pending = new ArrayDeque<PbsModuleVisibilityValidator.ModuleCoordinates>();
final var resolved = new HashSet<ModuleId>();
enqueueReservedImportsFromKnownModules(modulesByCoordinates, pending);
while (!pending.isEmpty()) {
final var target = pending.removeFirst();
final var targetId = moduleId(moduleTable, target);
if (!resolved.add(targetId)) {
final var moduleCoordinates = pending.removeFirst();
final var moduleId = moduleId(moduleTable, moduleCoordinates);
if (!resolved.add(moduleId)) {
continue;
}
if (modulesByCoordinates.containsKey(target)) {
if (modulesByCoordinates.containsKey(moduleCoordinates)) {
continue;
}
final var moduleSource = stdlibEnvironment.resolveModule(target.project(), target.pathSegments());
final var moduleSource = stdlibEnvironment.resolveModule(moduleCoordinates.project(), moduleCoordinates.pathSegments());
if (moduleSource.isEmpty()) {
continue;
}
final var syntheticOwnerProjectId = projectIdByName.getOrDefault(target.project(), defaultSyntheticOwnerProjectId);
final var syntheticOwnerProjectId = projectIdByName.getOrDefault(moduleCoordinates.project(), defaultSyntheticOwnerProjectId);
if (syntheticOwnerProjectId == null) {
continue;
}
@@ -241,15 +244,15 @@ final class PbsModuleAssemblyService {
moduleData.barrels.addAll(loadedModule.barrelFiles().asList());
modulesByCoordinates.put(loadedModule.coordinates(), moduleData);
for (final var sourceFile : loadedModule.sourceFiles()) {
moduleIdByFile.put(sourceFile.fileId(), targetId);
moduleIdByFile.put(sourceFile.fileId(), moduleId);
parsedSourceFiles.add(new PbsParsedSourceFile(
sourceFile.fileId(),
sourceFile.ast(),
targetId,
moduleId,
SourceKind.SDK_INTERFACE));
}
for (final var barrelFile : loadedModule.barrelFiles()) {
moduleIdByFile.put(barrelFile.fileId(), targetId);
moduleIdByFile.put(barrelFile.fileId(), moduleId);
}
enqueueReservedImportsFromSourceFiles(loadedModule.sourceFiles().asList(), pending);
}
@@ -2,6 +2,7 @@ package p.studio.compiler.pbs;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.AppMode;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.*;
@@ -460,7 +461,8 @@ class PbsGateUSdkInterfaceConformanceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
stdlibVersion);
stdlibVersion,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -2,6 +2,7 @@ package p.studio.compiler.pbs;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import p.studio.AppMode;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.BuildStack;
@@ -79,7 +80,8 @@ class PbsGateUStdlibCompileTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(projectIds)),
stdlibVersion);
stdlibVersion,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
new PBSFrontendPhaseService().compile(
@@ -96,7 +98,7 @@ class PbsGateUStdlibCompileTest {
private Map<String, StdlibProjectFiles> discoverStdlibProjects(
final int stdlibVersion) throws Exception {
final var resourcePath = "stdlib/" + stdlibVersion;
final var resourcePath = "game/stdlib/" + stdlibVersion;
final var classLoader = PbsGateUStdlibCompileTest.class.getClassLoader();
final var resource = classLoader.getResource(resourcePath);
assertNotNull(resource, "Stdlib version " + stdlibVersion + " was not found on classpath at " + resourcePath);
@@ -2,16 +2,12 @@ package p.studio.compiler.services;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.AppMode;
import p.studio.compiler.messages.Addressable;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FESurfaceContext;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.IRGlobalVisibility;
import p.studio.compiler.models.BuildStack;
import p.studio.compiler.models.IRHiddenGlobalKind;
import p.studio.compiler.models.ProjectDescriptor;
import p.studio.compiler.models.SourceHandle;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.models.*;
import p.studio.compiler.pbs.PbsHostAdmissionErrors;
import p.studio.compiler.pbs.linking.PbsLinkErrors;
import p.studio.compiler.pbs.semantics.PbsSemanticsErrors;
@@ -78,6 +74,7 @@ class PBSFrontendPhaseServiceTest {
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1,
AppMode.Game,
p.studio.compiler.messages.HostAdmissionContext.permissiveDefault(),
new FESurfaceContext(ReadOnlyList.from(new Addressable("assets.ui.panel", 91))));
final var diagnostics = DiagnosticSink.empty();
@@ -134,7 +131,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -185,7 +183,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -238,7 +237,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -308,7 +308,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -372,7 +373,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -416,7 +418,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
new PBSFrontendPhaseService().compile(
@@ -469,7 +472,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -557,7 +561,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -607,7 +612,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -664,7 +670,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -728,7 +735,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
7);
7,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = frontendService.compile(
@@ -779,7 +787,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
7);
7,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = frontendService.compile(
@@ -826,7 +835,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -879,7 +889,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -932,7 +943,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -991,7 +1003,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1050,7 +1063,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1121,7 +1135,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1193,7 +1208,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1256,7 +1272,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = frontendService.compile(
@@ -1320,7 +1337,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = frontendService.compile(
@@ -1401,7 +1419,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1473,7 +1492,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
9);
9,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = frontendService.compile(
@@ -1527,7 +1547,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1557,7 +1578,7 @@ class PBSFrontendPhaseServiceTest {
final var callableCalls = frameExecutable.instructions().stream()
.filter(instruction ->
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(instruction -> instruction.calleeCallableName())
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
final var intrinsicCalls = frameExecutable.instructions().stream()
.filter(instruction ->
@@ -1624,7 +1645,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1643,7 +1665,7 @@ class PBSFrontendPhaseServiceTest {
final var callableCalls = frameExecutable.instructions().stream()
.filter(instruction ->
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(instruction -> instruction.calleeCallableName())
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
final var intrinsicCalls = frameExecutable.instructions().stream()
.filter(instruction ->
@@ -1717,7 +1739,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
1,
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
@@ -1736,7 +1759,7 @@ class PBSFrontendPhaseServiceTest {
final var callableCalls = frameExecutable.instructions().stream()
.filter(instruction ->
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
.map(instruction -> instruction.calleeCallableName())
.map(IRBackendExecutableFunction.Instruction::calleeCallableName)
.toList();
final var intrinsicCalls = frameExecutable.instructions().stream()
.filter(instruction ->
@@ -1804,7 +1827,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
new PBSFrontendPhaseService().compile(
@@ -1861,7 +1885,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
new PBSFrontendPhaseService().compile(
@@ -1932,7 +1957,8 @@ class PBSFrontendPhaseServiceTest {
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
11);
11,
AppMode.Game);
final var deniedDiagnostics = DiagnosticSink.empty();
deniedFrontendService.compile(
@@ -1998,7 +2024,8 @@ class PBSFrontendPhaseServiceTest {
allowedProjectTable,
allowedFileTable,
new BuildStack(ReadOnlyList.wrap(List.of(allowedProjectId))),
12);
12,
AppMode.Game);
final var allowedDiagnostics = DiagnosticSink.empty();
allowedFrontendService.compile(
@@ -2056,7 +2083,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var inlineHintsByFile = PBSFrontendPhaseService.inlineHintsByFile(
@@ -2113,7 +2141,8 @@ class PBSFrontendPhaseServiceTest {
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))));
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
AppMode.Game);
final var diagnostics = DiagnosticSink.empty();
final var inlineHints = PBSFrontendPhaseService.inlineHintsByFile(
@@ -2148,7 +2177,7 @@ class PBSFrontendPhaseServiceTest {
for (final var module : modules) {
byModuleKey.put(moduleKey(module.project(), module.pathSegments()), module);
}
return stdlib -> {
return (stdlib, target) -> {
if (stdlib != acceptedStdlib) {
return (project, pathSegments) -> Optional.empty();
}
@@ -5,8 +5,8 @@ import p.studio.compiler.FrontendRegistryService;
import p.studio.compiler.messages.BuildingIssueSink;
import p.studio.compiler.messages.FrontendPhaseContext;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.workspaces.AssetSurfaceContextLoader;
import p.studio.compiler.source.diagnostics.DiagnosticSink;
import p.studio.compiler.workspaces.AssetSurfaceContextLoader;
import p.studio.compiler.workspaces.PipelineStage;
import p.studio.utilities.logs.LogAggregator;
@@ -31,6 +31,7 @@ public class FrontendPhasePipelineStage implements PipelineStage {
fileTable,
ctx.resolvedWorkspace.stack(),
ctx.resolvedWorkspace.stdlib(),
ctx.resolvedWorkspace.target(),
p.studio.compiler.messages.HostAdmissionContext.permissiveDefault(),
assetSurfaceContextLoader.load(ctx.resolvedWorkspace.mainProject().getRootPath()));
final var diagnostics = DiagnosticSink.empty();
@@ -2,6 +2,7 @@ package p.studio.compiler.models;
import lombok.Builder;
import lombok.Getter;
import p.studio.AppMode;
import p.studio.utilities.structures.ReadOnlyList;
import java.nio.file.Path;
@@ -12,6 +13,7 @@ public final class ProjectDescriptor {
private final Path rootPath; // canon root path
private final String name; // project name
private final String version; // project version
private final AppMode target; // project target (Game or System)
private final ReadOnlyList<Path> sourceRoots; // source roots canon paths for the project
@Builder.Default
private final SourceKind sourceKind = SourceKind.PROJECT;
@@ -10,6 +10,7 @@ public record PrometeuManifestDTO(
String version,
String language,
String stdlib,
String target,
List<DependencyDeclaration> dependencies) {
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@@ -1,5 +1,6 @@
package p.studio.compiler.models;
import p.studio.AppMode;
import p.studio.compiler.exceptions.BuildException;
import p.studio.compiler.messages.DependencyConfig;
import p.studio.compiler.source.identifiers.ProjectId;
@@ -23,6 +24,7 @@ public final class DependencyContext {
public Path mainProjectRootPathCanon;
public FrontendSpec frontendSpec;
public Integer rootStdlib;
public AppMode target;
public ProjectId rootProjectId;
public BuildStack stack;
@@ -51,7 +53,7 @@ public final class DependencyContext {
}
final var dependenciesByProject = buildDependenciesByProject();
final var workspaceGraph = new WorkspaceGraph(projectTable, dependenciesByProject);
return new ResolvedWorkspace(rootProjectId, frontendSpec, rootStdlib, workspaceGraph, stack);
return new ResolvedWorkspace(rootProjectId, frontendSpec, rootStdlib, target, workspaceGraph, stack);
}
@@ -1,5 +1,6 @@
package p.studio.compiler.models;
import p.studio.AppMode;
import p.studio.compiler.workspaces.DependencyReference;
import p.studio.utilities.structures.ReadOnlyList;
@@ -8,5 +9,6 @@ public record PrometeuManifest(
String version,
String language,
int stdlib,
AppMode target,
ReadOnlyList<DependencyReference> dependencies) {
}
@@ -1,11 +1,13 @@
package p.studio.compiler.models;
import p.studio.AppMode;
import p.studio.compiler.source.identifiers.ProjectId;
public record ResolvedWorkspace(
ProjectId mainProjectId,
FrontendSpec frontendSpec,
int stdlib,
AppMode target,
WorkspaceGraph graph,
BuildStack stack) {
public ProjectDescriptor mainProject() {
@@ -2,7 +2,9 @@ package p.studio.compiler.utilities;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import p.studio.AppMode;
import p.studio.compiler.FrontendRegistryService;
import p.studio.compiler.dtos.PrometeuManifestDTO;
import p.studio.compiler.messages.BuildingIssueSink;
@@ -45,7 +47,18 @@ public final class PrometeuManifestUtils {
.error(true)
.message("[DEPS]: manifest missing 'version': " + manifestPathCanon));
}
if (StringUtils.isBlank(dto.target())) {
issuesLocal.report(builder -> builder
.error(true)
.message("[DEPS]: manifest missing 'target': " + manifestPathCanon));
}
final var stdlibMaybe = parseStdlib(dto.stdlib(), manifestPathCanon, issuesLocal);
final var target = EnumUtils.getEnum(AppMode.class, dto.target());
if (target == null) {
issuesLocal.report(builder -> builder
.error(true)
.message("[DEPS]: invalid 'target' \"" + dto.target() + "\": " + manifestPathCanon));
}
final var language = StringUtils.isBlank(dto.language())
? FrontendRegistryService.getDefaultFrontendSpec().getLanguageId()
: dto.language();
@@ -54,7 +67,7 @@ public final class PrometeuManifestUtils {
issues.merge(issuesLocal);
return Optional.empty();
}
return Optional.of(new PrometeuManifest(dto.name(), dto.version(), language, stdlibMaybe.getAsInt(), ReadOnlyList.wrap(dependencies)));
return Optional.of(new PrometeuManifest(dto.name(), dto.version(), language, stdlibMaybe.getAsInt(), target, ReadOnlyList.wrap(dependencies)));
}
private static OptionalInt parseStdlib(
@@ -53,6 +53,7 @@ public class DiscoverPhase implements DependencyPhase {
}
if (rootPathCanon.equals(ctx.mainProjectRootPathCanon)) {
ctx.rootStdlib = manifest.get().stdlib();
ctx.target = manifest.get().target();
}
final var frontendSpec = FrontendRegistryService.getFrontendSpec(manifest.get().language());
// Returns empty when language is unknown
@@ -89,6 +89,7 @@ public final class WireProjectsPhase implements DependencyPhase {
.rootPath(projectInfo.rootDirectory)
.name(projectInfo.manifest.name())
.version(projectInfo.manifest.version())
.target(projectInfo.manifest.target())
.sourceRoots(ReadOnlyList.wrap(sourceRoots))
.build();
}
@@ -23,6 +23,7 @@ class PrometeuManifestUtilsTest {
"version": "1.0.0",
"language": "pbs",
"stdlib": "1",
"target": "Game",
"dependencies": []
}
""");
@@ -74,6 +75,47 @@ class PrometeuManifestUtilsTest {
assertTrue(issues.asCollection().stream().anyMatch(issue -> issue.getMessage().contains("invalid 'stdlib'")));
}
@Test
void buildManifestRejectsNoTarget() throws IOException {
final var manifestPath = writeManifest("""
{
"name": "main",
"version": "1.0.0",
"language": "pbs",
"stdlib": "1",
"dependencies": []
}
""");
final var issues = BuildingIssueSink.empty();
final var manifest = PrometeuManifestUtils.buildManifest(tempDir, manifestPath, issues);
assertTrue(manifest.isEmpty());
assertTrue(issues.hasErrors());
assertTrue(issues.asCollection().stream().anyMatch(issue -> issue.getMessage().contains("missing 'target'")));
}
@Test
void buildManifestRejectsInvalidTarget() throws IOException {
final var manifestPath = writeManifest("""
{
"name": "main",
"version": "1.0.0",
"language": "pbs",
"stdlib": "1",
"target": "UnknownTarget",
"dependencies": []
}
""");
final var issues = BuildingIssueSink.empty();
final var manifest = PrometeuManifestUtils.buildManifest(tempDir, manifestPath, issues);
assertTrue(manifest.isEmpty());
assertTrue(issues.hasErrors());
assertTrue(issues.asCollection().stream().anyMatch(issue -> issue.getMessage().contains("invalid 'target'")));
}
private Path writeManifest(final String content) throws IOException {
final var manifestPath = tempDir.resolve("prometeu.json");
Files.writeString(manifestPath, content);
@@ -2,6 +2,7 @@ package p.studio.compiler.workspaces.phases;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.AppMode;
import p.studio.compiler.messages.DependencyConfig;
import p.studio.compiler.models.DependencyContext;
import p.studio.compiler.models.ProjectDescriptor;
@@ -66,7 +67,7 @@ class StackPhaseTest {
ctx.projectInfoTable.register(ProjectInfo.builder()
.rootDirectory(root)
.manifestPath(root.resolve("prometeu.json"))
.manifest(new PrometeuManifest(name, "1.0.0", "pbs", 1, ReadOnlyList.wrap(List.of())))
.manifest(new PrometeuManifest(name, "1.0.0", "pbs", 1, AppMode.Game, ReadOnlyList.wrap(List.of())))
.build());
}
}
@@ -2,6 +2,7 @@ package p.studio.compiler.workspaces.phases;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.AppMode;
import p.studio.compiler.messages.DependencyConfig;
import p.studio.compiler.models.DependencyContext;
import p.studio.compiler.models.ProjectDescriptor;
@@ -42,16 +43,17 @@ class ValidatePhaseTest {
ctx.projectInfoTable.register(ProjectInfo.builder()
.rootDirectory(rootPath)
.manifestPath(rootPath.resolve("prometeu.json"))
.manifest(new PrometeuManifest("root", "1.0.0", "pbs", 1, ReadOnlyList.wrap(List.of())))
.manifest(new PrometeuManifest("root", "1.0.0", "pbs", 1, AppMode.Game, ReadOnlyList.wrap(List.of())))
.build());
ctx.projectInfoTable.register(ProjectInfo.builder()
.rootDirectory(depPath)
.manifestPath(depPath.resolve("prometeu.json"))
.manifest(new PrometeuManifest("dep", "1.0.0", "pbs", 2, ReadOnlyList.wrap(List.of())))
.manifest(new PrometeuManifest("dep", "1.0.0", "pbs", 2, AppMode.Game, ReadOnlyList.wrap(List.of())))
.build());
ctx.rootProjectId = rootProjectId;
ctx.rootStdlib = 1;
ctx.target = AppMode.Game;
ctx.dependenciesByProject.add(List.of());
ctx.dependenciesByProject.add(List.of());
ctx.projectNameAndVersions.put("root", new java.util.HashSet<>(List.of("1.0.0")));
@@ -85,16 +87,17 @@ class ValidatePhaseTest {
ctx.projectInfoTable.register(ProjectInfo.builder()
.rootDirectory(rootPath)
.manifestPath(rootPath.resolve("prometeu.json"))
.manifest(new PrometeuManifest("root", "1.0.0", "pbs", 2, ReadOnlyList.wrap(List.of())))
.manifest(new PrometeuManifest("root", "1.0.0", "pbs", 2, AppMode.Game, ReadOnlyList.wrap(List.of())))
.build());
ctx.projectInfoTable.register(ProjectInfo.builder()
.rootDirectory(depPath)
.manifestPath(depPath.resolve("prometeu.json"))
.manifest(new PrometeuManifest("dep", "1.0.0", "pbs", 1, ReadOnlyList.wrap(List.of())))
.manifest(new PrometeuManifest("dep", "1.0.0", "pbs", 1, AppMode.Game, ReadOnlyList.wrap(List.of())))
.build());
ctx.rootProjectId = rootProjectId;
ctx.rootStdlib = 2;
ctx.target = AppMode.Game;
ctx.dependenciesByProject.add(List.of());
ctx.dependenciesByProject.add(List.of());
ctx.projectNameAndVersions.put("root", new java.util.HashSet<>(List.of("1.0.0")));
@@ -1,5 +1,6 @@
package p.studio.compiler.messages;
import p.studio.AppMode;
import p.studio.compiler.models.BuildStack;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.source.identifiers.ProjectId;
@@ -13,22 +14,16 @@ public class FrontendPhaseContext {
public final BuildStack stack;
private final NameTable nameTable;
private final int stdlibVersion;
private final AppMode target;
private final HostAdmissionContext hostAdmissionContext;
private final FESurfaceContext feSurfaceContext;
public FrontendPhaseContext(
final ProjectTableReader projectTable,
final FileTableReader fileTable,
final BuildStack stack) {
this(projectTable, fileTable, stack, 1, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
}
public FrontendPhaseContext(
final ProjectTableReader projectTable,
final FileTableReader fileTable,
final BuildStack stack,
final int stdlibVersion) {
this(projectTable, fileTable, stack, stdlibVersion, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
final AppMode target) {
this(projectTable, fileTable, stack, 1, target, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
}
public FrontendPhaseContext(
@@ -36,8 +31,18 @@ public class FrontendPhaseContext {
final FileTableReader fileTable,
final BuildStack stack,
final int stdlibVersion,
final AppMode target) {
this(projectTable, fileTable, stack, stdlibVersion, target, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
}
public FrontendPhaseContext(
final ProjectTableReader projectTable,
final FileTableReader fileTable,
final BuildStack stack,
final int stdlibVersion,
final AppMode target,
final HostAdmissionContext hostAdmissionContext) {
this(projectTable, fileTable, stack, stdlibVersion, hostAdmissionContext, FESurfaceContext.empty());
this(projectTable, fileTable, stack, stdlibVersion, target, hostAdmissionContext, FESurfaceContext.empty());
}
public FrontendPhaseContext(
@@ -45,6 +50,7 @@ public class FrontendPhaseContext {
final FileTableReader fileTable,
final BuildStack stack,
final int stdlibVersion,
final AppMode target,
final HostAdmissionContext hostAdmissionContext,
final FESurfaceContext feSurfaceContext) {
this.projectTable = projectTable;
@@ -52,6 +58,7 @@ public class FrontendPhaseContext {
this.stack = stack;
this.nameTable = new NameTable();
this.stdlibVersion = stdlibVersion;
this.target = target;
this.hostAdmissionContext = hostAdmissionContext == null
? HostAdmissionContext.permissiveDefault()
: hostAdmissionContext;
@@ -68,6 +75,10 @@ public class FrontendPhaseContext {
return stdlibVersion;
}
public AppMode target() {
return target;
}
public HostAdmissionContext hostAdmissionContext() {
return hostAdmissionContext;
}