import java.security.MessageDigest plugins { id("gradle.java-library-conventions") } dependencies { implementation(project(":prometeu-infra")) implementation(project(":prometeu-compiler:prometeu-frontend-api")) implementation(project(":prometeu-compiler:prometeu-compiler-core")) } // Build-time projection of owner-maintained sources; no second normative copy is edited by Studio. val pbsSpecs = rootProject.layout.projectDirectory.dir("docs/specs/compiler-languages/pbs") val pbsResources = layout.projectDirectory.dir("src/main/resources") val generatePbsKnowledge by tasks.registering(Sync::class) { from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") } into(layout.buildDirectory.dir("generated/pbsKnowledge")) inputs.files(fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel", "pbs-knowledge/examples/**") }) doLast { val entries = mutableListOf>() fun entry(id: String, title: String, kind: String, resource: String, source: File, sdk: Int? = null, target: String? = null) { check(source.isFile) { "Missing PBS reference: $source" } val digest = MessageDigest.getInstance("SHA-256").digest(source.readBytes()) .joinToString("") { "%02x".format(it) } entries.add(linkedMapOf("id" to id, "title" to title, "kind" to kind, "resource" to resource, "sha256" to digest, "sdkVersion" to sdk, "target" to target)) } // Published filename IDs alias the single canonical numbered resource. val legacyReferenceIds = mapOf( "14" to "typed-arrays-and-optional-execution.md", "15" to "first-class-functions-and-captures.md", "16" to "generic-contracts.md", "17" to "generic-structs-and-free-functions.md", "18" to "input-and-existing-type-runtime-alignment.md", "19" to "service-constants-and-runtime-math.md", "20" to "runtime-random-integration.md", "21" to "sdk-list-and-cursor.md", "22" to "sdk-linked-and-cursor.md", "23" to "sdk-set-and-identity.md", "24" to "sdk-map-and-keyval.md", "25" to "sdk-stack-and-queue.md" ) val sources = checkNotNull(pbsSpecs.asFile.listFiles()) { "Missing canonical PBS specifications: $pbsSpecs" } .filter { it.extension == "md" }.sortedBy { it.name } check(legacyReferenceIds.keys.all { chapter -> sources.any { it.name.substringBefore(". ") == chapter } }) { "Missing canonical target for a published PBS reference ID" } sources.forEach { source -> val chapter = source.name.substringBefore(". ") val quickstart = source.name == "README.md" val title = source.readLines().first { it.startsWith("# ") }.removePrefix("# ") val kind = if (quickstart) "QUICKSTART" else if (chapter == "3") "SYNTAX" else "SEMANTICS" val resource = "pbs-knowledge/specs/${source.name}" entry(if (quickstart) "pbs:quickstart" else "pbs:spec:$chapter", title, kind, resource, source) legacyReferenceIds[chapter]?.let { legacy -> entry("pbs:spec:$legacy", title, kind, resource, source) } } fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel") }.files.sorted().forEach { source -> val path = source.relativeTo(pbsResources.asFile).invariantSeparatorsPath val parts = path.split('/') val sdk = parts[2].toInt() val module = parts.drop(3).dropLast(1).joinToString(":") entry("pbs:sdk:game:$sdk:${parts.drop(3).joinToString("/")}", "PBS SDK $sdk @$module / ${source.name}", "SDK", path, source, sdk, "Game") } fileTree(pbsResources.dir("pbs-knowledge/examples/game/1")) { include("**/*") }.files.sorted().forEach { source -> val relative = source.relativeTo(pbsResources.dir("pbs-knowledge/examples/game/1").asFile).invariantSeparatorsPath entry("pbs:example:game:1:$relative", "PBS Game / SDK 1 example: $relative", "EXAMPLE", "pbs-knowledge/examples/game/1/$relative", source, 1, "Game") } check(entries.map { it["id"] }.distinct().size == entries.size) { "Duplicate PBS reference IDs" } destinationDir.resolve("pbs-knowledge/index.json").writeText(groovy.json.JsonOutput.prettyPrint( groovy.json.JsonOutput.toJson(mapOf("schemaVersion" to 1, "owner" to "pbs", "references" to entries)))) } } sourceSets.main { resources.srcDir(generatePbsKnowledge) } tasks.named("processResources") { from(rootProject.layout.projectDirectory.dir("docs/vm-arch")) { include("INTRINSICS.csv", "BUILTIN_CONSTANTS.csv", "runtime-catalog.properties") into("runtime-catalog/pbs-sdk") } }