add specs

This commit is contained in:
2026-03-24 13:42:17 +00:00
parent 4c4ba1d603
commit 40785bfb63
23 changed files with 1845 additions and 91 deletions
@@ -9,6 +9,7 @@ public record PrometeuManifestDTO(
String name,
String version,
String language,
String stdlib,
List<DependencyDeclaration> dependencies) {
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@@ -32,4 +33,4 @@ public record PrometeuManifestDTO(
}
}
}
}
}
@@ -22,6 +22,7 @@ public final class DependencyContext {
public Path mainProjectRootPathCanon;
public FrontendSpec frontendSpec;
public Integer rootStdlib;
public ProjectId rootProjectId;
public BuildStack stack;
@@ -45,9 +46,12 @@ public final class DependencyContext {
if (rootProjectId == null) {
throw new BuildException("dependenciesByProjectId: internal error: rootProjectId ProjectId not set");
}
if (rootStdlib == null) {
throw new BuildException("dependenciesByProjectId: internal error: rootStdlibMajor not set");
}
final var dependenciesByProject = buildDependenciesByProject();
final var workspaceGraph = new WorkspaceGraph(projectTable, dependenciesByProject);
return new ResolvedWorkspace(rootProjectId, frontendSpec, workspaceGraph, stack);
return new ResolvedWorkspace(rootProjectId, frontendSpec, rootStdlib, workspaceGraph, stack);
}
@@ -7,5 +7,6 @@ public record PrometeuManifest(
String name,
String version,
String language,
int stdlib,
ReadOnlyList<DependencyReference> dependencies) {
}
@@ -5,6 +5,7 @@ import p.studio.compiler.source.identifiers.ProjectId;
public record ResolvedWorkspace(
ProjectId mainProjectId,
FrontendSpec frontendSpec,
int stdlibMajor,
WorkspaceGraph graph,
BuildStack stack) {
public ProjectDescriptor mainProject() {
@@ -14,6 +14,7 @@ import p.studio.utilities.structures.ReadOnlyList;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.OptionalInt;
@UtilityClass
public final class PrometeuManifestUtils {
@@ -44,6 +45,7 @@ public final class PrometeuManifestUtils {
.error(true)
.message("[DEPS]: manifest missing 'version': " + manifestPathCanon));
}
final var stdlibMajorMaybe = parseStdlibMajor(dto.stdlib(), manifestPathCanon, issuesLocal);
final var language = StringUtils.isBlank(dto.language())
? FrontendRegistryService.getDefaultFrontendSpec().getLanguageId()
: dto.language();
@@ -52,6 +54,34 @@ public final class PrometeuManifestUtils {
issues.merge(issuesLocal);
return Optional.empty();
}
return Optional.of(new PrometeuManifest(dto.name(), dto.version(), language, ReadOnlyList.wrap(dependencies)));
return Optional.of(new PrometeuManifest(dto.name(), dto.version(), language, stdlibMajorMaybe.getAsInt(), ReadOnlyList.wrap(dependencies)));
}
private static OptionalInt parseStdlibMajor(
final String stdlib,
final Path manifestPathCanon,
final BuildingIssueSink issues) {
if (StringUtils.isBlank(stdlib)) {
issues.report(builder -> builder
.error(true)
.message("[DEPS]: manifest missing 'stdlib': " + manifestPathCanon));
return OptionalInt.empty();
}
final int stdlibMajor;
try {
stdlibMajor = Integer.parseInt(stdlib);
} catch (NumberFormatException e) {
issues.report(builder -> builder
.error(true)
.message("[DEPS]: invalid 'stdlib' major version \"" + stdlib + "\": " + manifestPathCanon));
return OptionalInt.empty();
}
if (stdlibMajor <= 0 || !stdlib.equals(Integer.toString(stdlibMajor))) {
issues.report(builder -> builder
.error(true)
.message("[DEPS]: invalid 'stdlib' major version \"" + stdlib + "\": " + manifestPathCanon));
return OptionalInt.empty();
}
return OptionalInt.of(stdlibMajor);
}
}
@@ -51,6 +51,9 @@ public class DiscoverPhase implements DependencyPhase {
if (manifest.isEmpty()) {
return Optional.empty();
}
if (rootPathCanon.equals(ctx.mainProjectRootPathCanon)) {
ctx.rootStdlib = manifest.get().stdlib();
}
final var frontendSpec = FrontendRegistryService.getFrontendSpec(manifest.get().language());
// Returns empty when language is unknown
if (frontendSpec.isEmpty()) {
@@ -14,6 +14,12 @@ public final class ValidatePhase implements DependencyPhase {
.error(true)
.message("[DEPS]: rootProjectId ProjectId not set"));
}
if (ctx.rootStdlib == null) {
return BuildingIssueSink.empty()
.report(builder -> builder
.error(true)
.message("[DEPS]: root stdlib major not set"));
}
// ensure the dependenciesByProject matches the number of projectDescriptors
if (ctx.dependenciesByProject.size() != ctx.projectTable.size()) {
@@ -23,18 +29,36 @@ public final class ValidatePhase implements DependencyPhase {
.message("[DEPS]: internal error: dependenciesByProject and projectDescriptors size mismatch"));
}
final BuildingIssueSink depIssues = BuildingIssueSink.empty();
// ensure compatibility across stdlibs
for (final var projectInfo : ctx.projectInfoTable.values()) {
if (projectInfo.manifest.stdlib() > ctx.rootStdlib) {
depIssues.report(builder -> builder
.error(true)
.message(String.format(
"[DEPS]: incompatible stdlib: [%s] requires stdlib \"%d\" but root project uses stdlib \"%d\"",
projectInfo.manifest.name(),
projectInfo.manifest.stdlib(),
ctx.rootStdlib)));
}
}
// ensure uniformity to version across the same projectIds (associated by name)
for (final var entry : ctx.projectNameAndVersions.entrySet()) {
final var name = entry.getKey();
final var versions = entry.getValue();
if (versions.size() > 1) {
return BuildingIssueSink.empty()
.report(builder -> builder
.error(true)
.message("[DEPS]: inconsistent version for project: " + name + " (" + versions + ")"));
depIssues.report(builder -> builder
.error(true)
.message("[DEPS]: inconsistent version for project: " + name + " (" + versions + ")"));
}
}
if (!depIssues.isEmpty()) {
return depIssues;
}
// run check over source policy (if any) from here (FrontedSpec)
return BuildingIssueSink.empty();