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

[flutter_tools] remove local engine from globals in gradle (#76277)

parent 7233d963
...@@ -22,7 +22,7 @@ import '../build_info.dart'; ...@@ -22,7 +22,7 @@ import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
import '../convert.dart'; import '../convert.dart';
import '../flutter_manifest.dart'; import '../flutter_manifest.dart';
import '../globals.dart' as globals hide logger, printStatus, printTrace, printError, processManager, processUtils, fs; import '../globals.dart' as globals hide logger, printStatus, printTrace, printError, processManager, processUtils, fs, artifacts;
import '../project.dart'; import '../project.dart';
import '../reporting/reporting.dart'; import '../reporting/reporting.dart';
import 'android_builder.dart'; import 'android_builder.dart';
...@@ -216,13 +216,16 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -216,13 +216,16 @@ class AndroidGradleBuilder implements AndroidBuilder {
@required Logger logger, @required Logger logger,
@required ProcessManager processManager, @required ProcessManager processManager,
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required Artifacts artifacts,
}) : _logger = logger, }) : _logger = logger,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_artifacts = artifacts,
_processUtils = ProcessUtils(logger: logger, processManager: processManager); _processUtils = ProcessUtils(logger: logger, processManager: processManager);
final Logger _logger; final Logger _logger;
final ProcessUtils _processUtils; final ProcessUtils _processUtils;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Artifacts _artifacts;
/// Builds the AAR and POM files for the current Flutter module or plugin. /// Builds the AAR and POM files for the current Flutter module or plugin.
@override @override
...@@ -387,8 +390,8 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -387,8 +390,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
if (!buildInfo.androidGradleDaemon) { if (!buildInfo.androidGradleDaemon) {
command.add('--no-daemon'); command.add('--no-daemon');
} }
if (globals.artifacts is LocalEngineArtifacts) { if (_artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts; final LocalEngineArtifacts localEngineArtifacts = _artifacts as LocalEngineArtifacts;
final Directory localEngineRepo = _getLocalEngineRepo( final Directory localEngineRepo = _getLocalEngineRepo(
engineOutPath: localEngineArtifacts.engineOutPath, engineOutPath: localEngineArtifacts.engineOutPath,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
...@@ -704,8 +707,8 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -704,8 +707,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
); );
} }
if (globals.artifacts is LocalEngineArtifacts) { if (_artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts; final LocalEngineArtifacts localEngineArtifacts = _artifacts as LocalEngineArtifacts;
final Directory localEngineRepo = _getLocalEngineRepo( final Directory localEngineRepo = _getLocalEngineRepo(
engineOutPath: localEngineArtifacts.engineOutPath, engineOutPath: localEngineArtifacts.engineOutPath,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
...@@ -1137,16 +1140,6 @@ Directory _getLocalEngineRepo({ ...@@ -1137,16 +1140,6 @@ Directory _getLocalEngineRepo({
final String abi = _getAbiByLocalEnginePath(engineOutPath); final String abi = _getAbiByLocalEnginePath(engineOutPath);
final Directory localEngineRepo = fileSystem.systemTempDirectory final Directory localEngineRepo = fileSystem.systemTempDirectory
.createTempSync('flutter_tool_local_engine_repo.'); .createTempSync('flutter_tool_local_engine_repo.');
// Remove the local engine repo before the tool exits.
shutdownHooks.addShutdownHook(() {
if (localEngineRepo.existsSync()) {
localEngineRepo.deleteSync(recursive: true);
}
},
ShutdownStage.CLEANUP,
);
final String buildMode = androidBuildInfo.buildInfo.modeName; final String buildMode = androidBuildInfo.buildInfo.modeName;
final String artifactVersion = _getLocalArtifactVersion( final String artifactVersion = _getLocalArtifactVersion(
fileSystem.path.join( fileSystem.path.join(
......
...@@ -209,8 +209,15 @@ class EngineBuildPaths { ...@@ -209,8 +209,15 @@ class EngineBuildPaths {
abstract class Artifacts { abstract class Artifacts {
/// A test-specific implementation of artifacts that returns stable paths for /// A test-specific implementation of artifacts that returns stable paths for
/// all artifacts. /// all artifacts.
///
/// Creates a [LocalEngineArtifacts] if `localEngine` is non-null
@visibleForTesting @visibleForTesting
factory Artifacts.test() = _TestArtifacts; factory Artifacts.test({String localEngine}) {
if (localEngine != null) {
return _TestLocalEngine(localEngine);
}
return _TestArtifacts();
}
static LocalEngineArtifacts getLocalEngine(EngineBuildPaths engineBuildPaths) { static LocalEngineArtifacts getLocalEngine(EngineBuildPaths engineBuildPaths) {
return LocalEngineArtifacts( return LocalEngineArtifacts(
...@@ -569,9 +576,21 @@ String _getIosEngineArtifactPath(String engineDirectory, ...@@ -569,9 +576,21 @@ String _getIosEngineArtifactPath(String engineDirectory,
.path; .path;
} }
abstract class LocalEngineArtifacts implements Artifacts {
factory LocalEngineArtifacts(String engineOutPath, String hostEngineOutPath, {
@required FileSystem fileSystem,
@required Cache cache,
@required ProcessManager processManager,
@required Platform platform,
@required OperatingSystemUtils operatingSystemUtils,
}) = CachedLocalEngineArtifacts;
String get engineOutPath;
}
/// Manages the artifacts of a locally built engine. /// Manages the artifacts of a locally built engine.
class LocalEngineArtifacts implements Artifacts { class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
LocalEngineArtifacts( CachedLocalEngineArtifacts(
this.engineOutPath, this.engineOutPath,
this._hostEngineOutPath, { this._hostEngineOutPath, {
@required FileSystem fileSystem, @required FileSystem fileSystem,
...@@ -585,7 +604,9 @@ class LocalEngineArtifacts implements Artifacts { ...@@ -585,7 +604,9 @@ class LocalEngineArtifacts implements Artifacts {
_platform = platform, _platform = platform,
_operatingSystemUtils = operatingSystemUtils; _operatingSystemUtils = operatingSystemUtils;
final String engineOutPath; // TODO(goderbauer): This should be private. @override
final String engineOutPath;
final String _hostEngineOutPath; final String _hostEngineOutPath;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Cache _cache; final Cache _cache;
...@@ -847,3 +868,13 @@ class _TestArtifacts implements Artifacts { ...@@ -847,3 +868,13 @@ class _TestArtifacts implements Artifacts {
@override @override
bool get isLocalEngine => false; bool get isLocalEngine => false;
} }
class _TestLocalEngine extends _TestArtifacts implements LocalEngineArtifacts {
_TestLocalEngine(this.engineOutPath);
@override
bool get isLocalEngine => true;
@override
final String engineOutPath;
}
...@@ -83,6 +83,7 @@ Future<T> runInContext<T>( ...@@ -83,6 +83,7 @@ Future<T> runInContext<T>(
logger: globals.logger, logger: globals.logger,
processManager: globals.processManager, processManager: globals.processManager,
fileSystem: globals.fs, fileSystem: globals.fs,
artifacts: globals.artifacts,
), ),
AndroidLicenseValidator: () => AndroidLicenseValidator( AndroidLicenseValidator: () => AndroidLicenseValidator(
operatingSystemUtils: globals.os, operatingSystemUtils: globals.os,
......
...@@ -33,11 +33,9 @@ void main() { ...@@ -33,11 +33,9 @@ void main() {
TestUsage testUsage; TestUsage testUsage;
MockAndroidSdk mockAndroidSdk; MockAndroidSdk mockAndroidSdk;
MockAndroidStudio mockAndroidStudio; MockAndroidStudio mockAndroidStudio;
MockLocalEngineArtifacts mockArtifacts;
FakePlatform android; FakePlatform android;
FileSystem fileSystem; FileSystem fileSystem;
Cache cache; Cache cache;
AndroidGradleBuilder builder;
FakeProcessManager processManager; FakeProcessManager processManager;
setUp(() { setUp(() {
...@@ -47,14 +45,7 @@ void main() { ...@@ -47,14 +45,7 @@ void main() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
mockAndroidSdk = MockAndroidSdk(); mockAndroidSdk = MockAndroidSdk();
mockAndroidStudio = MockAndroidStudio(); mockAndroidStudio = MockAndroidStudio();
mockArtifacts = MockLocalEngineArtifacts();
android = fakePlatform('android'); android = fakePlatform('android');
builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
);
when(mockAndroidSdk.directory).thenReturn(fileSystem.directory('irrelevant')); when(mockAndroidSdk.directory).thenReturn(fileSystem.directory('irrelevant'));
final Directory rootDirectory = fileSystem.currentDirectory; final Directory rootDirectory = fileSystem.currentDirectory;
...@@ -85,6 +76,12 @@ void main() { ...@@ -85,6 +76,12 @@ void main() {
}); });
testUsingContext('Can immediately tool exit on recognized exit code/stderr', () async { testUsingContext('Can immediately tool exit on recognized exit code/stderr', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -170,6 +167,12 @@ void main() { ...@@ -170,6 +167,12 @@ void main() {
}); });
testUsingContext('Can retry build on recognized exit code/stderr', () async { testUsingContext('Can retry build on recognized exit code/stderr', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -270,6 +273,12 @@ void main() { ...@@ -270,6 +273,12 @@ void main() {
}); });
testUsingContext('Converts recognized ProcessExceptions into tools exits', () async { testUsingContext('Converts recognized ProcessExceptions into tools exits', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -355,6 +364,12 @@ void main() { ...@@ -355,6 +364,12 @@ void main() {
}); });
testUsingContext('rethrows unrecognized ProcessException', () async { testUsingContext('rethrows unrecognized ProcessException', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(FakeCommand( processManager.addCommand(FakeCommand(
command: const <String>[ command: const <String>[
'/android/gradlew', '/android/gradlew',
...@@ -412,6 +427,12 @@ void main() { ...@@ -412,6 +427,12 @@ void main() {
}); });
testUsingContext('logs success event after a successful retry', () async { testUsingContext('logs success event after a successful retry', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -508,6 +529,12 @@ void main() { ...@@ -508,6 +529,12 @@ void main() {
}); });
testUsingContext('performs code size analysis and sends analytics', () async { testUsingContext('performs code size analysis and sends analytics', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -599,6 +626,12 @@ void main() { ...@@ -599,6 +626,12 @@ void main() {
}); });
testUsingContext('Can retry gradle build with plugins built as AARs', () async { testUsingContext('Can retry gradle build with plugins built as AARs', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -708,6 +741,12 @@ void main() { ...@@ -708,6 +741,12 @@ void main() {
}); });
testUsingContext('indicates that an APK has been built successfully', () async { testUsingContext('indicates that an APK has been built successfully', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -769,6 +808,12 @@ void main() { ...@@ -769,6 +808,12 @@ void main() {
}); });
testUsingContext("doesn't indicate how to consume an AAR when printHowToConsumeAar is false", () async { testUsingContext("doesn't indicate how to consume an AAR when printHowToConsumeAar is false", () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -797,13 +842,10 @@ void main() { ...@@ -797,13 +842,10 @@ void main() {
); );
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await builder.buildGradleAar( await builder.buildGradleAar(
...@@ -833,6 +875,12 @@ void main() { ...@@ -833,6 +875,12 @@ void main() {
}); });
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(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -862,13 +910,10 @@ void main() { ...@@ -862,13 +910,10 @@ void main() {
); );
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await expectLater(() async => await expectLater(() async =>
...@@ -890,6 +935,12 @@ void main() { ...@@ -890,6 +935,12 @@ void main() {
}); });
testUsingContext('build apk uses selected local engine with arm32 ABI', () async { testUsingContext('build apk uses selected local engine with arm32 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_arm'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -907,14 +958,6 @@ void main() { ...@@ -907,14 +958,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.android_arm,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm'));
fileSystem.file('out/android_arm/flutter_embedding_release.pom') fileSystem.file('out/android_arm/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -933,14 +976,11 @@ void main() { ...@@ -933,14 +976,11 @@ void main() {
fileSystem.file('out/android_arm/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true); fileSystem.file('out/android_arm/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true);
fileSystem.file('android/gradlew').createSync(recursive: true); fileSystem.file('android/gradlew').createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
...@@ -962,17 +1002,10 @@ void main() { ...@@ -962,17 +1002,10 @@ void main() {
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
expect(processManager.hasRemainingExpectations, false);
// expect(actualGradlewCall, contains('/android/gradlew'));
// expect(actualGradlewCall, contains('-Plocal-engine-out=out/android_arm'));
// expect(actualGradlewCall, contains('-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0'));
// expect(actualGradlewCall, contains('-Plocal-engine-build-mode=release'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -980,6 +1013,12 @@ void main() { ...@@ -980,6 +1013,12 @@ void main() {
}); });
testUsingContext('build apk uses selected local engine with arm64 ABI', () async { testUsingContext('build apk uses selected local engine with arm64 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_arm64'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -997,14 +1036,6 @@ void main() { ...@@ -997,14 +1036,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm64'));
fileSystem.file('out/android_arm64/flutter_embedding_release.pom') fileSystem.file('out/android_arm64/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1023,14 +1054,11 @@ void main() { ...@@ -1023,14 +1054,11 @@ void main() {
fileSystem.file('out/android_arm64/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true); fileSystem.file('out/android_arm64/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true);
fileSystem.file('android/gradlew').createSync(recursive: true); fileSystem.file('android/gradlew').createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
...@@ -1056,7 +1084,6 @@ void main() { ...@@ -1056,7 +1084,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1064,6 +1091,12 @@ void main() { ...@@ -1064,6 +1091,12 @@ void main() {
}); });
testUsingContext('build apk uses selected local engine with x86 ABI', () async { testUsingContext('build apk uses selected local engine with x86 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_x86'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -1081,14 +1114,6 @@ void main() { ...@@ -1081,14 +1114,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_x86'));
fileSystem.file('out/android_x86/flutter_embedding_release.pom') fileSystem.file('out/android_x86/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1107,14 +1132,11 @@ void main() { ...@@ -1107,14 +1132,11 @@ void main() {
fileSystem.file('out/android_x86/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true); fileSystem.file('out/android_x86/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true);
fileSystem.file('android/gradlew').createSync(recursive: true); fileSystem.file('android/gradlew').createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
...@@ -1140,7 +1162,6 @@ void main() { ...@@ -1140,7 +1162,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1148,6 +1169,12 @@ void main() { ...@@ -1148,6 +1169,12 @@ void main() {
}); });
testUsingContext('build apk uses selected local engine with x64 ABI', () async { testUsingContext('build apk uses selected local engine with x64 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_x64'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -1165,14 +1192,6 @@ void main() { ...@@ -1165,14 +1192,6 @@ void main() {
exitCode: 1, exitCode: 1,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_x64'));
fileSystem.file('out/android_x64/flutter_embedding_release.pom') fileSystem.file('out/android_x64/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1191,14 +1210,11 @@ void main() { ...@@ -1191,14 +1210,11 @@ void main() {
fileSystem.file('out/android_x64/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true); fileSystem.file('out/android_x64/flutter_embedding_release.maven-metadata.xml').createSync(recursive: true);
fileSystem.file('android/gradlew').createSync(recursive: true); fileSystem.file('android/gradlew').createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
...@@ -1224,7 +1240,6 @@ void main() { ...@@ -1224,7 +1240,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1232,6 +1247,12 @@ void main() { ...@@ -1232,6 +1247,12 @@ void main() {
}); });
testUsingContext('honors --no-android-gradle-daemon setting', () async { testUsingContext('honors --no-android-gradle-daemon setting', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(),
);
processManager.addCommand( processManager.addCommand(
const FakeCommand(command: <String>[ const FakeCommand(command: <String>[
'/android/gradlew', '/android/gradlew',
...@@ -1250,10 +1271,8 @@ void main() { ...@@ -1250,10 +1271,8 @@ void main() {
fileSystem.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
...@@ -1280,7 +1299,6 @@ void main() { ...@@ -1280,7 +1299,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => Artifacts.test(),
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1288,6 +1306,12 @@ void main() { ...@@ -1288,6 +1306,12 @@ void main() {
}); });
testUsingContext('build aar uses selected local engine with arm32 ABI', () async { testUsingContext('build aar uses selected local engine with arm32 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_arm'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -1309,14 +1333,6 @@ void main() { ...@@ -1309,14 +1333,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.android_arm,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm'));
fileSystem.file('out/android_arm/flutter_embedding_release.pom') fileSystem.file('out/android_arm/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1345,15 +1361,11 @@ void main() { ...@@ -1345,15 +1361,11 @@ void main() {
fileSystem.directory('.android/gradle') fileSystem.directory('.android/gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('.android/gradle/wrapper') fileSystem.directory('.android/gradle/wrapper')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
...@@ -1376,7 +1388,6 @@ void main() { ...@@ -1376,7 +1388,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1384,6 +1395,12 @@ void main() { ...@@ -1384,6 +1395,12 @@ void main() {
}); });
testUsingContext('build aar uses selected local engine with x64 ABI', () async { testUsingContext('build aar uses selected local engine with x64 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_arm64'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -1405,14 +1422,6 @@ void main() { ...@@ -1405,14 +1422,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm64'));
fileSystem.file('out/android_arm64/flutter_embedding_release.pom') fileSystem.file('out/android_arm64/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1441,18 +1450,13 @@ void main() { ...@@ -1441,18 +1450,13 @@ void main() {
fileSystem.directory('.android/gradle') fileSystem.directory('.android/gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('.android/gradle/wrapper') fileSystem.directory('.android/gradle/wrapper')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await builder.buildGradleAar( await builder.buildGradleAar(
...@@ -1473,7 +1477,6 @@ void main() { ...@@ -1473,7 +1477,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1481,6 +1484,12 @@ void main() { ...@@ -1481,6 +1484,12 @@ void main() {
}); });
testUsingContext('build aar uses selected local engine with x86 ABI', () async { testUsingContext('build aar uses selected local engine with x86 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_x86'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -1502,14 +1511,6 @@ void main() { ...@@ -1502,14 +1511,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_x86'));
fileSystem.file('out/android_x86/flutter_embedding_release.pom') fileSystem.file('out/android_x86/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1538,18 +1539,13 @@ void main() { ...@@ -1538,18 +1539,13 @@ void main() {
fileSystem.directory('.android/gradle') fileSystem.directory('.android/gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('.android/gradle/wrapper') fileSystem.directory('.android/gradle/wrapper')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await builder.buildGradleAar( await builder.buildGradleAar(
...@@ -1570,7 +1566,6 @@ void main() { ...@@ -1570,7 +1566,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1578,6 +1573,12 @@ void main() { ...@@ -1578,6 +1573,12 @@ void main() {
}); });
testUsingContext('build aar uses selected local engine on x64 ABI', () async { testUsingContext('build aar uses selected local engine on x64 ABI', () async {
final AndroidGradleBuilder builder = AndroidGradleBuilder(
logger: logger,
processManager: processManager,
fileSystem: fileSystem,
artifacts: Artifacts.test(localEngine: 'out/android_x64'),
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>[ command: <String>[
'/.android/gradlew', '/.android/gradlew',
...@@ -1599,14 +1600,6 @@ void main() { ...@@ -1599,14 +1600,6 @@ void main() {
exitCode: 0, exitCode: 0,
)); ));
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: anyNamed('platform'),
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_x64'));
fileSystem.file('out/android_x64/flutter_embedding_release.pom') fileSystem.file('out/android_x64/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(''' ..writeAsStringSync('''
...@@ -1635,18 +1628,13 @@ void main() { ...@@ -1635,18 +1628,13 @@ void main() {
fileSystem.directory('.android/gradle') fileSystem.directory('.android/gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('.android/gradle/wrapper') fileSystem.directory('.android/gradle/wrapper')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
fileSystem.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
fileSystem.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
fileSystem.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await builder.buildGradleAar( await builder.buildGradleAar(
...@@ -1667,7 +1655,6 @@ void main() { ...@@ -1667,7 +1655,6 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
...@@ -1686,4 +1673,3 @@ FakePlatform fakePlatform(String name) { ...@@ -1686,4 +1673,3 @@ FakePlatform fakePlatform(String name) {
class MockAndroidSdk extends Mock implements AndroidSdk {} class MockAndroidSdk extends Mock implements AndroidSdk {}
class MockAndroidStudio extends Mock implements AndroidStudio {} class MockAndroidStudio extends Mock implements AndroidStudio {}
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
...@@ -860,7 +860,12 @@ flutter: ...@@ -860,7 +860,12 @@ flutter:
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]); fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
mockAndroidSdk = MockAndroidSdk(); mockAndroidSdk = MockAndroidSdk();
when(mockAndroidSdk.directory).thenReturn(fs.directory('irrelevant')); when(mockAndroidSdk.directory).thenReturn(fs.directory('irrelevant'));
builder = AndroidGradleBuilder(logger: logger, processManager: fakeProcessManager, fileSystem: fs); builder = AndroidGradleBuilder(
logger: logger,
processManager: fakeProcessManager,
fileSystem: fs,
artifacts: Artifacts.test(),
);
}); });
testUsingContext('calls gradle', () async { testUsingContext('calls gradle', () async {
......
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