-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[follow-up] Use RedHat code detection from Microsoft.DotNet.PlatformAbstractions #24531
Conversation
{ | ||
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); | ||
Id = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem, | ||
VersionId = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VersionId = M [](start = 11, length = 14)
can we change this to Version struct instead of string? that will make it easier to use in the code and in comparison too,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarekgh, @eerhardt sorry for late response here, I had to suspend this work for a while - I've just tried converting the code to use Version class but there is one detail which may cause us some problems and might be worth mentioning: Version class requires that we pass at minimum 2 arguments (major, minor) and does not allow negative minor version - in some cases we might expect something to work on any 6.X version (like with RedHat or CentOS case) and in some cases to work only on 6.0 but not on other 6.X versions - this might be problematic. I was thinking that example code comparing version could look something like following:
// NOTE: this does not work as expected
private static bool VersionEquivalentWith(Version expectedVersionId, Version actualVersionId)
{
return expectedVersionId.Major == actualVersionId.Major
&& expectedVersionId.Minor == actualVersionId.Minor
&& (expectedVersionId.Build == -1 || expectedVersionId.Build == actualVersionId.Build)
&& (expectedVersionId.Revision == -1 || expectedVersionId.Revision == actualVersionId.Revision);
}
but this is causing problems as mentioned above (i.e. expecting RHEL6, got 6.9 => condition failed). We might approach working around this limitation in different ways:
- use some placeholder number as "minor not defined" i.e. 9999999
- compare ranges - that sounds fairly non-intuitive to define, i.e. checking for any RHEL6 would be something along the lines of: X >= V(6) && X < V(7), where more intuitive X == V(6) will not work as expected
- define expected version in terms of 4 numbers and actual as Version class - that could work but not sure if that would make the code cleaner as all of these variable version parts would have to be handled
- leave string comparison
any opinions? Perhaps there is some way to simplify this overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when we don't have a minor version we just use 0 which should work for any checks use this version. what would be wrong with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarekgh that was the first thing I've tried. Example problem: You want condition like:
IsCentOS7 -> you have to compare with new Version(7,0) -> let's assume you're on CentOS 7.2 - should this comparison return true or false?
Other case: IsCentOS70, you check for new Version(7,0) -> no matter what you answered before this is a problematic situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, talked with @tarekgh offline we will go with:
- parse to Version class in such a way that when minor is not provided interpret it as minor = 0
- each function which compares versions takes 4 integers and compares them with Version handling minor == -1
// CentOS 7, RHEL 7 and Ubuntu 14.04, as well as Fedora 25 and OpenSUSE 4.22 are running outdated versions of libgdiplus | ||
if (PlatformDetection.IsCentos7 || PlatformDetection.IsRedHat || PlatformDetection.IsUbuntu1404 || PlatformDetection.IsFedora || PlatformDetection.IsOpenSUSE) | ||
// RedHat and Ubuntu 14.04, as well as Fedora 25 and OpenSUSE 4.22 are running outdated versions of libgdiplus | ||
if (PlatformDetection.IsRedHatFamily || PlatformDetection.IsUbuntu1404 || PlatformDetection.IsFedora || PlatformDetection.IsOpenSUSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PlatformDetection.IsRedHatFamily [](start = 16, length = 32)
we should check version 7 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, I am seeing the original code was checking for redhat without the version. If you are not getting any problem with your change here, then I think your change would be ok.
// CentOS 7, RHEL 7 and Ubuntu 14.04 are running outdated versions of libgdiplus | ||
if (PlatformDetection.IsCentos7 || PlatformDetection.IsRedHat || PlatformDetection.IsUbuntu1404) | ||
// RedHat and Ubuntu 14.04 are running outdated versions of libgdiplus | ||
if (PlatformDetection.IsRedHatFamily || PlatformDetection.IsUbuntu1404) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(PlatformDetection.IsRedHatFamily [](start = 15, length = 33)
same
|
@@ -50,6 +50,9 @@ | |||
<PackageReference Include="Microsoft.3rdpartytools.MarkdownLog"> | |||
<Version>0.10.0-alpha-experimental</Version> | |||
</PackageReference> | |||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions"> | |||
<Version>2.1.0-preview1-25806-02</Version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to either reuse this property:
Line 34 in e273e7f
<MicrosoftNETCoreAppPackageVersion>2.1.0-preview1-25806-02</MicrosoftNETCoreAppPackageVersion> |
Or even better, define a new MicrosoftDotNetPlatformAbstractionsPackageVersion
property in dependencies.props. That way this version automatically gets updated when a new version comes out.
i++; | ||
private static bool VersionEqual(string expectedVersionId, string actualVersionId) | ||
{ | ||
if (expectedVersionId == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to parse these into Version
structs and use the comparisons that come with it?
} | ||
} | ||
|
||
return ret; | ||
return true; | ||
} | ||
|
||
private static string RemoveQuotes(string s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this method is used anymore.
|
||
return "Distro=" + v.Id + " VersionId=" + v.VersionId + " Pretty=" + v.PrettyName + " Version=" + v.Version; | ||
return "Distro=" + v.Id + " VersionId=" + v.VersionId; | ||
} | ||
|
||
private static readonly Version s_osxProductVersion = GetOSXProductVersion(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetOSXProductVersion()
should be able to be removed as well and just use RuntimeEnvironment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant GetOSXKernelVersion()
. That is the method that appears to be duplicated with PlatformAbstractions.
RuntimeEnvironment.OperatingSystemVersion
will give you the same value as what GetOSXKernelVersion()
will return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for delay - had to suspend this PR. The value was not identical since they adjust version a little bit (10.<old major version - 4>.<rest of version>
) but there were only two usages of that so I've changed those
sorry for delay, had to suspend this work for a while. PTAL |
@@ -82,6 +82,7 @@ public bool CheckAndClearCredentials(ITestOutputHelper output) | |||
output.WriteLine("kdestroy returned {0}", clearCreds.ExitCode); | |||
return (clearCreds.ExitCode == 0); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to remove this
|
||
public static Version OSXKernelVersion { get; } = GetOSXKernelVersion(); | ||
public static Version OSXKernelVersion { get; } = ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Does it work to using Microsoft.DotNet.PlatformAbstractions;
, or is there some type collision?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eerhardt - type collision - class RuntimeEnvironment unfortunatelly also exists in corefx :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for following up on this @krwq.
Thanks @eerhardt! Merging since previous build was green and I only changed whitespace |
@krwq did you see my question above? |
@tarekgh not seeing any question, could you resend? |
[11/3/2017 2:52 PM] |
This PR is a follow up on my PR against release/2.0.0 which cleaned up bunch of code related to RedHat: https://github.com/dotnet/corefx/pull/24340/files
This also addresses feedback from @eerhardt about reusing core-setup code.
Changes included here: