add specs
This commit is contained in:
+2
-1
@@ -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(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
@@ -7,5 +7,6 @@ public record PrometeuManifest(
|
||||
String name,
|
||||
String version,
|
||||
String language,
|
||||
int stdlib,
|
||||
ReadOnlyList<DependencyReference> dependencies) {
|
||||
}
|
||||
|
||||
+1
@@ -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() {
|
||||
|
||||
+31
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -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()) {
|
||||
|
||||
+28
-4
@@ -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();
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package p.studio.compiler.utilities;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PrometeuManifestUtilsTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void buildManifestParsesStdlibMajor() 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.isPresent());
|
||||
assertFalse(issues.hasErrors());
|
||||
assertEquals(1, manifest.get().stdlib());
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildManifestRejectsMissingStdlib() throws IOException {
|
||||
final var manifestPath = writeManifest("""
|
||||
{
|
||||
"name": "main",
|
||||
"version": "1.0.0",
|
||||
"language": "pbs",
|
||||
"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 'stdlib'")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildManifestRejectsNonMajorStdlib() throws IOException {
|
||||
final var manifestPath = writeManifest("""
|
||||
{
|
||||
"name": "main",
|
||||
"version": "1.0.0",
|
||||
"language": "pbs",
|
||||
"stdlib": "1.0",
|
||||
"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 'stdlib'")));
|
||||
}
|
||||
|
||||
private Path writeManifest(final String content) throws IOException {
|
||||
final var manifestPath = tempDir.resolve("prometeu.json");
|
||||
Files.writeString(manifestPath, content);
|
||||
return manifestPath;
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package p.studio.compiler.workspaces.phases;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.compiler.messages.DependencyConfig;
|
||||
import p.studio.compiler.models.DependencyContext;
|
||||
import p.studio.compiler.models.ProjectDescriptor;
|
||||
import p.studio.compiler.models.ProjectInfo;
|
||||
import p.studio.compiler.models.PrometeuManifest;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ValidatePhaseTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void rejectsDependencyWithHigherStdlibThanRoot() {
|
||||
final var ctx = DependencyContext.basedOn(new DependencyConfig(false, tempDir));
|
||||
final var rootPath = tempDir.resolve("root");
|
||||
final var depPath = tempDir.resolve("dep");
|
||||
|
||||
final var rootProjectId = ctx.projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(rootPath)
|
||||
.name("root")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of()))
|
||||
.build());
|
||||
ctx.projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(depPath)
|
||||
.name("dep")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of()))
|
||||
.build());
|
||||
|
||||
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())))
|
||||
.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())))
|
||||
.build());
|
||||
|
||||
ctx.rootProjectId = rootProjectId;
|
||||
ctx.rootStdlib = 1;
|
||||
ctx.dependenciesByProject.add(List.of());
|
||||
ctx.dependenciesByProject.add(List.of());
|
||||
ctx.projectNameAndVersions.put("root", new java.util.HashSet<>(List.of("1.0.0")));
|
||||
ctx.projectNameAndVersions.put("dep", new java.util.HashSet<>(List.of("1.0.0")));
|
||||
|
||||
final var issues = new ValidatePhase().run(ctx);
|
||||
|
||||
assertTrue(issues.hasErrors());
|
||||
assertTrue(issues.asCollection().stream().anyMatch(issue -> issue.getMessage().contains("incompatible stdlib")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsDependencyWithLowerOrEqualStdlibThanRoot() {
|
||||
final var ctx = DependencyContext.basedOn(new DependencyConfig(false, tempDir));
|
||||
final var rootPath = tempDir.resolve("root");
|
||||
final var depPath = tempDir.resolve("dep");
|
||||
|
||||
final var rootProjectId = ctx.projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(rootPath)
|
||||
.name("root")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of()))
|
||||
.build());
|
||||
ctx.projectTable.register(ProjectDescriptor.builder()
|
||||
.rootPath(depPath)
|
||||
.name("dep")
|
||||
.version("1.0.0")
|
||||
.sourceRoots(ReadOnlyList.wrap(List.of()))
|
||||
.build());
|
||||
|
||||
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())))
|
||||
.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())))
|
||||
.build());
|
||||
|
||||
ctx.rootProjectId = rootProjectId;
|
||||
ctx.rootStdlib = 2;
|
||||
ctx.dependenciesByProject.add(List.of());
|
||||
ctx.dependenciesByProject.add(List.of());
|
||||
ctx.projectNameAndVersions.put("root", new java.util.HashSet<>(List.of("1.0.0")));
|
||||
ctx.projectNameAndVersions.put("dep", new java.util.HashSet<>(List.of("1.0.0")));
|
||||
|
||||
final var issues = new ValidatePhase().run(ctx);
|
||||
|
||||
assertFalse(issues.hasErrors());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user