mirror of
https://github.com/mitch030504/Wiicompiled_VR_Frame.git
synced 2026-10-06 07:00:30 +02:00
Quest: address flavor safety review
This commit is contained in:
1 parent
6e6406c200
commit
02dd9bf8cc
15 files changed
+162
-67
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import javax.inject.Inject
|
||||
import org.gradle.api.provider.Property
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
@@ -145,6 +146,7 @@ android {
|
||||
dimension = "headset"
|
||||
manifestPlaceholders["mkwQuestSupportedDevices"] = "quest2|quest3|quest3s|questpro"
|
||||
buildConfigField("boolean", "QUEST1_DIRECT_LAUNCH", "false")
|
||||
buildConfigField("String", "ANDROID_CPU", "\"cortex-a77\"")
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// Snapdragon XR2 and newer. Keep this as the default build target.
|
||||
@@ -156,6 +158,7 @@ android {
|
||||
dimension = "headset"
|
||||
manifestPlaceholders["mkwQuestSupportedDevices"] = "quest|quest2"
|
||||
buildConfigField("boolean", "QUEST1_DIRECT_LAUNCH", "true")
|
||||
buildConfigField("String", "ANDROID_CPU", "\"kryo\"")
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
// Snapdragon 835. cortex-a77 binaries terminate with SIGILL on Quest 1.
|
||||
@@ -221,6 +224,12 @@ abstract class ExportQuestGameKit : DefaultTask() {
|
||||
@get:Internal
|
||||
abstract val llvmStrip: RegularFileProperty
|
||||
|
||||
@get:Input
|
||||
abstract val androidCpu: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val cmakeBuildType: Property<String>
|
||||
|
||||
@get:Inject
|
||||
abstract val execOperations: ExecOperations
|
||||
|
||||
@@ -232,18 +241,39 @@ abstract class ExportQuestGameKit : DefaultTask() {
|
||||
@TaskAction
|
||||
fun export() {
|
||||
val app = appDir.get().asFile
|
||||
val probe = File(app, "build/intermediates/cxx").walkTopDown()
|
||||
data class Candidate(val probe: File, val binaryDir: File, val cpu: String?, val buildType: String?)
|
||||
fun cacheValue(cache: String, name: String): String? =
|
||||
Regex("(?m)^${Regex.escape(name)}(?::[^=\\r\\n]*)?=([^\\r\\n]*)$")
|
||||
.find(cache)?.groupValues?.get(1)?.trim()
|
||||
|
||||
val candidates = File(app, "build/intermediates/cxx").walkTopDown()
|
||||
.filter { it.name == "libmkw_quest_kit_probe.so" && it.parentFile.name == "arm64-v8a" }
|
||||
.maxByOrNull { it.lastModified() }
|
||||
?: throw GradleException("No libmkw_quest_kit_probe.so; the native build did not produce the game kit probe")
|
||||
val configuration = probe.parentFile.parentFile.parentFile // <BuildType>/<hash>
|
||||
val binaryDir = File(app, ".cxx/${configuration.parentFile.name}/${configuration.name}/arm64-v8a")
|
||||
if (!File(binaryDir, "build.ninja").isFile) throw GradleException("No CMake tree at $binaryDir")
|
||||
.map { probe ->
|
||||
val configuration = probe.parentFile.parentFile.parentFile // <Variant>/<hash>
|
||||
val binaryDir = File(app, ".cxx/${configuration.parentFile.name}/${configuration.name}/arm64-v8a")
|
||||
val cacheFile = File(binaryDir, "CMakeCache.txt")
|
||||
val cache = cacheFile.takeIf { it.isFile }?.readText().orEmpty()
|
||||
Candidate(probe, binaryDir, cacheValue(cache, "MKW_ANDROID_CPU"), cacheValue(cache, "CMAKE_BUILD_TYPE"))
|
||||
}
|
||||
.toList()
|
||||
val expectedCpu = androidCpu.get()
|
||||
val expectedBuildType = cmakeBuildType.get()
|
||||
val matching = candidates.filter {
|
||||
it.cpu == expectedCpu && it.buildType.equals(expectedBuildType, ignoreCase = true) &&
|
||||
File(it.binaryDir, "build.ninja").isFile
|
||||
}
|
||||
val chosen = matching.maxByOrNull { it.probe.lastModified() }
|
||||
?: throw GradleException(
|
||||
"No $expectedBuildType CMake tree for Android CPU $expectedCpu. Found: " +
|
||||
candidates.joinToString { "${it.binaryDir} (cpu=${it.cpu}, type=${it.buildType})" }
|
||||
)
|
||||
val binaryDir = chosen.binaryDir
|
||||
val kitDir = File(outputDir.get().asFile, "game_kit")
|
||||
execOperations.exec {
|
||||
commandLine(
|
||||
"powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", script.get().asFile.path,
|
||||
"-CMakeBinaryDir", binaryDir.path, "-OutputDir", kitDir.path, "-LlvmStrip", llvmStrip.get().asFile.path,
|
||||
"-AndroidCpu", expectedCpu,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -293,6 +323,9 @@ androidComponents {
|
||||
dependsOn("merge${capitalized}NativeLibs")
|
||||
appDir.set(layout.projectDirectory)
|
||||
script.set(rootProject.layout.projectDirectory.file("Export-QuestGameKit.ps1"))
|
||||
androidCpu.set(if (variant.name.startsWith("quest1", ignoreCase = true)) "kryo" else "cortex-a77")
|
||||
cmakeBuildType.set(variant.buildType)
|
||||
outputDir.set(layout.buildDirectory.dir("generated/assets/questGameKit/${variant.name}"))
|
||||
llvmStrip.set(sdkComponents.ndkDirectory.map {
|
||||
it.file("toolchains/llvm/prebuilt/$host/bin/llvm-strip" + if (host.startsWith("windows")) ".exe" else "")
|
||||
})
|
||||
|
||||
@@ -50,6 +50,8 @@ object GameLibrary {
|
||||
if (manifest == null || !library(context, profile).isFile) {
|
||||
return Status.Missing
|
||||
}
|
||||
return if (manifest.optString("kitFingerprint") == kitFingerprint(context)) Status.Ready else Status.Stale
|
||||
return if (manifest.optString("kitFingerprint") == kitFingerprint(context) &&
|
||||
manifest.optString("androidCpu") == BuildConfig.ANDROID_CPU
|
||||
) Status.Ready else Status.Stale
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,9 @@ object GameBuild {
|
||||
if (kitJson.optInt("schema") != KIT_SCHEMA) {
|
||||
return "This app's game kit is version ${kitJson.optInt("schema")}, which this builder does not know."
|
||||
}
|
||||
if (kitJson.optString("androidCpu") != BuildConfig.ANDROID_CPU) {
|
||||
return "This app contains a game kit for ${kitJson.optString("androidCpu")}, but this build requires ${BuildConfig.ANDROID_CPU}."
|
||||
}
|
||||
val recipe = kitJson.getJSONObject("products").optJSONObject(profile.id)
|
||||
?: return "This app's game kit cannot build ${profile.id}."
|
||||
report(40, Step.Prepare)
|
||||
@@ -570,6 +573,7 @@ object GameBuild {
|
||||
.put("dolSha256", BuildConfig.DISC_DOL_SHA256)
|
||||
.put("relSha256", BuildConfig.DISC_REL_SHA256)
|
||||
.put("kitFingerprint", kitFingerprint)
|
||||
.put("androidCpu", BuildConfig.ANDROID_CPU)
|
||||
.put("library", GameLibrary.LIBRARY_NAME)
|
||||
.put("librarySha256", BuildRecipe.hex(digest.digest()))
|
||||
.put("includesData", false)
|
||||
|
||||
@@ -157,6 +157,9 @@ object GamePackageImport {
|
||||
if (manifest.optString("kitFingerprint") != GameLibrary.kitFingerprint(context)) {
|
||||
return "This game file was built for a different version of this app. Build it again against the version installed on the headset."
|
||||
}
|
||||
if (manifest.optString("androidCpu") != BuildConfig.ANDROID_CPU) {
|
||||
return "This game file targets ${manifest.optString("androidCpu")}, but this app requires ${BuildConfig.ANDROID_CPU}. Build it again for the correct headset."
|
||||
}
|
||||
val expected = manifest.optString("librarySha256")
|
||||
if (librarySha256 == null) {
|
||||
return "This game file has no game library (libmain.so)."
|
||||
|
||||
Reference in new issue
Block a user