Skip to content

Commit 10335e6

Browse files
authored
[Linux] Properly detect Debian bookworm/sid (#6221)
The current Debian unstable distribution (codenamed "bookworm") no longer contains any release version information in the `/etc/os-release` file (the `VERSION` and `VERSION_ID` and `VERSION_CODENAME` fields were removed) causing `xaprepare` to fail when running on this version of Debian. Fix the Debian/unstable version detection by looking for known release codenames and faking the version number.
1 parent 1dbb547 commit 10335e6

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

build-tools/xaprepare/xaprepare/ConfigAndData/Dependencies/Linux.Debian.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class LinuxDebian : LinuxDebianCommon
2222
new DebianLinuxProgram ("zulu-8"),
2323
};
2424

25+
static readonly Dictionary<string, string> DebianUnstableVersionMap = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase) {
26+
{ "bookworm", "12" },
27+
{ "bookworm/sid", "12" },
28+
};
29+
2530
protected Version DebianRelease { get; private set; } = new Version (0, 0);
2631
protected bool IsTesting { get; private set; }
2732

@@ -42,24 +47,49 @@ protected override void InitializeDependencies ()
4247
Dependencies.AddRange (packagesPre10);
4348
}
4449

45-
static bool IsDebian10OrNewer (string[] lines)
50+
static bool IsDebian10OrNewer (string? version)
4651
{
47-
if (lines == null || lines.Length < 1)
48-
return false;
49-
50-
string version = lines[0].Trim ();
51-
if (String.IsNullOrEmpty (version))
52+
if (String.IsNullOrEmpty (version)) {
5253
return false;
54+
}
5355

5456
return
5557
version.IndexOf ("bullseye", StringComparison.OrdinalIgnoreCase) >= 0 ||
58+
version.IndexOf ("bookworm", StringComparison.OrdinalIgnoreCase) >= 0 ||
5659
version.IndexOf ("sid", StringComparison.OrdinalIgnoreCase) >= 0;
5760
}
5861

59-
protected override bool InitOS ()
62+
static string? ReadDebianVersion ()
63+
{
64+
if (!File.Exists (DebianVersionPath)) {
65+
return null;
66+
}
67+
68+
string[] lines = File.ReadAllLines (DebianVersionPath);
69+
return lines[0].Trim ();
70+
}
71+
72+
static bool IsBookwormSidOrNewer (string? debian_version)
6073
{
61-
if (!base.InitOS ())
74+
if (String.IsNullOrEmpty (debian_version)) {
6275
return false;
76+
}
77+
78+
return debian_version!.IndexOf ("bookworm", StringComparison.OrdinalIgnoreCase) >= 0;
79+
}
80+
81+
protected override bool EnsureVersionInformation (Context context)
82+
{
83+
string? debian_version = null;
84+
if (String.IsNullOrEmpty (Release)) {
85+
// Debian/unstable "bookworm" (to become Debian 12 eventually) removed
86+
// VERSION_ID and VERSION_CODENAME from /etc/os-release, so we need to
87+
// fake it
88+
debian_version = ReadDebianVersion ();
89+
if (IsBookwormSidOrNewer (debian_version) && DebianUnstableVersionMap.TryGetValue (debian_version!, out string unstable_version)) {
90+
Release = unstable_version;
91+
};
92+
}
6393

6494
Version debianRelease;
6595
if (!Version.TryParse (Release, out debianRelease)) {
@@ -76,7 +106,11 @@ protected override bool InitOS ()
76106
}
77107

78108
if (debianRelease.Major < 10 && DerivativeDistro && File.Exists (DebianVersionPath)) {
79-
if (IsDebian10OrNewer (File.ReadAllLines (DebianVersionPath)))
109+
if (String.IsNullOrEmpty (debian_version)) {
110+
debian_version = ReadDebianVersion ();
111+
}
112+
113+
if (IsDebian10OrNewer (debian_version))
80114
debianRelease = new Version (10, 0); // faking it, but it's ok
81115
}
82116

build-tools/xaprepare/xaprepare/ConfigAndData/Dependencies/Linux.Ubuntu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override void InitializeDependencies ()
3838
}
3939
}
4040

41-
protected override bool InitOS ()
41+
protected override bool EnsureVersionInformation (Context context)
4242
{
4343
Version ubuntuRelease;
4444
if (!Version.TryParse (Release, out ubuntuRelease)) {
@@ -51,7 +51,7 @@ protected override bool InitOS ()
5151
}
5252
UbuntuRelease = ubuntuRelease;
5353

54-
return base.InitOS ();
54+
return true;
5555
}
5656
};
5757
}

build-tools/xaprepare/xaprepare/OperatingSystems/Linux.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ static bool MapDistro (string id, ref string distro)
172172
return true;
173173
}
174174

175+
protected virtual bool EnsureVersionInformation (Context context)
176+
{
177+
return true;
178+
}
179+
175180
public static Linux DetectAndCreate (Context context)
176181
{
177182
string name = String.Empty;
@@ -234,6 +239,10 @@ public static Linux DetectAndCreate (Context context)
234239
linux.codeName = codeName;
235240
linux.derived = usingBaseDistro;
236241

242+
if (!linux.EnsureVersionInformation (context)) {
243+
throw new InvalidOperationException ("Unable to detect version of your Linux distribution");
244+
}
245+
237246
return linux;
238247
}
239248

0 commit comments

Comments
 (0)