mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +00:00
feat: community recipe library for DroidDeck Proton (Auto) from BannerHub configs
This commit is contained in:
1 parent
c5d5ac904e
commit
465c3cd594
7 files changed
+3828
-23
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.session
|
||||
import android.content.Context
|
||||
import android.util.AtomicFile
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.gpu.GpuInfo
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
@@ -11,7 +12,8 @@ import java.io.File
|
||||
* The recipes behind "DroidDeck Proton (Auto)": per game, a DXVK, VKD3D-Proton and/or FEX package
|
||||
* from the Nightlies "-Linux" releases and a few environment variables.
|
||||
*
|
||||
* The app keeps the recipes ([OVERRIDE] in its files, else the bundled [ASSET]), makes sure every
|
||||
* The app keeps the recipes ([OVERRIDE] in its files, else the bundled [ASSET], the community library
|
||||
* tools/recipes/convert.py builds), picks each game's variants for this device's GPU, makes sure every
|
||||
* package they name is stored (the same download Components uses), unpacks each into the runtime's
|
||||
* recipe store, and publishes [GUEST_FILE] with those paths. droiddeck-recipe reads that file when
|
||||
* the Auto tool launches a game and starts Proton from a tree assembled for it; nothing is swapped
|
||||
@@ -44,32 +46,52 @@ object DdProtonRecipes {
|
||||
return true
|
||||
}
|
||||
|
||||
/** The recipes in [text]; throws IllegalArgumentException naming the first thing wrong. */
|
||||
fun parse(text: String): List<Recipe> {
|
||||
/**
|
||||
* The recipes in [text] for a device whose GPU is [family] (a GpuInfo.Family name, or null for
|
||||
* none); throws IllegalArgumentException naming the first thing wrong.
|
||||
*
|
||||
* Version 1 gives each game one recipe. Version 2 (tools/recipes/convert.py) gives each game a
|
||||
* list of variants, each optionally limited to GPU families: the matching ones are merged in
|
||||
* order, the first to name a component providing it and later variables winning.
|
||||
*/
|
||||
fun parse(text: String, family: String? = null): List<Recipe> {
|
||||
val json = JSONObject(text)
|
||||
require(json.optInt("version") == 1) { "recipes: version must be 1" }
|
||||
val version = json.optInt("version")
|
||||
require(version == 1 || version == 2) { "recipes: version must be 1 or 2" }
|
||||
val games = json.optJSONObject("games") ?: return emptyList()
|
||||
return games.keys().asSequence().sorted().map { id ->
|
||||
return games.keys().asSequence().sorted().mapNotNull { id ->
|
||||
require(id.isNotEmpty() && GameEnvironment.validScope(id)) { "recipes: $id is not a Steam app or shortcut id" }
|
||||
val game = games.getJSONObject(id)
|
||||
val packages = ComponentsManager.COMPONENTS.mapNotNull { comp ->
|
||||
val ref = game.optJSONObject(comp) ?: return@mapNotNull null
|
||||
val file = ref.optString("file")
|
||||
val release = ref.optString("release")
|
||||
require(file.endsWith(".wcp") && ComponentsManager.safeName(file) == file) { "recipes: $id: $comp file '$file'" }
|
||||
require(release.isNotEmpty() && ComponentsManager.safeName(release) == release) { "recipes: $id: $comp release '$release'" }
|
||||
PackageRef(comp, file, release)
|
||||
val variants = if (version == 1) listOf(game) else {
|
||||
val list = game.getJSONArray("variants")
|
||||
(0 until list.length()).map { list.getJSONObject(it) }.filter { variant ->
|
||||
val gpu = variant.optJSONArray("gpu") ?: return@filter true
|
||||
(0 until gpu.length()).any { gpu.getString(it) == family }
|
||||
}
|
||||
}
|
||||
val env = buildMap {
|
||||
game.optJSONObject("env")?.let { vars ->
|
||||
val packages = LinkedHashMap<String, PackageRef>()
|
||||
val env = LinkedHashMap<String, String>()
|
||||
val notes = LinkedHashSet<String>()
|
||||
for (variant in variants) {
|
||||
for (comp in ComponentsManager.COMPONENTS) {
|
||||
val ref = variant.optJSONObject(comp) ?: continue
|
||||
val file = ref.optString("file")
|
||||
val release = ref.optString("release")
|
||||
require(file.endsWith(".wcp") && ComponentsManager.safeName(file) == file) { "recipes: $id: $comp file '$file'" }
|
||||
require(release.isNotEmpty() && ComponentsManager.safeName(release) == release) { "recipes: $id: $comp release '$release'" }
|
||||
packages.putIfAbsent(comp, PackageRef(comp, file, release))
|
||||
}
|
||||
variant.optJSONObject("env")?.let { vars ->
|
||||
vars.keys().forEach { name ->
|
||||
val value = vars.get(name)
|
||||
require(value is String && envAllowed(name, value)) { "recipes: $id: $name is not a variable a recipe may set" }
|
||||
put(name, value)
|
||||
env[name] = value
|
||||
}
|
||||
}
|
||||
variant.optString("note").takeIf { it.isNotEmpty() }?.let { notes += it }
|
||||
}
|
||||
Recipe(id, packages, env, game.optString("note").take(200))
|
||||
if (packages.isEmpty() && env.isEmpty()) null
|
||||
else Recipe(id, packages.values.toList(), env, notes.joinToString("; ").take(200))
|
||||
}.toList()
|
||||
}
|
||||
|
||||
@@ -104,19 +126,21 @@ object DdProtonRecipes {
|
||||
*/
|
||||
fun ensure(context: Context): String = ensure(
|
||||
context,
|
||||
GpuInfo.detect().family.name,
|
||||
{ file, release -> ComponentsManager.catalogItem(context, file, release) },
|
||||
{ ComponentsManager.download(context, it) {} },
|
||||
)
|
||||
|
||||
internal fun ensure(
|
||||
context: Context,
|
||||
family: String?,
|
||||
lookup: (file: String, release: String) -> ComponentsManager.CatalogItem?,
|
||||
fetch: (ComponentsManager.CatalogItem) -> Unit,
|
||||
kind: (file: String) -> String? = { ComponentsManager.storedPackage(context, it)?.comp },
|
||||
unpack: (file: String, dir: File) -> Unit = { file, dir -> ComponentsManager.unpack(ComponentsManager.packageFile(context, file), dir) },
|
||||
): String {
|
||||
val text = source(context)
|
||||
val recipes = if (text == null) emptyList() else parse(text)
|
||||
val recipes = if (text == null) emptyList() else parse(text, family)
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
val store = File(root, STORE).apply { mkdirs() }
|
||||
val available = LinkedHashMap<String, String>()
|
||||
|
||||
@@ -39,9 +39,37 @@ class DdProtonRecipesTest {
|
||||
assertEquals("fex", recipes[1].packages.single().comp)
|
||||
}
|
||||
|
||||
@Test fun version2PicksTheVariantsForThisGpu() {
|
||||
val text = """{"version":2,"games":{
|
||||
"42":{"name":"Game","variants":[
|
||||
{"env":{"FEX_X87REDUCEDPRECISION":"1"},"note":"community"},
|
||||
{"gpu":["A6XX"],"dxvk":{"file":"dxvk-gplasync-2.7.1-1-linux.wcp","release":"Dxvk-gplasync-Linux"},"env":{"DXVK_ASYNC":"1"},"note":"community"},
|
||||
{"gpu":["A7XX","A8XX"],"vkd3d":{"file":"$vkd3d","release":"Vkd3d-proton-Linux"},"env":{"FEX_X87REDUCEDPRECISION":"0"}}]},
|
||||
"43":{"name":"Only 6xx","variants":[{"gpu":["A6XX"],"env":{"DXVK_ASYNC":"1"}}]}}}"""
|
||||
val a7 = DdProtonRecipes.parse(text, "A7XX")
|
||||
assertEquals(listOf("42"), a7.map { it.id })
|
||||
assertEquals(listOf("vkd3d"), a7[0].packages.map { it.comp })
|
||||
assertEquals(mapOf("FEX_X87REDUCEDPRECISION" to "0"), a7[0].env)
|
||||
assertEquals("community", a7[0].note)
|
||||
val a6 = DdProtonRecipes.parse(text, "A6XX")
|
||||
assertEquals(listOf("42", "43"), a6.map { it.id })
|
||||
assertEquals(listOf("dxvk"), a6[0].packages.map { it.comp })
|
||||
assertEquals(mapOf("FEX_X87REDUCEDPRECISION" to "1", "DXVK_ASYNC" to "1"), a6[0].env)
|
||||
val none = DdProtonRecipes.parse(text, null)
|
||||
assertEquals(listOf("42"), none.map { it.id })
|
||||
assertTrue(none[0].packages.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun theBundledLibraryParsesForEveryFamily() {
|
||||
val text = File("src/main/assets/${DdProtonRecipes.ASSET}").readText()
|
||||
for (family in listOf("A6XX", "A7XX_LOW", "A7XX", "A8XX", "ADRENO_UNKNOWN", "NOT_ADRENO")) {
|
||||
DdProtonRecipes.parse(text, family)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anythingOutsideTheFormatIsRefused() {
|
||||
val bad = listOf(
|
||||
"""{"version":2,"games":{}}""",
|
||||
"""{"version":3,"games":{}}""",
|
||||
"""{"version":1,"games":{"0":{}}}""",
|
||||
"""{"version":1,"games":{"steam":{}}}""",
|
||||
"""{"version":1,"games":{"42":{"dxvk":{"file":"../x.wcp","release":"Dxvk-Linux"}}}}""",
|
||||
@@ -92,6 +120,7 @@ class DdProtonRecipesTest {
|
||||
val fetched = mutableListOf<String>()
|
||||
val line = DdProtonRecipes.ensure(
|
||||
context,
|
||||
"A7XX",
|
||||
{ file, release -> if (file == dxvk) item(file, release) else null },
|
||||
{ fetched += it.file },
|
||||
kind = { file -> if (file == dxvk) "dxvk" else null },
|
||||
@@ -112,20 +141,31 @@ class DdProtonRecipesTest {
|
||||
File(context.filesDir, DdProtonRecipes.OVERRIDE).writeText(
|
||||
"""{"version":1,"games":{"42":{"vkd3d":{"file":"$dxvk","release":"Dxvk-Linux"}}}}""",
|
||||
)
|
||||
val second = DdProtonRecipes.ensure(context, { f, r -> item(f, r) }, {}, kind = { "dxvk" }, unpack = ::fakeUnpack)
|
||||
val second = DdProtonRecipes.ensure(context, "A7XX", { f, r -> item(f, r) }, {}, kind = { "dxvk" }, unpack = ::fakeUnpack)
|
||||
assertTrue(second, second.endsWith("$dxvk is not a vkd3d package"))
|
||||
assertFalse(store.exists())
|
||||
assertFalse(JSONObject(File(root, "root/.config/droiddeck/recipes.json").readText())
|
||||
.getJSONObject("games").getJSONObject("42").has("vkd3d"))
|
||||
}
|
||||
|
||||
@Test fun noRecipesPublishesAnEmptyFile() {
|
||||
val line = DdProtonRecipes.ensure(context, { _, _ -> null }, {}, kind = { null }, unpack = ::fakeUnpack)
|
||||
@Test fun anEmptyOverridePublishesAnEmptyFile() {
|
||||
File(context.filesDir, DdProtonRecipes.OVERRIDE).writeText("""{"version":1,"games":{}}""")
|
||||
val line = DdProtonRecipes.ensure(context, "A7XX", { _, _ -> null }, {}, kind = { null }, unpack = ::fakeUnpack)
|
||||
assertEquals("DdProtonRecipes: 0 recipe(s), 0 package(s) ready", line)
|
||||
val published = JSONObject(File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/recipes.json").readText())
|
||||
assertEquals(0, published.getJSONObject("games").length())
|
||||
}
|
||||
|
||||
@Test fun withoutAnOverrideTheBundledLibraryIsPublished() {
|
||||
val line = DdProtonRecipes.ensure(context, "A7XX", { _, _ -> null }, {}, kind = { null }, unpack = ::fakeUnpack)
|
||||
val count = Regex("(\\d+) recipe").find(line)!!.groupValues[1].toInt()
|
||||
assertTrue(line, count > 100)
|
||||
val games = JSONObject(File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/recipes.json").readText()).getJSONObject("games")
|
||||
assertEquals(count, games.length())
|
||||
// Packages could not be fetched here, so every published recipe carries only its variables.
|
||||
games.keys().forEach { id -> assertFalse(id, games.getJSONObject(id).has("dxvk")) }
|
||||
}
|
||||
|
||||
private fun item(file: String, release: String) =
|
||||
ComponentsManager.CatalogItem(file, "dxvk", release, "https://example.invalid/$file", 1, "sha256:00")
|
||||
|
||||
|
||||
Reference in new issue
Block a user