[macOS] Set correct Platform.executable (argv[0]) (flutter/engine#33128)
This commit is contained in:
@@ -264,11 +264,9 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
|
||||
// TODO(stuartmorgan): Move internal channel registration from FlutterViewController to here.
|
||||
|
||||
// FlutterProjectArgs is expecting a full argv, so when processing it for
|
||||
// flags the first item is treated as the executable and ignored. Add a dummy
|
||||
// value so that all provided arguments are used.
|
||||
// The first argument of argv is required to be the executable name.
|
||||
std::vector<const char*> argv = {[self.executableName UTF8String]};
|
||||
std::vector<std::string> switches = _project.switches;
|
||||
std::vector<const char*> argv = {"placeholder"};
|
||||
std::transform(switches.begin(), switches.end(), std::back_inserter(argv),
|
||||
[](const std::string& arg) -> const char* { return arg.c_str(); });
|
||||
|
||||
@@ -517,6 +515,10 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
return _bridge;
|
||||
}
|
||||
|
||||
- (nonnull NSString*)executableName {
|
||||
return [[[NSProcessInfo processInfo] arguments] firstObject] ?: @"Flutter";
|
||||
}
|
||||
|
||||
- (void)updateWindowMetrics {
|
||||
if (!_engine || !_viewController.viewLoaded) {
|
||||
return;
|
||||
|
||||
@@ -39,6 +39,23 @@ TEST_F(FlutterEngineTest, CanLaunch) {
|
||||
EXPECT_TRUE(engine.running);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEngineTest, HasNonNullExecutableName) {
|
||||
// Launch the test entrypoint.
|
||||
FlutterEngine* engine = GetFlutterEngine();
|
||||
std::string executable_name = [[engine executableName] UTF8String];
|
||||
EXPECT_TRUE([engine runWithEntrypoint:@"executableNameNotNull"]);
|
||||
|
||||
// Block until notified by the Dart test of the value of Platform.executable.
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
AddNativeCallback("NotifyStringValue", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
|
||||
const auto dart_string = tonic::DartConverter<std::string>::FromDart(
|
||||
Dart_GetNativeArgument(args, 0));
|
||||
EXPECT_EQ(executable_name, dart_string);
|
||||
latch.Signal();
|
||||
}));
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(FlutterEngineTest, MessengerSend) {
|
||||
FlutterEngine* engine = GetFlutterEngine();
|
||||
EXPECT_TRUE([engine runWithEntrypoint:@"main"]);
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
*/
|
||||
@property(nonatomic) BOOL semanticsEnabled;
|
||||
|
||||
/**
|
||||
* The executable name for the current process.
|
||||
*/
|
||||
@property(nonatomic, readonly, nonnull) NSString* executableName;
|
||||
|
||||
/**
|
||||
* Informs the engine that the associated view controller's view size has changed.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
void signalNativeTest() native 'SignalNativeTest';
|
||||
@@ -9,6 +10,17 @@ void signalNativeTest() native 'SignalNativeTest';
|
||||
void main() {
|
||||
}
|
||||
|
||||
/// Notifies the test of a string value.
|
||||
///
|
||||
/// This is used to notify the native side of the test of a string value from
|
||||
/// the Dart fixture under test.
|
||||
void notifyStringValue(String s) native 'NotifyStringValue';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void executableNameNotNull() {
|
||||
notifyStringValue(Platform.executable);
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void canLogToStdout() {
|
||||
// Emit hello world message to output then signal the test.
|
||||
|
||||
Reference in New Issue
Block a user