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 support for net5.0-<platform> #3339

Merged
merged 1 commit into from
Jun 5, 2020
Merged

add support for net5.0-<platform> #3339

merged 1 commit into from
Jun 5, 2020

Conversation

zkat
Copy link
Contributor

@zkat zkat commented Apr 10, 2020

Fixes: NuGet/Home#9240

This PR adds support for net5.0-<platform> to NuGetFramework and related classes.

This isn't quite ready to merge, but I'd like to start getting reviews about the stuff that's already there. It turns out that I was missing a lot of stuff in NuGet/Home#9382, which I can go back and update the document with, although I'm tempted to just drop that PR altogether in favor of a straight-up implementation.

Copy link
Contributor

@rrelyea rrelyea left a comment

Choose a reason for hiding this comment

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

🕐

looks very good. found a few minor things so far.

@zkat zkat force-pushed the dev-zkat-net5.0-platforms branch from 773c045 to 51a29a5 Compare April 14, 2020 00:14
Copy link
Member

@nkolev92 nkolev92 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 so far.

A few questions/suggestions.
No complaints on the public API part.

@zkat zkat force-pushed the dev-zkat-net5.0-platforms branch 2 times, most recently from f1082db to b696695 Compare April 23, 2020 19:33
@zkat zkat requested a review from nkolev92 April 23, 2020 19:35
@zkat zkat requested review from nkolev92 and zivkan May 29, 2020 20:38
@zkat zkat force-pushed the dev-zkat-net5.0-platforms branch from caad68f to 962a44b Compare June 2, 2020 17:51
@@ -134,6 +137,20 @@ public bool TryGetShortProfile(string frameworkIdentifier, string profile, out s
return TryConvertOrNormalize(profile, _profilesToShortName, _profileShortToLong, out profileShortName);
}

public bool TryGetPlatform(string frameworkIdentifier, Version frameworkVersion, string platformIdentifier, out string platformShortName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there null checks needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

The platformIdentifier is not used for an identification is this intended?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need UnitTests for this method?

@@ -33,6 +33,11 @@ interface IFrameworkNameProvider
/// </summary>
bool TryGetShortProfile(string frameworkIdentifier, string profile, out string profileShortName);

/// <summary>
/// Get the official platform name from the short name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it the other way: "Get the official platform short name from the platform name" ? The out argument is platformShortName

@@ -73,6 +74,8 @@ public FrameworkNameProvider(IEnumerable<IFrameworkMappings> mappings, IEnumerab
_profilesToShortName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_identifierShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_profileShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_platformToShortName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_platformShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_portableFrameworks = new Dictionary<int, HashSet<NuGetFramework>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Added 2 dictionaries( _platformToShortName, _platformShortToLong ) are initialized values, but never used.
Why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, it's a leftover from a previous iteration.

bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key)
=> { return IsCompatibleCore(target, candidate) == true; }));
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key)
=>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we simplify this part like bool? result = _cache.GetOrAdd(cacheKey, IsCompatibleCore(target, candidate) == true);
Otherwise very hard to read and understand.

Copy link
Member

Choose a reason for hiding this comment

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

This looks to me like a re-formatting of existing code, but its functionality hasn't changed at all. I'm all for simplifying syntax, but I consider it out of scope for the PR (I wouldn't complain if it's improved, but I wouldn't hold up the PR because of it)

/// True if the platform is non-empty
/// </summary>
public bool HasPlatform
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use more modern syntax here? public bool HasPlatform => !string.IsNullOrEmpty(Platform);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather keep things consistent with the rest of the file, and I think it's out of scope to change all the other ones that work this way.

@@ -92,18 +92,19 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework
// if the first part is a special framework, ignore the rest
if (!TryParseSpecialFramework(parts[0], out result))
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Just in case add parts.Any() if expecting at least 1 item in array which is parts[0] for not to get index out of range exception.
if (parts.Any() && !TryParseSpecialFramework(parts[0], out result))

Copy link
Member

Choose a reason for hiding this comment

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

When you know the data type, using .Length > 0 or .Count > 0 is a lot faster than using LINQ to do the same. Of course, this one thing is such a small part of the overall execution that in customer experience % terms it'll be just about zero, but I personally encourage people to avoid LINQ where possible.

bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort);
if (validProfile)
// Find a platform version if it exists and yank it out
var platformChars = profileShort;
Copy link
Contributor

