[web] move all build artifacts under web_ui/build (flutter/engine#29666)
* [web] move all build artifacts under web_ui/build
This commit is contained in:
@@ -38,20 +38,11 @@ class CleanCommand extends Command<bool> with ArgUtils<bool> {
|
||||
|
||||
@override
|
||||
FutureOr<bool> run() async {
|
||||
final io.Directory assetsDir = io.Directory(path.join(
|
||||
environment.webUiRootDir.path, 'lib', 'assets'
|
||||
));
|
||||
final Iterable<io.File> fontFiles = assetsDir
|
||||
.listSync()
|
||||
.whereType<io.File>()
|
||||
.where((io.File file) => file.path.endsWith('.ttf'));
|
||||
|
||||
final List<io.FileSystemEntity> thingsToBeCleaned = <io.FileSystemEntity>[
|
||||
environment.webUiDartToolDir,
|
||||
environment.webUiBuildDir,
|
||||
io.File(path.join(environment.webUiRootDir.path, '.packages')),
|
||||
io.File(path.join(environment.webUiRootDir.path, 'pubspec.lock')),
|
||||
...fontFiles,
|
||||
if (_alsoCleanNinja)
|
||||
environment.outDir,
|
||||
if(_alsoCleanFlutterRepo)
|
||||
|
||||
@@ -151,7 +151,7 @@ class Environment {
|
||||
|
||||
/// Path to the clone of the flutter/goldens repository.
|
||||
io.Directory get webUiGoldensRepositoryDirectory => io.Directory(pathlib.join(
|
||||
webUiDartToolDir.path,
|
||||
webUiBuildDir.path,
|
||||
'goldens',
|
||||
));
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert' show JsonEncoder;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:path/path.dart' as pathlib;
|
||||
@@ -13,12 +14,16 @@ import '../exceptions.dart';
|
||||
import '../pipeline.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
/// Compiles web tests and their dependencies.
|
||||
/// Compiles web tests and their dependencies into web_ui/build/.
|
||||
///
|
||||
/// Includes:
|
||||
/// * compile the test code itself
|
||||
/// * compile the page that hosts the tests
|
||||
/// * fetch the golden repo for screenshot comparison
|
||||
/// Outputs of this step:
|
||||
///
|
||||
/// * canvaskit/ - CanvasKit artifacts
|
||||
/// * assets/ - test fonts
|
||||
/// * goldens/ - the goldens fetched from flutter/goldens
|
||||
/// * host/ - compiled test host page and static artifacts
|
||||
/// * test/ - compiled test code
|
||||
/// * test_images/ - test images copied from Skis sources.
|
||||
class CompileTestsStep implements PipelineStep {
|
||||
CompileTestsStep({
|
||||
this.skipGoldensRepoFetch = false,
|
||||
@@ -41,14 +46,118 @@ class CompileTestsStep implements PipelineStep {
|
||||
|
||||
@override
|
||||
Future<void> run() async {
|
||||
await environment.webUiBuildDir.create();
|
||||
if (!skipGoldensRepoFetch) {
|
||||
await fetchGoldensRepo();
|
||||
}
|
||||
await copyCanvasKitFiles();
|
||||
await buildHostPage();
|
||||
await copyTestFonts();
|
||||
await copySkiaTestImages();
|
||||
await compileTests(testFiles ?? findAllTests());
|
||||
}
|
||||
}
|
||||
|
||||
const Map<String, String> _kTestFonts = <String, String>{
|
||||
'Ahem': 'ahem.ttf',
|
||||
'Roboto': 'Roboto-Regular.ttf',
|
||||
'Noto Naskh Arabic UI': 'NotoNaskhArabic-Regular.ttf',
|
||||
'Noto Color Emoji': 'NotoColorEmoji.ttf',
|
||||
};
|
||||
|
||||
Future<void> copyTestFonts() async {
|
||||
final String fontsPath = pathlib.join(
|
||||
environment.flutterDirectory.path,
|
||||
'third_party',
|
||||
'txt',
|
||||
'third_party',
|
||||
'fonts',
|
||||
);
|
||||
|
||||
final List<dynamic> fontManifest = <dynamic>[];
|
||||
for (final MapEntry<String, String> fontEntry in _kTestFonts.entries) {
|
||||
final String family = fontEntry.key;
|
||||
final String fontFile = fontEntry.value;
|
||||
|
||||
fontManifest.add(<String, dynamic>{
|
||||
'family': family,
|
||||
'fonts': <dynamic>[
|
||||
<String, String>{
|
||||
'asset': 'fonts/$fontFile',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
final io.File sourceTtf = io.File(pathlib.join(fontsPath, fontFile));
|
||||
final io.File destinationTtf = io.File(pathlib.join(
|
||||
environment.webUiBuildDir.path,
|
||||
'assets',
|
||||
'fonts',
|
||||
fontFile,
|
||||
));
|
||||
await destinationTtf.create(recursive: true);
|
||||
await sourceTtf.copy(destinationTtf.path);
|
||||
}
|
||||
|
||||
final io.File fontManifestFile = io.File(pathlib.join(
|
||||
environment.webUiBuildDir.path,
|
||||
'assets',
|
||||
'FontManifest.json',
|
||||
));
|
||||
await fontManifestFile.create(recursive: true);
|
||||
await fontManifestFile.writeAsString(
|
||||
const JsonEncoder.withIndent(' ').convert(fontManifest),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> copySkiaTestImages() async {
|
||||
final io.Directory testImagesDir = io.Directory(pathlib.join(
|
||||
environment.engineSrcDir.path,
|
||||
'third_party',
|
||||
'skia',
|
||||
'resources',
|
||||
'images',
|
||||
));
|
||||
|
||||
for (final io.File imageFile in testImagesDir.listSync(recursive: true).whereType<io.File>()) {
|
||||
final io.File destination = io.File(pathlib.join(
|
||||
environment.webUiBuildDir.path,
|
||||
'test_images',
|
||||
pathlib.relative(imageFile.path, from: testImagesDir.path),
|
||||
));
|
||||
destination.createSync(recursive: true);
|
||||
await imageFile.copy(destination.path);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> copyCanvasKitFiles() async {
|
||||
final io.Directory canvasKitDir = io.Directory(pathlib.join(
|
||||
environment.engineSrcDir.path,
|
||||
'third_party',
|
||||
'web_dependencies',
|
||||
'canvaskit',
|
||||
));
|
||||
|
||||
final Iterable<io.File> canvasKitFiles = canvasKitDir
|
||||
.listSync(recursive: true, followLinks: true)
|
||||
.whereType<io.File>();
|
||||
|
||||
final io.Directory targetDir = io.Directory(pathlib.join(
|
||||
environment.webUiBuildDir.path,
|
||||
'canvaskit',
|
||||
));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// Compiles the specified unit tests.
|
||||
Future<void> compileTests(List<FilePath> testFiles) async {
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
@@ -176,9 +285,38 @@ Future<void> buildHostPage() async {
|
||||
environment.webEngineTesterRootDir.path,
|
||||
hostDartPath,
|
||||
));
|
||||
final String targetDirectoryPath = pathlib.join(
|
||||
environment.webUiBuildDir.path,
|
||||
'host',
|
||||
);
|
||||
io.Directory(targetDirectoryPath).createSync(recursive: true);
|
||||
final String targetFilePath = pathlib.join(
|
||||
targetDirectoryPath,
|
||||
'host.dart',
|
||||
);
|
||||
|
||||
const List<String> staticFiles = <String>[
|
||||
'favicon.ico',
|
||||
'host.css',
|
||||
'index.html',
|
||||
];
|
||||
for (final String staticFilePath in staticFiles) {
|
||||
final io.File source = io.File(pathlib.join(
|
||||
environment.webEngineTesterRootDir.path,
|
||||
'lib',
|
||||
'static',
|
||||
staticFilePath,
|
||||
));
|
||||
final io.File destination = io.File(pathlib.join(
|
||||
targetDirectoryPath,
|
||||
staticFilePath,
|
||||
));
|
||||
await source.copy(destination.path);
|
||||
}
|
||||
|
||||
final io.File timestampFile = io.File(pathlib.join(
|
||||
environment.webEngineTesterRootDir.path,
|
||||
'$hostDartPath.js.timestamp',
|
||||
'$targetFilePath.js.timestamp',
|
||||
));
|
||||
|
||||
final String timestamp =
|
||||
@@ -203,7 +341,7 @@ Future<void> buildHostPage() async {
|
||||
'js',
|
||||
hostDartPath,
|
||||
'-o',
|
||||
'$hostDartPath.js',
|
||||
'$targetFilePath.js',
|
||||
],
|
||||
workingDirectory: environment.webEngineTesterRootDir.path,
|
||||
);
|
||||
|
||||
@@ -66,7 +66,6 @@ class RunTestsStep implements PipelineStep {
|
||||
|
||||
@override
|
||||
Future<void> run() async {
|
||||
_copyTestFontsIntoWebUi();
|
||||
await _prepareTestResultsDirectory();
|
||||
await browserEnvironment.prepareEnvironment();
|
||||
|
||||
@@ -173,30 +172,6 @@ Future<void> _prepareTestResultsDirectory() async {
|
||||
environment.webUiTestResultsDirectory.createSync(recursive: true);
|
||||
}
|
||||
|
||||
const List<String> _kTestFonts = <String>[
|
||||
'ahem.ttf',
|
||||
'Roboto-Regular.ttf',
|
||||
'NotoNaskhArabic-Regular.ttf',
|
||||
'NotoColorEmoji.ttf',
|
||||
];
|
||||
|
||||
void _copyTestFontsIntoWebUi() {
|
||||
final String fontsPath = pathlib.join(
|
||||
environment.flutterDirectory.path,
|
||||
'third_party',
|
||||
'txt',
|
||||
'third_party',
|
||||
'fonts',
|
||||
);
|
||||
|
||||
for (final String fontFile in _kTestFonts) {
|
||||
final io.File sourceTtf = io.File(pathlib.join(fontsPath, fontFile));
|
||||
final String destinationTtfPath =
|
||||
pathlib.join(environment.webUiRootDir.path, 'lib', 'assets', fontFile);
|
||||
sourceTtf.copySync(destinationTtfPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs a batch of tests.
|
||||
///
|
||||
/// Unless [expectFailure] is set to false, sets [io.exitCode] to a non-zero
|
||||
|
||||
@@ -57,8 +57,6 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
browserEnvironment: browserEnvironment,
|
||||
server: server,
|
||||
isDebug: Configuration.current.pauseAfterLoad,
|
||||
faviconPath: p.fromUri(await Isolate.resolvePackageUri(
|
||||
Uri.parse('package:test/src/runner/browser/static/favicon.ico'))),
|
||||
doUpdateScreenshotGoldens: doUpdateScreenshotGoldens,
|
||||
packageConfig: await loadPackageConfigUri((await Isolate.packageConfig)!),
|
||||
);
|
||||
@@ -104,7 +102,6 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
required this.browserEnvironment,
|
||||
required this.server,
|
||||
required this.isDebug,
|
||||
required String faviconPath,
|
||||
required this.doUpdateScreenshotGoldens,
|
||||
required this.packageConfig,
|
||||
}) : _screenshotManager = browserEnvironment.getScreenshotManager() {
|
||||
@@ -115,9 +112,6 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
// for details on how the channels are established.
|
||||
.add(_webSocketHandler.handler)
|
||||
|
||||
// Serves /favicon.ico
|
||||
.add(createFileHandler(faviconPath))
|
||||
|
||||
// Serves /packages/* requests; fetches files and sources from
|
||||
// pubspec dependencies.
|
||||
//
|
||||
@@ -126,15 +120,8 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
// * Assets that are part of the engine sources, such as Ahem.ttf
|
||||
.add(_packageUrlHandler)
|
||||
|
||||
// Serves CanvasKit assets.
|
||||
.add(_canvasKitHandler)
|
||||
|
||||
// Serves files from the web_ui/build/ directory at the root (/) URL path.
|
||||
//
|
||||
// Includes:
|
||||
// * Precompiles .js files for tests
|
||||
// * Sourcemaps
|
||||
.add(createStaticHandler(env.environment.webUiBuildDir.path))
|
||||
.add(buildDirectoryHandler)
|
||||
|
||||
// Serves the initial HTML for the test.
|
||||
.add(_testBootstrapHandler)
|
||||
@@ -152,11 +139,17 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
// Serves absolute package URLs (i.e. not /packages/* but /Users/user/*/hosted/pub.dartlang.org/*).
|
||||
// This handler goes last, after all more specific handlers failed to handle the request.
|
||||
.add(_createAbsolutePackageUrlHandler())
|
||||
.add(_screeshotHandler);
|
||||
.add(_screeshotHandler)
|
||||
.add(_fileNotFoundCatcher);
|
||||
|
||||
server.mount(cascade.handler);
|
||||
}
|
||||
|
||||
Future<shelf.Response> _fileNotFoundCatcher(shelf.Request request) async {
|
||||
print('HTTP 404: ${request.url}');
|
||||
return shelf.Response.notFound('File not found');
|
||||
}
|
||||
|
||||
/// Handles URLs pointing to Dart sources using absolute URI paths.
|
||||
///
|
||||
/// Dart source paths that dart2js puts in source maps for pub packages are
|
||||
@@ -313,44 +306,51 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
write: write);
|
||||
}
|
||||
|
||||
/// Serves /canvaskit/* requests.
|
||||
///
|
||||
/// The requested path is rewritten to look for CanvasKit assets under:
|
||||
///
|
||||
/// ENGINE_ROOT/src/third_party/web_dependencies/canvaskit
|
||||
shelf.Response _canvasKitHandler(shelf.Request request) {
|
||||
if (!request.url.path.startsWith('canvaskit/')) {
|
||||
return shelf.Response.notFound('Not found.');
|
||||
}
|
||||
static const Map<String, String> contentTypes = <String, String>{
|
||||
'.js': 'text/javascript',
|
||||
'.wasm': 'application/wasm',
|
||||
'.html': 'text/html',
|
||||
'.htm': 'text/html',
|
||||
'.css': 'text/css',
|
||||
'.ico': 'image/icon-x',
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.gif': 'image/gif',
|
||||
'.webp': 'image/webp',
|
||||
'.bmp': 'image/bmp',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.json': 'application/json',
|
||||
'.ttf': 'font/ttf',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
};
|
||||
|
||||
final String filePath = p.join(
|
||||
env.environment.engineSrcDir.path,
|
||||
'third_party',
|
||||
'web_dependencies',
|
||||
/// A simple file handler that serves files whose URLs and paths are
|
||||
/// statically known.
|
||||
///
|
||||
/// This is used for trivial use-cases, such as `favicon.ico`, host pages, etc.
|
||||
shelf.Response buildDirectoryHandler(shelf.Request request) {
|
||||
final File fileInBuild = File(p.join(
|
||||
env.environment.webUiBuildDir.path,
|
||||
request.url.path,
|
||||
);
|
||||
final File fileInPackage = File(filePath);
|
||||
if (!fileInPackage.existsSync()) {
|
||||
));
|
||||
|
||||
if (!fileInBuild.existsSync()) {
|
||||
return shelf.Response.notFound('File not found: ${request.url.path}');
|
||||
}
|
||||
|
||||
final String extension = p.extension(filePath);
|
||||
final String contentType;
|
||||
switch (extension) {
|
||||
case '.js':
|
||||
contentType = 'text/javascript';
|
||||
break;
|
||||
case '.wasm':
|
||||
contentType = 'application/wasm';
|
||||
break;
|
||||
default:
|
||||
final String error = 'Failed to determine Content-Type for "${request.url.path}".';
|
||||
stderr.writeln(error);
|
||||
return shelf.Response.internalServerError(body: error);
|
||||
final String extension = p.extension(fileInBuild.path);
|
||||
final String? contentType = contentTypes[extension];
|
||||
|
||||
if (contentType == null) {
|
||||
final String error = 'Failed to determine Content-Type for "${request.url.path}".';
|
||||
stderr.writeln(error);
|
||||
return shelf.Response.internalServerError(body: error);
|
||||
}
|
||||
|
||||
return shelf.Response.ok(
|
||||
fileInPackage.readAsBytesSync(),
|
||||
fileInBuild.readAsBytesSync(),
|
||||
headers: <String, Object>{
|
||||
HttpHeaders.contentTypeHeader: contentType,
|
||||
},
|
||||
@@ -373,6 +373,7 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
<html>
|
||||
<head>
|
||||
<title>${htmlEscape.convert(test)} Test</title>
|
||||
<meta name="assetBase" content="/">
|
||||
<script>
|
||||
window.flutterConfiguration = {
|
||||
canvasKitBaseUrl: "/canvaskit/"
|
||||
@@ -446,7 +447,7 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
final String path = _webSocketHandler.create(webSocketHandler(completer.complete));
|
||||
final Uri webSocketUrl = url.replace(scheme: 'ws').resolve(path);
|
||||
final Uri hostUrl = url
|
||||
.resolve('packages/web_engine_tester/static/index.html')
|
||||
.resolve('host/index.html')
|
||||
.replace(queryParameters: <String, dynamic>{
|
||||
'managerUrl': webSocketUrl.toString(),
|
||||
'debug': isDebug.toString()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
*.ttf
|
||||
@@ -20,7 +20,7 @@ const String _robotoUrl =
|
||||
'https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf';
|
||||
|
||||
// URL for the Ahem font, only used in tests.
|
||||
const String _ahemUrl = 'packages/ui/assets/ahem.ttf';
|
||||
const String _ahemUrl = '/assets/fonts/ahem.ttf';
|
||||
|
||||
/// Manages the fonts used in the Skia-based backend.
|
||||
class SkiaFontCollection {
|
||||
|
||||
@@ -14,9 +14,9 @@ import '../util.dart';
|
||||
import 'layout_service.dart';
|
||||
|
||||
const String ahemFontFamily = 'Ahem';
|
||||
const String ahemFontUrl = 'packages/ui/assets/ahem.ttf';
|
||||
const String ahemFontUrl = '/assets/fonts/ahem.ttf';
|
||||
const String robotoFontFamily = 'Roboto';
|
||||
const String robotoTestFontUrl = 'packages/ui/assets/Roboto-Regular.ttf';
|
||||
const String robotoTestFontUrl = '/assets/fonts/Roboto-Regular.ttf';
|
||||
|
||||
/// This class is responsible for registering and loading fonts.
|
||||
///
|
||||
|
||||
@@ -65,7 +65,7 @@ void testMain() {
|
||||
font-family: 'Noto Naskh Arabic UI';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(packages/ui/assets/NotoNaskhArabic-Regular.ttf) format('ttf');
|
||||
src: url(/assets/fonts/NotoNaskhArabic-Regular.ttf) format('ttf');
|
||||
unicode-range: U+0600-06FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE80-FEFC;
|
||||
}
|
||||
''';
|
||||
@@ -113,7 +113,7 @@ void testMain() {
|
||||
'''
|
||||
@font-face {
|
||||
font-family: 'Noto Color Emoji';
|
||||
src: url(packages/ui/assets/NotoColorEmoji.ttf) format('ttf');
|
||||
src: url(/assets/fonts/NotoColorEmoji.ttf) format('ttf');
|
||||
}
|
||||
''';
|
||||
|
||||
@@ -125,7 +125,7 @@ void testMain() {
|
||||
font-family: 'Noto Naskh Arabic UI';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url(packages/ui/assets/NotoNaskhArabic-Regular.ttf) format('ttf');
|
||||
src: url(/assets/fonts/NotoNaskhArabic-Regular.ttf) format('ttf');
|
||||
unicode-range: U+0600-06FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE80-FEFC;
|
||||
}
|
||||
''';
|
||||
@@ -173,7 +173,7 @@ void testMain() {
|
||||
'''
|
||||
@font-face {
|
||||
font-family: 'Noto Color Emoji';
|
||||
src: url(packages/ui/assets/NotoColorEmoji.ttf) format('ttf');
|
||||
src: url(/assets/fonts/NotoColorEmoji.ttf) format('ttf');
|
||||
}
|
||||
''';
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ void testMain() {
|
||||
[
|
||||
{
|
||||
"family":"Roboto",
|
||||
"fonts":[{"asset":"packages/ui/assets/Roboto-Regular.ttf"}]
|
||||
"fonts":[{"asset":"/fonts/Roboto-Regular.ttf"}]
|
||||
},
|
||||
{
|
||||
"family": "BrokenFont",
|
||||
|
||||
@@ -16,7 +16,7 @@ void main() {
|
||||
void testMain() {
|
||||
group('$FontManager', () {
|
||||
late FontManager fontManager;
|
||||
const String _testFontUrl = 'packages/ui/assets/ahem.ttf';
|
||||
const String _testFontUrl = '/assets/fonts/ahem.ttf';
|
||||
|
||||
setUp(() {
|
||||
fontManager = FontManager();
|
||||
|
||||
@@ -19,7 +19,7 @@ void main() {
|
||||
Future<void> testMain() async {
|
||||
await ui.webOnlyInitializeTestDomRenderer();
|
||||
group('loadFontFromList', () {
|
||||
const String _testFontUrl = 'packages/ui/assets/ahem.ttf';
|
||||
const String _testFontUrl = '/assets/fonts/ahem.ttf';
|
||||
|
||||
tearDown(() {
|
||||
html.document.fonts!.clear();
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
host.dart.js*
|
||||
Reference in New Issue
Block a user