d6889ba492
(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>
90 lines
3.0 KiB
Dart
90 lines
3.0 KiB
Dart
// Copyright (c) 2018, 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:typed_data';
|
|
|
|
// ignore: implementation_imports
|
|
import 'package:front_end/src/api_unstable/build_integration.dart';
|
|
|
|
/// A [FileSystem] that resolves custom URIs to entities under a specified root
|
|
/// folder on an underlying [FileSystem].
|
|
///
|
|
/// This abstraction lets packages like `package:front_end` use absolute URIs
|
|
/// freely, while hiding machine-specific or user-specific details. In
|
|
/// particular, this file-system is used to create a machine-independent .dill
|
|
/// files in distributed build systems.
|
|
///
|
|
/// The resolution rules are as follows: if a given URI uses a special
|
|
/// [markerScheme] it gets resolved under the given [root], while a given URI
|
|
/// with any other scheme will produce an error.
|
|
///
|
|
/// For example, if [markerScheme] is `single-root`, and [root] is
|
|
/// `file:///a/b/c/`, then, calling [entityForUri] will:
|
|
///
|
|
/// * resolve `single-root:///f1.dart` to `file:///a/b/c/f1.dart`.
|
|
/// * resolve `single-root:///d/f2.dart` to `file:///a/b/c/d/f2.dart`.
|
|
/// * throw on `other-custom-scheme:///d/f2.dart`.
|
|
/// * throw on `file:///d/f2.dart`.
|
|
class SingleRootFileSystem implements FileSystem {
|
|
final String markerScheme;
|
|
final Uri root;
|
|
final FileSystem original;
|
|
|
|
new(this.markerScheme, Uri root, this.original) : root = _normalize(root);
|
|
|
|
@override
|
|
FileSystemEntity entityForUri(Uri uri) {
|
|
if (!uri.isScheme(markerScheme)) {
|
|
throw FileSystemException(
|
|
uri,
|
|
"This SingleRootFileSystem only handles URIs with the '$markerScheme'"
|
|
" scheme and cannot handle URIs with scheme '${uri.scheme}': $uri",
|
|
);
|
|
}
|
|
if (!uri.path.startsWith('/')) {
|
|
throw FileSystemException(
|
|
uri,
|
|
"This SingleRootFileSystem only handles absolutes URIs: $uri",
|
|
);
|
|
}
|
|
var path = uri.path.substring(1);
|
|
return SingleRootFileSystemEntity(
|
|
uri,
|
|
original.entityForUri(root.resolve(path)),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// [FileSystemEntity] with a URI of the `SingleRootFileSystem.markerScheme`,
|
|
/// that delegates all operations to an underlying entity in the original
|
|
/// `SingleRootFileSystem.filesystem`.
|
|
class SingleRootFileSystemEntity implements FileSystemEntity {
|
|
@override
|
|
final Uri uri;
|
|
final FileSystemEntity delegate;
|
|
|
|
new(this.uri, this.delegate);
|
|
|
|
@override
|
|
Future<bool> exists() async => delegate.exists();
|
|
|
|
@override
|
|
Future<bool> existsAsyncIfPossible() async =>
|
|
delegate.existsAsyncIfPossible();
|
|
|
|
@override
|
|
Future<Uint8List> readAsBytes() async => delegate.readAsBytes();
|
|
|
|
@override
|
|
Future<Uint8List> readAsBytesAsyncIfPossible() async =>
|
|
delegate.readAsBytesAsyncIfPossible();
|
|
|
|
@override
|
|
Future<String> readAsString() async => delegate.readAsString();
|
|
}
|
|
|
|
Uri _normalize(Uri uri) {
|
|
return uri.path.endsWith('/') ? uri : uri.replace(path: '${uri.path}/');
|
|
}
|