diff --git a/engine/src/flutter/benchmarking/benchmarking.cc b/engine/src/flutter/benchmarking/benchmarking.cc index 2f2125464f..03e32e070c 100644 --- a/engine/src/flutter/benchmarking/benchmarking.cc +++ b/engine/src/flutter/benchmarking/benchmarking.cc @@ -14,7 +14,7 @@ namespace benchmarking { int Main(int argc, char** argv) { fml::InstallCrashHandler(); #if !defined(FML_OS_ANDROID) - fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); + fml::CommandLine cmd = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); std::string icudtl_path = cmd.GetOptionValueWithDefault("icu-data-file-path", "icudtl.dat"); fml::icu::InitializeICU(icudtl_path); diff --git a/engine/src/flutter/flow/flow_run_all_unittests.cc b/engine/src/flutter/flow/flow_run_all_unittests.cc index e2106829a8..eb7a58b5a8 100644 --- a/engine/src/flutter/flow/flow_run_all_unittests.cc +++ b/engine/src/flutter/flow/flow_run_all_unittests.cc @@ -13,7 +13,7 @@ int main(int argc, char** argv) { fml::InstallCrashHandler(); testing::InitGoogleTest(&argc, argv); - fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); + fml::CommandLine cmd = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); #if defined(OS_FUCHSIA) flutter::SetGoldenDir(cmd.GetOptionValueWithDefault( diff --git a/engine/src/flutter/fml/command_line.h b/engine/src/flutter/fml/command_line.h index c3f27803b9..c920da4023 100644 --- a/engine/src/flutter/fml/command_line.h +++ b/engine/src/flutter/fml/command_line.h @@ -222,11 +222,32 @@ inline CommandLine CommandLineFromIteratorsWithArgv0(const std::string& argv0, return builder.Build(); } +// Builds a |CommandLine| by obtaining the arguments of the process using host +// platform APIs. The resulting |CommandLine| will be encoded in UTF-8. +// Returns an empty optional if this is not supported on the host platform. +// +// This can be useful on platforms where argv may not be provided as UTF-8. +std::optional CommandLineFromPlatform(); + // Builds a |CommandLine| from the usual argc/argv. inline CommandLine CommandLineFromArgcArgv(int argc, const char* const* argv) { return CommandLineFromIterators(argv, argv + argc); } +// Builds a |CommandLine| by first trying the platform specific implementation, +// and then falling back to the argc/argv. +// +// If the platform provides a special way of getting arguments, this method may +// discard the values passed in to argc/argv. +inline CommandLine CommandLineFromPlatformOrArgcArgv(int argc, + const char* const* argv) { + auto command_line = CommandLineFromPlatform(); + if (command_line.has_value()) { + return *command_line; + } + return CommandLineFromArgcArgv(argc, argv); +} + // Builds a |CommandLine| from an initializer list of |std::string|s or things // that implicitly convert to |std::string|. template @@ -240,13 +261,6 @@ inline CommandLine CommandLineFromInitializerList( // outlined at the top of this file. std::vector CommandLineToArgv(const CommandLine& command_line); -// Builds a |CommandLine| by obtaining the arguments of the process using host -// platform APIs. The resulting |CommandLine| will be encoded in UTF-8. -// Returns an empty optional if this is not supported on the host platform. -// -// This can be useful on platforms where argv may not be provided as UTF-8. -std::optional CommandLineFromPlatform(); - } // namespace fml #endif // LIB_FML_COMMAND_LINE_H_ diff --git a/engine/src/flutter/impeller/blobcat/blobcat_main.cc b/engine/src/flutter/impeller/blobcat/blobcat_main.cc index e62814d832..16a128a01d 100644 --- a/engine/src/flutter/impeller/blobcat/blobcat_main.cc +++ b/engine/src/flutter/impeller/blobcat/blobcat_main.cc @@ -49,7 +49,7 @@ bool Main(const fml::CommandLine& command_line) { } // namespace impeller int main(int argc, char const* argv[]) { - return impeller::Main(fml::CommandLineFromArgcArgv(argc, argv)) + return impeller::Main(fml::CommandLineFromPlatformOrArgcArgv(argc, argv)) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/engine/src/flutter/impeller/compiler/impellerc_main.cc b/engine/src/flutter/impeller/compiler/impellerc_main.cc index 2c0b6cf715..0c6df17fcf 100644 --- a/engine/src/flutter/impeller/compiler/impellerc_main.cc +++ b/engine/src/flutter/impeller/compiler/impellerc_main.cc @@ -226,9 +226,8 @@ bool Main(const fml::CommandLine& command_line) { } // namespace impeller int main(int argc, char const* argv[]) { - std::optional command_line = fml::CommandLineFromPlatform(); - if (!command_line) { - command_line = fml::CommandLineFromArgcArgv(argc, argv); - } - return impeller::compiler::Main(*command_line) ? EXIT_SUCCESS : EXIT_FAILURE; + return impeller::compiler::Main( + fml::CommandLineFromPlatformOrArgcArgv(argc, argv)) + ? EXIT_SUCCESS + : EXIT_FAILURE; } diff --git a/engine/src/flutter/shell/testing/tester_main.cc b/engine/src/flutter/shell/testing/tester_main.cc index 9aec07a52e..443e22b3a5 100644 --- a/engine/src/flutter/shell/testing/tester_main.cc +++ b/engine/src/flutter/shell/testing/tester_main.cc @@ -372,7 +372,7 @@ int main(int argc, char* argv[]) { dart::bin::SetExecutableName(argv[0]); dart::bin::SetExecutableArguments(argc - 1, argv); - auto command_line = fml::CommandLineFromArgcArgv(argc, argv); + auto command_line = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); if (command_line.HasOption(flutter::FlagForSwitch(flutter::Switch::Help))) { flutter::PrintUsage("flutter_tester"); diff --git a/engine/src/flutter/testing/run_all_unittests.cc b/engine/src/flutter/testing/run_all_unittests.cc index e6baa80f37..ae5105fc21 100644 --- a/engine/src/flutter/testing/run_all_unittests.cc +++ b/engine/src/flutter/testing/run_all_unittests.cc @@ -18,7 +18,7 @@ #endif // FML_OS_IOS std::optional GetTestTimeoutFromArgs(int argc, char** argv) { - const auto command_line = fml::CommandLineFromArgcArgv(argc, argv); + const auto command_line = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); std::string timeout_seconds; if (!command_line.GetOptionValue("timeout", &timeout_seconds)) { diff --git a/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc b/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc index 6e7f2d8fb0..9f4027e2a5 100644 --- a/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc +++ b/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc @@ -23,7 +23,7 @@ // We will use a custom main to allow custom font directories for consistency. int main(int argc, char** argv) { ::benchmark::Initialize(&argc, argv); - fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); + fml::CommandLine cmd = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); txt::SetCommandLine(cmd); txt::SetFontDir(flutter::testing::GetFixturesPath()); if (txt::GetFontDir().length() <= 0) { diff --git a/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc b/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc index 0e791c3c67..f0d2bcf54f 100644 --- a/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc +++ b/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc @@ -26,7 +26,7 @@ int main(int argc, char** argv) { fml::InstallCrashHandler(); - fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); + fml::CommandLine cmd = fml::CommandLineFromPlatformOrArgcArgv(argc, argv); txt::SetCommandLine(cmd); txt::SetFontDir(flutter::testing::GetFixturesPath()); if (txt::GetFontDir().length() <= 0) {