mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
[CFE] Use package config v2
Change-Id: I32da9e8b2c1040db1521af4345f8e952c22bd30d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130864 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
ed2df21191
commit
81d4ac07d4
|
@ -74,6 +74,7 @@ oauth2:third_party/pkg/oauth2/lib
|
|||
observatory:runtime/observatory/lib
|
||||
observatory_test_package:runtime/observatory/tests/service/observatory_test_package
|
||||
package_config:third_party/pkg_tested/package_config/lib
|
||||
package_config_v2:third_party/pkg/package_config_v2/lib
|
||||
package_resolver:third_party/pkg_tested/package_resolver/lib
|
||||
path:third_party/pkg/path/lib
|
||||
pedantic:third_party/pkg/pedantic/lib
|
||||
|
|
4
DEPS
4
DEPS
|
@ -113,6 +113,7 @@ vars = {
|
|||
"oauth2_tag": "1.2.1",
|
||||
"observatory_pub_packages_rev": "0894122173b0f98eb08863a7712e78407d4477bc",
|
||||
"package_config_tag": "2453cd2e78c2db56ee2669ced17ce70dd00bf576", # should be 1.1.0
|
||||
"package_config_v2_tag": "8e776a8b05951d4104aa101151df26a2c5ac931f", # should be 3.0
|
||||
"package_resolver_tag": "1.0.10",
|
||||
"path_tag": "1.6.2",
|
||||
"pedantic_tag": "v1.8.0",
|
||||
|
@ -341,6 +342,9 @@ deps = {
|
|||
Var("dart_root") + "/third_party/pkg_tested/package_config":
|
||||
Var("dart_git") + "package_config.git" +
|
||||
"@" + Var("package_config_tag"),
|
||||
Var("dart_root") + "/third_party/pkg/package_config_v2":
|
||||
Var("dart_git") + "package_config.git" +
|
||||
"@" + Var("package_config_v2_tag"),
|
||||
Var("dart_root") + "/third_party/pkg_tested/package_resolver":
|
||||
Var("dart_git") + "package_resolver.git"
|
||||
+ "@" + Var("package_resolver_tag"),
|
||||
|
|
|
@ -497,8 +497,7 @@ const Code<Null> codeCantInferPackagesFromManyInputs =
|
|||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const MessageCode messageCantInferPackagesFromManyInputs = const MessageCode(
|
||||
"CantInferPackagesFromManyInputs",
|
||||
message:
|
||||
r"""Can't infer a .packages file when compiling multiple inputs.""",
|
||||
message: r"""Can't infer a packages file when compiling multiple inputs.""",
|
||||
tip: r"""Try specifying the file explicitly with the --packages option.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
|
@ -508,7 +507,7 @@ const Code<Null> codeCantInferPackagesFromPackageUri =
|
|||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const MessageCode messageCantInferPackagesFromPackageUri = const MessageCode(
|
||||
"CantInferPackagesFromPackageUri",
|
||||
message: r"""Can't infer a .packages file from an input 'package:*' URI.""",
|
||||
message: r"""Can't infer a packages file from an input 'package:*' URI.""",
|
||||
tip: r"""Try specifying the file explicitly with the --packages option.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
|
@ -5325,7 +5324,7 @@ const Code<Null> codeLanguageVersionInvalidInDotPackages =
|
|||
const MessageCode messageLanguageVersionInvalidInDotPackages = const MessageCode(
|
||||
"LanguageVersionInvalidInDotPackages",
|
||||
message:
|
||||
r"""The language version is not specified correctly in the .packages file.""");
|
||||
r"""The language version is not specified correctly in the packages file.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Code<Null> codeLanguageVersionLibraryContext =
|
||||
|
|
|
@ -501,8 +501,7 @@ Future<TestResult<T>> checkCode<T>(
|
|||
Set<Uri> neededDiffs = new Set<Uri>();
|
||||
|
||||
void checkActualMap(
|
||||
Map<Id, ActualData<T>> actualMap, Map<Id, IdValue> expectedMap,
|
||||
[Uri uri]) {
|
||||
Map<Id, ActualData<T>> actualMap, Map<Id, IdValue> expectedMap, Uri uri) {
|
||||
expectedMap ??= {};
|
||||
bool hasLocalFailure = false;
|
||||
actualMap?.forEach((Id id, ActualData<T> actualData) {
|
||||
|
@ -561,7 +560,8 @@ Future<TestResult<T>> checkCode<T>(
|
|||
compiledData.actualMaps.forEach((Uri uri, Map<Id, ActualData<T>> actualMap) {
|
||||
checkActualMap(actualMap, expectedMaps[uri], uri);
|
||||
});
|
||||
checkActualMap(compiledData.globalData, expectedMaps.globalData);
|
||||
checkActualMap(compiledData.globalData, expectedMaps.globalData,
|
||||
Uri.parse("global:data"));
|
||||
|
||||
Set<Id> missingIds = new Set<Id>();
|
||||
void checkMissing(
|
||||
|
@ -603,8 +603,8 @@ Future<TestResult<T>> checkCode<T>(
|
|||
for (Uri uri in neededDiffs) {
|
||||
print('--annotations diff [${uri.pathSegments.last}]-------------');
|
||||
AnnotatedCode annotatedCode = code[uri];
|
||||
print(new AnnotatedCode(annotatedCode.annotatedCode,
|
||||
annotatedCode.sourceCode, annotations[uri])
|
||||
print(new AnnotatedCode(annotatedCode?.annotatedCode ?? "",
|
||||
annotatedCode?.sourceCode ?? "", annotations[uri])
|
||||
.toText());
|
||||
print('----------------------------------------------------------');
|
||||
}
|
||||
|
@ -625,7 +625,8 @@ typedef Future<Map<String, TestResult<T>>> RunTestFunction<T>(TestData testData,
|
|||
bool verbose,
|
||||
bool succinct,
|
||||
bool printCode,
|
||||
Map<String, List<String>> skipMap});
|
||||
Map<String, List<String>> skipMap,
|
||||
Uri nullUri});
|
||||
|
||||
/// Check code for all tests in [dataDir] using [runTest].
|
||||
Future<void> runTests<T>(Directory dataDir,
|
||||
|
@ -679,13 +680,17 @@ Future<void> runTests<T>(Directory dataDir,
|
|||
print('----------------------------------------------------------------');
|
||||
|
||||
Map<Uri, Uri> testToFileUri = {};
|
||||
TestData testData =
|
||||
computeTestData(entity, supportedMarkers: supportedMarkers,
|
||||
createTestUri: (Uri fileUri, String fileName) {
|
||||
|
||||
Uri createTestUri(Uri fileUri, String fileName) {
|
||||
Uri testUri = createUriForFileName(fileName);
|
||||
testToFileUri[testUri] = fileUri;
|
||||
return testUri;
|
||||
}, onFailure: onFailure);
|
||||
}
|
||||
|
||||
TestData testData = computeTestData(entity,
|
||||
supportedMarkers: supportedMarkers,
|
||||
createTestUri: createTestUri,
|
||||
onFailure: onFailure);
|
||||
print('Test: ${testData.testFileUri}');
|
||||
|
||||
Map<String, TestResult<T>> results = await runTest(testData,
|
||||
|
@ -693,7 +698,8 @@ Future<void> runTests<T>(Directory dataDir,
|
|||
verbose: verbose,
|
||||
succinct: succinct,
|
||||
printCode: printCode,
|
||||
skipMap: skipMap);
|
||||
skipMap: skipMap,
|
||||
nullUri: createTestUri(entity.uri.resolve("null"), "null"));
|
||||
|
||||
bool hasMismatches = false;
|
||||
bool hasErrors = false;
|
||||
|
@ -746,7 +752,7 @@ Future<void> runTests<T>(Directory dataDir,
|
|||
assert(code != null,
|
||||
"No annotated code for $uri with annotations: $annotations");
|
||||
AnnotatedCode generated = new AnnotatedCode(
|
||||
code.annotatedCode, code.sourceCode, annotations);
|
||||
code?.annotatedCode ?? "", code?.sourceCode ?? "", annotations);
|
||||
Uri fileUri = testToFileUri[uri];
|
||||
new File.fromUri(fileUri).writeAsStringSync(generated.toText());
|
||||
print('Generated annotations for ${fileUri}');
|
||||
|
|
|
@ -102,7 +102,8 @@ RunTestFunction<T> runTestFor<T>(
|
|||
bool verbose,
|
||||
bool succinct,
|
||||
bool printCode,
|
||||
Map<String, List<String>> skipMap}) {
|
||||
Map<String, List<String>> skipMap,
|
||||
Uri nullUri}) {
|
||||
return runTest(testData, dataComputer, testedConfigs,
|
||||
testAfterFailures: testAfterFailures,
|
||||
onFailure: onFailure,
|
||||
|
|
|
@ -105,9 +105,11 @@ class SourceToDillStep implements IOModularStep {
|
|||
packagesContents.write('${module.name}:${module.packageBase}\n');
|
||||
}
|
||||
Set<Module> transitiveDependencies = computeTransitiveDependencies(module);
|
||||
int unusedNum = 0;
|
||||
for (Module dependency in transitiveDependencies) {
|
||||
if (dependency.isPackage) {
|
||||
packagesContents.write('${dependency.name}:unused\n');
|
||||
unusedNum++;
|
||||
packagesContents.write('${dependency.name}:unused$unusedNum\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -301,9 +301,11 @@ Future<void> _createPackagesFile(
|
|||
if (module.isPackage) {
|
||||
packagesContents.write('${module.name}:${module.packageBase}\n');
|
||||
}
|
||||
var unusedNum = 0;
|
||||
for (var dependency in transitiveDependencies) {
|
||||
if (dependency.isPackage) {
|
||||
packagesContents.write('${dependency.name}:unused\n');
|
||||
unusedNum++;
|
||||
packagesContents.write('${dependency.name}:unused$unusedNum\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,15 @@ class CompilerOptions {
|
|||
|
||||
DiagnosticMessageHandler onDiagnostic;
|
||||
|
||||
/// URI of the ".packages" file (typically a "file:" URI).
|
||||
/// URI of the ".dart_tool/package_config.json" or ".packages" file
|
||||
/// (typically a "file:" URI).
|
||||
///
|
||||
/// If `null`, the ".packages" file will be found via the standard
|
||||
/// package_config search algorithm.
|
||||
/// If a ".packages" file is given and a ".dart_tool/package_config.json" file
|
||||
/// exists next to it, the ".dart_tool/package_config.json" file is used
|
||||
/// instead.
|
||||
///
|
||||
/// If `null`, the file will be found via the standard package_config search
|
||||
/// algorithm.
|
||||
///
|
||||
/// If the URI's path component is empty (e.g. `new Uri()`), no packages file
|
||||
/// will be used.
|
||||
|
|
|
@ -17,11 +17,7 @@ import 'package:kernel/kernel.dart' show CanonicalName, Component, Location;
|
|||
import 'package:kernel/target/targets.dart'
|
||||
show NoneTarget, Target, TargetFlags;
|
||||
|
||||
import 'package:package_config/packages.dart' show Packages;
|
||||
|
||||
import 'package:package_config/packages_file.dart' as package_config;
|
||||
|
||||
import 'package:package_config/src/packages_impl.dart' show MapPackages;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
|
||||
import '../api_prototype/compiler_options.dart'
|
||||
show CompilerOptions, DiagnosticMessage;
|
||||
|
@ -92,7 +88,7 @@ class ProcessedOptions {
|
|||
|
||||
/// The package map derived from the options, or `null` if the package map has
|
||||
/// not been computed yet.
|
||||
Packages _packages;
|
||||
PackageConfig _packages;
|
||||
|
||||
/// The uri for .packages derived from the options, or `null` if the package
|
||||
/// map has not been computed yet or there is no .packages in effect.
|
||||
|
@ -429,7 +425,7 @@ class ProcessedOptions {
|
|||
TargetLibrariesSpecification libraries =
|
||||
await _computeLibrarySpecification();
|
||||
ticker.logMs("Read libraries file");
|
||||
Packages packages = await _getPackages();
|
||||
PackageConfig packages = await _getPackages();
|
||||
ticker.logMs("Read packages file");
|
||||
_uriTranslator = new UriTranslator(libraries, packages);
|
||||
}
|
||||
|
@ -471,7 +467,7 @@ class ProcessedOptions {
|
|||
///
|
||||
/// This is an asynchronous getter since file system operations may be
|
||||
/// required to locate/read the packages file.
|
||||
Future<Packages> _getPackages() async {
|
||||
Future<PackageConfig> _getPackages() async {
|
||||
if (_packages != null) return _packages;
|
||||
_packagesUri = null;
|
||||
if (_raw.packagesFileUri != null) {
|
||||
|
@ -483,54 +479,120 @@ class ProcessedOptions {
|
|||
// the same .packages file from all of the inputs.
|
||||
reportWithoutLocation(
|
||||
messageCantInferPackagesFromManyInputs, Severity.error);
|
||||
return _packages = Packages.noPackages;
|
||||
return _packages = PackageConfig.empty;
|
||||
}
|
||||
if (inputs.isEmpty) {
|
||||
return _packages = PackageConfig.empty;
|
||||
}
|
||||
|
||||
Uri input = inputs.first;
|
||||
|
||||
// When compiling the SDK the input files are normally `dart:` URIs.
|
||||
if (input.scheme == 'dart') return _packages = Packages.noPackages;
|
||||
if (input.scheme == 'dart') return _packages = PackageConfig.empty;
|
||||
|
||||
if (input.scheme == 'packages') {
|
||||
report(
|
||||
messageCantInferPackagesFromPackageUri.withLocation(
|
||||
input, -1, noLength),
|
||||
Severity.error);
|
||||
return _packages = Packages.noPackages;
|
||||
return _packages = PackageConfig.empty;
|
||||
}
|
||||
|
||||
return _packages = await _findPackages(inputs.first);
|
||||
}
|
||||
|
||||
/// Create a [Packages] given the Uri to a `.packages` file.
|
||||
Future<Packages> createPackagesFromFile(Uri file) async {
|
||||
List<int> contents;
|
||||
Future<Uint8List> _readFile(Uri uri, bool reportError) async {
|
||||
try {
|
||||
// TODO(ahe): We need to compute line endings for this file.
|
||||
contents = await fileSystem.entityForUri(file).readAsBytes();
|
||||
FileSystemEntity entityForUri = fileSystem.entityForUri(uri);
|
||||
if (!reportError && !await entityForUri.exists()) return null;
|
||||
List<int> fileContents = await entityForUri.readAsBytes();
|
||||
if (fileContents is Uint8List) {
|
||||
return fileContents;
|
||||
} else {
|
||||
return new Uint8List.fromList(fileContents);
|
||||
}
|
||||
} on FileSystemException catch (e) {
|
||||
reportWithoutLocation(
|
||||
templateCantReadFile.withArguments(file, e.message), Severity.error);
|
||||
}
|
||||
if (contents != null) {
|
||||
_packagesUri = file;
|
||||
try {
|
||||
Map<String, Uri> map =
|
||||
package_config.parse(contents, file, allowDefaultPackage: true);
|
||||
return new MapPackages(map);
|
||||
} on FormatException catch (e) {
|
||||
report(
|
||||
templatePackagesFileFormat
|
||||
.withArguments(e.message)
|
||||
.withLocation(file, e.offset, noLength),
|
||||
Severity.error);
|
||||
} catch (e) {
|
||||
if (reportError) {
|
||||
reportWithoutLocation(
|
||||
templateCantReadFile.withArguments(file, "$e"), Severity.error);
|
||||
templateCantReadFile.withArguments(uri, e.message), Severity.error);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Create a [PackageConfig] given the Uri to a `.packages` or
|
||||
/// `package_config.json` file.
|
||||
///
|
||||
/// If the file doesn't exist, it returns null (and an error is reported
|
||||
/// based in [forceCreation]).
|
||||
/// If the file does exist but is invalid an error is always reported and an
|
||||
/// empty package config is returned.
|
||||
Future<PackageConfig> _createPackagesFromFile(
|
||||
Uri requestedUri, bool forceCreation) async {
|
||||
Uint8List contents = await _readFile(requestedUri, forceCreation);
|
||||
if (contents == null) {
|
||||
if (forceCreation) {
|
||||
_packagesUri = null;
|
||||
return PackageConfig.empty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_packagesUri = requestedUri;
|
||||
try {
|
||||
return await loadPackageConfigUri(requestedUri, preferNewest: false,
|
||||
loader: (uri) {
|
||||
if (uri != requestedUri) {
|
||||
throw new StateError(
|
||||
"Unexpected request from package config package");
|
||||
}
|
||||
return new Future.value(contents);
|
||||
}, onError: (Object error) {
|
||||
if (error is FormatException) {
|
||||
report(
|
||||
templatePackagesFileFormat
|
||||
.withArguments(error.message)
|
||||
.withLocation(requestedUri, error.offset, noLength),
|
||||
Severity.error);
|
||||
} else {
|
||||
reportWithoutLocation(
|
||||
templateCantReadFile.withArguments(requestedUri, "$error"),
|
||||
Severity.error);
|
||||
}
|
||||
});
|
||||
} on FormatException catch (e) {
|
||||
report(
|
||||
templatePackagesFileFormat
|
||||
.withArguments(e.message)
|
||||
.withLocation(requestedUri, e.offset, noLength),
|
||||
Severity.error);
|
||||
} catch (e) {
|
||||
reportWithoutLocation(
|
||||
templateCantReadFile.withArguments(requestedUri, "$e"),
|
||||
Severity.error);
|
||||
}
|
||||
_packagesUri = null;
|
||||
return Packages.noPackages;
|
||||
return PackageConfig.empty;
|
||||
}
|
||||
|
||||
/// Create a [PackageConfig] given the Uri to a `.packages` or
|
||||
/// `package_config.json` file.
|
||||
///
|
||||
/// Note that if a `.packages` file is provided and an appropriately placed
|
||||
/// (relative to the .packages file) `package_config.json` file exists, the
|
||||
/// `package_config.json` file will be used instead.
|
||||
Future<PackageConfig> createPackagesFromFile(Uri file) async {
|
||||
if (file.path.endsWith("/.dart_tool/package_config.json")) {
|
||||
// Already a package config json file.
|
||||
return _createPackagesFromFile(file, true);
|
||||
} else {
|
||||
// .packages -> try the package_config first.
|
||||
Uri tryFirst = file.resolve(".dart_tool/package_config.json");
|
||||
PackageConfig result = await _createPackagesFromFile(tryFirst, false);
|
||||
if (result != null) return result;
|
||||
return await _createPackagesFromFile(file, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds a package resolution strategy using a [FileSystem].
|
||||
|
@ -538,32 +600,27 @@ class ProcessedOptions {
|
|||
/// The [scriptUri] points to a Dart script with a valid scheme accepted by
|
||||
/// the [FileSystem].
|
||||
///
|
||||
/// This function first tries to locate a `.packages` file in the `scriptUri`
|
||||
/// directory. If that is not found, it starts checking parent directories for
|
||||
/// a `.packages` file, and stops if it finds it. Otherwise it gives up and
|
||||
/// returns [Packages.noPackages].
|
||||
/// This function first tries to locate a `.dart_tool/package_config.json`
|
||||
/// (then a `.packages`) file in the `scriptUri` directory.
|
||||
/// If that is not found, it starts checking parent directories, and stops if
|
||||
/// it finds it. Otherwise it gives up and returns [PackageConfig.empty].
|
||||
///
|
||||
/// Note: this is a fork from `package:package_config/discovery.dart` to adapt
|
||||
/// it to use [FileSystem]. The logic here is a mix of the logic in the
|
||||
/// `findPackagesFromFile` and `findPackagesFromNonFile`:
|
||||
///
|
||||
/// * Like `findPackagesFromFile` resolution searches for parent
|
||||
/// directories
|
||||
///
|
||||
/// * Unlike package:package_config, it does not look for a `packages/`
|
||||
/// directory, as that won't be supported in Dart 2.
|
||||
Future<Packages> _findPackages(Uri scriptUri) async {
|
||||
/// Note: this is a fork from `package:package_config`s discovery to make sure
|
||||
/// we use the expected error reporting etc.
|
||||
Future<PackageConfig> _findPackages(Uri scriptUri) async {
|
||||
Uri dir = scriptUri.resolve('.');
|
||||
if (!dir.isAbsolute) {
|
||||
reportWithoutLocation(
|
||||
templateInternalProblemUnsupported
|
||||
.withArguments("Expected input Uri to be absolute: $scriptUri."),
|
||||
Severity.internalProblem);
|
||||
return Packages.noPackages;
|
||||
return PackageConfig.empty;
|
||||
}
|
||||
|
||||
Future<Uri> checkInDir(Uri dir) async {
|
||||
Uri candidate = dir.resolve('.packages');
|
||||
Uri candidate = dir.resolve('.dart_tool/package_config.json');
|
||||
if (await fileSystem.entityForUri(candidate).exists()) return candidate;
|
||||
candidate = dir.resolve('.packages');
|
||||
if (await fileSystem.entityForUri(candidate).exists()) return candidate;
|
||||
return null;
|
||||
}
|
||||
|
@ -582,7 +639,7 @@ class ProcessedOptions {
|
|||
}
|
||||
|
||||
if (candidate != null) return createPackagesFromFile(candidate);
|
||||
return Packages.noPackages;
|
||||
return PackageConfig.empty;
|
||||
}
|
||||
|
||||
bool _computedSdkDefaults = false;
|
||||
|
|
|
@ -43,6 +43,9 @@ import 'package:kernel/kernel.dart' as kernel show Combinator;
|
|||
import 'package:kernel/target/changed_structure_notifier.dart'
|
||||
show ChangedStructureNotifier;
|
||||
|
||||
import 'package:package_config_v2/package_config.dart'
|
||||
show Package, PackageConfig;
|
||||
|
||||
import '../api_prototype/file_system.dart' show FileSystem, FileSystemEntity;
|
||||
|
||||
import '../api_prototype/incremental_kernel_generator.dart'
|
||||
|
@ -133,8 +136,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
|||
bool initializedFromDill = false;
|
||||
bool initializedIncrementalSerializer = false;
|
||||
Uri previousPackagesUri;
|
||||
Map<String, Uri> previousPackagesMap;
|
||||
Map<String, Uri> currentPackagesMap;
|
||||
Map<String, Package> previousPackagesMap;
|
||||
Map<String, Package> currentPackagesMap;
|
||||
bool hasToCheckPackageUris = false;
|
||||
Map<Uri, List<DiagnosticMessageFromJson>> remainingComponentProblems =
|
||||
new Map<Uri, List<DiagnosticMessageFromJson>>();
|
||||
|
@ -910,7 +913,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
|||
UriTranslator uriTranslator =
|
||||
await c.options.getUriTranslator(bypassCache: bypassCache);
|
||||
previousPackagesMap = currentPackagesMap;
|
||||
currentPackagesMap = uriTranslator.packages.asMap();
|
||||
currentPackagesMap = createPackagesMap(uriTranslator.packages);
|
||||
// TODO(jensj): We can probably (from the maps above) figure out if anything
|
||||
// changed and only set this to true if it did.
|
||||
hasToCheckPackageUris = hasToCheckPackageUris || bypassCache;
|
||||
|
@ -918,6 +921,14 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
|||
return uriTranslator;
|
||||
}
|
||||
|
||||
Map<String, Package> createPackagesMap(PackageConfig packages) {
|
||||
Map<String, Package> result = new Map<String, Package>();
|
||||
for (Package package in packages.packages) {
|
||||
result[package.name] = package;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Load platform and (potentially) initialize from dill,
|
||||
/// or initialize from component.
|
||||
Future<IncrementalCompilerData> ensurePlatformAndInitialize(
|
||||
|
@ -1604,6 +1615,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
|||
});
|
||||
}
|
||||
|
||||
bool packagesEqual(Package a, Package b) {
|
||||
if (a == null || b == null) return false;
|
||||
if (a.name != b.name) return false;
|
||||
if (a.root != b.root) return false;
|
||||
if (a.packageUriRoot != b.packageUriRoot) return false;
|
||||
if (a.languageVersion != b.languageVersion) return false;
|
||||
if (a.extraData != b.extraData) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Internal method.
|
||||
ReusageResult computeReusedLibraries(
|
||||
Set<Uri> invalidatedUris, UriTranslator uriTranslator) {
|
||||
|
@ -1641,7 +1662,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
|||
int firstSlash = path.indexOf('/');
|
||||
String packageName = path.substring(0, firstSlash);
|
||||
if (previousPackagesMap == null ||
|
||||
(previousPackagesMap[packageName] !=
|
||||
!packagesEqual(previousPackagesMap[packageName],
|
||||
currentPackagesMap[packageName])) {
|
||||
Uri newFileUri = uriTranslator.translate(importUri, false);
|
||||
if (newFileUri != fileUri) {
|
||||
|
|
|
@ -51,6 +51,7 @@ import 'package:kernel/target/changed_structure_notifier.dart'
|
|||
import 'package:kernel/target/targets.dart' show DiagnosticReporter;
|
||||
import 'package:kernel/type_environment.dart' show TypeEnvironment;
|
||||
import 'package:kernel/verifier.dart' show verifyGetStaticType;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
|
||||
import '../../api_prototype/file_system.dart' show FileSystem;
|
||||
|
||||
|
@ -182,12 +183,10 @@ class KernelTarget extends TargetImplementation {
|
|||
|
||||
/// Return list of same size as input with possibly translated uris.
|
||||
List<Uri> setEntryPoints(List<Uri> entryPoints) {
|
||||
Map<String, Uri> packagesMap;
|
||||
List<Uri> result = new List<Uri>();
|
||||
for (Uri entryPoint in entryPoints) {
|
||||
packagesMap ??= uriTranslator.packages.asMap();
|
||||
Uri translatedEntryPoint = getEntryPointUri(entryPoint,
|
||||
packagesMap: packagesMap, issueProblem: true);
|
||||
Uri translatedEntryPoint =
|
||||
getEntryPointUri(entryPoint, issueProblem: true);
|
||||
result.add(translatedEntryPoint);
|
||||
loader.read(translatedEntryPoint, -1,
|
||||
accessor: loader.first,
|
||||
|
@ -197,8 +196,7 @@ class KernelTarget extends TargetImplementation {
|
|||
}
|
||||
|
||||
/// Return list of same size as input with possibly translated uris.
|
||||
Uri getEntryPointUri(Uri entryPoint,
|
||||
{Map<String, Uri> packagesMap, bool issueProblem: false}) {
|
||||
Uri getEntryPointUri(Uri entryPoint, {bool issueProblem: false}) {
|
||||
String scheme = entryPoint.scheme;
|
||||
switch (scheme) {
|
||||
case "package":
|
||||
|
@ -208,9 +206,10 @@ class KernelTarget extends TargetImplementation {
|
|||
default:
|
||||
// Attempt to reverse-lookup [entryPoint] in package config.
|
||||
String asString = "$entryPoint";
|
||||
packagesMap ??= uriTranslator.packages.asMap();
|
||||
for (String packageName in packagesMap.keys) {
|
||||
Uri packageUri = packagesMap[packageName];
|
||||
Package package = uriTranslator.packages.packageOf(entryPoint);
|
||||
if (package != null) {
|
||||
String packageName = package.name;
|
||||
Uri packageUri = package.packageUriRoot;
|
||||
if (packageUri?.hasFragment == true) {
|
||||
packageUri = packageUri.removeFragment();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'dart:collection' show Queue;
|
|||
import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
|
||||
|
||||
import 'package:kernel/ast.dart' show Class, DartType, Library;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
|
||||
import 'scope.dart';
|
||||
|
||||
|
@ -116,7 +117,7 @@ abstract class Loader {
|
|||
fileUri.scheme == "dart-ext")) {
|
||||
fileUri = null;
|
||||
}
|
||||
String packageFragment;
|
||||
Package packageForLanguageVersion;
|
||||
if (fileUri == null) {
|
||||
switch (uri.scheme) {
|
||||
case "package":
|
||||
|
@ -125,47 +126,31 @@ abstract class Loader {
|
|||
new Uri(
|
||||
scheme: untranslatableUriScheme,
|
||||
path: Uri.encodeComponent("$uri"));
|
||||
packageFragment = target.uriTranslator.getPackageFragment(uri);
|
||||
packageForLanguageVersion = target.uriTranslator.getPackage(uri);
|
||||
break;
|
||||
|
||||
default:
|
||||
fileUri = uri;
|
||||
// Check for empty package name entry (redirecting to package name
|
||||
// from which we should get the fragment part).
|
||||
packageFragment = target.uriTranslator?.getDefaultPackageFragment();
|
||||
packageForLanguageVersion =
|
||||
target.uriTranslator.packages.packageOf(fileUri);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
packageForLanguageVersion =
|
||||
target.uriTranslator.packages.packageOf(fileUri);
|
||||
}
|
||||
bool hasPackageSpecifiedLanguageVersion = false;
|
||||
int packageSpecifiedLanguageVersionMajor;
|
||||
int packageSpecifiedLanguageVersionMinor;
|
||||
if (packageFragment != null) {
|
||||
List<String> properties = packageFragment.split("&");
|
||||
int foundEntries = 0;
|
||||
for (int i = 0; i < properties.length; ++i) {
|
||||
String property = properties[i];
|
||||
if (property.startsWith("dart=")) {
|
||||
if (++foundEntries > 1) {
|
||||
// Force error to be issued if more than one "dart=" entry.
|
||||
// (The error will be issued in library.setLanguageVersion below
|
||||
// when giving it `null` version numbers.)
|
||||
packageSpecifiedLanguageVersionMajor = null;
|
||||
packageSpecifiedLanguageVersionMinor = null;
|
||||
break;
|
||||
}
|
||||
|
||||
hasPackageSpecifiedLanguageVersion = true;
|
||||
String languageVersionString = property.substring(5);
|
||||
|
||||
// Verify that the version is x.y[whatever]
|
||||
List<String> dotSeparatedParts = languageVersionString.split(".");
|
||||
if (dotSeparatedParts.length >= 2) {
|
||||
packageSpecifiedLanguageVersionMajor =
|
||||
int.tryParse(dotSeparatedParts[0]);
|
||||
packageSpecifiedLanguageVersionMinor =
|
||||
int.tryParse(dotSeparatedParts[1]);
|
||||
}
|
||||
}
|
||||
if (packageForLanguageVersion != null &&
|
||||
packageForLanguageVersion.languageVersion != null) {
|
||||
hasPackageSpecifiedLanguageVersion = true;
|
||||
if (packageForLanguageVersion.languageVersion
|
||||
is! InvalidLanguageVersion) {
|
||||
packageSpecifiedLanguageVersionMajor =
|
||||
packageForLanguageVersion.languageVersion.major;
|
||||
packageSpecifiedLanguageVersionMinor =
|
||||
packageForLanguageVersion.languageVersion.minor;
|
||||
}
|
||||
}
|
||||
LibraryBuilder library = target.createLibraryBuilder(
|
||||
|
|
|
@ -56,7 +56,10 @@ abstract class TargetImplementation extends Target {
|
|||
bool performNnbdChecks;
|
||||
|
||||
TargetImplementation(Ticker ticker, this.uriTranslator, this.backendTarget)
|
||||
: enableExtensionMethods = CompilerContext.current.options
|
||||
: assert(ticker != null),
|
||||
assert(uriTranslator != null),
|
||||
assert(backendTarget != null),
|
||||
enableExtensionMethods = CompilerContext.current.options
|
||||
.isExperimentEnabled(ExperimentalFlag.extensionMethods),
|
||||
enableNonNullable = CompilerContext.current.options
|
||||
.isExperimentEnabled(ExperimentalFlag.nonNullable),
|
||||
|
|
|
@ -6,7 +6,7 @@ library fasta.uri_translator;
|
|||
|
||||
import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
|
||||
|
||||
import 'package:package_config/packages.dart' show Packages;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
|
||||
import '../base/libraries_specification.dart' show TargetLibrariesSpecification;
|
||||
import 'compiler_context.dart' show CompilerContext;
|
||||
|
@ -15,7 +15,7 @@ import 'fasta_codes.dart';
|
|||
class UriTranslator {
|
||||
final TargetLibrariesSpecification dartLibraries;
|
||||
|
||||
final Packages packages;
|
||||
final PackageConfig packages;
|
||||
|
||||
UriTranslator(this.dartLibraries, this.packages);
|
||||
|
||||
|
@ -39,26 +39,14 @@ class UriTranslator {
|
|||
return null;
|
||||
}
|
||||
|
||||
/// For a package uri, get the fragment of the uri specified for that package.
|
||||
String getPackageFragment(Uri uri) {
|
||||
/// For a package uri, get the corresponding [Package].
|
||||
Package getPackage(Uri uri) {
|
||||
if (packages == null) return null;
|
||||
if (uri.scheme != "package") return null;
|
||||
int firstSlash = uri.path.indexOf('/');
|
||||
if (firstSlash == -1) return null;
|
||||
String packageName = uri.path.substring(0, firstSlash);
|
||||
Uri packageBaseUri = packages.asMap()[packageName];
|
||||
if (packageBaseUri == null) return null;
|
||||
return packageBaseUri.fragment;
|
||||
}
|
||||
|
||||
/// Get the fragment for the package specified as the default package, if any.
|
||||
String getDefaultPackageFragment() {
|
||||
Uri emptyPackageRedirect = packages.asMap()[""];
|
||||
if (emptyPackageRedirect == null) return null;
|
||||
String packageName = emptyPackageRedirect.toString();
|
||||
Uri packageBaseUri = packages.asMap()[packageName];
|
||||
if (packageBaseUri == null) return null;
|
||||
return packageBaseUri.fragment;
|
||||
return packages[packageName];
|
||||
}
|
||||
|
||||
bool isLibrarySupported(String libraryName) {
|
||||
|
@ -76,10 +64,13 @@ class UriTranslator {
|
|||
try {
|
||||
// TODO(sigmund): once we remove the `parse` API, we can ensure that
|
||||
// packages will never be null and get rid of `?` below.
|
||||
return packages?.resolve(uri,
|
||||
notFound: reportMessage
|
||||
? _packageUriNotFound
|
||||
: _packageUriNotFoundNoReport);
|
||||
Uri translated = packages?.resolve(uri);
|
||||
if (translated == null) {
|
||||
return (reportMessage
|
||||
? _packageUriNotFound
|
||||
: _packageUriNotFoundNoReport)(uri);
|
||||
}
|
||||
return translated;
|
||||
} on ArgumentError catch (e) {
|
||||
// TODO(sigmund): catch a more precise error when
|
||||
// https://github.com/dart-lang/package_config/issues/40 is fixed.
|
||||
|
|
|
@ -208,14 +208,16 @@ RunTestFunction<T> runTestFor<T>(
|
|||
bool verbose,
|
||||
bool succinct,
|
||||
bool printCode,
|
||||
Map<String, List<String>> skipMap}) {
|
||||
Map<String, List<String>> skipMap,
|
||||
Uri nullUri}) {
|
||||
return runTest(testData, dataComputer, testedConfigs,
|
||||
testAfterFailures: testAfterFailures,
|
||||
verbose: verbose,
|
||||
succinct: succinct,
|
||||
printCode: printCode,
|
||||
onFailure: onFailure,
|
||||
skipMap: skipMap);
|
||||
skipMap: skipMap,
|
||||
nullUri: nullUri);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -231,7 +233,8 @@ Future<Map<String, TestResult<T>>> runTest<T>(TestData testData,
|
|||
bool forUserLibrariesOnly: true,
|
||||
Iterable<Id> globalIds: const <Id>[],
|
||||
void onFailure(String message),
|
||||
Map<String, List<String>> skipMap}) async {
|
||||
Map<String, List<String>> skipMap,
|
||||
Uri nullUri}) async {
|
||||
Map<String, TestResult<T>> results = {};
|
||||
for (TestConfig config in testedConfigs) {
|
||||
if (skipForConfig(testData.name, config.marker, skipMap)) {
|
||||
|
@ -243,7 +246,8 @@ Future<Map<String, TestResult<T>>> runTest<T>(TestData testData,
|
|||
onFailure: onFailure,
|
||||
verbose: verbose,
|
||||
succinct: succinct,
|
||||
printCode: printCode);
|
||||
printCode: printCode,
|
||||
nullUri: nullUri);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -259,7 +263,8 @@ Future<TestResult<T>> runTestForConfig<T>(
|
|||
bool printCode,
|
||||
bool forUserLibrariesOnly: true,
|
||||
Iterable<Id> globalIds: const <Id>[],
|
||||
void onFailure(String message)}) async {
|
||||
void onFailure(String message),
|
||||
Uri nullUri}) async {
|
||||
MemberAnnotations<IdValue> memberAnnotations =
|
||||
testData.expectedMaps[config.marker];
|
||||
Iterable<Id> globalIds = memberAnnotations.globalData.keys;
|
||||
|
@ -293,7 +298,7 @@ Future<TestResult<T>> runTestForConfig<T>(
|
|||
Map<Id, ActualData<T>> globalData = <Id, ActualData<T>>{};
|
||||
|
||||
Map<Id, ActualData<T>> actualMapForUri(Uri uri) {
|
||||
return actualMaps.putIfAbsent(uri, () => <Id, ActualData<T>>{});
|
||||
return actualMaps.putIfAbsent(uri ?? nullUri, () => <Id, ActualData<T>>{});
|
||||
}
|
||||
|
||||
if (errors.isNotEmpty) {
|
||||
|
@ -305,14 +310,14 @@ Future<TestResult<T>> runTestForConfig<T>(
|
|||
Map<Uri, Map<int, List<FormattedMessage>>> errorMap = {};
|
||||
for (FormattedMessage error in errors) {
|
||||
Map<int, List<FormattedMessage>> map =
|
||||
errorMap.putIfAbsent(error.uri, () => {});
|
||||
errorMap.putIfAbsent(error.uri ?? nullUri, () => {});
|
||||
List<FormattedMessage> list = map.putIfAbsent(error.charOffset, () => []);
|
||||
list.add(error);
|
||||
}
|
||||
|
||||
errorMap.forEach((Uri uri, Map<int, List<FormattedMessage>> map) {
|
||||
map.forEach((int offset, List<DiagnosticMessage> list) {
|
||||
if (offset < 0) {
|
||||
if (offset == null || offset < 0) {
|
||||
// Position errors without offset in the begin of the file.
|
||||
offset = 0;
|
||||
}
|
||||
|
@ -457,7 +462,7 @@ void printMessageInLocation(
|
|||
Map<Uri, Source> uriToSource, Uri uri, int offset, String message,
|
||||
{bool succinct: false}) {
|
||||
if (uri == null) {
|
||||
print(message);
|
||||
print("(null uri)@$offset: $message");
|
||||
} else {
|
||||
Source source = uriToSource[uri];
|
||||
if (source == null) {
|
||||
|
|
|
@ -406,7 +406,6 @@ InvalidVoid/script2: Fail
|
|||
JsInteropIndexNotSupported/analyzerCode: Fail # Web compiler specific
|
||||
JsInteropIndexNotSupported/example: Fail # Web compiler specific
|
||||
LanguageVersionInvalidInDotPackages/analyzerCode: Fail
|
||||
LanguageVersionInvalidInDotPackages/part_wrapped_script: Fail # Importing file in the (now) part.
|
||||
LanguageVersionMismatchInPart/analyzerCode: Fail
|
||||
LanguageVersionMismatchInPart/part_wrapped_script: Fail # Part in (now) part.
|
||||
LanguageVersionMismatchInPatch/analyzerCode: Fail
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
# should be the path to an external test. The external test will not be run,
|
||||
# but the existence of the file will be verified.
|
||||
#
|
||||
# Note that it can be hard or impossible to write an example that only gives the
|
||||
# specific error. To allow for this, one can specify
|
||||
# "exampleAllowMoreCodes: true" which filters out every message with a
|
||||
# different code, and just verifies we got exactly one message of the code in
|
||||
# question (in addition too different codes).
|
||||
#
|
||||
# A message shouldn't indicate which kind of diagnostic it is, for example,
|
||||
# warning or error. Tools are expected to prepend "Warning: ", or "Error: ",
|
||||
# and should be allowed to change the kind of diagnostic without affecting the
|
||||
|
@ -2823,11 +2829,11 @@ CannotReadSdkSpecification:
|
|||
template: "Unable to read the 'libraries.json' specification file:\n #string."
|
||||
|
||||
CantInferPackagesFromManyInputs:
|
||||
template: "Can't infer a .packages file when compiling multiple inputs."
|
||||
template: "Can't infer a packages file when compiling multiple inputs."
|
||||
tip: "Try specifying the file explicitly with the --packages option."
|
||||
|
||||
CantInferPackagesFromPackageUri:
|
||||
template: "Can't infer a .packages file from an input 'package:*' URI."
|
||||
template: "Can't infer a packages file from an input 'package:*' URI."
|
||||
tip: "Try specifying the file explicitly with the --packages option."
|
||||
|
||||
PackageNotFound:
|
||||
|
@ -3721,11 +3727,22 @@ LanguageVersionTooHigh:
|
|||
// @dart = 100.200
|
||||
|
||||
LanguageVersionInvalidInDotPackages:
|
||||
template: "The language version is not specified correctly in the .packages file."
|
||||
template: "The language version is not specified correctly in the packages file."
|
||||
exampleAllowMoreCodes: true
|
||||
script:
|
||||
main.dart: "import 'package:foo/foo.dart';"
|
||||
lib/foo.dart: "// blah blah blah"
|
||||
.packages: "foo:lib/#dart=arglebargle"
|
||||
.dart_tool/package_config.json: >
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "arglebargle"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
LanguageVersionMismatchInPart:
|
||||
template: "The language version override has to be the same in the library and its part(s)."
|
||||
|
|
|
@ -10,7 +10,8 @@ environment:
|
|||
dependencies:
|
||||
_fe_analyzer_shared: 1.0.0
|
||||
kernel: 0.3.29
|
||||
package_config: '^1.1.0'
|
||||
package_config_v2:
|
||||
path: ../../third_party/pkg/package_config_v2/
|
||||
meta: ^1.0.2
|
||||
dev_dependencies:
|
||||
analyzer: 0.39.1
|
||||
|
|
|
@ -20,10 +20,16 @@ final Uri repoDir = computeRepoDirUri();
|
|||
|
||||
Set<String> whitelistedExternalDartFiles = {
|
||||
"third_party/pkg/charcode/lib/ascii.dart",
|
||||
"third_party/pkg_tested/package_config/lib/packages.dart",
|
||||
"third_party/pkg_tested/package_config/lib/packages_file.dart",
|
||||
"third_party/pkg_tested/package_config/lib/src/packages_impl.dart",
|
||||
"third_party/pkg_tested/package_config/lib/src/util.dart",
|
||||
|
||||
"third_party/pkg/package_config_v2/lib/package_config.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/discovery.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/errors.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/package_config_impl.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/package_config_json.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/package_config.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/packages_file.dart",
|
||||
"third_party/pkg/package_config_v2/lib/src/util.dart",
|
||||
|
||||
// TODO(CFE-team): This file should not be included.
|
||||
// The package isn't even in pubspec.yaml.
|
||||
"pkg/meta/lib/meta.dart",
|
||||
|
|
|
@ -26,8 +26,8 @@ main() async {
|
|||
library.addMember(field);
|
||||
Component component = new Component(libraries: <Library>[library]);
|
||||
await CompilerContext.runWithDefaultOptions((CompilerContext c) async {
|
||||
DillTarget target =
|
||||
new DillTarget(c.options.ticker, null, c.options.target);
|
||||
DillTarget target = new DillTarget(c.options.ticker,
|
||||
await c.options.getUriTranslator(), c.options.target);
|
||||
target.loader.appendLibraries(component);
|
||||
DillLibraryBuilder builder = target.loader.read(library.importUri, -1);
|
||||
await target.loader.buildOutline(builder);
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/scanner/scanner.dart'
|
|||
show Token, scanString;
|
||||
|
||||
import 'package:expect/expect.dart' show Expect;
|
||||
import 'package:front_end/src/fasta/uri_translator.dart';
|
||||
|
||||
import 'package:kernel/ast.dart'
|
||||
show
|
||||
|
@ -57,8 +58,8 @@ void check(String expected, Generator generator) {
|
|||
Expect.stringEquals(expected, "$generator");
|
||||
}
|
||||
|
||||
main() {
|
||||
CompilerContext.runWithDefaultOptions((CompilerContext c) {
|
||||
main() async {
|
||||
await CompilerContext.runWithDefaultOptions((CompilerContext c) async {
|
||||
Token token = scanString(" myToken").tokens;
|
||||
Uri uri = Uri.parse("org-dartlang-test:my_library.dart");
|
||||
|
||||
|
@ -67,14 +68,16 @@ main() {
|
|||
Expression expression =
|
||||
new VariableGet(new VariableDeclaration("expression"));
|
||||
Expression index = new VariableGet(new VariableDeclaration("index"));
|
||||
UriTranslator uriTranslator = await c.options.getUriTranslator();
|
||||
SourceLibraryBuilder libraryBuilder = new SourceLibraryBuilder(
|
||||
uri,
|
||||
uri,
|
||||
new KernelTarget(
|
||||
null,
|
||||
false,
|
||||
new DillTarget(null, null, new NoneTarget(new TargetFlags())),
|
||||
null)
|
||||
new DillTarget(c.options.ticker, uriTranslator,
|
||||
new NoneTarget(new TargetFlags())),
|
||||
uriTranslator)
|
||||
.loader,
|
||||
null);
|
||||
LoadLibraryBuilder loadLibraryBuilder =
|
||||
|
|
|
@ -106,6 +106,7 @@ class MessageTestSuite extends ChainContext {
|
|||
if (message is String) continue;
|
||||
|
||||
List<String> unknownKeys = <String>[];
|
||||
bool exampleAllowMoreCodes = false;
|
||||
List<Example> examples = <Example>[];
|
||||
String externalTest;
|
||||
bool frontendInternal = false;
|
||||
|
@ -206,6 +207,10 @@ class MessageTestSuite extends ChainContext {
|
|||
: new List<String>.from(value);
|
||||
break;
|
||||
|
||||
case "exampleAllowMoreCodes":
|
||||
exampleAllowMoreCodes = value;
|
||||
break;
|
||||
|
||||
case "bytes":
|
||||
YamlList list = node;
|
||||
if (list.first is List) {
|
||||
|
@ -285,6 +290,13 @@ class MessageTestSuite extends ChainContext {
|
|||
}
|
||||
}
|
||||
|
||||
if (exampleAllowMoreCodes) {
|
||||
// Update all examples.
|
||||
for (Example example in examples) {
|
||||
example.allowMoreCodes = exampleAllowMoreCodes;
|
||||
}
|
||||
}
|
||||
|
||||
MessageTestDescription createDescription(
|
||||
String subName, Example example, String problem,
|
||||
{location}) {
|
||||
|
@ -308,8 +320,8 @@ class MessageTestSuite extends ChainContext {
|
|||
for (Example example in examples) {
|
||||
yield createDescription(
|
||||
"part_wrapped_${example.name}",
|
||||
new PartWrapExample(
|
||||
"part_wrapped_${example.name}", name, example),
|
||||
new PartWrapExample("part_wrapped_${example.name}", name,
|
||||
exampleAllowMoreCodes, example),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
@ -420,6 +432,8 @@ abstract class Example {
|
|||
|
||||
final String expectedCode;
|
||||
|
||||
bool allowMoreCodes = false;
|
||||
|
||||
Example(this.name, this.expectedCode);
|
||||
|
||||
YamlNode get node;
|
||||
|
@ -532,6 +546,7 @@ class ScriptExample extends Example {
|
|||
var scriptFiles = <String, Uint8List>{};
|
||||
script.forEach((fileName, value) {
|
||||
scriptFiles[fileName] = new Uint8List.fromList(utf8.encode(value));
|
||||
print("$fileName => $value\n\n======\n\n");
|
||||
});
|
||||
return scriptFiles;
|
||||
} else {
|
||||
|
@ -542,7 +557,10 @@ class ScriptExample extends Example {
|
|||
|
||||
class PartWrapExample extends Example {
|
||||
final Example example;
|
||||
PartWrapExample(String name, String code, this.example) : super(name, code);
|
||||
@override
|
||||
final bool allowMoreCodes;
|
||||
PartWrapExample(String name, String code, this.allowMoreCodes, this.example)
|
||||
: super(name, code);
|
||||
|
||||
@override
|
||||
Uint8List get bytes => throw "Unsupported: PartWrapExample.bytes";
|
||||
|
@ -618,10 +636,13 @@ class Compile extends Step<Example, Null, MessageTestSuite> {
|
|||
Uri output =
|
||||
suite.fileSystem.currentDirectory.resolve("$dir/main.dart.dill");
|
||||
|
||||
// Setup .packages if it doesn't exist.
|
||||
// Setup .packages if it (or package_config.json) doesn't exist.
|
||||
Uri dotPackagesUri =
|
||||
suite.fileSystem.currentDirectory.resolve("$dir/.packages");
|
||||
if (!await suite.fileSystem.entityForUri(dotPackagesUri).exists()) {
|
||||
Uri packageConfigJsonUri = suite.fileSystem.currentDirectory
|
||||
.resolve("$dir/.dart_tool/package_config.json");
|
||||
if (!await suite.fileSystem.entityForUri(dotPackagesUri).exists() &&
|
||||
!await suite.fileSystem.entityForUri(packageConfigJsonUri).exists()) {
|
||||
suite.fileSystem.entityForUri(dotPackagesUri).writeAsBytesSync([]);
|
||||
}
|
||||
|
||||
|
@ -641,6 +662,15 @@ class Compile extends Step<Example, Null, MessageTestSuite> {
|
|||
output);
|
||||
|
||||
List<DiagnosticMessage> unexpectedMessages = <DiagnosticMessage>[];
|
||||
if (example.allowMoreCodes) {
|
||||
List<DiagnosticMessage> messagesFiltered = new List<DiagnosticMessage>();
|
||||
for (DiagnosticMessage message in messages) {
|
||||
if (getMessageCodeObject(message).name == example.expectedCode) {
|
||||
messagesFiltered.add(message);
|
||||
}
|
||||
}
|
||||
messages = messagesFiltered;
|
||||
}
|
||||
for (DiagnosticMessage message in messages) {
|
||||
if (getMessageCodeObject(message).name != example.expectedCode) {
|
||||
unexpectedMessages.add(message);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import 'package:front_end/src/base/libraries_specification.dart';
|
||||
import 'package:front_end/src/fasta/uri_translator.dart';
|
||||
import 'package:package_config/packages.dart';
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -23,7 +23,7 @@ class UriTranslatorImplTest {
|
|||
'math': new LibraryInfo('core',
|
||||
Uri.parse('org-dartlang-test:///sdk/math/math.dart'), const []),
|
||||
}),
|
||||
Packages.noPackages);
|
||||
PackageConfig.empty);
|
||||
|
||||
void test_isPlatformImplementation() {
|
||||
bool isPlatform(String uriStr) {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../foo2/"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
foo:foo1/
|
|
@ -0,0 +1,5 @@
|
|||
// No language version --- this file shouldn't even be compiled.
|
||||
|
||||
int notNamedFoo() {
|
||||
return 42;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/*library: languageVersion=2.8*/
|
||||
|
||||
String foo() {
|
||||
return "42";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Set version of this file (not technically in package) explicitly to test as
|
||||
// much as possibly separately.
|
||||
|
||||
// @dart = 2.4
|
||||
|
||||
import 'package:foo/foo.dart';
|
||||
|
||||
/*library: languageVersion=2.4*/
|
||||
|
||||
main() {
|
||||
var result = foo();
|
||||
print(result);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
foo:lib//*error: PackagesFileFormat*/#dart=2.6
|
|
@ -0,0 +1,5 @@
|
|||
/*library: languageVersion=2.8*/
|
||||
|
||||
String foo() {
|
||||
return "42";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
// Set version of this file (not technically in package) explicitly to test as
|
||||
// much as possibly separately.
|
||||
|
||||
// @dart = 2.4
|
||||
|
||||
import 'package:foo/foo.dart';
|
||||
|
||||
/*library: languageVersion=2.4*/
|
||||
|
||||
main() {
|
||||
var result = foo();
|
||||
print(result);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.5.3-dev.2
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
/*library: languageVersion=2.5*/
|
||||
|
||||
foo() {
|
||||
part 'foos_part.dart';
|
||||
|
||||
fooWithPart() {
|
||||
print("Hello from foo!");
|
||||
fooPart();
|
||||
}
|
|
@ -2,10 +2,8 @@
|
|||
// 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 'package:foo/foo.dart';
|
||||
part of 'foo_with_part.dart';
|
||||
|
||||
/*library: languageVersion=2.8*/
|
||||
|
||||
main() {
|
||||
foo();
|
||||
fooPart() {
|
||||
print("Hello from foo part!");
|
||||
}
|
|
@ -8,9 +8,11 @@
|
|||
// @dart = 2.4
|
||||
|
||||
import 'package:foo/foo.dart';
|
||||
import 'package:foo/foo_with_part.dart';
|
||||
|
||||
/*library: languageVersion=2.4*/
|
||||
|
||||
main() {
|
||||
foo();
|
||||
fooWithPart();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/*error: PackagesFileFormat*/
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": ""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=
|
|
@ -0,0 +1,11 @@
|
|||
/*error: PackagesFileFormat*/
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "arglebargle"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=arglebargle
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "arglebargle",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=arglebargle&dart=2.5
|
|
@ -0,0 +1,12 @@
|
|||
/*error: PackagesFileFormat*/
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.5",
|
||||
"languageVersion": "arglebargle"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.5&dart=arglebargle
|
|
@ -0,0 +1,11 @@
|
|||
/*error: PackagesFileFormat*/
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": 2.5
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*error: LanguageVersionInvalidInDotPackages*/
|
||||
// Copyright (c) 2019, 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.
|
||||
|
||||
/*library: languageVersion=2.8*/
|
||||
|
||||
import 'foo2.dart';
|
||||
|
||||
foo() {
|
||||
print("Hello from foo!");
|
||||
foo2();
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*error: LanguageVersionInvalidInDotPackages*/
|
||||
// Copyright (c) 2019, 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.
|
||||
|
||||
// @dart = 2.4
|
||||
|
||||
/*library: languageVersion=2.4*/
|
||||
|
||||
foo2() {
|
||||
print("Hello from foo2!");
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2019, 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.
|
||||
|
||||
// Set version of this file (not technically in package) explicitly to test as
|
||||
// much as possibly separately.
|
||||
|
||||
// @dart = 2.4
|
||||
|
||||
import 'package:foo/foo.dart';
|
||||
|
||||
/*library: languageVersion=2.4*/
|
||||
|
||||
main() {
|
||||
foo();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) 2019, 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.
|
||||
|
||||
# Analyzer workaround, see https://github.com/dart-lang/sdk/issues/37513
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
foo:lib/#dart=2.5.3-dev.2
|
||||
:foo
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import 'package:foo/foo.dart';
|
||||
|
||||
// Version comes from "default package" in .packages.
|
||||
// Version comes from the package foo having this file in it's root uri.
|
||||
|
||||
/*library: languageVersion=2.5*/
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.5.3-dev.2
|
|
@ -1,2 +0,0 @@
|
|||
foo:lib/#dart=2.5.3-dev.2
|
||||
:bar
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.9"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.9
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.5
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "foo",
|
||||
"rootUri": "../lib/",
|
||||
"languageVersion": "2.5"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
foo:lib/#dart=2.5
|
|
@ -32,7 +32,11 @@ main(List<String> args) async {
|
|||
supportedMarkers: [cfeMarker],
|
||||
createUriForFileName: createUriForFileName,
|
||||
onFailure: onFailure,
|
||||
runTest: runTestFor(const LanguageVersioningDataComputer(), [cfeConfig]));
|
||||
runTest: runTestFor(const LanguageVersioningDataComputer(), [cfeConfig]),
|
||||
skipList: [
|
||||
// Two language versions specified, the last one is ok and is used here.
|
||||
"package_default_version_is_wrong_2",
|
||||
]);
|
||||
}
|
||||
|
||||
class TestConfigWithLanguageVersion extends TestConfig {
|
||||
|
|
|
@ -25,9 +25,7 @@ import 'package:front_end/src/fasta/command_line_reporting.dart'
|
|||
|
||||
import 'package:kernel/kernel.dart';
|
||||
|
||||
import 'package:package_config/packages.dart' show Packages;
|
||||
|
||||
import 'package:package_config/discovery.dart' show loadPackagesFile;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
|
||||
import 'package:testing/testing.dart'
|
||||
show Chain, ChainContext, Result, Step, TestDescription, runMe;
|
||||
|
@ -68,7 +66,7 @@ class LintTestCache {
|
|||
List<int> lineStarts;
|
||||
Source source;
|
||||
Token firstToken;
|
||||
Packages packages;
|
||||
PackageConfig packages;
|
||||
}
|
||||
|
||||
class Context extends ChainContext {
|
||||
|
@ -164,7 +162,7 @@ class LintStep extends Step<LintTestDescription, LintTestDescription, Context> {
|
|||
|
||||
File dotPackagesFile = new File.fromUri(dotPackages);
|
||||
if (dotPackagesFile.existsSync()) {
|
||||
description.cache.packages = await loadPackagesFile(dotPackages);
|
||||
description.cache.packages = await loadPackageConfigUri(dotPackages);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -630,6 +630,7 @@ ncurses
|
|||
nd
|
||||
near
|
||||
neighboring
|
||||
newest
|
||||
nextnext
|
||||
ni
|
||||
nine
|
||||
|
|
|
@ -13,7 +13,7 @@ import 'package:front_end/src/fasta/fasta_codes.dart';
|
|||
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
||||
import 'package:kernel/kernel.dart'
|
||||
show CanonicalName, Library, Component, loadComponentFromBytes;
|
||||
import 'package:package_config/packages.dart' show Packages;
|
||||
import 'package:package_config_v2/package_config.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -163,7 +163,7 @@ class ProcessedOptionsTest {
|
|||
}
|
||||
|
||||
checkPackageExpansion(
|
||||
String packageName, String packageDir, Packages packages) {
|
||||
String packageName, String packageDir, PackageConfig packages) {
|
||||
var input = Uri.parse('package:$packageName/a.dart');
|
||||
var expected = Uri.parse('org-dartlang-test:///$packageDir/a.dart');
|
||||
expect(packages.resolve(input), expected);
|
||||
|
@ -308,7 +308,7 @@ class ProcessedOptionsTest {
|
|||
inputs: [Uri.parse('org-dartlang-test:///base/location/script.dart')]);
|
||||
var uriTranslator = await processed.getUriTranslator();
|
||||
expect(errors, isEmpty);
|
||||
expect(uriTranslator.packages.asMap(), isEmpty);
|
||||
expect(uriTranslator.packages.packages, isEmpty);
|
||||
}
|
||||
|
||||
test_getUriTranslator_noPackages() async {
|
||||
|
@ -323,7 +323,7 @@ class ProcessedOptionsTest {
|
|||
..onDiagnostic = errors.add;
|
||||
var processed = new ProcessedOptions(options: raw);
|
||||
var uriTranslator = await processed.getUriTranslator();
|
||||
expect(uriTranslator.packages.asMap(), isEmpty);
|
||||
expect(uriTranslator.packages.packages, isEmpty);
|
||||
expect(errors.single.message,
|
||||
startsWith(_stringPrefixOf(templateCantReadFile)));
|
||||
}
|
||||
|
|
|
@ -420,7 +420,8 @@ Future<void> checkTests<T>(Directory dataDir, DataComputer<T> dataComputer,
|
|||
bool verbose,
|
||||
bool succinct,
|
||||
bool printCode,
|
||||
Map<String, List<String>> skipMap}) async {
|
||||
Map<String, List<String>> skipMap,
|
||||
Uri nullUri}) async {
|
||||
String name = testData.name;
|
||||
List<String> testOptions = options.toList();
|
||||
if (name.endsWith('_ea.dart')) {
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# 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.
|
||||
f0:.
|
||||
f1:.
|
||||
f1:f1
|
||||
a:a
|
||||
|
|
Loading…
Reference in a new issue