[CFE] Get in line with update on which package description file to use

Fixes #40864

Change-Id: I681186660162c55e66c1deee68a4052de4cfcfe9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139201
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen 2020-03-12 11:33:52 +00:00 committed by commit-bot@chromium.org
parent 13dbe2a815
commit a55fed2e5f
35 changed files with 217 additions and 23 deletions

View file

@ -512,7 +512,7 @@ class ProcessedOptions {
/// 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 {
Uri requestedUri, bool forceCreation, bool requireJson) async {
Uint8List contents = await _readFile(requestedUri, forceCreation);
if (contents == null) {
if (forceCreation) {
@ -524,14 +524,7 @@ class ProcessedOptions {
_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) {
void Function(Object error) onError = (Object error) {
if (error is FormatException) {
report(
templatePackagesFileFormat
@ -543,7 +536,19 @@ class ProcessedOptions {
templateCantReadFile.withArguments(requestedUri, "$error"),
Severity.error);
}
});
};
if (requireJson) {
return PackageConfig.parseBytes(contents, requestedUri,
onError: onError);
}
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: onError);
} on FormatException catch (e) {
report(
templatePackagesFileFormat
@ -566,16 +571,17 @@ class ProcessedOptions {
/// (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 {
// If the input is a ".packages" file we assume the standard layout, and
// if a ".dart_tool/package_config.json" exists, we'll use that (and require
// it to be a json file).
if (file.path.endsWith("/.packages")) {
// .packages -> try the package_config first.
Uri tryFirst = file.resolve(".dart_tool/package_config.json");
PackageConfig result = await _createPackagesFromFile(tryFirst, false);
PackageConfig result =
await _createPackagesFromFile(tryFirst, false, true);
if (result != null) return result;
return await _createPackagesFromFile(file, true);
}
return _createPackagesFromFile(file, true, false);
}
/// Finds a package resolution strategy using a [FileSystem].

View file

@ -105,8 +105,10 @@ Future<Null> setup(CompilerOptions options, Map<String, dynamic> sources,
options
..verify = true
..fileSystem = new HybridFileSystem(fs)
..additionalDills = additionalDills.map(toTestUri).toList()
..packagesFileUri = toTestUri('.packages');
..additionalDills = additionalDills.map(toTestUri).toList();
if (options.packagesFileUri == null) {
options.packagesFileUri = toTestUri('.packages');
}
if (options.sdkSummary == null) {
options.sdkRoot = computePlatformBinariesLocation(forceBuildDir: true);

View file

@ -51,7 +51,7 @@ class TestConfig {
this.librariesSpecificationUri,
this.compileSdk: false});
void customizeCompilerOptions(CompilerOptions options) {}
void customizeCompilerOptions(CompilerOptions options, TestData testData) {}
}
// TODO(johnniwinther): Support annotations for compile-time errors.
@ -293,7 +293,7 @@ Future<TestResult<T>> runTestForConfig<T>(
options.compileSdk = config.compileSdk;
}
}
config.customizeCompilerOptions(options);
config.customizeCompilerOptions(options, testData);
InternalCompilerResult compilerResult = await compileScript(
testData.memorySourceFiles,
options: options,

View file

@ -0,0 +1,9 @@
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "../foo2/"
}
]
}

View file

@ -0,0 +1 @@
foo:foo1/

View file

@ -0,0 +1,5 @@
// No language version --- this file shouldn't even be compiled.
int notNamedFoo() {
return 42;
}

View file

@ -0,0 +1,5 @@
/*library: languageVersion=2.8*/
String foo() {
return "42";
}

View file

@ -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);
}

View file

@ -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

View file

@ -0,0 +1,2 @@
# Point to .packages => Standard layout; redirect to .dart_tool/package_config.json
--packages=.packages

View file

@ -0,0 +1,9 @@
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "../foo2/"
}
]
}

View file

@ -0,0 +1,5 @@
/*library: languageVersion=2.8*/
int notNamedFoo() {
return 42;
}

View file

@ -0,0 +1,5 @@
// No language version --- this file shouldn't even be compiled.
String foo() {
return "42";
}

View file

@ -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 = notNamedFoo();
print(result);
}

View file

@ -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

View file

@ -0,0 +1,2 @@
# Point to .packagesX => non-standard layout; use it directly
--packages=.packagesX

View file

@ -0,0 +1 @@
foo:foo1/

View file

@ -0,0 +1,5 @@
// No language version --- this file shouldn't even be compiled.
int notNamedFoo() {
return 42;
}

View file

@ -0,0 +1,5 @@
/*library: languageVersion=2.8*/
String foo() {
return "42";
}

View file

@ -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);
}

View file

@ -0,0 +1,9 @@
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "foo2/"
}
]
}

View file

@ -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

View file

@ -0,0 +1,2 @@
# Point to package_config.json => non-standard layout; use it directly
--packages=package_config.json

View file

@ -0,0 +1 @@
/*error: PackagesFileFormat*/foo:foo2/

View file

@ -0,0 +1 @@
foo:foo1/

View file

@ -0,0 +1,5 @@
// No language version --- this file shouldn't even be compiled.
int notNamedFoo() {
return 42;
}

View file

@ -0,0 +1,5 @@
// No language version --- this file shouldn't even be compiled.
String foo() {
return "42";
}

View file

@ -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 /*error: UntranslatableUri*/ 'package:foo/foo.dart';
/*library: languageVersion=2.4*/
main() {
var result = /*error: MethodNotFound*/ notNamedFoo();
print(result);
}

View file

@ -0,0 +1 @@
/*error: PackageNotFound*/

View file

@ -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

View file

@ -0,0 +1,2 @@
# Point to .packages => Standard layout; redirect to .dart_tool/package_config.json which in this case isn't a json file. That's an error!
--packages=.packages

View file

@ -2,7 +2,7 @@
// 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:io' show Directory, Platform;
import 'dart:io' show Directory, File, Platform;
import 'package:_fe_analyzer_shared/src/testing/id.dart' show ActualData, Id;
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart'
show DataInterpreter, StringDataInterpreter, runTests;
@ -43,8 +43,24 @@ class TestConfigWithLanguageVersion extends TestConfig {
: super(marker, name);
@override
void customizeCompilerOptions(CompilerOptions options) {
void customizeCompilerOptions(CompilerOptions options, TestData testData) {
options.currentSdkVersion = "2.8";
File f = new File.fromUri(testData.testFileUri.resolve("test.options"));
if (f.existsSync()) {
List<String> lines = f.readAsStringSync().split("\n");
for (String line in lines) {
const String packages = "--packages=";
if (line == "" || line.startsWith("#")) continue;
if (line.startsWith(packages)) {
String value = line.substring(packages.length);
options.packagesFileUri = testData.entryPoint.resolve(value);
print("Setting package file uri to ${options.packagesFileUri}");
} else {
throw "Unsupported: $line";
}
}
}
}
}

View file

@ -53,7 +53,7 @@ class TestConfigWithLanguageVersion extends TestConfig {
experimentalFlags: experimentalFlags);
@override
void customizeCompilerOptions(CompilerOptions options) {
void customizeCompilerOptions(CompilerOptions options, TestData testData) {
options.currentSdkVersion = "2.9999";
}
}

View file

@ -538,6 +538,7 @@ lang
largest
lattice
layer
layout
leafp
len
lets