Platform binaries reland (#115502)

You can now specify a --local-web-sdk flag to point to a wasm_release folder. This will make it so that only artifacts that pertain to the web sdk are overridden to point to the wasm_release folder. Other artifacts (such as impellerc) will pull from the cache, or from the --local-engine path if that is specified.

This also uses precompiled platform kernel files for both ddc and dart2js
This commit is contained in:
Jackson Gardner
2022-12-02 14:13:40 -08:00
committed by GitHub
parent 08a2635e2b
commit db1c3e208d
45 changed files with 810 additions and 471 deletions

View File

@@ -29,6 +29,7 @@ import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../reporting/reporting.dart';
import '../web/compile.dart';
import 'flutter_command_runner.dart';
export '../cache.dart' show DevelopmentArtifact;
@@ -122,6 +123,7 @@ class FlutterOptions {
static const String kFatalWarnings = 'fatal-warnings';
static const String kUseApplicationBinary = 'use-application-binary';
static const String kWebBrowserFlag = 'web-browser-flag';
static const String kWebRendererFlag = 'web-renderer';
}
/// flutter command categories for usage.
@@ -149,17 +151,25 @@ abstract class FlutterCommand extends Command<void> {
/// The flag name for whether or not to use ipv6.
static const String ipv6Flag = 'ipv6';
/// The map used to convert web-renderer option to a List of dart-defines.
static const Map<String, Iterable<String>> _webRendererDartDefines =
<String, Iterable<String>> {
'auto': <String>[
/// Maps command line web renderer strings to the corresponding web renderer mode
static const Map<String, WebRendererMode> _webRendererModeMap =
<String, WebRendererMode> {
'auto': WebRendererMode.autoDetect,
'canvaskit': WebRendererMode.canvaskit,
'html': WebRendererMode.html,
};
/// The map used to convert web renderer mode to a List of dart-defines.
static const Map<WebRendererMode, Iterable<String>> _webRendererDartDefines =
<WebRendererMode, Iterable<String>> {
WebRendererMode.autoDetect: <String>[
'FLUTTER_WEB_AUTO_DETECT=true',
],
'canvaskit': <String>[
WebRendererMode.canvaskit: <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=true',
],
'html': <String>[
WebRendererMode.html: <String>[
'FLUTTER_WEB_AUTO_DETECT=false',
'FLUTTER_WEB_USE_SKIA=false',
],
@@ -620,7 +630,8 @@ abstract class FlutterCommand extends Command<void> {
}
void usesWebRendererOption() {
argParser.addOption('web-renderer',
argParser.addOption(
FlutterOptions.kWebRendererFlag,
defaultsTo: 'auto',
allowed: <String>['auto', 'canvaskit', 'html'],
help: 'The renderer implementation to use when building for the web.',
@@ -1144,8 +1155,13 @@ abstract class FlutterCommand extends Command<void> {
? stringsArg(FlutterOptions.kDartDefinesOption)
: <String>[];
if (argParser.options.containsKey('web-renderer')) {
dartDefines = updateDartDefines(dartDefines, stringArgDeprecated('web-renderer')!);
WebRendererMode webRenderer = WebRendererMode.autoDetect;
if (argParser.options.containsKey(FlutterOptions.kWebRendererFlag)) {
final WebRendererMode? mappedMode = _webRendererModeMap[stringArgDeprecated(FlutterOptions.kWebRendererFlag)!];
if (mappedMode != null) {
webRenderer = mappedMode;
}
dartDefines = updateDartDefines(dartDefines, webRenderer);
}
Map<String, Object>? defineConfigJsonMap;
@@ -1192,6 +1208,7 @@ abstract class FlutterCommand extends Command<void> {
dartDefines: dartDefines,
bundleSkSLPath: bundleSkSLPath,
dartExperiments: experiments,
webRenderer: webRenderer,
performanceMeasurementFile: performanceMeasurementFile,
dartDefineConfigJsonMap: defineConfigJsonMap,
packagesPath: packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
@@ -1285,7 +1302,7 @@ abstract class FlutterCommand extends Command<void> {
/// Updates dart-defines based on [webRenderer].
@visibleForTesting
static List<String> updateDartDefines(List<String> dartDefines, String webRenderer) {
static List<String> updateDartDefines(List<String> dartDefines, WebRendererMode webRenderer) {
final Set<String> dartDefinesSet = dartDefines.toSet();
if (!dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_AUTO_DETECT='))
&& dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {

View File

@@ -96,7 +96,13 @@ class FlutterCommandRunner extends CommandRunner<void> {
hide: !verboseHelp,
help: 'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the engine if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" or "--local-engine-src-out" (q.v.).');
'This path is relative to "--local-engine-src-path" (see above).');
argParser.addOption('local-web-sdk',
hide: !verboseHelp,
help: 'Name of a build output within the engine out directory, if you are building Flutter locally.\n'
'Use this to select a specific version of the web sdk if you have built multiple engine targets.\n'
'This path is relative to "--local-engine-src-path" (see above).');
if (verboseHelp) {
argParser.addSeparator('Options for testing the "flutter" tool itself:');
@@ -216,9 +222,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
// Set up the tooling configuration.
final EngineBuildPaths? engineBuildPaths = await globals.localEngineLocator?.findEnginePath(
topLevelResults['local-engine-src-path'] as String?,
topLevelResults['local-engine'] as String?,
topLevelResults['packages'] as String?,
engineSourcePath: topLevelResults['local-engine-src-path'] as String?,
localEngine: topLevelResults['local-engine'] as String?,
localWebSdk: topLevelResults['local-web-sdk'] as String?,
packagePath: topLevelResults['packages'] as String?,
);
if (engineBuildPaths != null) {
contextOverrides.addAll(<Type, Object?>{

View File

@@ -46,17 +46,26 @@ class LocalEngineLocator {
final UserMessages _userMessages;
/// Returns the engine build path of a local engine if one is located, otherwise `null`.
Future<EngineBuildPaths?> findEnginePath(String? engineSourcePath, String? localEngine, String? packagePath) async {
Future<EngineBuildPaths?> findEnginePath({String? engineSourcePath, String? localEngine, String? localWebSdk, String? packagePath}) async {
engineSourcePath ??= _platform.environment[kFlutterEngineEnvironmentVariableName];
if (engineSourcePath == null && localEngine == null && localWebSdk == null && packagePath == null) {
return null;
}
if (engineSourcePath == null && localEngine != null) {
if (engineSourcePath == null) {
try {
engineSourcePath = _findEngineSourceByLocalEngine(localEngine);
if (localEngine != null) {
engineSourcePath = _findEngineSourceByBuildPath(localEngine);
}
if (localWebSdk != null) {
engineSourcePath ??= _findEngineSourceByBuildPath(localWebSdk);
}
engineSourcePath ??= await _findEngineSourceByPackageConfig(packagePath);
} on FileSystemException catch (e) {
_logger.printTrace('Local engine auto-detection file exception: $e');
engineSourcePath = null;
}
// If engineSourcePath is still not set, try to determine it by flutter root.
engineSourcePath ??= _tryEnginePath(
_fileSystem.path.join(_fileSystem.directory(_flutterRoot).parent.path, 'engine', 'src'),
@@ -72,9 +81,9 @@ class LocalEngineLocator {
if (engineSourcePath != null) {
_logger.printTrace('Local engine source at $engineSourcePath');
return _findEngineBuildPath(localEngine, engineSourcePath);
return _findEngineBuildPath(localEngine, localWebSdk, engineSourcePath);
}
if (localEngine != null) {
if (localEngine != null || localWebSdk != null) {
throwToolExit(
_userMessages.runnerNoEngineSrcDir(
kFlutterEnginePackageName,
@@ -86,15 +95,15 @@ class LocalEngineLocator {
return null;
}
String? _findEngineSourceByLocalEngine(String localEngine) {
String? _findEngineSourceByBuildPath(String buildPath) {
// When the local engine is an absolute path to a variant inside the
// out directory, parse the engine source.
// --local-engine /path/to/cache/builder/src/out/host_debug_unopt
if (_fileSystem.path.isAbsolute(localEngine)) {
final Directory localEngineDirectory = _fileSystem.directory(localEngine);
final Directory outDirectory = localEngineDirectory.parent;
if (_fileSystem.path.isAbsolute(buildPath)) {
final Directory buildDirectory = _fileSystem.directory(buildPath);
final Directory outDirectory = buildDirectory.parent;
final Directory srcDirectory = outDirectory.parent;
if (localEngineDirectory.existsSync() && outDirectory.basename == 'out' && srcDirectory.basename == 'src') {
if (buildDirectory.existsSync() && outDirectory.basename == 'out' && srcDirectory.basename == 'src') {
_logger.printTrace('Parsed engine source from local engine as ${srcDirectory.path}.');
return srcDirectory.path;
}
@@ -167,26 +176,38 @@ class LocalEngineLocator {
return 'host_$tmpBasename';
}
EngineBuildPaths _findEngineBuildPath(String? localEngine, String enginePath) {
if (localEngine == null) {
throwToolExit(_userMessages.runnerLocalEngineRequired, exitCode: 2);
EngineBuildPaths _findEngineBuildPath(String? localEngine, String? localWebSdk, String enginePath) {
if (localEngine == null && localWebSdk == null) {
throwToolExit(_userMessages.runnerLocalEngineOrWebSdkRequired, exitCode: 2);
}
final String engineBuildPath = _fileSystem.path.normalize(_fileSystem.path.join(enginePath, 'out', localEngine));
if (!_fileSystem.isDirectorySync(engineBuildPath)) {
throwToolExit(_userMessages.runnerNoEngineBuild(engineBuildPath), exitCode: 2);
String? engineBuildPath;
String? engineHostBuildPath;
if (localEngine != null) {
engineBuildPath = _fileSystem.path.normalize(_fileSystem.path.join(enginePath, 'out', localEngine));
if (!_fileSystem.isDirectorySync(engineBuildPath)) {
throwToolExit(_userMessages.runnerNoEngineBuild(engineBuildPath), exitCode: 2);
}
final String basename = _fileSystem.path.basename(engineBuildPath);
final String hostBasename = _getHostEngineBasename(basename);
engineHostBuildPath = _fileSystem.path.normalize(
_fileSystem.path.join(_fileSystem.path.dirname(engineBuildPath), hostBasename),
);
if (!_fileSystem.isDirectorySync(engineHostBuildPath)) {
throwToolExit(_userMessages.runnerNoEngineBuild(engineHostBuildPath), exitCode: 2);
}
}
final String basename = _fileSystem.path.basename(engineBuildPath);
final String hostBasename = _getHostEngineBasename(basename);
final String engineHostBuildPath = _fileSystem.path.normalize(
_fileSystem.path.join(_fileSystem.path.dirname(engineBuildPath), hostBasename),
);
if (!_fileSystem.isDirectorySync(engineHostBuildPath)) {
throwToolExit(_userMessages.runnerNoEngineBuild(engineHostBuildPath), exitCode: 2);
String? webSdkPath;
if (localWebSdk != null) {
webSdkPath = _fileSystem.path.normalize(_fileSystem.path.join(enginePath, 'out', localWebSdk));
if (!_fileSystem.isDirectorySync(webSdkPath)) {
throwToolExit(_userMessages.runnerNoWebSdk(webSdkPath), exitCode: 2);
}
}
return EngineBuildPaths(targetEngine: engineBuildPath, hostEngine: engineHostBuildPath);
return EngineBuildPaths(targetEngine: engineBuildPath, webSdk: webSdkPath, hostEngine: engineHostBuildPath);
}
String? _tryEnginePath(String enginePath) {