-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[flutter_tools] post process the gradle log output #71499
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
Merged
jonahwilliams
merged 4 commits into
flutter:master
from
jonahwilliams:remove_gradle_footer
Dec 2, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/flutter_tools/lib/src/android/gradle_log_processor.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'gradle_errors.dart'; | ||
|
||
/// Process log output from gradle, removing irrelevant output and capturing | ||
/// exception information. | ||
class GradleLogProcessor { | ||
GradleLogProcessor(this.localGradleErrors, this.verbose); | ||
|
||
final List<GradleHandledError> localGradleErrors; | ||
final bool verbose; | ||
|
||
GradleHandledError detectedGradleError; | ||
String detectedGradleErrorLine; | ||
bool atFailureFooter = false; | ||
|
||
String consumeLog(String line) { | ||
// All gradle failures lead to a fairly long footer which contains mostly | ||
// irrelevant information for a flutter build, along with misleading advice to | ||
// run with --stacktrace (which does not exist for the flutter CLI). remove this. | ||
if (!verbose && (line.startsWith('FAILURE: Build failed with an exception.') || atFailureFooter)) { | ||
atFailureFooter = true; | ||
return null; | ||
} | ||
// This message was removed from first-party plugins, | ||
// but older plugin versions still display this message. | ||
if (androidXPluginWarningRegex.hasMatch(line)) { | ||
// Don't pipe. | ||
return null; | ||
} | ||
if (detectedGradleError != null) { | ||
// Pipe stdout/stderr from Gradle. | ||
return line; | ||
} | ||
for (final GradleHandledError gradleError in localGradleErrors) { | ||
if (gradleError.test(line)) { | ||
detectedGradleErrorLine = line; | ||
detectedGradleError = gradleError; | ||
// The first error match wins. | ||
break; | ||
} | ||
} | ||
// Pipe stdout/stderr from Gradle. | ||
return line; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/flutter_tools/test/general.shard/android/gradle_log_processor_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_tools/src/android/gradle_errors.dart'; | ||
import 'package:flutter_tools/src/android/gradle_log_processor.dart'; | ||
|
||
import '../../src/common.dart'; | ||
|
||
final List<String> gradleErrorOutputLines = r''' | ||
Some other stuff. | ||
FAILURE: Build failed with an exception. | ||
|
||
* Where: | ||
Script '/Users/mit/dev/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 900 | ||
|
||
* What went wrong: | ||
Execution failed for task ':app:compileFlutterBuildRelease'. | ||
> Process 'command '/Users/mit/dev/flutter/bin/flutter'' finished with non-zero exit value 1 | ||
|
||
* Try: | ||
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. | ||
|
||
* Get more help at https://help.gradle.org | ||
|
||
BUILD FAILED in 24s | ||
'''.split('\n'); | ||
|
||
void main() { | ||
testWithoutContext('Does not print failure footer in non-verbose mode', () async { | ||
final GradleLogProcessor gradleLogProcessor = GradleLogProcessor(<GradleHandledError>[], false); | ||
|
||
expect(gradleErrorOutputLines.map(gradleLogProcessor.consumeLog).where((String line) => line != null), <String>['Some other stuff.']); | ||
expect(gradleLogProcessor.atFailureFooter, true); | ||
}); | ||
|
||
testWithoutContext('Does print failure footer in verbose mode', () async { | ||
final GradleLogProcessor gradleLogProcessor = GradleLogProcessor(<GradleHandledError>[], true); | ||
|
||
expect(gradleErrorOutputLines.map(gradleLogProcessor.consumeLog).where((String line) => line != null), gradleErrorOutputLines); | ||
expect(gradleLogProcessor.atFailureFooter, false); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 there any way split on output that we control instead of a line from gradle? Like could the tool emit a known line from the recursive call?
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 you elaborate a bit on what that would be used for?
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.
Sure, just taking a possibly naive look at the example 'before' output in the PR description, we have:
Instead of detecting gradle output using the first line emitted by gradle, which we don't control, the idea would be to detect gradle output using the last line of
[lines emitted by the tool or the Dart compiler]
, which we do control, adding a new sentinel line there if needed.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 can't hide all Gradle output though. For example, a compilation error in the users Java code:
We still want to chop off the footer since it is wrong, but we need to show the output from the javac task
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.
Ah, okay. Got it. Thanks.