Skip to content

Conversation

@dellis1972
Copy link
Contributor

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems?id=528572

The current RegEx was capturing output which was not and error
or warning. It turns out that aapt is not very consistent with
its error messaging. Sometimes they use error, sometimes then
use 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 Aapt a bit as well. This logic will
only log as an error if we have an error level or we have
a file and line. This seems to be fairly consistent when
looking at the aapt source code.

We also added 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.

if (!string.IsNullOrEmpty (match.Groups["line"]?.Value))
line = int.Parse (match.Groups["line"].Value) + 1;
var level = match.Groups["level"].Value;
var level = match.Groups["level"].Value.ToLower ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be ToLowerInvariant?

( # optional warning|error:
\s*
(?<level>(warning|error)[^:]*)\s*
(?<level>(warning|error|Error|ERROR)[^:]*)\s*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just use RegexOptions.IgnoreCase, and it would also handle if they decide to use Warning or WARNING?


LogError ("APT0000", message, file, line);
return;
if (level.Contains ("error") || (line != 0 && !string.IsNullOrEmpty (file))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once concern with this change is that previously, any message which wasn't a warning or fakeLogOpen was treated as an error.

Now, only messages which contain error are errors.

This sounds reasonable, but will there be any unexpected fallout? Will we "miss" any errors with this change?

Additionally, it looks like we won't log message at all if it's not explicitly a warning or an error. Is that desirable? (Presumably we should always log, no?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated google is not consistent with its labelling of errors/warnings. I went through the aapt code and added any additional ones to https://github.com/xamarin/xamarin-android/pull/1047/files#diff-97e1ab3c8027acfecf85b8bb5a88dd9aR409

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always log the message? Or are there messages we should skip entirely?

It looks like the new version will only log messages which contain warning, fakeLogOpen, error, or contain a filename. Is that desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fall through to https://github.com/dellis1972/xamarin-android/blob/79e432f32f08f4b2c867e07cdd225a5de2c9449a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs#L405 if the regex does not match, or its not one of the KnownInvalidErrorMessages

That said, I'm sure we had an old bug where if we do log the error/warning using LogMessage as well as LogError or LogWarning we ended up with the same error appearing in the error list twice (sometimes). I think because msbuild does some parsing too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Handle additional errors that doesn't match the regex
foreach (var knownInvalidError in KnownInvalidErrorMessages) {
if (singleLine.Trim ().StartsWith (knownInvalidError, StringComparison.OrdinalIgnoreCase)) {
LogError ("APT0000", string.Format ("{0} \"{1}\".", knownInvalidError, singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1)), ToolName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only provide the "rightmost" directory name, and not the entire path? Is it too long and noisy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea. its been that way for a long time from what I can see.

@dellis1972
Copy link
Contributor Author

build

(?<message>.*)
$
", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace, RegexOptions.IgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dellis1972 I think this needs | instead of ,

Copy link
Contributor Author

@dellis1972 dellis1972 Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOH

…ported from aapt output parsing

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems?id=528572

The current RegEx was capturing output which was not and error
or warning. It turns out that aapt is not very consistent with
its error messaging. Sometimes they use `error`, sometimes then
use `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 `Aapt` a bit as well. This logic will
only log as an error if we have an error `level` or we have
a `file` and `line`. This seems to be fairly consistent when
looking at the `aapt` source code.

We also added 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.
@jonpryor jonpryor merged commit 2135856 into dotnet:master Nov 30, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants