Download and handle product version of flutter patched sdk (#31063)

* Support release/debug flavors of flutter_patched_sdk

* Use [anyNamed] instead of [any] for mocking named arguments

* Fix use of local engine in release mode
This commit is contained in:
Alexander Aprelev
2019-04-15 21:02:20 -07:00
committed by GitHub
parent 4ef0292790
commit d775908c7e
15 changed files with 72 additions and 47 deletions

View File

@@ -105,7 +105,7 @@ abstract class Artifacts {
}
// Returns the requested [artifact] for the [platform] and [mode] combination.
String getArtifactPath(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]);
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode });
// Returns which set of engine artifacts is currently used for the [platform]
// and [mode] combination.
@@ -116,7 +116,7 @@ abstract class Artifacts {
class CachedArtifacts extends Artifacts {
@override
String getArtifactPath(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
platform ??= _currentHostPlatform;
switch (platform) {
case TargetPlatform.android_arm:
@@ -173,9 +173,10 @@ class CachedArtifacts extends Artifacts {
}
}
String _getFlutterPatchedSdkPath() {
String _getFlutterPatchedSdkPath(BuildMode mode) {
final String engineArtifactsPath = cache.getArtifactDirectory('engine').path;
return fs.path.join(engineArtifactsPath, 'common', 'flutter_patched_sdk');
return fs.path.join(engineArtifactsPath, 'common',
mode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
}
String _getFlutterWebSdkPath() {
@@ -200,11 +201,11 @@ class CachedArtifacts extends Artifacts {
case Artifact.engineDartBinary:
return fs.path.join(dartSdkPath, 'bin', _artifactToFileName(artifact));
case Artifact.platformKernelDill:
return fs.path.join(_getFlutterPatchedSdkPath(), _artifactToFileName(artifact));
return fs.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact));
case Artifact.platformLibrariesJson:
return fs.path.join(_getFlutterPatchedSdkPath(), 'lib', _artifactToFileName(artifact));
return fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact));
case Artifact.flutterPatchedSdkPath:
return _getFlutterPatchedSdkPath();
return _getFlutterPatchedSdkPath(mode);
case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath();
case Artifact.dart2jsSnapshot:
@@ -262,7 +263,7 @@ class LocalEngineArtifacts extends Artifacts {
String _hostEngineOutPath;
@override
String getArtifactPath(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
switch (artifact) {
case Artifact.snapshotDart:
return fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact));
@@ -274,13 +275,17 @@ class LocalEngineArtifacts extends Artifacts {
case Artifact.vmSnapshotData:
return fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact));
case Artifact.platformKernelDill:
return fs.path.join(_getFlutterPatchedSdkPath(), _artifactToFileName(artifact));
return fs.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact));
case Artifact.platformLibrariesJson:
return fs.path.join(_getFlutterPatchedSdkPath(), 'lib', _artifactToFileName(artifact));
return fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact));
case Artifact.flutterFramework:
return fs.path.join(engineOutPath, _artifactToFileName(artifact));
case Artifact.flutterPatchedSdkPath:
return _getFlutterPatchedSdkPath();
// When using local engine always use [BuildMode.debug] regardless of
// what was specified in [mode] argument because local engine will
// have only one flutter_patched_sdk in standard location, that
// is happen to be what debug(non-release) mode is using.
return _getFlutterPatchedSdkPath(BuildMode.debug);
case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath();
case Artifact.frontendServerSnapshotForEngineDartSdk:
@@ -303,8 +308,9 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.basename(engineOutPath);
}
String _getFlutterPatchedSdkPath() {
return fs.path.join(engineOutPath, 'flutter_patched_sdk');
String _getFlutterPatchedSdkPath(BuildMode buildMode) {
return fs.path.join(engineOutPath,
buildMode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
}
String _getFlutterWebSdkPath() {
@@ -356,7 +362,7 @@ class OverrideArtifacts implements Artifacts {
final File flutterPatchedSdk;
@override
String getArtifactPath(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) {
return frontendServer.path;
}
@@ -369,7 +375,7 @@ class OverrideArtifacts implements Artifacts {
if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) {
return flutterPatchedSdk.path;
}
return parent.getArtifactPath(artifact, platform, mode);
return parent.getArtifactPath(artifact, platform: platform, mode: mode);
}
@override

View File

@@ -43,7 +43,7 @@ class GenSnapshot {
static String getSnapshotterPath(SnapshotType snapshotType) {
return artifacts.getArtifactPath(
Artifact.genSnapshot, snapshotType.platform, snapshotType.mode);
Artifact.genSnapshot, platform: snapshotType.platform, mode: snapshotType.mode);
}
Future<int> run({
@@ -317,7 +317,7 @@ class AOTSnapshotter {
final String depfilePath = fs.path.join(outputPath, 'kernel_compile.d');
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(flutterProject);
final CompilerOutput compilerOutput = await _timedStep('frontend', () => kernelCompiler.compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
mainPath: mainPath,
packagesPath: packagesPath,
outputFilePath: getKernelPathForTransformerOptions(
@@ -391,8 +391,8 @@ class JITSnapshotter {
final Directory outputDir = fs.directory(outputPath);
outputDir.createSync(recursive: true);
final String engineVmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, null, buildMode);
final String engineIsolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData, null, buildMode);
final String engineVmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: buildMode);
final String engineIsolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: buildMode);
final String isolateSnapshotData = fs.path.join(outputDir.path, 'isolate_snapshot_data');
final String isolateSnapshotInstructions = fs.path.join(outputDir.path, 'isolate_snapshot_instr');

View File

@@ -103,7 +103,7 @@ Future<void> build({
ensureDirectoryExists(applicationKernelFilePath);
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(flutterProject);
final CompilerOutput compilerOutput = await kernelCompiler.compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
incrementalCompilerByteStorePath: compilationTraceFilePath != null ? null :
fs.path.absolute(getIncrementalCompilerByteStoreDirectory()),
mainPath: fs.file(mainPath).absolute.path,
@@ -202,15 +202,15 @@ Future<void> assemble({
final Map<String, DevFSContent> assetEntries = Map<String, DevFSContent>.from(assetBundle.entries);
if (kernelContent != null) {
if (compilationTraceFilePath != null) {
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, null, buildMode);
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: buildMode);
final String isolateSnapshotData = fs.path.join(getBuildDirectory(), _kIsolateSnapshotData);
final String isolateSnapshotInstr = fs.path.join(getBuildDirectory(), _kIsolateSnapshotInstr);
assetEntries[_kVMSnapshotData] = DevFSFileContent(fs.file(vmSnapshotData));
assetEntries[_kIsolateSnapshotData] = DevFSFileContent(fs.file(isolateSnapshotData));
assetEntries[_kIsolateSnapshotInstr] = DevFSFileContent(fs.file(isolateSnapshotInstr));
} else {
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, null, buildMode);
final String isolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData, null, buildMode);
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: buildMode);
final String isolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: buildMode);
assetEntries[_kKernelKey] = kernelContent;
assetEntries[_kVMSnapshotData] = DevFSFileContent(fs.file(vmSnapshotData));
assetEntries[_kIsolateSnapshotData] = DevFSFileContent(fs.file(isolateSnapshotData));

View File

@@ -609,6 +609,7 @@ class FlutterSdk extends EngineCachedArtifact {
List<List<String>> getBinaryDirs() {
final List<List<String>> binaryDirs = <List<String>>[
<String>['common', 'flutter_patched_sdk.zip'],
<String>['common', 'flutter_patched_sdk_product.zip'],
];
if (cache.includeAllPlatforms) {
binaryDirs.addAll(<List<String>>[

View File

@@ -216,6 +216,7 @@ class AttachCommand extends FlutterCommand {
viewFilter: argResults['isolate-filter'],
target: argResults['target'],
targetModel: TargetModel(argResults['target-model']),
buildMode: getBuildMode(),
);
flutterDevice.observatoryUris = <Uri>[ observatoryUri ];
final List<FlutterDevice> flutterDevices = <FlutterDevice>[flutterDevice];

View File

@@ -351,6 +351,7 @@ class AppDomain extends Domain {
dillOutputPath: dillOutputPath,
viewFilter: isolateFilter,
target: target,
buildMode: options.buildInfo.mode,
);
ResidentRunner runner;

View File

@@ -369,6 +369,7 @@ class RunCommand extends RunCommandBase {
viewFilter: argResults['isolate-filter'],
experimentalFlags: expFlags,
target: argResults['target'],
buildMode: getBuildMode(),
);
flutterDevices.add(flutterDevice);
}

View File

@@ -23,7 +23,8 @@ final RegExp _settingExpr = RegExp(r'(\w+)\s*=\s*(.*)$');
final RegExp _varExpr = RegExp(r'\$\(([^)]*)\)');
String flutterFrameworkDir(BuildMode mode) {
return fs.path.normalize(fs.path.dirname(artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, mode)));
return fs.path.normalize(fs.path.dirname(artifacts.getArtifactPath(
Artifact.flutterFramework, platform: TargetPlatform.ios, mode: mode)));
}
/// Writes or rewrites Xcode property files with the specified information.

View File

@@ -38,9 +38,10 @@ class FlutterDevice {
TargetModel targetModel = TargetModel.flutter,
List<String> experimentalFlags,
ResidentCompiler generator,
@required BuildMode buildMode,
}) : assert(trackWidgetCreation != null),
generator = generator ?? ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
trackWidgetCreation: trackWidgetCreation,
fileSystemRoots: fileSystemRoots,
fileSystemScheme: fileSystemScheme,
@@ -60,6 +61,7 @@ class FlutterDevice {
TargetModel targetModel = TargetModel.flutter,
List<String> experimentalFlags,
ResidentCompiler generator,
@required BuildMode buildMode,
}) async {
ResidentCompiler generator;
final FlutterProject flutterProject = await FlutterProject.current();
@@ -69,7 +71,7 @@ class FlutterDevice {
);
} else {
generator = ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath, mode: buildMode),
trackWidgetCreation: trackWidgetCreation,
fileSystemRoots: fileSystemRoots,
fileSystemScheme: fileSystemScheme,
@@ -87,6 +89,7 @@ class FlutterDevice {
experimentalFlags: experimentalFlags,
targetModel: targetModel,
generator: generator,
buildMode: buildMode,
);
}