-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove nullable disable warnings #48846
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable disable warnings | ||
|
||
using System.CommandLine; | ||
using System.CommandLine.Completions; | ||
using System.CommandLine.Parsing; | ||
|
@@ -69,14 +67,14 @@ public static IEnumerable<string> RuntimeArgFunc(string rid) | |
new DynamicForwardedOption<string>("--runtime", "-r") | ||
{ | ||
HelpName = RuntimeArgName | ||
}.ForwardAsMany(RuntimeArgFunc) | ||
}.ForwardAsMany(RuntimeArgFunc!) | ||
.AddCompletions(CliCompletion.RunTimesFromProjectFile); | ||
|
||
public static Option<string> LongFormRuntimeOption = | ||
new DynamicForwardedOption<string>("--runtime") | ||
{ | ||
HelpName = RuntimeArgName | ||
}.ForwardAsMany(RuntimeArgFunc) | ||
}.ForwardAsMany(RuntimeArgFunc!) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public static Option<T> ForwardAsMany<T>(this ForwardedOption<T> option, Func<T?, IEnumerable<string>> format); This requires that the delegate have a |
||
.AddCompletions(CliCompletion.RunTimesFromProjectFile); | ||
|
||
public static Option<bool> CurrentRuntimeOption(string description) => | ||
|
@@ -162,7 +160,7 @@ public static ForwardedOption<bool> InteractiveOption(bool acceptArgument = fals | |
HelpName = CliStrings.ArchArgumentName | ||
}.SetForwardingFunction(ResolveArchOptionToRuntimeIdentifier); | ||
|
||
internal static string ArchOptionValue(ParseResult parseResult) => | ||
internal static string? ArchOptionValue(ParseResult parseResult) => | ||
string.IsNullOrEmpty(parseResult.GetValue(ArchitectureOption)) ? | ||
parseResult.GetValue(LongFormArchitectureOption) : | ||
parseResult.GetValue(ArchitectureOption); | ||
|
@@ -254,7 +252,7 @@ public static void ValidateSelfContainedOptions(bool hasSelfContainedOption, boo | |
} | ||
} | ||
|
||
internal static IEnumerable<string> ResolveArchOptionToRuntimeIdentifier(string arg, ParseResult parseResult) | ||
internal static IEnumerable<string> ResolveArchOptionToRuntimeIdentifier(string? arg, ParseResult parseResult) | ||
{ | ||
if ((parseResult.GetResult(RuntimeOption) ?? parseResult.GetResult(LongFormRuntimeOption)) is not null) | ||
{ | ||
|
@@ -270,7 +268,7 @@ internal static IEnumerable<string> ResolveArchOptionToRuntimeIdentifier(string | |
return ResolveRidShorthandOptions(null, arg); | ||
} | ||
|
||
internal static IEnumerable<string> ResolveOsOptionToRuntimeIdentifier(string arg, ParseResult parseResult) | ||
internal static IEnumerable<string> ResolveOsOptionToRuntimeIdentifier(string? arg, ParseResult parseResult) | ||
{ | ||
if ((parseResult.GetResult(RuntimeOption) ?? parseResult.GetResult(LongFormRuntimeOption)) is not null) | ||
{ | ||
|
@@ -281,10 +279,10 @@ internal static IEnumerable<string> ResolveOsOptionToRuntimeIdentifier(string ar | |
return ResolveRidShorthandOptions(arg, arch); | ||
} | ||
|
||
private static IEnumerable<string> ResolveRidShorthandOptions(string os, string arch) => | ||
private static IEnumerable<string> ResolveRidShorthandOptions(string? os, string? arch) => | ||
[$"-property:RuntimeIdentifier={ResolveRidShorthandOptionsToRuntimeIdentifier(os, arch)}"]; | ||
|
||
internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, string arch) | ||
internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string? os, string? arch) | ||
{ | ||
var currentRid = GetCurrentRuntimeId(); | ||
arch = arch == "amd64" ? "x64" : arch; | ||
|
@@ -296,15 +294,17 @@ internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, | |
public static string GetCurrentRuntimeId() | ||
{ | ||
// Get the dotnet directory, while ignoring custom msbuild resolvers | ||
string dotnetRootPath = NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(key => | ||
string? dotnetRootPath = NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(key => | ||
key.Equals("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", StringComparison.InvariantCultureIgnoreCase) | ||
? null | ||
: Environment.GetEnvironmentVariable(key)); | ||
57AE var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; | ||
var sdkPath = dotnetRootPath is not null ? Path.Combine(dotnetRootPath, "sdk") : "sdk"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a case where the NRT analysis seems to have spotted a legitimate bug in the code. In the case that |
||
|
||
// When running under test the Product.Version might be empty or point to version not installed in dotnetRootPath. | ||
string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) || !Directory.Exists(Path.Combine(dotnetRootPath, "sdk", Product.Version)) ? | ||
Path.Combine(Directory.GetDirectories(Path.Combine(dotnetRootPath, "sdk"))[0], ridFileName) : | ||
Path.Combine(dotnetRootPath, "sdk", Product.Version, ridFileName); | ||
string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) || !Directory.Exists(Path.Combine(sdkPath, Product.Version)) ? | ||
Path.Combine(Directory.GetDirectories(sdkPath)[0], ridFileName) : | ||
Path.Combine(sdkPath, Product.Version, ridFileName); | ||
string[] currentRuntimeIdentifiers = File.Exists(runtimeIdentifierChainPath) ? [.. File.ReadAllLines(runtimeIdentifierChainPath).Where(l => !string.IsNullOrEmpty(l))] : []; | ||
if (currentRuntimeIdentifiers == null || !currentRuntimeIdentifiers.Any() || !currentRuntimeIdentifiers[0].Contains("-")) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable disable warnings | ||
#nullable disable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For most of the build tasks there was a single |
||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
@@ -44,7 +44,7 @@ class CacheKey | |
public string TargetFrameworkVersion { get; set; } | ||
public HashSet<string> FrameworkReferences { get; set; } | ||
|
||
public override bool Equals(object? obj) => obj is CacheKey key && | ||
public override bool Equals(object obj) => obj is CacheKey key && | ||
TargetFrameworkIdentifier == key.TargetFrameworkIdentifier && | ||
TargetFrameworkVersion == key.TargetFrameworkVersion && | ||
FrameworkReferences.SetEquals(key.FrameworkReferences); | ||
|
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.
This is just a simple expansion of the original code that is more NRT friendly. Could also change this to be a tuple return but this seemed more readable.