-
Notifications
You must be signed in to change notification settings - Fork 128
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
RequiresAssemblyFilesAttribute resource manager changes #1790
Conversation
-Add test for RequiresAssemblyFilesAttribute with Url named argument only
<value>RequiresAssemblyFilesAnalyzer</value> | ||
</data> | ||
<data name="RequiresAssemblyFilesMessage" xml:space="preserve"> | ||
<value>Calling '{0}' which has `RequiresAssemblyFilesAttribute` can break functionality when bundling the application code. {1}. {2}</value> |
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'm not sure bundling the application code
is a well-understood term. The above terminology uses "embedded in a single-file app," which seems understandable for things like Xamarin or Blazor.
<data name="RequiresAssemblyFilesTitle" xml:space="preserve"> | ||
<value /> | ||
<value>RequiresAssemblyFilesAnalyzer</value> |
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 don't think this is supposed to be the title of the analyzer, it's the title of the warning, which is like a short description of what the warning is supposed to prevent.
Something like, "Avoid calling members marked with RequiresAssemblyFilesAttribute
when publishing as a single file"?
@@ -48,7 +48,7 @@ void M() | |||
} | |||
}"; | |||
return VerifyRequiresAssemblyFilesAnalyzer (TestRequiresAssemblyFieldsOnEvent, |
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.
These tests should print out a comment with the message when the test fails. If you include the comment, you can see if it looks right in the message and make the code easier to review.
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.
Are we sure we want the comments? they got deleted from the RequiresUnreferencedCodeAnalyzerTests too. I'm fine with or without them just want to homologate things between the analyzers code.
<data name="RequiresAssemblyFilesTitle" xml:space="preserve"> | ||
<value /> | ||
<value>Avoid calling members marked with `RequiresAssemblyFilesAttribute` when publishing as a single-file</value> |
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.
Nit: can we change (here and above) the backticks for common apostrophe (') similar to
Or https://github.com/mono/linker/blob/master/src/linker/Resources/Strings.resx ?
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.
Is calling the right terminology here?. Are we going to add a new message for each bundle like format?
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.
Is calling the right terminology here?
I'm changing the message to match something similar to #1778 (comment)
Are we going to add a new message for each bundle like format?
Since they all will use the same custom attribute I would expect to print the same message independent of the kind of bundle
<data name="RequiresUnreferencedCodeAnalyzerTitle" xml:space="preserve"> | ||
<value>RequiresUnreferencedCodeAnalyzer</value> | ||
<data name="RequiresUnreferencedCodeTitle" xml:space="preserve"> | ||
<value>Avoid calling members marked with `RequiresUnreferencedCodeAttribute` when trimming application code</value> |
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.
<value>Avoid calling members marked with `RequiresUnreferencedCodeAttribute` when trimming application code</value> | |
<value>Avoid calling methods marked with 'RequiresUnreferencedCodeAttribute' when trimming application code</value> |
Also I'm not sure that something marked with this attribute is something that the user should avoid calling, it's just a method that requires dynamic access, which is dangerous when linking the application (but I really don't have a good suggestion for framing this title).
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.
We could rephrase by saying something like "Members annotated with RequiresUnreferencedCodeAttribute
may behave differently or fail if the unreferenced code is removed by trimming"
I think that's a decent description of the problem, but it doesn't really give a call to action, like "don't call this when trimming." I don't have a strong opinion either way, but I think we should decide on what kind of title we want to present.
The context for this resource is that when you're looking at a list of the warnings, this will be the description of what the warning is about. The message is what's actually printed when the warning fires.
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.
In a previous commit, I changed the message to:
Methods marked with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
</data> | ||
<data name="RequiresUnreferencedCodeAnalyzerMessage" xml:space="preserve"> | ||
<data name="RequiresUnreferencedCodeMessage" xml:space="preserve"> | ||
<value>Calling '{0}' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. {1}. {2}</value> |
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.
Since you're editing things here, I think we should update this message to match the one we produce from within the linker: #1778 (comment)
-Change terminology of analyzers warnings messages to match linker -Change title description of analyzer RequiresUnreferenceCodeTitle
-Change RequireUnreferencedCodeCapability Expected warnings
break; | ||
expectedMessageContains.RemoveAt (0); | ||
var expectedMessages = expectedMessagesContains[1]; |
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.
It looks like this no longer handles params
arrays properly, namely it only looks at the second argument, instead of all the arguments.
…leResourceChange Update error messages Update ExpectedWarning usage
Throw whenever a named argument is passed in ExpectedWarning
@@ -56,7 +56,7 @@ public static void Main () | |||
TestRequiresInDynamicDependency (); | |||
} | |||
|
|||
[ExpectedWarning ("IL2026", "--RequiresWithMessageOnly--")] | |||
[ExpectedWarning ("IL2026", new string[] { "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresWithMessageOnly()'", "Message for --RequiresWithMessageOnly--." })] |
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.
Why add new string[]
?
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.
Ok, I changed the code to not support array creation, the code will throw in GetStringFromExpr if it ever tries to be used
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.
LGTM, although I'd prefer if we settle on one style for params array invocations in ExpectedWarning
: either use new string[]
everywhere, or don't use it anywhere.
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.
Can we remove the new string[]
usage in the tests? Why do we need it? Looks to me that it is enough to just look for the warning code and look for the message that was specified in the Message
parameter of the method that we think is the origin of the warning.
@@ -108,7 +108,7 @@ static void TestRequiresOnPropertyGetterAndSetter () | |||
set { } | |||
} | |||
|
|||
[ExpectedWarning ("IL2026", new string[] { "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresAndCallsOtherRequiresMethods<TPublicMethods>()'", "Message for --RequiresAndCallsOtherRequiresMethods--." })] | |||
[ExpectedWarning ("IL2026", "'Mono.Linker.Tests.Cases.RequiresCapability.RequiresUnreferencedCodeCapability.RequiresAndCallsOtherRequiresMethods<TPublicMethods>()'", "Message for --RequiresAndCallsOtherRequiresMethods--.")] |
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.
It's enough to only validate the message that's coming from the annotated method. We explicitly removed full text validation previously: #1778 (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.
My line of thinking was that this is not full-text validation, I only validate the method name and the message which are things that should not change in the message. The linker has code in the result checker to check for the method with the ExpectedWarning attribute. The analyzer on the other hand will match any messages that are within the span, which means that there is a chance for the analyzer to check for messages that were not produced by the method marked with ExpectedWarning. Although in this file, no message is repeated, so using the message is enough. I will change the implementation.
* Change resource file to have a default message and accept arguments * Add test for RequiresAssemblyFilesAttribute with Url named argument only * Add IL3XXX warning codes to the master error code registry * Throw whenever a named argument is passed in ExpectedWarning
…r#1790) * Change resource file to have a default message and accept arguments * Add test for RequiresAssemblyFilesAttribute with Url named argument only * Add IL3XXX warning codes to the master error code registry * Throw whenever a named argument is passed in ExpectedWarning Commit migrated from dotnet/linker@9b71e7b
PR for #1786
-Change resource file to have a default message and accept arguments
-Add test for RequiresAssemblyFilesAttribute with Url named argument only