Inject the gstatic CanvasKit CDN URL by default in flutter build web
(#122772)
This commit is contained in:
parent
cbdee52517
commit
897e3db40c
@ -60,6 +60,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
},
|
||||
);
|
||||
usesWebRendererOption();
|
||||
usesWebResourcesCdnFlag();
|
||||
|
||||
//
|
||||
// JavaScript compilation options
|
||||
|
@ -38,6 +38,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
usesDartDefineOption();
|
||||
usesFlavorOption();
|
||||
usesWebRendererOption();
|
||||
usesWebResourcesCdnFlag();
|
||||
addNativeNullAssertions(hide: !verboseHelp);
|
||||
addBundleSkSLPathOption(hide: !verboseHelp);
|
||||
usesApplicationBinaryOption();
|
||||
|
@ -125,6 +125,7 @@ class FlutterOptions {
|
||||
static const String kUseApplicationBinary = 'use-application-binary';
|
||||
static const String kWebBrowserFlag = 'web-browser-flag';
|
||||
static const String kWebRendererFlag = 'web-renderer';
|
||||
static const String kWebResourcesCdnFlag = 'web-resources-cdn';
|
||||
}
|
||||
|
||||
/// flutter command categories for usage.
|
||||
@ -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() {
|
||||
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.',
|
||||
@ -1207,6 +1216,15 @@ abstract class FlutterCommand extends Command<void> {
|
||||
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,
|
||||
argParser.options.containsKey('flavor')
|
||||
? stringArg('flavor')
|
||||
|
@ -112,7 +112,7 @@ void main() {
|
||||
);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
|
||||
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'));
|
||||
|
||||
@ -164,6 +164,7 @@ void main() {
|
||||
'build',
|
||||
'web',
|
||||
'--no-pub',
|
||||
'--no-web-resources-cdn',
|
||||
'--output=$newBuildDir'
|
||||
]);
|
||||
|
||||
@ -251,6 +252,38 @@ void main() {
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user