6
6
library vm.kernel_front_end;
7
7
8
8
import 'dart:async' ;
9
- import 'dart:io' show File, IOSink, IOException ;
9
+ import 'dart:io' show File, IOSink;
10
10
11
11
import 'package:args/args.dart' show ArgParser, ArgResults;
12
12
@@ -28,7 +28,6 @@ import 'package:front_end/src/api_unstable/vm.dart'
28
28
ExperimentalFlag,
29
29
FileSystem,
30
30
FileSystemEntity,
31
- FileSystemException,
32
31
NnbdMode,
33
32
ProcessedOptions,
34
33
Severity,
@@ -46,6 +45,7 @@ import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
46
45
import 'package:kernel/core_types.dart' show CoreTypes;
47
46
import 'package:kernel/kernel.dart' show loadComponentFromBinary;
48
47
import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
48
+ import 'package:package_config/package_config.dart' show loadPackageConfigUri;
49
49
50
50
import 'bytecode/bytecode_serialization.dart' show BytecodeSizeStatistics;
51
51
import 'bytecode/gen_bytecode.dart'
@@ -664,48 +664,22 @@ Future<Uri> asFileUri(FileSystem fileSystem, Uri uri) async {
664
664
}
665
665
666
666
/// Convert URI to a package URI if it is inside one of the packages.
667
+ /// TODO(alexmarkov) Remove this conversion after Fuchsia build rules are fixed.
667
668
Future <Uri > convertToPackageUri (
668
669
FileSystem fileSystem, Uri uri, Uri packagesUri) async {
669
670
if (uri.scheme == 'package' ) {
670
671
return uri;
671
672
}
672
673
// Convert virtual URI to a real file URI.
673
- String uriString = (await asFileUri (fileSystem, uri)).toString ();
674
- List <String > packages;
674
+ final Uri fileUri = await asFileUri (fileSystem, uri);
675
675
try {
676
- packages =
677
- await new File (( await asFileUri (fileSystem, packagesUri)). toFilePath ())
678
- . readAsLines () ;
679
- } on IOException {
676
+ final packageConfig =
677
+ await loadPackageConfigUri ( await asFileUri (fileSystem, packagesUri));
678
+ return packageConfig. toPackageUri (fileUri) ?? uri ;
679
+ } catch (_) {
680
680
// Can't read packages file - silently give up.
681
681
return uri;
682
682
}
683
- // file:///a/b/x/y/main.dart -> package:x.y/main.dart
684
- for (var line in packages) {
685
- if (line.isEmpty || line.startsWith ("#" )) {
686
- continue ;
687
- }
688
-
689
- final colon = line.indexOf (':' );
690
- if (colon == - 1 ) {
691
- continue ;
692
- }
693
- final packageName = line.substring (0 , colon);
694
- String packagePath;
695
- try {
696
- packagePath = (await asFileUri (
697
- fileSystem, packagesUri.resolve (line.substring (colon + 1 ))))
698
- .toString ();
699
- } on FileSystemException {
700
- // Can't resolve package path.
701
- continue ;
702
- }
703
- if (uriString.startsWith (packagePath)) {
704
- return Uri .parse (
705
- 'package:$packageName /${uriString .substring (packagePath .length )}' );
706
- }
707
- }
708
- return uri;
709
683
}
710
684
711
685
/// Write a separate kernel binary for each package. The name of the
0 commit comments