@erdembayar erdembayar Jun 2, 2020

Choose a reason for hiding this comment

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

No need this extra platformChars variable here, keep using profileShort unless we do profileShort.ToCharArray(), but most likely no need;

Copy link
Member

Choose a reason for hiding this comment

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

This improves the readability because the 3rd part can be either profile or platform depending on the context.

I'd expect both of these to compile to the same thing anyways.

@dsplaisted
Copy link

fwiw, I distinctly remember @rrelyea asking whether NuGet should validate the platform names and the answer back then was yes.
It was also captured in:
https://github.com/dotnet/designs/blob/master/accepted/2020/net5/net5.md#tfms-are-a-closed-set

We should update the doc to reflect this change:

@nkolev92 I've sent a designs PR to cover this: dotnet/designs#130

bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key)
=> { return IsCompatibleCore(target, candidate) == true; }));
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key)
=>
Copy link
Member

Choose a reason for hiding this comment

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

This looks to me like a re-formatting of existing code, but its functionality hasn't changed at all. I'm all for simplifying syntax, but I consider it out of scope for the PR (I wouldn't complain if it's improved, but I wouldn't hold up the PR because of it)

Comment on lines +214 to +213
// Always use decimals and 2+ digits for netstandard and
// netcoreapp, or if any parts of the version are over 9
// we need to use decimals
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't have noticed if you didn't reformat this comment, but I don't believe this is correct any longer. net5.0 and above (net5Era) should also be using ".0" at the end.

Well, technically net5 will work just fine, but we want to make sure any time we (or the SDK, or anything else calling NuGet's APIs) write the short name, we always use the ".0" version, so customers are used to that syntax for when "10.0" comes along. But I'm not sure if this is a non-net5era codepath, so maybe it's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

net5.0 is netcoreapp everywhere internally, so the comment is accurate, and the behavior is correct.

@@ -92,18 +92,19 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework
// if the first part is a special framework, ignore the rest
if (!TryParseSpecialFramework(parts[0], out result))
{
Copy link
Member

Choose a reason for hiding this comment

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

When you know the data type, using .Length > 0 or .Count > 0 is a lot faster than using LINQ to do the same. Of course, this one thing is such a small part of the overall execution that in customer experience % terms it'll be just about zero, but I personally encourage people to avoid LINQ where possible.

@zkat zkat dismissed rrelyea’s stale review June 4, 2020 18:12

changes were made

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

Looks great overall.

It's been a long journey, where the bulk of work was agreeing to the right design :)
Great job!

2 smaller comments left. First one is more important and I feel more confident about it.
2nd one is up to you and based on your analysis.

bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort);
if (validProfile)
// Find a platform version if it exists and yank it out
var platformChars = profileShort;
Copy link
Member

Choose a reason for hiding this comment

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

This improves the readability because the 3rd part can be either profile or platform depending on the context.

I'd expect both of these to compile to the same thing anyways.

@zkat zkat force-pushed the dev-zkat-net5.0-platforms branch from 2fde260 to 3e3d094 Compare June 4, 2020 23:56
Fixes: NuGet/Home#9240

add TFI and TFV arguments + return null for GetNearest

stop verifying platform names

let bad frameworkname parses fail explosively

fix tests

more PR feedback fixes

normalize platform shortnames and suppress resulting warning
@zkat zkat force-pushed the dev-zkat-net5.0-platforms branch from 3e3d094 to d576239 Compare June 5, 2020 00:03
@zkat
Copy link
Contributor Author

zkat commented Jun 5, 2020

@nkolev92 I've created an issue for it: NuGet/Home#9650

@zkat zkat merged commit 071769b into dev Jun 5, 2020
@zkat zkat deleted the dev-zkat-net5.0-platforms branch June 5, 2020 21:00
nkolev92 added a commit that referenced this pull request Jun 16, 2020
nkolev92 added a commit that referenced this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

net5.0-<TargetPlatformIdentifier><TargetPlatformVersion> support