30ae8e3d14
This CL is a warm-up to a follow-up change that will make running the CFE trybot faster. This CL: * Rename tests that require git (because when working with filesets and shards in the test system, the "checkout" is not a git checkout and git commands thus doesn't work properly. * Filters the front-end unit test setup on the front-end bot the way it was probably intended, i.e. run tests in pkg/kernel, pkg/front_end and pkg/fasta (actually, the last one doesn't exist, but still) instead of just in folders inside the "suite" 'pkg' that somewhere in the path has something called 'kernel', 'front_end' or 'fasta'. * Split unit_test_suites.dart into a "forwarding shell" and a impl. In a follow-up CL the impl will be converted to nnbd to allow for using 'required' on named parameters, but if the entry point was nnbd it would run in sound nnbd mode and nothing would compile because all imports are not nnbd. Overall this CL should change very little, mostly just run a few less tests, i.e. for instance skip tests that live inside a folder called 'fasta' somewhere inside the analyzer directory path. Change-Id: I3226c7261cff8b68cc287cff07dc1715dfd85159 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181381 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
168 lines
6.6 KiB
Dart
168 lines
6.6 KiB
Dart
// 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.md file.
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:_fe_analyzer_shared/src/messages/severity.dart';
|
|
import 'package:expect/expect.dart' show Expect;
|
|
import 'package:front_end/src/api_prototype/compiler_options.dart';
|
|
import 'package:front_end/src/base/processed_options.dart';
|
|
import 'package:front_end/src/fasta/compiler_context.dart';
|
|
import 'package:front_end/src/fasta/dill/dill_target.dart';
|
|
import 'package:front_end/src/fasta/kernel/kernel_target.dart';
|
|
import 'package:front_end/src/fasta/ticker.dart';
|
|
import 'package:front_end/src/fasta/uri_translator.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:kernel/target/targets.dart';
|
|
import 'package:front_end/src/compute_platform_binaries_location.dart'
|
|
show computePlatformBinariesLocation;
|
|
import "package:vm/target/vm.dart" show VmTarget;
|
|
import 'utils/io_utils.dart' show computeRepoDirUri;
|
|
|
|
final Uri repoDir = computeRepoDirUri();
|
|
|
|
Set<String> allowlistedExternalDartFiles = {
|
|
"third_party/pkg/charcode/lib/ascii.dart",
|
|
|
|
"third_party/pkg_tested/package_config/lib/package_config.dart",
|
|
"third_party/pkg_tested/package_config/lib/package_config_types.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/discovery.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/errors.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/package_config_impl.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/package_config_io.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/package_config_json.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/package_config.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/packages_file.dart",
|
|
"third_party/pkg_tested/package_config/lib/src/util.dart",
|
|
|
|
// TODO(johnniwinther): Fix to allow dependency of package:package_config.
|
|
"third_party/pkg_tested/package_config/lib/src/util_io.dart",
|
|
|
|
// TODO(CFE-team): These files should not be included.
|
|
// The package isn't even in pubspec.yaml.
|
|
"pkg/meta/lib/meta.dart",
|
|
"pkg/meta/lib/meta_meta.dart",
|
|
};
|
|
|
|
Future<void> main() async {
|
|
Ticker ticker = new Ticker(isVerbose: false);
|
|
CompilerOptions compilerOptions = getOptions();
|
|
|
|
Uri dotPackagesUri = repoDir.resolve(".packages");
|
|
if (!new File.fromUri(dotPackagesUri).existsSync()) {
|
|
throw "Couldn't find .packages";
|
|
}
|
|
compilerOptions.packagesFileUri = dotPackagesUri;
|
|
|
|
ProcessedOptions options = new ProcessedOptions(options: compilerOptions);
|
|
|
|
Uri frontendLibUri = repoDir.resolve("pkg/front_end/lib/");
|
|
List<FileSystemEntity> entities =
|
|
new Directory.fromUri(frontendLibUri).listSync(recursive: true);
|
|
for (FileSystemEntity entity in entities) {
|
|
if (entity is File && entity.path.endsWith(".dart")) {
|
|
options.inputs.add(entity.uri);
|
|
}
|
|
}
|
|
|
|
List<Uri> result = await CompilerContext.runWithOptions<List<Uri>>(options,
|
|
(CompilerContext c) async {
|
|
UriTranslator uriTranslator = await c.options.getUriTranslator();
|
|
DillTarget dillTarget =
|
|
new DillTarget(ticker, uriTranslator, c.options.target);
|
|
KernelTarget kernelTarget =
|
|
new KernelTarget(c.fileSystem, false, dillTarget, uriTranslator);
|
|
Uri platform = c.options.sdkSummary;
|
|
if (platform != null) {
|
|
var bytes = new File.fromUri(platform).readAsBytesSync();
|
|
var platformComponent = loadComponentFromBytes(bytes);
|
|
dillTarget.loader
|
|
.appendLibraries(platformComponent, byteCount: bytes.length);
|
|
}
|
|
|
|
kernelTarget.setEntryPoints(c.options.inputs);
|
|
await dillTarget.buildOutlines();
|
|
await kernelTarget.loader.buildOutlines();
|
|
return new List<Uri>.from(c.dependencies);
|
|
});
|
|
|
|
Set<Uri> otherDartUris = new Set<Uri>();
|
|
Set<Uri> otherNonDartUris = new Set<Uri>();
|
|
Set<Uri> frontEndUris = new Set<Uri>();
|
|
Set<Uri> kernelUris = new Set<Uri>();
|
|
Set<Uri> feAnalyzerSharedUris = new Set<Uri>();
|
|
Set<Uri> dartPlatformUris = new Set<Uri>();
|
|
Uri kernelUri = repoDir.resolve("pkg/kernel/");
|
|
Uri feAnalyzerSharedUri = repoDir.resolve("pkg/_fe_analyzer_shared/");
|
|
Uri platformUri1 = repoDir.resolve("sdk/lib/");
|
|
Uri platformUri2 = repoDir.resolve("runtime/lib/");
|
|
Uri platformUri3 = repoDir.resolve("runtime/bin/");
|
|
for (Uri uri in result) {
|
|
if (uri.toString().startsWith(frontendLibUri.toString())) {
|
|
frontEndUris.add(uri);
|
|
} else if (uri.toString().startsWith(kernelUri.toString())) {
|
|
kernelUris.add(uri);
|
|
} else if (uri.toString().startsWith(feAnalyzerSharedUri.toString())) {
|
|
feAnalyzerSharedUris.add(uri);
|
|
} else if (uri.toString().startsWith(platformUri1.toString()) ||
|
|
uri.toString().startsWith(platformUri2.toString()) ||
|
|
uri.toString().startsWith(platformUri3.toString())) {
|
|
dartPlatformUris.add(uri);
|
|
} else if (uri.toString().endsWith(".dart")) {
|
|
otherDartUris.add(uri);
|
|
} else {
|
|
otherNonDartUris.add(uri);
|
|
}
|
|
}
|
|
|
|
// * Everything in frontEndUris is okay --- the frontend can import itself.
|
|
// * Everything in kernel is okay --- the frontend is allowed to
|
|
// import package:kernel.
|
|
// * For other entries, remove allowlisted entries.
|
|
// * Everything else is an error.
|
|
|
|
// Remove white-listed non-dart files.
|
|
otherNonDartUris.remove(dotPackagesUri);
|
|
otherNonDartUris.remove(repoDir.resolve("sdk/lib/libraries.json"));
|
|
otherNonDartUris.remove(repoDir.resolve(".dart_tool/package_config.json"));
|
|
|
|
// Remove white-listed dart files.
|
|
for (String s in allowlistedExternalDartFiles) {
|
|
otherDartUris.remove(repoDir.resolve(s));
|
|
}
|
|
|
|
if (otherNonDartUris.isNotEmpty || otherDartUris.isNotEmpty) {
|
|
print("The following files was imported without being allowlisted:");
|
|
for (Uri uri in otherNonDartUris) {
|
|
print(" - $uri");
|
|
}
|
|
for (Uri uri in otherDartUris) {
|
|
print(" - $uri");
|
|
}
|
|
exitCode = 1;
|
|
}
|
|
}
|
|
|
|
CompilerOptions getOptions() {
|
|
// Compile sdk because when this is run from a lint it uses the checked-in sdk
|
|
// and we might not have a suitable compiled platform.dill file.
|
|
Uri sdkRoot = computePlatformBinariesLocation(forceBuildDir: true);
|
|
CompilerOptions options = new CompilerOptions()
|
|
..sdkRoot = sdkRoot
|
|
..compileSdk = true
|
|
..target = new VmTarget(new TargetFlags())
|
|
..librariesSpecificationUri = repoDir.resolve("sdk/lib/libraries.json")
|
|
..omitPlatform = true
|
|
..onDiagnostic = (DiagnosticMessage message) {
|
|
if (message.severity == Severity.error) {
|
|
Expect.fail(
|
|
"Unexpected error: ${message.plainTextFormatted.join('\n')}");
|
|
}
|
|
}
|
|
..environmentDefines = const {};
|
|
return options;
|
|
}
|