Skip to content
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

package-root bug in the vm: import a file with a 'package:' and a relative URL #3148

Closed
sigmundch opened this issue May 19, 2012 · 4 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior

Comments

@sigmundch
Copy link
Member

When importing a file with 'package:' the file should resolve to the same library as if it was imported with a relative URL. This is similar to issue #3147, but in the vm.

Example to repro this error:
./out/Release_ia32/dart --package-root=./ a.dart

Where a.dart is:

library("a");

import('b.dart', prefix: 'b1');

import('b.dart', prefix: 'b2');

import('package:b.dart', prefix: 'b3');

main() {
  print("${b1.x === b2.x} ${b1.x === b3.x}");
}

And b.dart is:

library("b");

class X {
  const X();
}

@sigmundch
Copy link
Member Author

On that example: the program should print "true true", but prints "true false"

@iposva-google
Copy link
Contributor

I think you are misunderstanding how URLs are handled. Assuming that a.dart is in the /home/sigmund/dart/app1 directory then the script is loaded from "file:///home/sigmund/dart/app1/a.dart", which means that resolving the relative URI "b.dart" from within that script loads "file:///home/sigmund/dart/app1/b.dart", which is demonstrably not equal to "package:b.dart" even if they end up loading the same file.

Similar rules exist when the browser loads resources from "file:///somepath" vs. "http://127.0.0.1/somepath" vs. "https://sigmunds_machine/somepath".


Added AsDesigned label.

@peter-ahe-google
Copy link
Contributor

Hi Siggi,

I think the VM handles this correctly. You must take care to load the script correctly. If you give a relative URI on the command line, the VM should create this URI for the script:

new Uri.fromString("file://${new File('.').fullPathSync()}/a.dart");

As Ivan says, this would be something like "file:///home/sigmund/dart/app1/a.dart".

If you give the VM an absolute URI, for example, package:a.dart, it handles this program as you expect:

$ ./xcodebuild/Release_ia32/dart --package-root=./ package:a.dart
true true
$

This is important as this allows moving a directory hierarchy to the package directory without having to rewrite relative URIs in the directory.

To understand why you have to specify the package URI on the command line, consider how URI resolution works. The example contains two URIs, "b.dart" and "package:b.dart". Each of these must be resolved according to a base URI (that is the URI of the current compilation unit).

new Uri.fromString("file:///home/sigmund/dart/app1/a.dart").resolve("b.dart") is "file:///home/sigmund/dart/app1/b.dart".

new Uri.fromString("file:///home/sigmund/dart/app1/a.dart").resolve("package:b.dart") is "package:b.dart".

BUT

new Uri.fromString("package:a.dart").resolve("b.dart") is "package:b.dart".

new Uri.fromString("package:a.dart").resolve("package:b.dart") is "package:b.dart".

You can read about how this works here: http://tools.ietf.org/html/rfc3986#section-5

In those terms, the VM uses a "Default Base URI" of file://CURRENT_DIRECTORY/ for resolving the URI on the command line, and that then defines the "Base URI from the Retrieval URI" for resolving URIs in #import and #source tags.

Cheers,
Peter

@sigmundch
Copy link
Member Author

Thanks for the clarification!

I also over simplified my example. I really care about the situation you describe (running 'package:a.dart') or equivalently if I add a third file 'c.dart' with this contents:

#library('c');
#import('package:a.dart');

Then I expect to have 'true true' when I call
./out/Release_ia32/dart --package-root=./ c.dart

This is working as intended in the VM, seems broken in frog (I'll update that bug).

@sigmundch sigmundch added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior labels May 21, 2012
copybara-service bot pushed a commit that referenced this issue Sep 28, 2021
Changes:
```
> git log --format="%C(auto) %h %s" 15a46117da29cc572fba620241c83a2117cdae09..a817863ee93241ff36fce6856c6d12fd8fde0907
 a817863e Use pool for file reading (#3156)
 59237e29 Don't ask packageLister for availabe versions (#3151)
 f2f86c01 Fix analyze errors (#3148)
 39c9779c Environment credentials support (#3115)
 f0020823 Improved handling for authentication errors (#3120)
 1bb9f923 Migrate ignore.dart to null-safety (#3142)

```

Change-Id: I01d6637e3de8e523596394383393f5eda1a728c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214804
Reviewed-by: Jonas Jensen <[email protected]>
Commit-Queue: Jonas Jensen <[email protected]>
copybara-service bot pushed a commit that referenced this issue Sep 9, 2022
…1 revision)

https://dart.googlesource.com/dartdoc/+log/aba679e24310..401a7e8adfa2

2022-09-09 [email protected] Improve assertion message in typedef issue with flutter (#3148)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/dart-doc-dart-sdk
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Dart Documentation Generator: https://github.com/dart-lang/dartdoc/issues
To file a bug in Dart SDK: https://github.com/dart-lang/sdk/issues

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

Tbr: [email protected]
Change-Id: I1ce79666bdee12f63f131d66a7f5796ee0a95814
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258620
Commit-Queue: DEPS Autoroller <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
Commit-Queue: Nate Bosch <[email protected]>
This issue was closed.
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. closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

3 participants