Switch over from libbrillo flags to gflags am: 77cb1c6b3b am: 9e81651a6b am: f795272f34 am: 847190d961

Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/2518715

Change-Id: I0840816b1180618c35263bf6208b906b8847fd27
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/Android.bp b/Android.bp
index 833d766..c321de8 100644
--- a/Android.bp
+++ b/Android.bp
@@ -558,7 +558,10 @@
         "libupdate_engine_android_exports",
     ],
 
-    static_libs: ["libupdate_engine_android"],
+    static_libs: [
+        "libupdate_engine_android",
+        "libgflags",
+    ],
     required: [
         "cacerts_google",
         "otacerts",
@@ -858,6 +861,7 @@
         "libavb_host_sysdeps",
         "libpayload_consumer",
         "libpayload_generator",
+        "libgflags",
     ],
 
     srcs: ["payload_generator/generate_delta_main.cc"],
@@ -875,6 +879,7 @@
     static_libs: [
         "libpayload_consumer",
         "libpayload_generator",
+        "libgflags",
     ],
 
     srcs: ["payload_generator/generate_delta_main.cc"],
diff --git a/main.cc b/main.cc
index a23a08b..103e1a1 100644
--- a/main.cc
+++ b/main.cc
@@ -21,25 +21,24 @@
 #include <base/at_exit.h>
 #include <base/command_line.h>
 #include <base/logging.h>
-#include <brillo/flag_helper.h>
+#include <gflags/gflags.h>
 
 #include "update_engine/common/daemon_base.h"
 #include "update_engine/common/logging.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/common/terminator.h"
-#include "update_engine/common/utils.h"
 
 using std::string;
+DEFINE_bool(logtofile, false, "Write logs to a file in log_dir.");
+DEFINE_bool(logtostderr,
+            false,
+            "Write logs to stderr instead of to a file in log_dir.");
+DEFINE_bool(foreground, false, "Don't daemon()ize; run in foreground.");
 
 int main(int argc, char** argv) {
-  DEFINE_bool(logtofile, false, "Write logs to a file in log_dir.");
-  DEFINE_bool(logtostderr,
-              false,
-              "Write logs to stderr instead of to a file in log_dir.");
-  DEFINE_bool(foreground, false, "Don't daemon()ize; run in foreground.");
-
   chromeos_update_engine::Terminator::Init();
-  brillo::FlagHelper::Init(argc, argv, "A/B Update Engine");
+  gflags::SetUsageMessage("A/B Update Engine");
+  gflags::ParseCommandLineFlags(&argc, &argv, true);
 
   // We have two logging flags "--logtostderr" and "--logtofile"; and the logic
   // to choose the logging destination is:
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index 64e7249..3a8d91a 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -18,6 +18,7 @@
 #include <string>
 #include <vector>
 
+#include <android-base/strings.h>
 #include <base/bind.h>
 #include <base/files/file_path.h>
 #include <base/files/file_util.h>
@@ -25,10 +26,10 @@
 #include <base/strings/string_number_conversions.h>
 #include <base/strings/string_split.h>
 #include <base/strings/string_util.h>
-#include <brillo/flag_helper.h>
 #include <brillo/key_value_store.h>
 #include <brillo/message_loops/base_message_loop.h>
 #include <xz.h>
+#include <gflags/gflags.h>
 
 #include "update_engine/common/download_action.h"
 #include "update_engine/common/fake_boot_control.h"
@@ -165,7 +166,7 @@
   void ProcessingStopped(const ActionProcessor* processor) override {
     brillo::MessageLoop::current()->BreakLoop();
   }
-  ErrorCode code_;
+  ErrorCode code_{};
 };
 
 // TODO(deymo): Move this function to a new file and make the delta_performer
@@ -303,7 +304,6 @@
   return true;
 }
 
-int Main(int argc, char** argv) {
   DEFINE_string(old_image, "", "Path to the old rootfs");
   DEFINE_string(new_image, "", "Path to the new rootfs");
   DEFINE_string(old_kernel, "", "Path to the old kernel partition image");
@@ -453,14 +453,17 @@
                 "",
                 "Compression parameter passed to mkfs.erofs's -z option. "
                 "Example: lz4 lz4hc,9");
-
-  brillo::FlagHelper::Init(
-      argc,
-      argv,
+  int Main(int argc, char** argv) {
+  gflags::SetUsageMessage(
       "Generates a payload to provide to ChromeOS' update_engine.\n\n"
       "This tool can create full payloads and also delta payloads if the src\n"
       "image is provided. It also provides debugging options to apply, sign\n"
       "and verify payloads.");
+  gflags::ParseCommandLineFlags(&argc, &argv, true);
+  CHECK_EQ(argc, 1) << " Unused args: "
+                    << android::base::Join(
+                           std::vector<char*>(argv + 1, argv + argc), " ");
+
   Terminator::Init();
 
   logging::LoggingSettings log_settings;
@@ -770,7 +773,7 @@
                            metadata_size_string.size()));
   }
   return 0;
-}
+  }
 
 }  // namespace