-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Fix bug when resolving entrypoint against package config #81248
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
Conversation
packages/flutter_tools/test/general.shard/build_system/targets/dart_plugin_registrant_test.dart
Outdated
Show resolved
Hide resolved
@@ -45,9 +45,9 @@ class DartPluginRegistrantTarget extends Target { | |||
final String targetFile = environment.defines[kTargetFile] ?? | |||
environment.fileSystem.path.join('lib', 'main.dart'); | |||
final File mainFile = environment.fileSystem.file(targetFile); | |||
final Uri mainFileUri = mainFile.uri; | |||
assert(packagesFile.path != null); | |||
final Uri mainFileUri = mainFile.absolute.uri; | |||
final String mainUri = packageConfig.toPackageUri(mainFileUri)?.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the main file URI is not in any package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. flutter run --target some/absolute/path/test/test_foo.dart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we validate the target earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats not an invalid target though - you'd need to fallback to embedding an absolute URI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure what you mean - if the package config fails to resolve the absolute file URI to a package URI, it only means that the file was not under any of the defined package roots. Its still an otherwise valid target file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see what you mean, import 'package:<package-name>/some/absolute/path/test/test_foo.dart
in this case, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
import 'file:///C:/Users/Jonah/flutter/packages/flutter_tools/bin/flutter_tools.dart';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally valid (well, on my computer at least)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I cleaned up the test file a bit, and added the new test. PTAL
…/dart_plugin_registrant_test.dart Co-authored-by: Jonah Williams <jonahwilliams@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It should use the target's absolute path URI as opposed to the relative one.
The relative path produces
null
in all cases.