-
Notifications
You must be signed in to change notification settings - Fork 6k
[macOS] Set correct Platform.executable (argv[0]) #33128
[macOS] Set correct Platform.executable (argv[0]) #33128
Conversation
Oops, I always thought it was just dropped. In my defense, I don't think it was documented at all when I started using it :) |
|
Cleanups pushed. PTAL. |
Agreed and done. For any future archaeologists who dig this up, it's worth noting that the path returned by
I believe this is is still acceptable because it neither violates the Platform.executable docs, nor the embedder API docs with regards to the command-line arguments. |
loic-sharma
left a comment
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
stuartmorgan-g
left a comment
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
Previously, in the macOS embedder, we set the first argument of FlutterProjectArgs::command_line_argv to the hardcoded string "placeholder". As per the documentation of embedder.h, this argument is required to be the executable name, if present. This value is available to Flutter applications via Platform.executable in dart:io. This corrects the value to be the executable name for the current process. In the case where the correct name cannot be determined, we fall back to "Flutter" in order to avoid violating the (non-nullable) type annoation on Platform.executable. Since the string pointers in command_line_argv are required to be valid for the lifetime of the Dart runtime, and since the name of the executable associated with this process will not change over the lifetime of the app, we hold this in a static. This also adds the internal method [FlutterEngine executableName] in order to facilitate testing. See: https://api.flutter.dev/flutter/dart-io/Platform/executable.html See: dart-lang/sdk#48427 Issue: flutter/flutter#83921
When testing executable name for macOS Flutter apps, verify that it's not the empty string. This was review feedback on #33128 which was labelled 'waiting for tree to go green' but it was merged by the bot before I had a chance to push the update. Issue: flutter/flutter#83921
Previously, in the macOS embedder, we set the first argument of
FlutterProjectArgs::command_line_argv to the hardcoded string
"placeholder". As per the documentation of embedder.h, this argument is
required to be the executable name, if present. This value is available
to Flutter applications via Platform.executable in dart:io.
This corrects the value to be the executable name for the current
process. In the case where the correct name cannot be determined, we
fall back to "Flutter" in order to avoid violating the (non-nullable)
type annoation on Platform.executable.
Since the string pointers in command_line_argv are required to
be valid for the lifetime of the Dart runtime, and since the name of the
executable associated with this process will not change over the
lifetime of the app, we hold this in a static.
This also adds the internal method [FlutterEngine executableName] in
order to facilitate testing.
See: https://api.flutter.dev/flutter/dart-io/Platform/executable.html
See: dart-lang/sdk#48427
Issue: flutter/flutter#83921
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.