-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments
On that example: the program should print "true true", but prints "true false" |
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. |
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 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, |
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'); Then I expect to have 'true true' when I call This is working as intended in the VM, seems broken in frog (I'll update that bug). |
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]>
…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]>
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();
}
The text was updated successfully, but these errors were encountered: