-
Notifications
You must be signed in to change notification settings - Fork 564
[XABT] Enable NRT for some tasks. #10099
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
Conversation
28d1aee to
e2761df
Compare
| if (!string.IsNullOrEmpty (ExtraArgs)) | ||
| if (!ExtraArgs.IsNullOrEmpty ()) |
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.
So, you can also use pattern matching instead:
android/.github/copilot-instructions.md
Lines 61 to 75 in dc07800
| If you see a `string.IsNullOrEmpty()` check: | |
| ```csharp | |
| if (!string.IsNullOrEmpty (NonRequiredProperty)) { | |
| // Code here | |
| } | |
| ``` | |
| Convert this to: | |
| ```csharp | |
| if (NonRequiredProperty is { Length: > 0 }) { | |
| // Code here | |
| } | |
| ``` |
Should we do this instead of an extension method?
GH Copilot was also able to make the change as mentioned here. I'm not sure it will be able to know about an extension method we made unless the file was somehow always added in its context.
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.
Maybe we need a poll, but I find string.IsNullOrEmpty() or value.IsNullOrEmpty() to be easier to read than value is { Length: > 0 }. I want proper semantic names, not expressions!
How does everyone else feel?
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 find IsNullOrEmpty() to be easier to read as well, it's documenting the intent and the effect very clearly.
|
|
||
| [Required] | ||
| public ITaskItem[] MappingFiles { get; set; } | ||
| public ITaskItem[] MappingFiles { get; set; } = []; |
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.
Should this also be = null!? It would prevent a GC allocation, and it'll be set to a different value by MSBuild anyway…
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.
They are the same as Array.Empty<ITaskItem>(), it shouldn't allocate.
|
|
||
| [Required] | ||
| public ITaskItem[] AssetDirectories { get; set; } | ||
| public ITaskItem[] AssetDirectories { get; set; } = []; |
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.
Ditto here.
|
Array initializers: public ITaskItem[] AssetDirectories { get; set; } = [];result in use of Given MSBuild semantics here, I think we should use |
I find
As the only 2 types of
In general my preference is to use the null forgiveness operator as sparingly as possible if there's a cheap/easy alternative. |
jonathanpeppers
left a comment
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.
If we are good with the other syntax in here, I think I am.
Maybe the last thing is to update this example to use IsNullOrEmpty() extension method:
android/.github/copilot-instructions.md
Lines 61 to 75 in dc07800
| If you see a `string.IsNullOrEmpty()` check: | |
| ```csharp | |
| if (!string.IsNullOrEmpty (NonRequiredProperty)) { | |
| // Code here | |
| } | |
| ``` | |
| Convert this to: | |
| ```csharp | |
| if (NonRequiredProperty is { Length: > 0 }) { | |
| // Code here | |
| } | |
| ``` |
If someone ever asked copilot to opt into NRT, it could have a chance at doing the right thing.
I guess we'd also put a path to where the new extension method lives?
Is there a way to scope that example solely to the I also noticed those instructions specify using |
|
It says to only do it for "For MSBuild task properties like:", but we could put a stronger suggestion in there. Could mention netstandard2.0? |
e2761df to
105d65b
Compare
105d65b to
4652b88
Compare
|
Updated |
Context: #10099 Context: #9918 #10099 enabled NRT checks for a number of XABT Tasks and was merged because all the tests passed. However, #10099 was not rebased on the tip of `main` which, in the meantime, contained code from the recently merged #9918 PR. #9918 introduced a couple of `string` properties to the `AndroidComputeResPaths` and `CreateAar` tasks, which were not nullable annotated. This resulted in the following build errors once #10099 was merged: src/Xamarin.Android.Build.Tasks/Tasks/AndroidComputeResPaths.cs(52,17): error CS8618: Non-nullable property 'PrefixProperty' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. src/Xamarin.Android.Build.Tasks/Tasks/CreateAar.cs(37,17): error CS8618: Non-nullable property 'PrefixProperty' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. This PR makes the `PrefixProperty` properties `[Required]` (because of the way they are used in the tasks) and assigns default values to them, as per convention introduced in #10099
Enable NRT for some "utility" classes in `Xamarin.Android.Build.Tasks` that only needed trivial changes. The conventions established in #10099 were used.
Enable NRT for tasks in
Xamarin.Android.Build.Tasksthat only needed trivial changes.The following conventions were used:
When the task property is guarded by
[Register], MSBuild will ensure the property is notnull, thus we set these values to a non-allocating default:For non-
[Required]properties and fields, set the type to nullable.Additionally,
string.IsNullOrEmpty (string)and friends are not properly annotated for NRT innetstandard2.0. Createstringextension methods likefoo.IsNullOrEmpty ()that are properly annotated and use them where needed.A few of our unit tests were not filling in
[Required]task properties and thus failing due to getting different results. Update the tests to pass the[Required]properties.