-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Provide a canonical way to find the Dart SDK root #16994
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
Comments
Konstantin/Rico- I'm wondering if there are some tricks that I'm missing for how to do this. Is there code elsewhere either for Analyzer tests or for other tests which finds the Dart SDK folder? I just seem to be running into many different configurations which is breaking the detection. |
Yes, had this question for months. |
Yeah, I have similar hackish code at: (Was also running into problems when executing from 'dart' when dart was on the path). Pub also has similar workarounds spread across: |
Removed Area-Library label. |
Removed Area-IO label. |
This comment was originally written by @zoechi See also http://dartbug.com/21225 |
Issue #21783 has been merged into this issue. |
I don't think this is something which fits into dart:io. dart:io has no awareness of a Dart SDK, it is part of the standalone dart executable. So adding specific logic trying to "guess" the SDK location that it might be part of using a number of probes is not well suited for dart:io. Looking at the code in issue #21783, why is there not an initial check for the DART_SDK environment variable? Maybe requiring DART_SDK to be set and failing otherwise is a better approach. Removed Type-Defect, Library-IO labels. |
This comment was originally written by @zoechi
If there is code in That there is no simple and official way to do this, caused/causes troubles with every package that needs access to the SDK. |
I agree that this should be part of dart:io. Note that I don't think the logic should be guessed by dart:io, I believe that because dart:io and the VM are built as part of the SDK, they should encode what is their relative position to the sdk sources (this might be a simple string added by our build bots, similar to how we attach the SDK version number) Then it should be possible to derive the exact location combining that with the location of the dart executable (resolving any symlinks first, as it's common for some installations of dart to add this level of indirection) Thoughts? |
The VM might not have an SDK. |
Another interested party here. Every service that builds on the analyzer is repeating and perpetuating these hacks. (And I'm about to embark on another!) +1 to Siggi's points on baking in at build time rather than guessing as well. As for the VM not having an SDK, I get that this might be a little bothersome from an API hygiene perspective but in practice I don't think this will detract from the value added. |
This comment was originally written by [email protected]
The original problem is about accessing the "dart:" sources. The proposed solution of locating the SDK seems like it's just one way to solve that problem. If that's the only thing we need the SDK directory for, maybe we should just have an API for accessing "dart:" sources directly? |
Lasse - you bring a very good point, but maybe there is an option in the middle, for example, could we provide a way to detect when the executable lives in the default SDK location? One possible way to address this would be an API as follows: class Platform { /// The fully resolved path to the Dart executable. Similar to [executable], except /// Returns whether [executablePath] is in the default SDK location. This will be true /// The path to the SDK home relative from the default location of the Dart binary in } There are actually many combinations of APIs we can come up with, but let me explain what are the issues behind we are trying to address: (b) it's adhoc to determine what is the root of the SDK, even when the Dart binary is inside the SDK. Today, we guess it by searching for an internal SDK file (c) we can't control that the vm will be inside the SDK default location. This is basically your concern, I propose that we just provide a way to detect this (isExecutableInDefaultSdkLocation). Thoughts? |
This is something which will fit nicely in a package. dart:io should already have all the API needed. Running main() => new File(Platform.executable).resolveSymbolicLinks().then(print); prints the path to the Dart executable. |
Does this work when that code is served up via a transformer? |
Platform.executable doesn't include the ".exe" extension on Windows, which causes symlink resolution for it to fail. Closes #133 [email protected] Review URL: https://codereview.chromium.org//1165313002.
The change to Platform.excutable in e03ab17 was a breaking change and it has been reverted. A new getter Platform.resolvedExecutable has been added to provide the the fully qualified path of the executable. BUG=#16994 [email protected], [email protected], [email protected] Review URL: https://codereview.chromium.org//1180623006.
The change to Platform.excutable in e03ab17 was a breaking change and it has been reverted. A new getter Platform.resolvedExecutable has been added to provide the the fully qualified path of the executable. BUG=#16994 [email protected], [email protected], [email protected] Review URL: https://codereview.chromium.org//1180623006.
After a number of different changes we have decided the following:
This landed on master, c05c8c6, and will go into 1.11, where is now in 1.11.0-dev.5.3, c0e90cb. |
Thanks for the update! |
In the development of pub transformers which resolve Dart source code, in order to resolve all of the code the Analyzer needs a path to the Dart SDK filter (in order to find the sources for dart: source code).
Unfortunately there does not seem to be a good way to find the SDK folder for the current Dart executable. I do have a user-configurable path, but this falls down when the code is used in unit-tests, transformers and other portable locations (location of SDK can differ across machines and test configurations).
Additional consideration- it might be good to look at something like .NET's reference assemblies which has a fixed root folder containing all versions installed, providing a structured environment for side-by-side installation of runtimes.
The text was updated successfully, but these errors were encountered: