Do not cleanup Gradle in non-Android integration tests (#66487)
This commit is contained in:
@@ -10,7 +10,7 @@ import 'package:path/path.dart' as path;
|
||||
import 'package:vm_service_client/vm_service_client.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
import 'package:flutter_devicelab/framework/adb.dart' show DeviceIdEnvName;
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
|
||||
/// Runs a task in a separate Dart VM and collects the result using the VM
|
||||
/// service protocol.
|
||||
@@ -123,43 +123,45 @@ Future<VMIsolateRef> _connectToRunnerIsolate(Uri vmServiceUri) async {
|
||||
}
|
||||
|
||||
Future<void> cleanupSystem() async {
|
||||
print('\n\nCleaning up system after task...');
|
||||
final String javaHome = await findJavaHome();
|
||||
if (javaHome != null) {
|
||||
// To shut gradle down, we have to call "gradlew --stop".
|
||||
// To call gradlew, we need to have a gradle-wrapper.properties file along
|
||||
// with a shell script, a .jar file, etc. We get these from various places
|
||||
// as you see in the code below, and we save them all into a temporary dir
|
||||
// which we can then delete after.
|
||||
// All the steps below are somewhat tolerant of errors, because it doesn't
|
||||
// really matter if this succeeds every time or not.
|
||||
print('\nTelling Gradle to shut down (JAVA_HOME=$javaHome)');
|
||||
final String gradlewBinaryName = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_devicelab_shutdown_gradle.');
|
||||
recursiveCopy(Directory(path.join(flutterDirectory.path, 'bin', 'cache', 'artifacts', 'gradle_wrapper')), tempDir);
|
||||
copy(File(path.join(path.join(flutterDirectory.path, 'packages', 'flutter_tools'), 'templates', 'app', 'android.tmpl', 'gradle', 'wrapper', 'gradle-wrapper.properties')), Directory(path.join(tempDir.path, 'gradle', 'wrapper')));
|
||||
if (!Platform.isWindows) {
|
||||
if (deviceOperatingSystem == null || deviceOperatingSystem == DeviceOperatingSystem.android) {
|
||||
print('\n\nCleaning up system after task...');
|
||||
final String javaHome = await findJavaHome();
|
||||
if (javaHome != null) {
|
||||
// To shut gradle down, we have to call "gradlew --stop".
|
||||
// To call gradlew, we need to have a gradle-wrapper.properties file along
|
||||
// with a shell script, a .jar file, etc. We get these from various places
|
||||
// as you see in the code below, and we save them all into a temporary dir
|
||||
// which we can then delete after.
|
||||
// All the steps below are somewhat tolerant of errors, because it doesn't
|
||||
// really matter if this succeeds every time or not.
|
||||
print('\nTelling Gradle to shut down (JAVA_HOME=$javaHome)');
|
||||
final String gradlewBinaryName = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_devicelab_shutdown_gradle.');
|
||||
recursiveCopy(Directory(path.join(flutterDirectory.path, 'bin', 'cache', 'artifacts', 'gradle_wrapper')), tempDir);
|
||||
copy(File(path.join(path.join(flutterDirectory.path, 'packages', 'flutter_tools'), 'templates', 'app', 'android.tmpl', 'gradle', 'wrapper', 'gradle-wrapper.properties')), Directory(path.join(tempDir.path, 'gradle', 'wrapper')));
|
||||
if (!Platform.isWindows) {
|
||||
await exec(
|
||||
'chmod',
|
||||
<String>['a+x', path.join(tempDir.path, gradlewBinaryName)],
|
||||
canFail: true,
|
||||
);
|
||||
}
|
||||
await exec(
|
||||
'chmod',
|
||||
<String>['a+x', path.join(tempDir.path, gradlewBinaryName)],
|
||||
path.join(tempDir.path, gradlewBinaryName),
|
||||
<String>['--stop'],
|
||||
environment: <String, String>{ 'JAVA_HOME': javaHome},
|
||||
workingDirectory: tempDir.path,
|
||||
canFail: true,
|
||||
);
|
||||
rmTree(tempDir);
|
||||
print('\n');
|
||||
} else {
|
||||
print('Could not determine JAVA_HOME; not shutting down Gradle.');
|
||||
}
|
||||
await exec(
|
||||
path.join(tempDir.path, gradlewBinaryName),
|
||||
<String>['--stop'],
|
||||
environment: <String, String>{ 'JAVA_HOME': javaHome },
|
||||
workingDirectory: tempDir.path,
|
||||
canFail: true,
|
||||
);
|
||||
rmTree(tempDir);
|
||||
print('\n');
|
||||
} else {
|
||||
print('Could not determine JAVA_HOME; not shutting down Gradle.');
|
||||
// Removes the .gradle directory because sometimes gradle fails in downloading
|
||||
// a new version and leaves a corrupted zip archive, which could cause the
|
||||
// next devicelab task to fail.
|
||||
// https://github.com/flutter/flutter/issues/65277
|
||||
rmTree(dir('${Platform.environment['HOME']}/.gradle'));
|
||||
}
|
||||
// Removes the .gradle directory because sometimes gradle fails in downloading
|
||||
// a new version and leaves a corrupted zip archive, which could cause the
|
||||
// next devicelab task to fail.
|
||||
// https://github.com/flutter/flutter/issues/65277
|
||||
rmTree(dir('${Platform.environment['HOME']}/.gradle'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user