Skip to content

Isolate.resolvePackageUri has inconsistent behavior when called from a script launched via relative path #32901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jcollins-g opened this issue Apr 16, 2018 · 9 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jcollins-g
Copy link
Contributor

jcollins-g commented Apr 16, 2018

When running in the VM with preview-dart-2, resolvePackageUri sometimes doesn't resolve to a file URI correctly unless the script was launched with an absolute path.

demo:

/tmp/resolve
$ cat pubspec.yaml
name: resolvedemo
version: 0.1.0
/tmp/resolve
$ pub get
Resolving dependencies... 
Got dependencies!
/tmp/resolve
$ cat bin/resolve.dart 
import "dart:isolate" show Isolate;

main() {
  Uri theUri = Uri.parse('package:resolvedemo/test.dart');
  print('theUri: $theUri');
  Isolate.resolvePackageUri(theUri).then((u) => print ('resolved Uri: $u'));
}

/tmp/resolve
$ dart `pwd`/bin/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///tmp/resolve/lib/test.dart
/tmp/resolve
$ dart bin/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///tmp/resolve/lib/test.dart
/tmp/resolve
$ dart --preview-dart-2 `pwd`/bin/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///tmp/resolve/lib/test.dart
/tmp/resolve
$ dart --preview-dart-2 bin/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: lib/test.dart
/tmp/resolve
$

I believe all four runs of the program should have the same output.
(edit: refined example for clarity)

@jcollins-g
Copy link
Contributor Author

This seems to be substantially worse on windows, with the resolution failing completely in all cases:

screenshot from 2018-04-16 13-55-01

@bwilkerson bwilkerson added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Apr 16, 2018
@jcollins-g
Copy link
Contributor Author

This blocks dart-lang/dartdoc#1668.

@lrhn
Copy link
Member

lrhn commented Apr 17, 2018

The behavior is correct, but it might not be useful.

The location of the .packages file is found relative to the entry point. There is no specification of what the result of that is, just that it finds the file, so choosing a relative path for the location of the .packages file is not wrong.
The .packages file contains a relative location that is interpreted as relative to the .packages file.
So, when the entry-point is relative, everything after that stays relative.

I think we should just decide that the path of the .packages file must be resolved into an absolute URI before resolving a relative path against it. That would likely be done by resolving the relative URI against the current working directory (aka, Uri.base). That would avoid resolving a relative URI against another relative URI, which is generally a code smell.

@jcollins-g
Copy link
Contributor Author

@lrhn Resolving to an absolute file URI would work for me. Also I'll mention that I don't think returning null here is correct on Windows -- no matter what we decide, that should be fixed.

@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 18, 2018
@lrhn
Copy link
Member

lrhn commented Apr 18, 2018

Returning null does seem like a bug.

@jcollins-g
Copy link
Contributor Author

The returning null on Windows is still a blocking bug for Dartdoc under Dart 2.0.

@srawlins
Copy link
Member

I get null on Macos if I am in a directory below the .packages file. With the same layout as @jcollins-g 's above:

$ cd bin/

$ pwd
/tmp/resolve/bin

$ dart `pwd`/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///tmp/resolve/lib/test.dart

$ dart resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///private/tmp/resolve/lib/test.dart

$ dart --preview-dart-2 `pwd`/resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: file:///tmp/resolve/lib/test.dart

$ dart --preview-dart-2 resolve.dart
theUri: package:resolvedemo/test.dart
resolved Uri: null

The second example returns file:///private/tmp/resolve/lib/test.dart, a bit of a head scratcher..., and the fourth example returns null. ☹️

@dgrove dgrove added the P1 A high priority bug; for example, a single project is unusable or has many test failures label May 21, 2018
@dgrove dgrove added this to the Dart2 Pre-Release 1.0 milestone May 21, 2018
@a-siva
Copy link
Contributor

a-siva commented May 24, 2018

I am able to reproduce the behavior that @srawlins reports on linux too.

@a-siva
Copy link
Contributor

a-siva commented May 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants