Skip to content

New API: dart:io.Platform.resolvedDartTool #60724

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

Open
srawlins opened this issue May 14, 2025 · 3 comments
Open

New API: dart:io.Platform.resolvedDartTool #60724

srawlins opened this issue May 14, 2025 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented May 14, 2025

Developers sometimes rely on Platform.resolvedExecutable to find the "running" dart command on which a script is running. Then you can run, for example, Process.start(Platform.resolvedExecutable, ['pub', 'get']). This works when the running script is being run as JIT, with dart or dart.exe as the resolved executable.

But for a script which is compiled with AOT, Platform.resolvedExecutable resolves to dartaotruntime. And dartaotruntime pub get does not work. In order to compatibly use a dart binary, for example to run pub get, you can use the dart sibling to Platform.resolvedExecutable (or the dart.exe sibling).

It would be nice to expose this executable as a static getter on Platform. Maybe dartExecutable or dartTool (dart --help describes itself as a "utility". The website docs call dart "The Dart command-line tool".

Developers of analyzer plugins may need to be aware of this as analyzer is compiled AOT. See #50498.

@srawlins
Copy link
Member Author

CC @a-siva

@a-siva
Copy link
Contributor

a-siva commented May 14, 2025

//cc @lrhn

@a-siva a-siva added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug labels May 14, 2025
@lrhn
Copy link
Member

lrhn commented May 15, 2025

That sounds like an "it depends".

If you do dart compile exe you can no longer assume that there is any Dart SDK available when the exe runs.

If you compile to an AoR snapshot, and run it with dartaotruntime, then presumably you have an SDK available, so you can find the SDK and the dart runtime three.

Which means that Platform is not the right place for it. The Platform is always there, the SDK might not be.

Consider instead having a helper library or package that can be used to find the Dart SDK, or it's features, and which only works (and may only compile) when run through an SDK.
(Make it be dart:sdk and make it not be there when AoT compiled to exe, or to JS, fx.)

The library can then interact with the runtime to find the SDK, which works when the runtime is from the SDK.

(This reminds me of a similar issue about finding the file path of the entry point script. That also only makes sense when you are running from source, or close to source, and not of you compile to exe.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants