Unverified Commit bf4a5484 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] no-op maven artifacts if Android SDK is absent (#73957)

parent f1718bcf
...@@ -1136,6 +1136,8 @@ class AndroidGenSnapshotArtifacts extends EngineCachedArtifact { ...@@ -1136,6 +1136,8 @@ class AndroidGenSnapshotArtifacts extends EngineCachedArtifact {
} }
/// A cached artifact containing the Maven dependencies used to build Android projects. /// A cached artifact containing the Maven dependencies used to build Android projects.
///
/// This is a no-op if the android SDK is not available.
class AndroidMavenArtifacts extends ArtifactSet { class AndroidMavenArtifacts extends ArtifactSet {
AndroidMavenArtifacts(this.cache, { AndroidMavenArtifacts(this.cache, {
@required Platform platform, @required Platform platform,
...@@ -1152,6 +1154,9 @@ class AndroidMavenArtifacts extends ArtifactSet { ...@@ -1152,6 +1154,9 @@ class AndroidMavenArtifacts extends ArtifactSet {
FileSystem fileSystem, FileSystem fileSystem,
OperatingSystemUtils operatingSystemUtils, OperatingSystemUtils operatingSystemUtils,
) async { ) async {
if (globals.androidSdk == null) {
return;
}
final Directory tempDir = cache.getRoot().createTempSync( final Directory tempDir = cache.getRoot().createTempSync(
'flutter_gradle_wrapper.', 'flutter_gradle_wrapper.',
); );
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/android/gradle_utils.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' show InternetAddress, SocketException; import 'package:flutter_tools/src/base/io.dart' show InternetAddress, SocketException;
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
...@@ -653,24 +653,23 @@ void main() { ...@@ -653,24 +653,23 @@ void main() {
group('AndroidMavenArtifacts', () { group('AndroidMavenArtifacts', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
MockProcessManager processManager;
Cache cache; Cache cache;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
processManager = MockProcessManager();
cache = Cache.test( cache = Cache.test(
fileSystem: memoryFileSystem, fileSystem: memoryFileSystem,
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
}); });
testWithoutContext('development artifact', () async { testWithoutContext('AndroidMavenArtifacts has a specified development artifact', () async {
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux')); final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux'));
expect(mavenArtifacts.developmentArtifact, DevelopmentArtifact.androidMaven); expect(mavenArtifacts.developmentArtifact, DevelopmentArtifact.androidMaven);
}); });
testUsingContext('update', () async { testUsingContext('AndroidMavenArtifacts can invoke Gradle resolve dependencies if Android SDK is present', () async {
Cache.flutterRoot = '';
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux')); final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux'));
expect(await mavenArtifacts.isUpToDate(memoryFileSystem), isFalse); expect(await mavenArtifacts.isUpToDate(memoryFileSystem), isFalse);
...@@ -678,16 +677,28 @@ void main() { ...@@ -678,16 +677,28 @@ void main() {
gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant'); gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant');
gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant'); gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant');
when(processManager.run(any, environment: captureAnyNamed('environment'))) await mavenArtifacts.update(MockArtifactUpdater(), BufferLogger.test(), memoryFileSystem, MockOperatingSystemUtils());
.thenAnswer((Invocation invocation) {
final List<String> args = invocation.positionalArguments[0] as List<String>; expect(await mavenArtifacts.isUpToDate(memoryFileSystem), isFalse);
expect(args.length, 6); }, overrides: <Type, Generator>{
expect(args[1], '-b'); Cache: () => cache,
expect(args[2].endsWith('resolve_dependencies.gradle'), isTrue); FileSystem: () => memoryFileSystem,
expect(args[5], 'resolveDependencies'); ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
expect(invocation.namedArguments[#environment], gradleEnvironment); const FakeCommand(command: <String>[
return Future<ProcessResult>.value(ProcessResult(0, 0, '', '')); '/cache/bin/cache/flutter_gradle_wrapper.rand0/gradlew',
}); '-b',
'packages/flutter_tools/gradle/resolve_dependencies.gradle',
'--project-cache-dir',
'cache/bin/cache/flutter_gradle_wrapper.rand0',
'resolveDependencies',
])
]),
AndroidSdk: () => FakeAndroidSdk()
});
testUsingContext('AndroidMavenArtifacts is a no-op if the Android SDK is absent', () async {
final AndroidMavenArtifacts mavenArtifacts = AndroidMavenArtifacts(cache, platform: FakePlatform(operatingSystem: 'linux'));
expect(await mavenArtifacts.isUpToDate(memoryFileSystem), isFalse);
await mavenArtifacts.update(MockArtifactUpdater(), BufferLogger.test(), memoryFileSystem, MockOperatingSystemUtils()); await mavenArtifacts.update(MockArtifactUpdater(), BufferLogger.test(), memoryFileSystem, MockOperatingSystemUtils());
...@@ -695,7 +706,8 @@ void main() { ...@@ -695,7 +706,8 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Cache: () => cache, Cache: () => cache,
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => processManager, ProcessManager: () => FakeProcessManager.list(<FakeCommand>[]),
AndroidSdk: () => null // Android SDK was not located.
}); });
}); });
} }
...@@ -782,3 +794,4 @@ class FakeCache extends Cache { ...@@ -782,3 +794,4 @@ class FakeCache extends Cache {
return stampFile; return stampFile;
} }
} }
class FakeAndroidSdk extends Fake implements AndroidSdk {}
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