Files
Paul Berry d6889ba492 Migrate pkg/build_integration to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates `pkg/build_integration` to use the new
constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)

Change-Id: Ifb2c4ca31f14c3e94f7b756969e730bf6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506023
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-05-29 13:06:59 -07:00

124 lines
3.8 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:typed_data';
// ignore: implementation_imports
import 'package:front_end/src/api_unstable/build_integration.dart';
/// Wraps a file system to create an overlay of files from multiple roots.
///
/// Regular `file:` URIs are resolved directly in the underlying file system,
/// but URIs that use a special [markerScheme] are resolved by searching
/// under a set of given roots in order.
///
/// For example, consider the following inputs:
///
/// - markerScheme is `multi-root`
/// - the set of roots are `file:///a/` and `file:///b/`
/// - the underlying file system contains files:
/// a/c/a1.dart
/// a/c/a2.dart
/// b/c/b1.dart
/// b/c/a2.dart
/// c/c1.dart
///
/// Then:
///
/// - file:///c/c1.dart is resolved as file:///c/c1.dart
/// - multi-root:///c/a1.dart is resolved as file:///a/c/a1.dart
/// - multi-root:///c/b1.dart is resolved as file:///b/c/b1.dart
/// - multi-root:///c/a2.dart is resolved as file:///a/c/b2.dart
class MultiRootFileSystem implements FileSystem {
final String markerScheme;
final List<Uri> roots;
final FileSystem original;
new(this.markerScheme, List<Uri> roots, this.original)
: roots = roots.map(_normalize).toList();
@override
FileSystemEntity entityForUri(Uri uri) =>
MultiRootFileSystemEntity(this, uri);
}
/// Entity that searches the multiple roots and resolve a, possibly multi-root,
/// entity to a plain entity under `multiRootFileSystem.original`.
class MultiRootFileSystemEntity implements FileSystemEntity {
final MultiRootFileSystem multiRootFileSystem;
@override
final Uri uri;
FileSystemEntity? _delegate;
Future<FileSystemEntity> get delegate async =>
_delegate ??= await _resolveEntity();
Future<FileSystemEntity> _resolveEntity() async {
if (uri.isScheme(multiRootFileSystem.markerScheme)) {
if (!uri.isAbsolute) {
throw FileSystemException(
uri,
"This MultiRootFileSystem only handles absolutes URIs: $uri",
);
}
var original = multiRootFileSystem.original;
assert(uri.path.startsWith('/'));
var path = uri.path.substring(1);
for (var root in multiRootFileSystem.roots) {
var candidate = original.entityForUri(root.resolve(path));
if (await candidate.exists()) return candidate;
}
return MissingFileSystemEntity(uri);
}
return multiRootFileSystem.original.entityForUri(uri);
}
new(this.multiRootFileSystem, this.uri);
@override
Future<bool> exists() async => (await delegate).exists();
@override
Future<bool> existsAsyncIfPossible() async =>
(await delegate).existsAsyncIfPossible();
@override
Future<Uint8List> readAsBytes() async => (await delegate).readAsBytes();
@override
Future<Uint8List> readAsBytesAsyncIfPossible() async =>
(await delegate).readAsBytes();
@override
Future<String> readAsString() async => (await delegate).readAsString();
}
class MissingFileSystemEntity implements FileSystemEntity {
@override
final Uri uri;
new(this.uri);
@override
Future<bool> exists() => Future.value(false);
@override
Future<bool> existsAsyncIfPossible() => exists();
@override
Future<Uint8List> readAsBytes() =>
Future.error(FileSystemException(uri, 'File not found'));
@override
Future<Uint8List> readAsBytesAsyncIfPossible() => readAsBytes();
@override
Future<String> readAsString() =>
Future.error(FileSystemException(uri, 'File not found'));
}
Uri _normalize(Uri uri) {
return uri.path.endsWith('/') ? uri : uri.replace(path: '${uri.path}/');
}