Unverified Commit 9e0f0fe9 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Add Gradle stacktrace and debug log level to verbose builds (#101734)

parent 712667fb
...@@ -268,6 +268,8 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -268,6 +268,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
_gradleUtils.getExecutable(project), _gradleUtils.getExecutable(project),
]; ];
if (_logger.isVerbose) { if (_logger.isVerbose) {
command.add('--full-stacktrace');
command.add('--debug');
command.add('-Pverbose=true'); command.add('-Pverbose=true');
} else { } else {
command.add('-q'); command.add('-q');
...@@ -590,6 +592,8 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -590,6 +592,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
'-PbuildNumber=$buildNumber' '-PbuildNumber=$buildNumber'
]; ];
if (_logger.isVerbose) { if (_logger.isVerbose) {
command.add('--full-stacktrace');
command.add('--debug');
command.add('-Pverbose=true'); command.add('-Pverbose=true');
} else { } else {
command.add('-q'); command.add('-q');
......
...@@ -732,16 +732,20 @@ class BufferLogger extends Logger { ...@@ -732,16 +732,20 @@ class BufferLogger extends Logger {
required this.terminal, required this.terminal,
required OutputPreferences outputPreferences, required OutputPreferences outputPreferences,
StopwatchFactory stopwatchFactory = const StopwatchFactory(), StopwatchFactory stopwatchFactory = const StopwatchFactory(),
bool verbose = false,
}) : _outputPreferences = outputPreferences, }) : _outputPreferences = outputPreferences,
_stopwatchFactory = stopwatchFactory; _stopwatchFactory = stopwatchFactory,
_verbose = verbose;
/// Create a [BufferLogger] with test preferences. /// Create a [BufferLogger] with test preferences.
BufferLogger.test({ BufferLogger.test({
Terminal? terminal, Terminal? terminal,
OutputPreferences? outputPreferences, OutputPreferences? outputPreferences,
bool verbose = false,
}) : terminal = terminal ?? Terminal.test(), }) : terminal = terminal ?? Terminal.test(),
_outputPreferences = outputPreferences ?? OutputPreferences.test(), _outputPreferences = outputPreferences ?? OutputPreferences.test(),
_stopwatchFactory = const StopwatchFactory(); _stopwatchFactory = const StopwatchFactory(),
_verbose = verbose;
@override @override
final OutputPreferences _outputPreferences; final OutputPreferences _outputPreferences;
...@@ -751,8 +755,10 @@ class BufferLogger extends Logger { ...@@ -751,8 +755,10 @@ class BufferLogger extends Logger {
final StopwatchFactory _stopwatchFactory; final StopwatchFactory _stopwatchFactory;
final bool _verbose;
@override @override
bool get isVerbose => false; bool get isVerbose => _verbose;
@override @override
bool get supportsColor => terminal.supportsColor; bool get supportsColor => terminal.supportsColor;
......
...@@ -128,6 +128,69 @@ void main() { ...@@ -128,6 +128,69 @@ void main() {
)); ));
}); });
testUsingContext('Verbose mode for APKs includes Gradle stacktrace and sets debug log level', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: BufferLogger.test(verbose: true),
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
usage: testUsage,
gradleUtils: FakeGradleUtils(),
platform: FakePlatform(),
);
processManager.addCommand(const FakeCommand(
command: <String>[
'gradlew',
'--full-stacktrace',
'--debug',
'-Pverbose=true',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=lib/main.dart',
'-Pbase-application-name=io.flutter.app.FlutterApplication',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=false',
'assembleRelease'
],
));
fileSystem.directory('android')
.childFile('build.gradle')
.createSync(recursive: true);
fileSystem.directory('android')
.childFile('gradle.properties')
.createSync(recursive: true);
fileSystem.directory('android')
.childDirectory('app')
.childFile('build.gradle')
..createSync(recursive: true)
..writeAsStringSync('apply from: irrelevant/flutter.gradle');
fileSystem.directory('build')
.childDirectory('app')
.childDirectory('outputs')
.childDirectory('flutter-apk')
.childFile('app-release.apk')
.createSync(recursive: true);
await builder.buildGradleApp(
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
androidBuildInfo: const AndroidBuildInfo(
BuildInfo(
BuildMode.release,
null,
treeShakeIcons: false,
),
),
target: 'lib/main.dart',
isBuildingBundle: false,
localGradleErrors: <GradleHandledError>[],
);
expect(processManager, hasNoRemainingExpectations);
});
testUsingContext('Can retry build on recognized exit code/stderr', () async { testUsingContext('Can retry build on recognized exit code/stderr', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder( final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger, logger: logger,
...@@ -700,6 +763,61 @@ void main() { ...@@ -700,6 +763,61 @@ void main() {
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
testUsingContext('Verbose mode for AARs includes Gradle stacktrace and sets debug log level', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: BufferLogger.test(verbose: true),
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
usage: testUsage,
gradleUtils: FakeGradleUtils(),
platform: FakePlatform(),
);
processManager.addCommand(const FakeCommand(
command: <String>[
'gradlew',
'-I=/packages/flutter_tools/gradle/aar_init_script.gradle',
'-Pflutter-root=/',
'-Poutput-dir=build/',
'-Pis-plugin=false',
'-PbuildNumber=1.0',
'--full-stacktrace',
'--debug',
'-Pverbose=true',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=false',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'assembleAarRelease'
],
));
final File manifestFile = fileSystem.file('pubspec.yaml');
manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync('''
flutter:
module:
androidPackage: com.example.test
'''
);
fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle')
.createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await builder.buildGradleAar(
androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null, treeShakeIcons: false)),
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
outputDirectory: fileSystem.directory('build/'),
target: '',
buildNumber: '1.0',
);
expect(processManager, hasNoRemainingExpectations);
});
testUsingContext('gradle exit code and stderr is forwarded to tool exit', () async { testUsingContext('gradle exit code and stderr is forwarded to tool exit', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder( final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger, logger: logger,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment