Skip to content

Commit 2135856

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] APT0000 errors are for *errors* (#1047)
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems?id=528572 The current Regex was capturing output which was not an error or a warning. It turns out that `aapt` is not very consistent with its error messaging: sometimes it uses `error`, other times it uses `Error` or `ERROR`. Or in the worse case, they don't flag it as anything. This commit adds a few more tests to `AndroidRegExTests` as well as alters the logic in the `<Aapt/>` task a bit as well. This logic will only log an error if: 1. We have an error `level` group, or 2. we have a `file` name group and `line` number group. This seems to be fairly consistent when looking at the `aapt` source code. We also update the tests to add a few extra `Known` errors which the regex might not pick. This is because they do not contain a `level` or a `file` and `line` number.
1 parent 33b6c95 commit 2135856

3 files changed

Lines changed: 72 additions & 13 deletions

File tree

‎src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool RunAapt (string commandLine)
117117
using(varproc=newProcess()){
118118
proc.OutputDataReceived+=(sender,e)=>{
119119
if(e.Data!=null)
120-
LogEventsFromTextOutput(e.Data,MessageImportance.Normal);
120+
LogMessage(e.Data,MessageImportance.Normal);
121121
else
122122
stdout_completed.Set();
123123
};
@@ -369,7 +369,7 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
369369
intline=0;
370370
if(!string.IsNullOrEmpty(match.Groups["line"]?.Value))
371371
line=int.Parse(match.Groups["line"].Value)+1;
372-
varlevel=match.Groups["level"].Value;
372+
varlevel=match.Groups["level"].Value.ToLowerInvariant();
373373
varmessage=match.Groups["message"].Value;
374374
if(message.Contains("fakeLogOpen")||level.Contains("warning")){
375375
LogWarning(singleLine);
@@ -388,17 +388,13 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
388388
if(message.StartsWith("error: ",StringComparison.InvariantCultureIgnoreCase))
389389
message=message.Substring("error: ".Length);
390390

391-
LogError("APT0000",message,file,line);
392-
return;
393-
}
394-
395-
// Handle additional error that doesn't match the regex
396-
if(singleLine.Trim().StartsWith("invalid resource directory name:")){
397-
LogError("APT0000",string.Format("Invalid resource directory name: \"{0}\".",singleLine.Substring(singleLine.LastIndexOfAny(newchar[]{'\\','/'})+1)),ToolName);
398-
return;
391+
if(level.Contains("error")||(line!=0&&!string.IsNullOrEmpty(file))){
392+
LogError("APT0000",message,file,line);
393+
return;
394+
}
399395
}
400396

401-
LogMessage(singleLine,messageImportance);
397+
LogError("APT0000",string.Format("{0} \"{1}\".",singleLine.Trim(),singleLine.Substring(singleLine.LastIndexOfAny(newchar[]{'\\','/'})+1)),ToolName);
402398
}
403399
}
404400
}

‎src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static Regex AndroidErrorRegex {
105105
\s*
106106
(?<message>.*)
107107
$
108-
",RegexOptions.Compiled|RegexOptions.ExplicitCapture|RegexOptions.IgnorePatternWhitespace);
108+
",RegexOptions.Compiled|RegexOptions.ExplicitCapture|RegexOptions.IgnorePatternWhitespace|RegexOptions.IgnoreCase);
109109
returnandroidErrorRegex;
110110
}
111111
}

‎src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidRegExTests.cs‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,70 @@ public IEnumerator GetEnumerator ()
5858
/*expectedLevel*/"",
5959
/*expectedMessage*/"Invalid file name: must contain only [a-z0-9_.]"
6060
};
61-
61+
yieldreturnnewobject[]{
62+
/*message*/"max res 10, skipping values-sw600dp",
63+
/*expectedToMatch*/true,
64+
/*expectedFile*/"",
65+
/*expectedLine*/"",
66+
/*expectedLevel*/"",
67+
/*expectedMessage*/"max res 10, skipping values-sw600dp"
68+
};
69+
yieldreturnnewobject[]{
70+
/*message*/"max res 10, skipping values-sw600dp-land",
71+
/*expectedToMatch*/true,
72+
/*expectedFile*/"",
73+
/*expectedLine*/"",
74+
/*expectedLevel*/"",
75+
/*expectedMessage*/"max res 10, skipping values-sw600dp-land"
76+
};
77+
yieldreturnnewobject[]{
78+
/*message*/"Error: unable to generate entry for resource data",
79+
/*expectedToMatch*/true,
80+
/*expectedFile*/"",
81+
/*expectedLine*/"",
82+
/*expectedLevel*/"Error",
83+
/*expectedMessage*/"unable to generate entry for resource data"
84+
};
85+
yieldreturnnewobject[]{
86+
/*message*/"Error: malformed resource filename",
87+
/*expectedToMatch*/true,
88+
/*expectedFile*/"",
89+
/*expectedLine*/"",
90+
/*expectedLevel*/"Error",
91+
/*expectedMessage*/"malformed resource filename"
92+
};
93+
yieldreturnnewobject[]{
94+
/*message*/"warning: Multiple AndroidManifest.xml files found, using foo\\AndroidManifest.xml",
95+
/*expectedToMatch*/true,
96+
/*expectedFile*/"",
97+
/*expectedLine*/"",
98+
/*expectedLevel*/"warning",
99+
/*expectedMessage*/"Multiple AndroidManifest.xml files found, using foo\\AndroidManifest.xml"
100+
};
101+
yieldreturnnewobject[]{
102+
/*message*/"Resources/values/theme.xml:55: No start tag found",
103+
/*expectedToMatch*/true,
104+
/*expectedFile*/"Resources/values/theme.xml",
105+
/*expectedLine*/"55",
106+
/*expectedLevel*/"",
107+
/*expectedMessage*/"No start tag found"
108+
};
109+
yieldreturnnewobject[]{
110+
/*message*/"package name is required with --rename-manifest-package.",
111+
/*expectedToMatch*/true,
112+
/*expectedFile*/"",
113+
/*expectedLine*/"",
114+
/*expectedLevel*/"",
115+
/*expectedMessage*/"package name is required with --rename-manifest-package."
116+
};
117+
yieldreturnnewobject[]{
118+
/*message*/"invalid resource directory name: bar-55",
119+
/*expectedToMatch*/true,
120+
/*expectedFile*/"",
121+
/*expectedLine*/"",
122+
/*expectedLevel*/"",
123+
/*expectedMessage*/"invalid resource directory name: bar-55"
124+
};
62125
}
63126
}
64127

0 commit comments

Comments
 (0)