diff --git a/examples/BUILD.gn b/examples/BUILD.gn index eed92229cc..fdff31a5c9 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -727,6 +727,8 @@ if (is_linux || is_win) { "../rtc_tools:command_line_parser", "../system_wrappers:field_trial", "../test:field_trial", + "//third_party/abseil-cpp/absl/flags:flag", + "//third_party/abseil-cpp/absl/flags:parse", ] } rtc_executable("relayserver") { diff --git a/examples/DEPS b/examples/DEPS index 114cda384b..1604a6a513 100644 --- a/examples/DEPS +++ b/examples/DEPS @@ -10,4 +10,7 @@ include_rules = [ "+sdk/objc", "+system_wrappers/include", "+third_party/libyuv", + + # Abseil flags are allowed in tests and tools. + "+absl/flags", ] diff --git a/examples/peerconnection/server/main.cc b/examples/peerconnection/server/main.cc index 79b2c2ce3b..9be7685660 100644 --- a/examples/peerconnection/server/main.cc +++ b/examples/peerconnection/server/main.cc @@ -19,14 +19,15 @@ #include #include +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #include "examples/peerconnection/server/data_socket.h" #include "examples/peerconnection/server/peer_channel.h" -#include "rtc_base/flags.h" -#include "rtc_tools/simple_command_line_parser.h" #include "system_wrappers/include/field_trial.h" #include "test/field_trial.h" -WEBRTC_DEFINE_string( +ABSL_FLAG( + std::string, force_fieldtrials, "", "Field trials control experimental features. This flag specifies the field " @@ -34,6 +35,7 @@ WEBRTC_DEFINE_string( "--force_fieldtrials=WebRTC-FooFeature/Enabled/ " "will assign the group Enabled to field trial WebRTC-FooFeature. Multiple " "trials are separated by \"/\""); +ABSL_FLAG(int, port, 8888, "default: 8888"); static const size_t kMaxConnections = (FD_SETSIZE - 2); @@ -63,25 +65,17 @@ void HandleBrowserRequest(DataSocket* ds, bool* quit) { } int main(int argc, char* argv[]) { - std::string program_name = argv[0]; - std::string usage = "Example usage: " + program_name + " --port=8888"; - webrtc::test::CommandLineParser parser; - parser.Init(argc, argv); - parser.SetUsageMessage(usage); - parser.SetFlag("port", "8888"); - parser.SetFlag("help", "false"); - parser.ProcessFlags(); - - if (parser.GetFlag("help") == "true") { - parser.PrintUsageMessage(); - return 0; - } + absl::ParseCommandLine(argc, argv); + // TODO(bugs.webrtc.org/10616): Add program usage message when Abseil + // flags supports it. + // std::string usage = "Example usage: " + program_name + " --port=8888"; // InitFieldTrialsFromString stores the char*, so the char array must outlive // the application. - webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials); + webrtc::field_trial::InitFieldTrialsFromString( + absl::GetFlag(FLAGS_force_fieldtrials).c_str()); - int port = strtol((parser.GetFlag("port")).c_str(), NULL, 10); + int port = absl::GetFlag(FLAGS_port); // Abort if the user specifies a port that is outside the allowed // range [1, 65535].