From 47a13f1719fe70e7f83e911e61243570e1569f04 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Fri, 15 Nov 2024 17:39:52 +0000
Subject: [PATCH] populate-depot: Set filter_exclusive_priority equal to major
 version
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously we were setting `filter_exclusive_priority` to 1 for all
"pure" (non-layered) container runtimes as per steamrt/tasks#426,
but in fact that was an oversight. Instead, we need to set a unique
priority for each distinct ABI (scout, soldier, sniper and so on).

This is because `Properties → Compatibility → Force the use of…`
lists all compatibility tools that have a `filter_exclusive_priority`
equal to the one that has been set on the app/game. We don't want
to list SLR 2.0 (soldier) for games that require the
Steam Runtime 3 (sniper) ABI, and we don't want to list a possible
future SLR 4 (medic) for sniper games either.

We assume here that future runtimes will follow the pattern set by
steamrt5 and have boring, pragmatic codenames. If we reach steamrt9
(which we should start work on in around 2031, assuming we continue
to do one Steam Runtime per Debian release) without the design having
changed, then we will need to do some renumbering at that point.

steamrt/tasks#597

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 .../container-runtime/populate-depot.py       | 39 ++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/subprojects/container-runtime/populate-depot.py b/subprojects/container-runtime/populate-depot.py
index 586be8a8d..ee74b5ae1 100755
--- a/subprojects/container-runtime/populate-depot.py
+++ b/subprojects/container-runtime/populate-depot.py
@@ -82,6 +82,13 @@ DEFAULT_IMAGES_URI = (
     'https://repo.steampowered.com/steamrt-images-SUITE/snapshots'
 )
 
+SUITES = {
+    'scout': 1,
+    'soldier': 2,
+    'sniper': 3,
+    'medic': 4,
+}
+
 
 class InvocationError(Exception):
     pass
@@ -1053,10 +1060,40 @@ class Main:
                     '--verb=%verb%',
                     '--',
                 ]
+
+                # Each ABI level needs a unique "priority" so that we will
+                # not suggest SLR 2.0 as a runtime for SLR 3.0 games, etc.;
+                # and they all need to be less than 10, to avoid colliding
+                # with SLR 1.0 (scout), which needs to be highest-priority
+                # to make it the default for legacy games.
+                filter_exclusive_priority = '9'
+
+                if runtime.suite.startswith('steamrt'):
+                    # steamrt5, steamrt6, ... get priority 5, 6, ...
+                    # If we get to steamrt9 with this limitation still
+                    # present, we'll have to bump the priority of SLR 1.0
+                    # or teach the Steam Client a different mechanism.
+                    major_version = runtime.suite[len('steamrt'):]
+                    assert int(major_version) >= 5, major_version
+                    assert int(major_version) <= 9, major_version
+                    filter_exclusive_priority = major_version
+                elif runtime.suite == 'scout':
+                    # Hypothetically we might have a super-strict scout
+                    # runtime for QA purposes (steamrt/tasks#59) and if
+                    # we do, it must match SLR 1.0
+                    filter_exclusive_priority = '10'
+                else:
+                    # For older suites with whimsical codenames, we have a
+                    # mapping from codename to major version.
+                    # Set the priority equal to the major version.
+                    filter_exclusive_priority = str(
+                        SUITES.get(runtime.suite, 9)
+                    )
+
                 content: Dict[str, Any] = dict(
                     manifest=dict(
                         commandline=' '.join(words),
-                        filter_exclusive_priority='1',
+                        filter_exclusive_priority=filter_exclusive_priority,
                         version='2',
                         use_tool_subprocess_reaper='1',
                     )
-- 
GitLab