Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[follow-up] Use RedHat code detection from Microsoft.DotNet.PlatformAbstractions #24531

Merged
merged 1 commit into from
Nov 3, 2017

Conversation

krwq
Copy link
Member

@krwq krwq commented Oct 10, 2017

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:

  • rename/join PlatformDetection properties:
IsRedHat => IsRedHatFamily
IsRedHat69 => IsRedHatFamily6
IsNotRedHat69 => IsNotRedHatFamily6
IsCentos7 => IsRedHatFamily7
IsNotFedoraOrRedHatOrCentos => IsNotFedoraOrRedHatFamily

{
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Id = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem,
VersionId = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion
Copy link
Member

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,

Copy link
Member Author

@krwq krwq Nov 2, 2017

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.

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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

@tarekgh
Copy link
Member

tarekgh commented Oct 10, 2017

System/PlatformDetection.Unix.cs(95,17): error CS0246: The type or namespace name 'IdVersionPair' could not be found (are you missing a using directive or an assembly reference?) [/opt/corefx/src/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj]

@@ -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>
Copy link
Member

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:

<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)
Copy link
Member

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)
Copy link
Member

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();
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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

@krwq
Copy link
Member Author

krwq commented Nov 3, 2017

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);
}

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

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 :-)

Copy link
Member

@eerhardt eerhardt left a 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.

@krwq
Copy link
Member Author

krwq commented Nov 3, 2017

Thanks @eerhardt! Merging since previous build was green and I only changed whitespace

@krwq krwq merged commit 4bf9019 into dotnet:master Nov 3, 2017
@tarekgh
Copy link
Member

tarekgh commented Nov 3, 2017

@krwq did you see my question above?

@krwq
Copy link
Member Author

krwq commented Nov 3, 2017

@tarekgh not seeing any question, could you resend?

@tarekgh
Copy link
Member

tarekgh commented Nov 3, 2017

[‎11/‎3/‎2017 2:52 PM]
why the version number changed here? if 10.12 is not really the kernel version, we should rename the property OSXKernelVersion to OSXVersion
regarding the line
- if (PlatformDetection.IsOSX && PlatformDetection.OSXKernelVersion < new Version(16, 0))      + if (PlatformDetection.IsOSX && PlatformDetection.OSXKernelVersion < new Version(10, 12))

@krwq
Copy link
Member Author

krwq commented Nov 3, 2017

@tarekgh I've addressed this in #25057

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants