@@ -10,52 +10,61 @@ import 'package:front_end/src/api_prototype/compiler_options.dart';
1010import 'package:front_end/src/api_prototype/standard_file_system.dart' ;
1111import 'package:front_end/src/base/compiler_context.dart' ;
1212import 'package:front_end/src/base/file_system_dependency_tracker.dart' ;
13+ import 'package:front_end/src/base/import_chains.dart' ;
1314import 'package:front_end/src/base/processed_options.dart' ;
1415import 'package:front_end/src/base/ticker.dart' ;
1516import 'package:front_end/src/base/uri_translator.dart' ;
17+ import 'package:front_end/src/builder/library_builder.dart' ;
1618import 'package:front_end/src/compute_platform_binaries_location.dart'
1719 show computePlatformBinariesLocation;
1820import 'package:front_end/src/dill/dill_target.dart' ;
1921import 'package:front_end/src/kernel/kernel_target.dart' ;
2022import 'package:kernel/kernel.dart' ;
2123import 'package:kernel/target/targets.dart' ;
24+ import 'package:package_config/src/package_config.dart' ;
2225import 'package:vm/modular/target/vm.dart' show VmTarget;
2326
2427import 'utils/io_utils.dart' show computeRepoDirUri;
2528
2629final Uri repoDir = computeRepoDirUri ();
2730
2831Set <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.
6069Future <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