Unverified Commit 897e3db4 authored by Harry Terkelsen's avatar Harry Terkelsen Committed by GitHub

Inject the gstatic CanvasKit CDN URL by default in `flutter build web` (#122772)

parent cbdee525
...@@ -60,6 +60,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -60,6 +60,7 @@ class BuildWebCommand extends BuildSubCommand {
}, },
); );
usesWebRendererOption(); usesWebRendererOption();
usesWebResourcesCdnFlag();
// //
// JavaScript compilation options // JavaScript compilation options
......
...@@ -38,6 +38,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -38,6 +38,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
usesDartDefineOption(); usesDartDefineOption();
usesFlavorOption(); usesFlavorOption();
usesWebRendererOption(); usesWebRendererOption();
usesWebResourcesCdnFlag();
addNativeNullAssertions(hide: !verboseHelp); addNativeNullAssertions(hide: !verboseHelp);
addBundleSkSLPathOption(hide: !verboseHelp); addBundleSkSLPathOption(hide: !verboseHelp);
usesApplicationBinaryOption(); usesApplicationBinaryOption();
......
...@@ -125,6 +125,7 @@ class FlutterOptions { ...@@ -125,6 +125,7 @@ class FlutterOptions {
static const String kUseApplicationBinary = 'use-application-binary'; static const String kUseApplicationBinary = 'use-application-binary';
static const String kWebBrowserFlag = 'web-browser-flag'; static const String kWebBrowserFlag = 'web-browser-flag';
static const String kWebRendererFlag = 'web-renderer'; static const String kWebRendererFlag = 'web-renderer';
static const String kWebResourcesCdnFlag = 'web-resources-cdn';
} }
/// flutter command categories for usage. /// flutter command categories for usage.
...@@ -668,6 +669,14 @@ abstract class FlutterCommand extends Command<void> { ...@@ -668,6 +669,14 @@ abstract class FlutterCommand extends Command<void> {
); );
} }
void usesWebResourcesCdnFlag() {
// TODO(hterkelsen): Default to true once we have a smoke test.
argParser.addFlag(
FlutterOptions.kWebResourcesCdnFlag,
help: 'Use Web static resources hosted on a CDN.',
);
}
void usesDeviceUserOption() { void usesDeviceUserOption() {
argParser.addOption(FlutterOptions.kDeviceUser, argParser.addOption(FlutterOptions.kDeviceUser,
help: 'Identifier number for a user or work profile on Android only. Run "adb shell pm list users" for available identifiers.', help: 'Identifier number for a user or work profile on Android only. Run "adb shell pm list users" for available identifiers.',
...@@ -1207,6 +1216,15 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1207,6 +1216,15 @@ abstract class FlutterCommand extends Command<void> {
dartDefines = updateDartDefines(dartDefines, webRenderer); dartDefines = updateDartDefines(dartDefines, webRenderer);
} }
if (argParser.options.containsKey(FlutterOptions.kWebResourcesCdnFlag)) {
final bool hasLocalWebSdk = argParser.options.containsKey('local-web-sdk') && stringArg('local-web-sdk') != null;
if (boolArg(FlutterOptions.kWebResourcesCdnFlag) && !hasLocalWebSdk) {
if (!dartDefines.any((String define) => define.startsWith('FLUTTER_WEB_CANVASKIT_URL='))) {
dartDefines.add('FLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/${globals.flutterVersion.engineRevision}/');
}
}
}
return BuildInfo(buildMode, return BuildInfo(buildMode,
argParser.options.containsKey('flavor') argParser.options.containsKey('flavor')
? stringArg('flavor') ? stringArg('flavor')
......
...@@ -112,7 +112,7 @@ void main() { ...@@ -112,7 +112,7 @@ void main() {
); );
final CommandRunner<void> runner = createTestCommandRunner(buildCommand); final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem); setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a', '--dart2js-optimization=O3']); await runner.run(<String>['build', 'web', '--no-pub', '--no-web-resources-cdn', '--dart-define=foo=a', '--dart2js-optimization=O3']);
final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web')); final Directory buildDir = fileSystem.directory(fileSystem.path.join('build', 'web'));
...@@ -164,6 +164,7 @@ void main() { ...@@ -164,6 +164,7 @@ void main() {
'build', 'build',
'web', 'web',
'--no-pub', '--no-pub',
'--no-web-resources-cdn',
'--output=$newBuildDir' '--output=$newBuildDir'
]); ]);
...@@ -251,6 +252,38 @@ void main() { ...@@ -251,6 +252,38 @@ void main() {
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)), BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)),
}); });
testUsingContext('Defaults to gstatic CanvasKit artifacts', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--web-resources-cdn']);
final BuildInfo buildInfo =
await buildCommand.webCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
expect(buildInfo.dartDefines, contains(startsWith('FLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/')));
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)),
});
testUsingContext('Does not override custom CanvasKit URL', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--web-resources-cdn', '--dart-define=FLUTTER_WEB_CANVASKIT_URL=abcdefg']);
final BuildInfo buildInfo =
await buildCommand.webCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
expect(buildInfo.dartDefines, contains('FLUTTER_WEB_CANVASKIT_URL=abcdefg'));
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)),
});
} }
void setupFileSystemForEndToEndTest(FileSystem fileSystem) { void setupFileSystemForEndToEndTest(FileSystem fileSystem) {
......
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