[buildSrc] Add default visibility to EmbedShadersTask
This commit is contained in:
51
buildSrc/build.garble
Normal file
51
buildSrc/build.garble
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
project.ext.lwjglVersion = "3.2.3"
|
||||
def osArch = System.getProperty("os.arch")
|
||||
project.ext.arch = osArch.startsWith("armv8") || osArch.contains("64") ? "x86-64" : "x86"
|
||||
|
||||
//switch ( OperatingSystem.current() ) {
|
||||
// case OperatingSystem.WINDOWS:
|
||||
// project.ext.OS = "windows"
|
||||
// break
|
||||
// case OperatingSystem.LINUX:
|
||||
// project.ext.OS = "linux"
|
||||
// break
|
||||
// case OperatingSystem.MAC_OS:
|
||||
// project.ext.OS = "macos"
|
||||
// break
|
||||
//}
|
||||
project.ext.OS = "linux"
|
||||
|
||||
class LwjglRule implements ComponentMetadataRule { //val os: String, val arch: String, val classifier: String)
|
||||
private def nativeVariants = [
|
||||
[os: OperatingSystemFamily.LINUX, arch: "arm32", classifier: "natives-linux-arm32"],
|
||||
[os: OperatingSystemFamily.LINUX, arch: "arm64", classifier: "natives-linux-arm64"],
|
||||
[os: OperatingSystemFamily.LINUX, arch: "x86-64", classifier: "natives-linux"],
|
||||
[os: OperatingSystemFamily.WINDOWS, arch: "x86", classifier: "natives-windows-x86"],
|
||||
[os: OperatingSystemFamily.WINDOWS, arch: "x86-64", classifier: "natives-windows"],
|
||||
[os: OperatingSystemFamily.MACOS, arch: "x86-64", classifier: "natives-macos"]
|
||||
]
|
||||
|
||||
@javax.inject.Inject
|
||||
ObjectFactory getObjects() { }
|
||||
|
||||
void execute(ComponentMetadataContext context) {
|
||||
context.details.withVariant("runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, "none"))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, "none"))
|
||||
}
|
||||
}
|
||||
nativeVariants.each { variantDefinition ->
|
||||
context.details.addVariant("${variantDefinition.classifier}-runtime", "runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, variantDefinition.os))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, variantDefinition.arch))
|
||||
}
|
||||
withFiles {
|
||||
addFile("${context.details.id.name}-${context.details.id.version}-${variantDefinition.classifier}.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
}
|
||||
dependencies {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class EmbedShadersTask : DefaultTask() {
|
||||
@get:Incremental
|
||||
@@ -12,18 +12,35 @@ abstract class EmbedShadersTask : DefaultTask() {
|
||||
@get:Input
|
||||
abstract val defaultPackage: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val defaultVisibility: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val namePrefix: Property<String>
|
||||
|
||||
@Inject
|
||||
abstract fun getWorkerExecutor(): WorkerExecutor
|
||||
|
||||
init {
|
||||
defaultVisibility.set("")
|
||||
namePrefix.set("")
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun execute(inputChanges: InputChanges) {
|
||||
inputChanges.getFileChanges(inputDir).forEach { change ->
|
||||
if (change.fileType == FileType.DIRECTORY) return@forEach
|
||||
val name = change.file.nameWithoutExtension
|
||||
val targetFile = outputDir.file(change.normalizedPath.replace(".","_")+".kt").get().asFile
|
||||
val name = "${namePrefix.get()}${change.file.nameWithoutExtension.replace("-", "_")}"
|
||||
val targetFile = outputDir.file(change.normalizedPath.replace(".", "_") + ".kt").get().asFile
|
||||
if (change.changeType == ChangeType.REMOVED) {
|
||||
targetFile.delete()
|
||||
} else {
|
||||
val contents = change.file.readText()
|
||||
val lines = contents.split("\n")
|
||||
var packageStatement = "package ${defaultPackage.get()}\n"
|
||||
val visibilityStatement =
|
||||
if (defaultVisibility.get().isNotBlank()) "${defaultVisibility.get()} " else ""
|
||||
|
||||
val r = Regex("#pragma package ([a-z.]+)")
|
||||
for (line in lines) {
|
||||
val m = r.find(line.trim())
|
||||
@@ -31,9 +48,10 @@ abstract class EmbedShadersTask : DefaultTask() {
|
||||
packageStatement = "package ${m.groupValues[1]}\n"
|
||||
}
|
||||
}
|
||||
val text = "${packageStatement}const val $name = ${"\"\"\""}${contents}${"\"\"\""}"
|
||||
val text =
|
||||
"${packageStatement}${visibilityStatement}const val $name = ${"\"\"\""}${contents}${"\"\"\""}"
|
||||
targetFile.writeText(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user