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';
import '../cache.dart';
import '../convert.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 '../reporting/reporting.dart';
import 'android_builder.dart';
......@@ -216,13 +216,16 @@ class AndroidGradleBuilder implements AndroidBuilder {
@required Logger logger,
@required ProcessManager processManager,
@required FileSystem fileSystem,
@required Artifacts artifacts,
}) : _logger = logger,
_fileSystem = fileSystem,
_artifacts = artifacts,
_processUtils = ProcessUtils(logger: logger, processManager: processManager);
final Logger _logger;
final ProcessUtils _processUtils;
final FileSystem _fileSystem;
final Artifacts _artifacts;
/// Builds the AAR and POM files for the current Flutter module or plugin.
@override
......@@ -387,8 +390,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
if (!buildInfo.androidGradleDaemon) {
command.add('--no-daemon');
}
if (globals.artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
if (_artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = _artifacts as LocalEngineArtifacts;
final Directory localEngineRepo = _getLocalEngineRepo(
engineOutPath: localEngineArtifacts.engineOutPath,
androidBuildInfo: androidBuildInfo,
......@@ -704,8 +707,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
);
}
if (globals.artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
if (_artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = _artifacts as LocalEngineArtifacts;
final Directory localEngineRepo = _getLocalEngineRepo(
engineOutPath: localEngineArtifacts.engineOutPath,
androidBuildInfo: androidBuildInfo,
......@@ -1137,16 +1140,6 @@ Directory _getLocalEngineRepo({
final String abi = _getAbiByLocalEnginePath(engineOutPath);
final Directory localEngineRepo = fileSystem.systemTempDirectory
.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 artifactVersion = _getLocalArtifactVersion(
fileSystem.path.join(
......
......@@ -209,8 +209,15 @@ class EngineBuildPaths {
abstract class Artifacts {
/// A test-specific implementation of artifacts that returns stable paths for
/// all artifacts.
///
/// Creates a [LocalEngineArtifacts] if `localEngine` is non-null
@visibleForTesting
factory Artifacts.test() = _TestArtifacts;
factory Artifacts.test({String localEngine}) {
if (localEngine != null) {
return _TestLocalEngine(localEngine);
}
return _TestArtifacts();
}
static LocalEngineArtifacts getLocalEngine(EngineBuildPaths engineBuildPaths) {
return LocalEngineArtifacts(
......@@ -569,9 +576,21 @@ String _getIosEngineArtifactPath(String engineDirectory,
.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.
class LocalEngineArtifacts implements Artifacts {
LocalEngineArtifacts(
class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
CachedLocalEngineArtifacts(
this.engineOutPath,
this._hostEngineOutPath, {
@required FileSystem fileSystem,
......@@ -585,7 +604,9 @@ class LocalEngineArtifacts implements Artifacts {
_platform = platform,
_operatingSystemUtils = operatingSystemUtils;
final String engineOutPath; // TODO(goderbauer): This should be private.
@override
final String engineOutPath;
final String _hostEngineOutPath;
final FileSystem _fileSystem;
final Cache _cache;
......@@ -847,3 +868,13 @@ class _TestArtifacts implements Artifacts {
@override
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>(
logger: globals.logger,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts,
),
AndroidLicenseValidator: () => AndroidLicenseValidator(
operatingSystemUtils: globals.os,
......
......@@ -860,7 +860,12 @@ flutter:
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
mockAndroidSdk = MockAndroidSdk();
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 {
......
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