From a6a8a14d028f88e0cc888d06849e26430e75c3c5 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 24 Sep 2020 18:34:07 -0700 Subject: [PATCH] Do not cleanup Gradle in non-Android integration tests (#66487) --- dev/devicelab/lib/framework/runner.dart | 72 +++++++++++++------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/dev/devicelab/lib/framework/runner.dart b/dev/devicelab/lib/framework/runner.dart index d045c83f04..a059a8e992 100644 --- a/dev/devicelab/lib/framework/runner.dart +++ b/dev/devicelab/lib/framework/runner.dart @@ -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 _connectToRunnerIsolate(Uri vmServiceUri) async { } Future 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', + ['a+x', path.join(tempDir.path, gradlewBinaryName)], + canFail: true, + ); + } await exec( - 'chmod', - ['a+x', path.join(tempDir.path, gradlewBinaryName)], + path.join(tempDir.path, gradlewBinaryName), + ['--stop'], + environment: { '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), - ['--stop'], - environment: { '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')); }