Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Deprecate --use-local-canvaskit flag #40680

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ vars = {
'ocmock_git': 'https://github.com/erikdoe/ocmock.git',
'skia_revision': 'c55605969a599681f4a5530ba84402f67f55bfa1',

# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
'canvaskit_cipd_instance': '61aeJQ9laGfEFF_Vlc_u0MCkqB6xb2hAYHRBxKH-Uw4C',

# Do not download the Emscripten SDK by default.
# This prevents us from downloading the Emscripten toolchain for builds
# which do not build for the web. This toolchain is needed to build CanvasKit
Expand Down Expand Up @@ -723,16 +719,6 @@ deps = {
'dep_type': 'cipd',
},

'src/third_party/web_dependencies': {
'packages': [
{
'package': 'flutter/web/canvaskit_bundle',
'version': Var('canvaskit_cipd_instance')
}
],
'dep_type': 'cipd',
},

'src/third_party/java/openjdk': {
'packages': [
{
Expand Down
86 changes: 40 additions & 46 deletions lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

import 'dart:convert' show JsonEncoder;
import 'dart:io' as io;
import 'dart:typed_data';

import 'package:http/http.dart' as http;
import 'package:path/path.dart' as pathlib;
import 'package:pool/pool.dart';

import '../common.dart';
import '../environment.dart';
import '../exceptions.dart';
import '../pipeline.dart';
import '../utils.dart';

// TODO(het): : We are using this hack while we wait for the built CanvasKit
// artifacts to be available on all platforms we test on, https://github.com/flutter/flutter/issues/119036.
const String _goodCanvasKitRevision = 'cc060144e81bff619f9c94bfeecf2a2987f166bb';

/// Compiles web tests and their dependencies into web_ui/build/.
///
/// Outputs of this step:
Expand All @@ -21,19 +28,16 @@ import '../utils.dart';
/// * assets/ - test fonts
/// * host/ - compiled test host page and static artifacts
/// * test/ - compiled test code
/// * test_images/ - test images copied from Skis sources.
/// * test_images/ - test images copied from Skia sources.
class CompileTestsStep implements PipelineStep {
CompileTestsStep({
this.testFiles,
this.useLocalCanvasKit = false,
this.isWasm = false
});

final List<FilePath>? testFiles;
final bool isWasm;

final bool useLocalCanvasKit;

@override
String get description => 'compile_tests';

Expand All @@ -52,7 +56,7 @@ class CompileTestsStep implements PipelineStep {
await copyDart2WasmTestScript();
await copySkwasm();
}
await copyCanvasKitFiles(useLocalCanvasKit: useLocalCanvasKit);
await copyCanvasKitFiles();
await buildHostPage();
await copyTestFonts();
await copySkiaTestImages();
Expand Down Expand Up @@ -179,57 +183,47 @@ final io.File _localCanvasKitWasm = io.File(pathlib.join(
'canvaskit.wasm',
));

Future<void> copyCanvasKitFiles({bool useLocalCanvasKit = false}) async {
// If CanvasKit has been built locally, use that instead of the CIPD version.
Future<void> copyCanvasKitFiles() async {
final bool localCanvasKitExists = _localCanvasKitWasm.existsSync();
if (useLocalCanvasKit && !localCanvasKitExists) {
throw ArgumentError('Requested to use local CanvasKit but could not find the '
'built CanvasKit at ${_localCanvasKitWasm.path}. Falling back to '
'CanvasKit from CIPD.');
if (!localCanvasKitExists && !isLuci) {
throw ArgumentError('Could not find the local CanvasKit build. Try running `felt build`');
}

final io.Directory targetDir = io.Directory(pathlib.join(
environment.webUiBuildDir.path,
'canvaskit',
));

if (useLocalCanvasKit) {
final Iterable<io.File> canvasKitFiles =
_localCanvasKitDir.listSync(recursive: true).whereType<io.File>();
for (final io.File file in canvasKitFiles) {
if (!file.path.endsWith('.wasm') && !file.path.endsWith('.js')) {
// We only need the .wasm and .js files.
continue;
}
final String relativePath =
pathlib.relative(file.path, from: _localCanvasKitDir.path);
final io.File normalTargetFile =
io.File(pathlib.join(targetDir.path, relativePath));
await normalTargetFile.create(recursive: true);
await file.copy(normalTargetFile.path);
}
} else {
final io.Directory canvasKitDir = io.Directory(pathlib.join(
environment.engineSrcDir.path,
'third_party',
'web_dependencies',
'canvaskit',
));
// TODO(het): Remove this hack once we are able to share build artifacts
// across multiple builders on LUCI.
if (!localCanvasKitExists) {
// If we're running on LUCI then we should temporarily just download
// a known good version of CanvasKit if we didn't already build one.
const String canvasKitBaseUrl = 'https://www.gstatic.com/flutter-canvaskit/$_goodCanvasKitRevision/';
final Uint8List canvasKitJs = (await http.get(Uri.parse('${canvasKitBaseUrl}canvaskit.js'))).bodyBytes;
final Uint8List canvasKitWasm = (await http.get(Uri.parse('${canvasKitBaseUrl}canvaskit.wasm'))).bodyBytes;
final io.File targetJsFile = io.File(pathlib.join(targetDir.path, 'canvaskit.js'));
final io.File targetWasmFile = io.File(pathlib.join(targetDir.path, 'canvaskit.wasm'));
await targetJsFile.create(recursive: true);
await targetWasmFile.create(recursive: true);
await targetJsFile.writeAsBytes(canvasKitJs);
await targetWasmFile.writeAsBytes(canvasKitWasm);
return;
}

final Iterable<io.File> canvasKitFiles = canvasKitDir
.listSync(recursive: true)
.whereType<io.File>();

for (final io.File file in canvasKitFiles) {
final String relativePath =
pathlib.relative(file.path, from: canvasKitDir.path);
final io.File targetFile = io.File(pathlib.join(
targetDir.path,
relativePath,
));
await targetFile.create(recursive: true);
await file.copy(targetFile.path);
final Iterable<io.File> canvasKitFiles =
_localCanvasKitDir.listSync(recursive: true).whereType<io.File>();
for (final io.File file in canvasKitFiles) {
if (!file.path.endsWith('.wasm') && !file.path.endsWith('.js')) {
// We only need the .wasm and .js files.
continue;
}
final String relativePath =
pathlib.relative(file.path, from: _localCanvasKitDir.path);
final io.File normalTargetFile =
io.File(pathlib.join(targetDir.path, relativePath));
await normalTargetFile.create(recursive: true);
await file.copy(normalTargetFile.path);
}
}

Expand Down
7 changes: 1 addition & 6 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
)
..addFlag(
'use-local-canvaskit',
help: 'Optional. Whether or not to use the locally built version of '
'CanvasKit in the tests.',
help: 'Deprecated. Has no effect. The local CanvasKit is always used.'
);
}

Expand Down Expand Up @@ -126,9 +125,6 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
/// Path to a CanvasKit build. Overrides the default CanvasKit.
String? get overridePathToCanvasKit => argResults!['canvaskit-path'] as String?;

/// Whether or not to use the locally built version of CanvasKit.
bool get useLocalCanvasKit => boolArg('use-local-canvaskit');

@override
Future<bool> run() async {
final List<FilePath> testFiles = runAllTests
Expand All @@ -139,7 +135,6 @@ class TestCommand extends Command<bool> with ArgUtils<bool> {
if (isWatchMode) ClearTerminalScreenStep(),
CompileTestsStep(
testFiles: testFiles,
useLocalCanvasKit: useLocalCanvasKit,
isWasm: isWasm
),
RunTestsStep(
Expand Down