Skip to content

Commit

Permalink
Ensure we preserve version string verbatim
Browse files Browse the repository at this point in the history
Versions may contain insignificant whitespace which must be preserved.
  • Loading branch information
ericstj committed Mar 23, 2021
1 parent 78dec6f commit 7916e11
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/Microsoft.DotNet.Build.Tasks.Packaging/src/RuntimeVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@ namespace Microsoft.DotNet.Build.Tasks.Packaging
/// </summary>
internal sealed class RuntimeVersion : IComparable, IComparable<RuntimeVersion>, IEquatable<RuntimeVersion>
{
private string versionString;
private Version version;
private bool hasMinor;

public RuntimeVersion(string versionString)
{
// intentionally don't support the type of version that omits the separators as it is abiguous.
// for example Windows 8.1 was encoded as win81, where as Windows 10.0 was encoded as win10

if (versionString.IndexOf('.') == -1)
this.versionString = versionString;
string toParse = versionString;
if (toParse.IndexOf('.') == -1)
{
versionString += ".0";
toParse += ".0";
hasMinor = false;
}
else
{
hasMinor = true;
}
version = Version.Parse(versionString);

version = Version.Parse(toParse);
}

public int CompareTo(object obj)
Expand Down Expand Up @@ -62,6 +63,8 @@ public int CompareTo(RuntimeVersion other)
{
return 1;
}

return string.CompareOrdinal(versionString, other.versionString);
}

return versionResult;
Expand All @@ -70,9 +73,7 @@ public int CompareTo(RuntimeVersion other)
public bool Equals(RuntimeVersion other)
{
return object.ReferenceEquals(other, this) ||
(!(other is null) &&
(hasMinor == other.hasMinor) &&
version.Equals(other.version));
versionString.Equals(other.versionString, StringComparison.Ordinal);
}

public override bool Equals(object obj)
Expand All @@ -82,12 +83,12 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return version.GetHashCode() | (hasMinor ? 1 : 0);
return versionString.GetHashCode();
}

public override string ToString()
{
return hasMinor ? version.ToString() : version.Major.ToString();
return versionString;
}

