57 lines
3.3 KiB
Kotlin
57 lines
3.3 KiB
Kotlin
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<Map<String, Any?>>()
|
|
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))
|
|
}
|
|
pbsSpecs.asFile.listFiles()!!.filter { it.extension == "md" }.sortedBy { it.name }.forEach { source ->
|
|
val chapter = source.name.substringBefore(". ")
|
|
val quickstart = source.name == "README.md"
|
|
entry(if (quickstart) "pbs:quickstart" else "pbs:spec:$chapter",
|
|
source.readLines().first { it.startsWith("# ") }.removePrefix("# "),
|
|
if (quickstart) "QUICKSTART" else if (chapter == "3") "SYNTAX" else "SEMANTICS",
|
|
"pbs-knowledge/specs/${source.name}", 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) }
|