Skip to content

Commit 397a397

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Improve deps test
Change-Id: I8b94f93a57e600d2b4925faf635690229c605ac8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400642 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 9b11bf4 commit 397a397

File tree

3 files changed

+73
-46
lines changed

3 files changed

+73
-46
lines changed

pkg/front_end/lib/src/base/import_chains.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ abstract class LoadedLibraries {
100100

101101
class LoadedLibrariesImpl implements LoadedLibraries {
102102
/// The library of the compilation entry point.
103-
final CompilationUnit rootCompilationUnit;
103+
final List<CompilationUnit> rootCompilationUnits;
104104
final Map<Uri, CompilationUnit> compilationUnits = {};
105105

106-
// TODO(johnniwinther): Support multiple entry-points.
107106
LoadedLibrariesImpl(
108-
this.rootCompilationUnit, Iterable<CompilationUnit> compilationUnits) {
107+
this.rootCompilationUnits, Iterable<CompilationUnit> compilationUnits) {
109108
compilationUnits.forEach((CompilationUnit compilationUnit) {
110109
this.compilationUnits[compilationUnit.importUri] = compilationUnit;
111110
});
@@ -183,12 +182,14 @@ class LoadedLibrariesImpl implements LoadedLibraries {
183182
return;
184183
}
185184

186-
computeSuffixes(rootCompilationUnit, const Link<Uri>());
185+
for (CompilationUnit rootCompilationUnit in rootCompilationUnits) {
186+
computeSuffixes(rootCompilationUnit, const Link<Uri>());
187+
}
187188
}
188189

189190
@override
190191
String toString() =>
191-
'root=$rootCompilationUnit,compilationUnits=${compilationUnits.keys}';
192+
'roots=$rootCompilationUnits,compilationUnits=${compilationUnits.keys}';
192193
}
193194

194195
/// [CodeLocation] divides uris into different classes.

pkg/front_end/lib/src/source/source_loader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ severity: $severity
11911191
templateUnavailableDartLibrary.withArguments(importUri);
11921192
if (rootLibrary != null) {
11931193
loadedLibraries ??=
1194-
new LoadedLibrariesImpl(rootLibrary, compilationUnits);
1194+
new LoadedLibrariesImpl([rootLibrary], compilationUnits);
11951195
Set<String> importChain = computeImportChainsFor(
11961196
rootLibrary.importUri, loadedLibraries, importUri,
11971197
verbose: false);

pkg/front_end/test/deps_git_test.dart

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,61 @@ import 'package:front_end/src/api_prototype/compiler_options.dart';
1010
import 'package:front_end/src/api_prototype/standard_file_system.dart';
1111
import 'package:front_end/src/base/compiler_context.dart';
1212
import 'package:front_end/src/base/file_system_dependency_tracker.dart';
13+
import 'package:front_end/src/base/import_chains.dart';
1314
import 'package:front_end/src/base/processed_options.dart';
1415
import 'package:front_end/src/base/ticker.dart';
1516
import 'package:front_end/src/base/uri_translator.dart';
17+
import 'package:front_end/src/builder/library_builder.dart';
1618
import 'package:front_end/src/compute_platform_binaries_location.dart'
1719
show computePlatformBinariesLocation;
1820
import 'package:front_end/src/dill/dill_target.dart';
1921
import 'package:front_end/src/kernel/kernel_target.dart';
2022
import 'package:kernel/kernel.dart';
2123
import 'package:kernel/target/targets.dart';
24+
import 'package:package_config/src/package_config.dart';
2225
import 'package:vm/modular/target/vm.dart' show VmTarget;
2326

2427
import 'utils/io_utils.dart' show computeRepoDirUri;
2528

2629
final Uri repoDir = computeRepoDirUri();
2730

2831
Set<String> allowlistedExternalDartFiles = {
29-
"third_party/pkg/package_config/lib/package_config.dart",
30-
"third_party/pkg/package_config/lib/package_config_types.dart",
31-
"third_party/pkg/package_config/lib/src/discovery.dart",
32-
"third_party/pkg/package_config/lib/src/errors.dart",
33-
"third_party/pkg/package_config/lib/src/package_config_impl.dart",
34-
"third_party/pkg/package_config/lib/src/package_config_io.dart",
35-
"third_party/pkg/package_config/lib/src/package_config_json.dart",
36-
"third_party/pkg/package_config/lib/src/package_config.dart",
37-
"third_party/pkg/package_config/lib/src/packages_file.dart",
38-
"third_party/pkg/package_config/lib/src/util.dart",
39-
40-
// TODO(johnniwinther): Fix to allow dependency of package:package_config.
41-
"third_party/pkg/package_config/lib/src/util_io.dart",
42-
4332
// TODO(CFE-team): These files should not be included.
4433
// The package isn't even in pubspec.yaml.
34+
// They're included via at least
35+
// _fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
4536
"pkg/meta/lib/meta.dart",
4637
"pkg/meta/lib/meta_meta.dart",
4738
};
4839

49-
Set<String> allowlistedThirdPartyPackages = {
40+
Set<String> allowedPackages = {
41+
"front_end",
42+
"kernel",
43+
"_fe_analyzer_shared",
44+
"package_config",
45+
"macros",
46+
"_macros",
47+
// package:front_end imports package:yaml for the 'dynamic modules'
48+
// experiment.
5049
"yaml",
51-
// package:yaml dependencies
52-
"core/pkgs/collection",
53-
"core/pkgs/path",
50+
// package:yaml uses package:source_span, package:string_scanner and
51+
// package:collection.
5452
"source_span",
5553
"string_scanner",
54+
"collection",
55+
// package:source_span imports package:path.
56+
"path",
57+
// package:source_span imports package:term_glyph.
5658
"term_glyph",
5759
};
5860

61+
List<String> allowedRelativePaths = [
62+
// For VmTarget for macros.
63+
"pkg/vm/lib/modular/",
64+
// Platform.
65+
"sdk/lib/",
66+
];
67+
5968
/// Returns true on no errors and false if errors was found.
6069
Future<bool> main() async {
6170
Ticker ticker = new Ticker(isVerbose: false);
@@ -80,9 +89,21 @@ Future<bool> main() async {
8089
}
8190
}
8291

92+
LoadedLibraries? loadedLibraries;
93+
Map<Uri, Uri> fileUriToImportUri = {};
94+
List<String> allowedUriPrefixes = [
95+
for (String relativePath in allowedRelativePaths)
96+
repoDir.resolve(relativePath).toString()
97+
];
98+
8399
List<Uri> result = await CompilerContext.runWithOptions<List<Uri>>(options,
84100
(CompilerContext c) async {
85101
UriTranslator uriTranslator = await c.options.getUriTranslator();
102+
for (Package package in uriTranslator.packages.packages) {
103+
if (allowedPackages.contains(package.name)) {
104+
allowedUriPrefixes.add(package.packageUriRoot.toString());
105+
}
106+
}
86107
DillTarget dillTarget =
87108
new DillTarget(c, ticker, uriTranslator, c.options.target);
88109
KernelTarget kernelTarget =
@@ -98,32 +119,27 @@ Future<bool> main() async {
98119
kernelTarget.setEntryPoints(c.options.inputs);
99120
dillTarget.buildOutlines();
100121
await kernelTarget.loader.buildOutlines();
122+
123+
{
124+
List<CompilationUnit> compilationUnits =
125+
kernelTarget.loader.compilationUnits.toList(growable: false);
126+
List<CompilationUnit> rootCompilationUnits = [];
127+
Set<Uri> inputs = new Set.of(options.inputs);
128+
for (CompilationUnit unit in compilationUnits) {
129+
fileUriToImportUri[unit.fileUri] = unit.importUri;
130+
if (inputs.contains(unit.fileUri) || inputs.contains(unit.importUri)) {
131+
rootCompilationUnits.add(unit);
132+
}
133+
}
134+
loadedLibraries =
135+
new LoadedLibrariesImpl(rootCompilationUnits, compilationUnits);
136+
}
137+
101138
return new List<Uri>.from(tracker.dependencies);
102139
});
103140

104141
Set<Uri> otherDartUris = new Set<Uri>();
105142
Set<Uri> otherNonDartUris = new Set<Uri>();
106-
List<String> allowedRelativePaths = [
107-
// Front-end.
108-
"pkg/kernel/",
109-
"pkg/_fe_analyzer_shared/",
110-
// For VmTarget for macros.
111-
"pkg/vm/lib/modular/",
112-
// Platform.
113-
"sdk/lib/",
114-
"runtime/lib/",
115-
"runtime/bin/",
116-
// Macros.
117-
"pkg/macros",
118-
"pkg/_macros",
119-
for (String package in allowlistedThirdPartyPackages)
120-
"third_party/pkg/$package/",
121-
];
122-
List<String> allowedUriPrefixes = [
123-
frontendLibUri.toString(),
124-
for (String relativePath in allowedRelativePaths)
125-
repoDir.resolve(relativePath).toString()
126-
];
127143
for (Uri uri in result) {
128144
final String uriAsString = uri.toString();
129145
bool allowed = false;
@@ -145,7 +161,6 @@ Future<bool> main() async {
145161
// Remove allow-listed non-dart files.
146162
otherNonDartUris.remove(packageConfigUri);
147163
otherNonDartUris.remove(repoDir.resolve("sdk/lib/libraries.json"));
148-
otherNonDartUris.remove(repoDir.resolve(".dart_tool/package_config.json"));
149164

150165
// Remove allow-listed dart files.
151166
for (String s in allowlistedExternalDartFiles) {
@@ -160,6 +175,17 @@ Future<bool> main() async {
160175
}
161176
for (Uri uri in otherDartUris) {
162177
print(" - $uri");
178+
if (loadedLibraries != null) {
179+
Uri? importUri = fileUriToImportUri[uri];
180+
if (importUri != null) {
181+
Set<String> importChains = (computeImportChainsFor(
182+
Uri.parse("<entry>"), loadedLibraries!, importUri,
183+
verbose: false));
184+
for (String s in importChains) {
185+
print(" => $s");
186+
}
187+
}
188+
}
163189
}
164190
exitCode = 1;
165191
return false;

0 commit comments

Comments
 (0)