Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OSPlatform.macOS, make OSPlatform.Equal use OrdinalIgnoreCaseComparison #39064

Closed
wants to merge 11 commits into from

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Jul 10, 2020

Contributes to #33331

/cc @jeffhandley

@Dotnet-GitSync-Bot
Copy link
Collaborator

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@akoeplinger
Copy link
Member

hey @adamsitnik I just merged my PR #36704 which also implemented most of these new additions, so please rebase this one :)

@adamsitnik
Copy link
Member Author

I just merged my PR #36704 which also implemented most of these new additions, so please rebase this one :)

@akoeplinger thanks for letting me know!

@adamsitnik adamsitnik changed the title add new OSPlatforms (Android, iOS, macOS, tvOS, watchOS) add OSPlatform.macOS, make OSPlatform.Equal use OrdinalIgnoreCaseComparison Jul 10, 2020
@jeffhandley
Copy link
Member

I think there was a spoken comment during the review that we could have macOS return “OSX”. If we did that, would it fee more or less hacky to you, @adamsitnik?

@adamsitnik
Copy link
Member Author

I think there was a spoken comment during the review that we could have macOS return “OSX”. If we did that, would it fee more or less hacky to you

it would make the following lines work:

Assert.Equal(OSPlatform.OSX, OSPlatform.macOS);

but not:

Assert.Equal(OSPlatform.macOS, OSPlatform.Create("macOS"));
Assert.Equal(OSPlatform.OSX, OSPlatform.Create("macOS"));

I like @akoeplinger idea and I am going to apply it

@adamsitnik
Copy link
Member Author

@akoeplinger @jeffhandley thanks for great suggestions, the code looks much better now!

public static OSPlatform macOS { get; } = new OSPlatform("MACOS");

[EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500
public static OSPlatform OSX { get; } = macOS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example

void Foo (OSPlatform osp)
{
	if (osp.ToString() == "OSX")
		return;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then we should add the macOS/OSX magic to ToString() too

Copy link
Member

@jkotas jkotas Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should be changing the string identifier for OSX/macOS. It should stay as OSX. OSX is hardcoded in many places that are hard/impossible to fix, like NuGet RIDs. We are not gaining much by changing it ad-hoc in subset of places. If we want to change it, it should be done everywhere and it should be a feature on its own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this during the Design Review meeting today and got a direction on how to address this breaking change risk while still handling equivalence. The comments are posted on #33331, but at a high-level, OSPlatform should not try to handle equivalence between platforms itself; instead, the RuntimeInformation.IsOSPlatform should handle it.

@adamsitnik
Copy link
Member Author

I've been trying to wrap my head around the macOS and OSX thing, and I got to the following conclusions:

Based on https://en.wikipedia.org/w/index.php?title=Macintosh_operating_systems&section=4#Releases_2

    Mac OS X 10.0 – code name "Cheetah", released to end users on Saturday, March 24, 2001
    Mac OS X 10.1 – code name "Puma", released to end users on Tuesday, September 25, 2001
    Mac OS X 10.2 – also marketed as "Jaguar", released to end users on Friday, August 23, 2002
    Mac OS X Panther – version 10.3, released to end users on Friday, October 24, 2003
    Mac OS X Tiger – version 10.4, released to end users on Friday, April 29, 2005
    Mac OS X Leopard – version 10.5, released to end users on Friday, October 26, 2007
    Mac OS X Snow Leopard – version 10.6, publicly unveiled on Monday, June 8, 2009
    Mac OS X Lion – version 10.7, released to end users on Wednesday, July 20, 2011
    OS X Mountain Lion – version 10.8, released to end users on Wednesday, July 25, 2012
    OS X Mavericks – version 10.9, released to end users on Tuesday, October 22, 2013
    OS X Yosemite – version 10.10, released to end users on Thursday, October 16, 2014
    OS X El Capitan – version 10.11, released to end users on Wednesday, September 30, 2015
    macOS Sierra – version 10.12, released to end users on Tuesday, September 20, 2016
    macOS High Sierra – version 10.13, released to end users on Monday, September 25, 2017
    macOS Mojave – version 10.14, released to end users on Monday, September 24, 2018
    macOS Catalina – version 10.15, released to end users on Monday, October 7, 2019
    macOS Big Sur - version 11.0, announced at WWDC 2020 on Monday, June 22, 2020 and currently in development

The value returned by Interop.Sys.GetUnixName() should be:

  • OSX for versions 10.0-10.11
  • macOS for versions 10.12-11.00

But .NET 5 officially supports only macOS 10.13+ so Interop.Sys.GetUnixName() should just return macOS

Moreover it's not just about the naming, so: OSPlatform.OSX != OSPlatform.macOS

Assert.NotEqual(OSPlatform.OSX, OSPlatform.macOS);

But for the sake of backward compatibility and usability:

RuntimeInformation.IsOSPlatform(OSPlatform.OSX) // should return true for every mac OS and .NET

And for .NET 5:

RuntimeInformation.IsOSPlatform(OSPlatform.macOS) // should return true only on .NET 5 on macOS 10.13+

Any comments on that before I apply the changes?

@akoeplinger
Copy link
Member

akoeplinger commented Jul 10, 2020

@adamsitnik the OSX -> macOS change was purely a marketing/branding change so it'd be very weird if OSPlatform.OSX != OSPlatform.macOS. IMHO we should treat them as the same, except the ToString() case.

public static System.Runtime.InteropServices.OSPlatform Linux { get { throw null; } }
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref files should not use comments like this. They will disappear next time the file is reformatted using auto-generator.

public static OSPlatform OSX { get; } = new OSPlatform("OSX");
public static OSPlatform macOS { get; } = new OSPlatform("MACOS");

[EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this link really useful for context? It points to several screens of API review notes, and it does not say much useful about the OSX.

Should this rather say "// superseded by macOS" ?

}

public override bool Equals(object? obj)
{
return obj is OSPlatform && Equals((OSPlatform)obj);
Debug.Fail("The non generic method should not be used by BCL");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the debug libraries to be fully usable. This should be removed.

If you would like to check that this method is not called by the BCL, it is a job for the analyzer.

internal bool Equals(string? other)
{
return string.Equals(_osPlatform, other, StringComparison.Ordinal);
return string.Equals(_osPlatform, other._osPlatform, StringComparison.OrdinalIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is motivating this change? This will make this API quite a bit more expensive.

public static OSPlatform macOS { get; } = new OSPlatform("MACOS");

[EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500
public static OSPlatform OSX { get; } = macOS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static OSPlatform OSX { get; } = macOS;
public static OSPlatform OSX => macOS;

@adamsitnik
Copy link
Member Author

I've sent a new PR: #39209

@adamsitnik adamsitnik closed this Jul 13, 2020
@adamsitnik adamsitnik deleted the 33331newOsPlatforms branch July 13, 2020 17:05
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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.

7 participants