-
Notifications
You must be signed in to change notification settings - Fork 565
[Xamarin.Android.Build.Tasks] Aapt MSBuild Task treats no default translation warnings as MSBuild errors #1006
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
|
dont merge I need to create a test. |
|
My concern with this approach is that if you happen to have a resource named "warning" which actually has an error, we won't properly report it as an error. Possibly bad example, based on the current commented examples: I believe that the above example would elicit a warning, not an error, even though it should be an error. Part of me wonders if the "proper" fix is to update Is that sane/plausible/possible? A not-very-well-tested regex: var r2 = new Regex(@"^(?<file>.+[\/].+)?([:(](?<line>\d+)[)])?(:+\s*)?((error)\s*(?<level>\w*(?=:)):?)?(?<message>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
var m2 = r2.Match ("warning: string 'app_name1' has no default translation.");
// m2.Groups ["file"].Value == '"
// m2.Groups ["line"].Value == ""
// m2.Groups ["level"].Value == ""
// m2.Groups ["message"].Value == "warning: string 'app_name1' has no default translation."This raises a different problem: it's a regex! Comments are not tests. :-) I think, regardless, that we should make Turning back to the regex, it seems to have "bad captures" to me. I'd expect |
|
Playing around a bit, I have: using System;
using System.Text.RegularExpressions;
class App {
public static void Main (string[] args)
{
var r = new Regex (
@"
^
( # start optional path followed by `:`
(?<path>
(?<file>.+[\\/][^:]+)
(
([:](?<line>\d+))
|
(\((?<line>\d+)\))
)?
)
\s*
:
)?
( # optional warning|error:
\s*
(?<level>(warning|error)[^:]*)\s*
:
)?
\s*
(?<message>.*)
$
",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace
);
foreach (var line in args) {
Console.WriteLine (line);
var m = r.Match (line);
if (!m.Success) {
Console.WriteLine ("\t# no match");
continue;
}
Console.WriteLine ($"\t path: '{m.Groups ["path"].Value}'");
Console.WriteLine ($"\t file: '{m.Groups ["file"].Value}'");
Console.WriteLine ($"\t line: '{m.Groups ["line"].Value}'");
Console.WriteLine ($"\t level: '{m.Groups ["level"].Value}'");
Console.WriteLine ($"\tmessage: '{m.Groups ["message"].Value}'");
}
}
}Samples: $ mono e.exe \
'warning: string 'app_name1' has no default translation.' \
'res\layout\main.axml: error: No resource identifier found for attribute "id2" in package "android" (TaskId:22)' \
"Resources/values/theme.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'." \
"Resources/values/theme.xml:2: error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'." \
"res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.]"
warning: string app_name1 has no default translation.
path: ''
file: ''
line: ''
level: 'warning'
message: 'string app_name1 has no default translation.'
res\layout\main.axml: error: No resource identifier found for attribute "id2" in package "android" (TaskId:22)
path: 'res\layout\main.axml'
file: 'res\layout\main.axml'
line: ''
level: 'error'
message: 'No resource identifier found for attribute "id2" in package "android" (TaskId:22)'
Resources/values/theme.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.
path: 'Resources/values/theme.xml(2)'
file: 'Resources/values/theme.xml(2)'
line: ''
level: 'error APT0000'
message: 'Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.'
Resources/values/theme.xml:2: error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.
path: 'Resources/values/theme.xml:2'
file: 'Resources/values/theme.xml'
line: '2'
level: 'error APT0000'
message: 'Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.'
res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.]
path: 'res/drawable/foo-bar.jpg'
file: 'res/drawable/foo-bar.jpg'
line: ''
level: ''
message: 'Invalid file name: must contain only [a-z0-9_.]'This isn't perfect -- note that |
|
Love the change, one more request; as requested above:
This is so that if we need to update the regex again, we'll have a set of tests to ensure we don't break current expectations. |
…nslation warnings as MSBuild errors Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=60445 The regex is picking up the warning in warning: string 'app_name1' has no default translation. but the "warning" part is being picked up by the very first capture group so the current code does not detect its a warning. So in addition to checking the capture group, we should look at the entire line and check for "warning"
…7123) Context: e1af958 Context: #7163 Changes: dotnet/java-interop@c942ab6...fadbb82 * dotnet/java-interop@fadbb82c: [generator] Add support for @explicitInterface metadata (#1006) * dotnet/java-interop@3e4a3c4f: [Java.Interop.Tools.JavaCallableWrappers] JavaCallableMethodClassifier (#998) dotnet/java-interop@3e4a3c4f reworked how `Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator` can be used to find JNI marshal methods. Update `Xamarin.Android.Build.Tasks.dll` to provide a `JavaCallableMethodClassifier` to `JavaCallableWrapperGenerator`, collecting Cecil `MethodDefinition` instances for JNI marshal methods which can be created at build time via LLVM Marshal Methods. Methods which cannot be created at build time include methods with `[Export]`. Once candidate LLVM marshal methods are found, the marshal method is updated to have the [`UnmanagedCallersOnlyAttribute` attribute][0], and related System.Reflection.Emit-based infrastructure such as the `Get…Handler()` methods and `cb_…` fields are removed. As with e1af958, this feature is *not* enabled by default, and remains a xamarin-android Build time configuration option. [0]:https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.unmanagedcallersonlyattribute?view=net-6.0
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=60445
The regex is picking up the warning in
but the "warning" part is being picked up by the very first
capture group so the current code does not detect its a warning.
So in addition to checking the capture group, we should look at
the entire line and check for "warning"