public static bool operator ==(RuntimeVersion v1, RuntimeVersion v2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,121 @@
"rhel-x64"
]
},
"ubuntu": {
"#import": [
"debian"
]
},
"ubuntu-arm": {
"#import": [
"ubuntu",
"debian-arm"
]
},
"ubuntu-x64": {
"#import": [
"ubuntu",
"debian-x64"
]
},
"ubuntu-x86": {
"#import": [
"ubuntu",
"debian-x86"
]
},
"ubuntu.14.04": {
"#import": [
"ubuntu"
]
},
"ubuntu.14.04-arm": {
"#import": [
"ubuntu.14.04",
"ubuntu-arm"
]
},
"ubuntu.14.04-x64": {
"#import": [
"ubuntu.14.04",
"ubuntu-x64"
]
},
"ubuntu.14.04-x86": {
"#import": [
"ubuntu.14.04",
"ubuntu-x86"
]
},
"ubuntu.14.10": {
"#import": [
"ubuntu"
]
},
"ubuntu.14.10-arm": {
"#import": [
"ubuntu.14.10",
"ubuntu-arm"
]
},
"ubuntu.14.10-x64": {
"#import": [
"ubuntu.14.10",
"ubuntu-x64"
]
},
"ubuntu.14.10-x86": {
"#import": [
"ubuntu.14.10",
"ubuntu-x86"
]
},
"ubuntu.15.04": {
"#import": [
"ubuntu"
]
},
"ubuntu.15.04-arm": {
"#import": [
"ubuntu.15.04",
"ubuntu-arm"
]
},
"ubuntu.15.04-x64": {
"#import": [
"ubuntu.15.04",
"ubuntu-x64"
]
},
"ubuntu.15.04-x86": {
"#import": [
"ubuntu.15.04",
"ubuntu-x86"
]
},
"ubuntu.15.10": {
"#import": [
"ubuntu"
]
},
"ubuntu.15.10-arm": {
"#import": [
"ubuntu.15.10",
"ubuntu-arm"
]
},
"ubuntu.15.10-x64": {
"#import": [
"ubuntu.15.10",
"ubuntu-x64"
]
},
"ubuntu.15.10-x86": {
"#import": [
"ubuntu.15.10",
"ubuntu-x86"
]
},
"unix": {
"#import": [
"any"
Expand Down Expand Up @@ -953,4 +1068,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,121 @@
"rhel.9-x64"
]
},
"ubuntu": {
"#import": [
"debian"
]
},
"ubuntu-arm": {
"#import": [
"ubuntu",
"debian-arm"
]
},
"ubuntu-x64": {
"#import": [
"ubuntu",
"debian-x64"
]
},
"ubuntu-x86": {
"#import": [
"ubuntu",
"debian-x86"
]
},
"ubuntu.14.04": {
"#import": [
"ubuntu"
]
},
"ubuntu.14.04-arm": {
"#import": [
"ubuntu.14.04",
"ubuntu-arm"
]
},
"ubuntu.14.04-x64": {
"#import": [
"ubuntu.14.04",
"ubuntu-x64"
]
},
"ubuntu.14.04-x86": {
"#import": [
"ubuntu.14.04",
"ubuntu-x86"
]
},
"ubuntu.14.10": {
"#import": [
"ubuntu"
]
},
"ubuntu.14.10-arm": {
"#import": [
"ubuntu.14.10",
"ubuntu-arm"
]
},
"ubuntu.14.10-x64": {
"#import": [
"ubuntu.14.10",
"ubuntu-x64"
]
},
"ubuntu.14.10-x86": {
"#import": [
"ubuntu.14.10",
"ubuntu-x86"
]
},
"ubuntu.15.04": {
"#import": [
"ubuntu"
]
},
"ubuntu.15.04-arm": {
"#import": [
"ubuntu.15.04",
"ubuntu-arm"
]
},
"ubuntu.15.04-x64": {
"#import": [
"ubuntu.15.04",
"ubuntu-x64"
]
},
"ubuntu.15.04-x86": {
"#import": [
"ubuntu.15.04",
"ubuntu-x86"
]
},
"ubuntu.15.10": {
"#import": [
"ubuntu"
]
},
"ubuntu.15.10-arm": {
"#import": [
"ubuntu.15.10",
"ubuntu-arm"
]
},
"ubuntu.15.10-x64": {
"#import": [
"ubuntu.15.10",
"ubuntu-x64"
]
},
"ubuntu.15.10-x86": {
"#import": [
"ubuntu.15.10",
"ubuntu-x86"
]
},
"unix": {
"#import": [
"any"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void CanIgnoreExistingInferRids()
CreateRuntimeGroup("osx", "unix", "x64;arm64", "10.10;10.11;10.12;10.13;10.14;10.15;10.16;11.0"),
CreateRuntimeGroup("win", "any", "x64;x86;arm;arm64", "7;8;81;10", additionalQualifiers:"aot", omitVersionDelimiter:true),
CreateRuntimeGroup("debian", "linux", "x64;x86;arm;armel;arm64", "8;9;10", treatVersionsAsCompatible:false),
CreateRuntimeGroup("ubuntu", "debian", "x64;x86;arm", "14.04;14.10;15.04;15.10", treatVersionsAsCompatible:false),
CreateRuntimeGroup("rhel", "linux", "x64", "6"),
CreateRuntimeGroup("rhel", "linux", "x64", "7;7.0;7.1;7.2;7.3;7.4;7.5;7.6"),
CreateRuntimeGroup("rhel", "linux", "x64;arm64", "8;8.0;8.1"),
Expand Down

0 comments on commit 7916e11

Please sign in to comment.