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,
......
...@@ -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