Move over to ABSL logging and flags.

Removes gperftools too since that wants gflags.

Here come the fireworks.

Change-Id: I79cb7bcf60f1047fbfa28bfffc21a0fd692e4b1c
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2023/localizer/localizer.cc b/y2023/localizer/localizer.cc
index a00ebe6..586ffb6 100644
--- a/y2023/localizer/localizer.cc
+++ b/y2023/localizer/localizer.cc
@@ -1,6 +1,6 @@
 #include "y2023/localizer/localizer.h"
 
-#include "gflags/gflags.h"
+#include "absl/flags/flag.h"
 
 #include "aos/containers/sized_array.h"
 #include "frc971/control_loops/drivetrain/localizer_generated.h"
@@ -8,28 +8,27 @@
 #include "frc971/vision/target_map_utils.h"
 #include "y2023/constants.h"
 
-DEFINE_double(max_pose_error, 1e-6,
-              "Throw out target poses with a higher pose error than this");
-DEFINE_double(
-    max_pose_error_ratio, 0.4,
-    "Throw out target poses with a higher pose error ratio than this");
-DEFINE_double(distortion_noise_scalar, 1.0,
-              "Scale the target pose distortion factor by this when computing "
-              "the noise.");
-DEFINE_double(
-    max_implied_yaw_error, 3.0,
+ABSL_FLAG(double, max_pose_error, 1e-6,
+          "Throw out target poses with a higher pose error than this");
+ABSL_FLAG(double, max_pose_error_ratio, 0.4,
+          "Throw out target poses with a higher pose error ratio than this");
+ABSL_FLAG(double, distortion_noise_scalar, 1.0,
+          "Scale the target pose distortion factor by this when computing "
+          "the noise.");
+ABSL_FLAG(
+    double, max_implied_yaw_error, 3.0,
     "Reject target poses that imply a robot yaw of more than this many degrees "
     "off from our estimate.");
-DEFINE_double(
-    max_implied_teleop_yaw_error, 30.0,
+ABSL_FLAG(
+    double, max_implied_teleop_yaw_error, 30.0,
     "Reject target poses that imply a robot yaw of more than this many degrees "
     "off from our estimate.");
-DEFINE_double(max_distance_to_target, 5.0,
-              "Reject target poses that have a 3d distance of more than this "
-              "many meters.");
-DEFINE_double(max_auto_image_robot_speed, 2.0,
-              "Reject target poses when the robot is travelling faster than "
-              "this speed in auto.");
+ABSL_FLAG(double, max_distance_to_target, 5.0,
+          "Reject target poses that have a 3d distance of more than this "
+          "many meters.");
+ABSL_FLAG(double, max_auto_image_robot_speed, 2.0,
+          "Reject target poses when the robot is travelling faster than "
+          "this speed in auto.");
 
 namespace y2023::localizer {
 namespace {
@@ -348,8 +347,9 @@
   Eigen::Matrix<double, 3, 1> noises(1.0, 1.0, 0.5);
   noises /= 4.0;
   // Scale noise by the distortion factor for this detection
-  noises *= (1.0 + FLAGS_distortion_noise_scalar * target.distortion_factor() *
-                       std::exp(distance_to_target));
+  noises *=
+      (1.0 + absl::GetFlag(FLAGS_distortion_noise_scalar) *
+                 target.distortion_factor() * std::exp(distance_to_target));
 
   Eigen::Matrix3d R = Eigen::Matrix3d::Zero();
   R.diagonal() = noises.cwiseAbs2();
@@ -365,12 +365,13 @@
   if (!state_at_capture.has_value()) {
     VLOG(1) << "Rejecting image due to being too old.";
     return RejectImage(camera_index, RejectionReason::IMAGE_TOO_OLD, &builder);
-  } else if (target.pose_error() > FLAGS_max_pose_error) {
+  } else if (target.pose_error() > absl::GetFlag(FLAGS_max_pose_error)) {
     VLOG(1) << "Rejecting target due to high pose error "
             << target.pose_error();
     return RejectImage(camera_index, RejectionReason::HIGH_POSE_ERROR,
                        &builder);
-  } else if (target.pose_error_ratio() > FLAGS_max_pose_error_ratio) {
+  } else if (target.pose_error_ratio() >
+             absl::GetFlag(FLAGS_max_pose_error_ratio)) {
     VLOG(1) << "Rejecting target due to high pose error ratio "
             << target.pose_error_ratio();
     return RejectImage(camera_index, RejectionReason::HIGH_POSE_ERROR_RATIO,
@@ -386,17 +387,19 @@
        state_at_capture.value()(StateIdx::kRightVelocity)) /
       2.0;
   const double yaw_threshold =
-      (utils_.MaybeInAutonomous() ? FLAGS_max_implied_yaw_error
-                                  : FLAGS_max_implied_teleop_yaw_error) *
+      (utils_.MaybeInAutonomous()
+           ? absl::GetFlag(FLAGS_max_implied_yaw_error)
+           : absl::GetFlag(FLAGS_max_implied_teleop_yaw_error)) *
       kDegToRad;
   if (utils_.MaybeInAutonomous() &&
-      (std::abs(robot_speed) > FLAGS_max_auto_image_robot_speed)) {
+      (std::abs(robot_speed) >
+       absl::GetFlag(FLAGS_max_auto_image_robot_speed))) {
     return RejectImage(camera_index, RejectionReason::ROBOT_TOO_FAST, &builder);
   } else if (std::abs(aos::math::NormalizeAngle(
                  camera_implied_theta - theta_at_capture)) > yaw_threshold) {
     return RejectImage(camera_index, RejectionReason::HIGH_IMPLIED_YAW_ERROR,
                        &builder);
-  } else if (distance_to_target > FLAGS_max_distance_to_target) {
+  } else if (distance_to_target > absl::GetFlag(FLAGS_max_distance_to_target)) {
     return RejectImage(camera_index, RejectionReason::HIGH_DISTANCE_TO_TARGET,
                        &builder);
   }
diff --git a/y2023/localizer/localizer_main.cc b/y2023/localizer/localizer_main.cc
index 98f0e81..40b3ee5 100644
--- a/y2023/localizer/localizer_main.cc
+++ b/y2023/localizer/localizer_main.cc
@@ -1,16 +1,19 @@
+#include "absl/flags/flag.h"
+
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
 #include "frc971/constants/constants_sender_lib.h"
 #include "y2023/control_loops/drivetrain/drivetrain_base.h"
 #include "y2023/localizer/localizer.h"
 
-DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
+ABSL_FLAG(std::string, config, "aos_config.json",
+          "Path to the config file to use.");
 
 int main(int argc, char *argv[]) {
   aos::InitGoogle(&argc, &argv);
 
   aos::FlatbufferDetachedBuffer<aos::Configuration> config =
-      aos::configuration::ReadConfig(FLAGS_config);
+      aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
 
   frc971::constants::WaitForConstants<y2023::Constants>(&config.message());
 
diff --git a/y2023/localizer/localizer_replay.cc b/y2023/localizer/localizer_replay.cc
index 859b77e..55b81b1 100644
--- a/y2023/localizer/localizer_replay.cc
+++ b/y2023/localizer/localizer_replay.cc
@@ -1,4 +1,4 @@
-#include "gflags/gflags.h"
+#include "absl/flags/flag.h"
 
 #include "aos/configuration.h"
 #include "aos/events/logging/log_reader.h"
@@ -11,19 +11,19 @@
 #include "y2023/control_loops/drivetrain/drivetrain_base.h"
 #include "y2023/localizer/localizer.h"
 
-DEFINE_string(config, "y2023/aos_config.json",
-              "Name of the config file to replay using.");
-DEFINE_int32(team, 9971, "Team number to use for logfile replay.");
-DEFINE_string(output_folder, "/tmp/replayed",
-              "Name of the folder to write replayed logs to.");
+ABSL_FLAG(std::string, config, "y2023/aos_config.json",
+          "Name of the config file to replay using.");
+ABSL_FLAG(int32_t, team, 9971, "Team number to use for logfile replay.");
+ABSL_FLAG(std::string, output_folder, "/tmp/replayed",
+          "Name of the folder to write replayed logs to.");
 
 int main(int argc, char **argv) {
   aos::InitGoogle(&argc, &argv);
 
-  aos::network::OverrideTeamNumber(FLAGS_team);
+  aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team));
 
   const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
-      aos::configuration::ReadConfig(FLAGS_config);
+      aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
 
   // sort logfiles
   const std::vector<aos::logger::LogFile> logfiles =
@@ -50,7 +50,7 @@
   const std::vector<std::string> nodes_to_log = {"imu"};
   std::vector<std::unique_ptr<aos::util::LoggerState>> loggers =
       aos::util::MakeLoggersForNodes(reader.event_loop_factory(), nodes_to_log,
-                                     FLAGS_output_folder);
+                                     absl::GetFlag(FLAGS_output_folder));
 
   const aos::Node *node = nullptr;
   if (aos::configuration::MultiNode(reader.configuration())) {
diff --git a/y2023/localizer/localizer_test.cc b/y2023/localizer/localizer_test.cc
index c47e46e..79454ab 100644
--- a/y2023/localizer/localizer_test.cc
+++ b/y2023/localizer/localizer_test.cc
@@ -1,5 +1,8 @@
 #include "y2023/localizer/localizer.h"
 
+#include "absl/flags/declare.h"
+#include "absl/flags/flag.h"
+#include "absl/flags/reflection.h"
 #include "gtest/gtest.h"
 
 #include "aos/events/logging/log_writer.h"
@@ -13,9 +16,9 @@
 #include "y2023/control_loops/drivetrain/drivetrain_base.h"
 #include "y2023/localizer/status_generated.h"
 
-DEFINE_string(output_folder, "",
-              "If set, logs all channels to the provided logfile.");
-DECLARE_double(max_distance_to_target);
+ABSL_FLAG(std::string, output_folder, "",
+          "If set, logs all channels to the provided logfile.");
+ABSL_DECLARE_FLAG(double, max_distance_to_target);
 
 namespace y2023::localizer::testing {
 
@@ -74,7 +77,7 @@
                 ->MakeFetcher<frc971::controls::LocalizerOutput>("/localizer")),
         status_fetcher_(
             imu_test_event_loop_->MakeFetcher<Status>("/localizer")) {
-    FLAGS_max_distance_to_target = 100.0;
+    absl::SetFlag(&FLAGS_max_distance_to_target, 100.0);
     {
       aos::TimerHandler *timer = roborio_test_event_loop_->AddTimer([this]() {
         {
@@ -191,11 +194,11 @@
     CHECK(status_fetcher_.Fetch());
     CHECK(status_fetcher_->imu()->zeroed());
 
-    if (!FLAGS_output_folder.empty()) {
+    if (!absl::GetFlag(FLAGS_output_folder).empty()) {
       logger_event_loop_ =
           event_loop_factory_.MakeEventLoop("logger", imu_node_);
       logger_ = std::make_unique<aos::logger::Logger>(logger_event_loop_.get());
-      logger_->StartLoggingOnRun(FLAGS_output_folder);
+      logger_->StartLoggingOnRun(absl::GetFlag(FLAGS_output_folder));
     }
   }
 
@@ -280,7 +283,7 @@
   double pose_error_ratio_ = 0.1;
   double implied_yaw_error_ = 0.0;
 
-  gflags::FlagSaver flag_saver_;
+  absl::FlagSaver flag_saver_;
 };
 
 // Test a simple scenario with no errors where the robot should just drive
diff --git a/y2023/localizer/map_expander.cc b/y2023/localizer/map_expander.cc
index 32efcd8..9582c6b 100644
--- a/y2023/localizer/map_expander.cc
+++ b/y2023/localizer/map_expander.cc
@@ -1,24 +1,25 @@
-#include "gflags/gflags.h"
+#include "absl/flags/flag.h"
 
 #include "aos/init.h"
 #include "aos/util/file.h"
 #include "y2023/localizer/map_expander_lib.h"
 
-DEFINE_string(target_map, "y2023/vision/maps/target_map.json",
-              "Path to the target map JSON file.");
-DEFINE_string(relative_map, "y2023/constants/relative_scoring_map.json",
-              "Path to the relative scoring map JSON file.");
-DEFINE_string(output, "y2023/constants/scoring_map.json",
-              "Path to the output scoring map JSON file.");
+ABSL_FLAG(std::string, target_map, "y2023/vision/maps/target_map.json",
+          "Path to the target map JSON file.");
+ABSL_FLAG(std::string, relative_map,
+          "y2023/constants/relative_scoring_map.json",
+          "Path to the relative scoring map JSON file.");
+ABSL_FLAG(std::string, output, "y2023/constants/scoring_map.json",
+          "Path to the output scoring map JSON file.");
 
 int main(int argc, char *argv[]) {
   aos::InitGoogle(&argc, &argv);
   aos::FlatbufferDetachedBuffer<y2023::localizer::ScoringMap> map =
       y2023::localizer::ExpandMap(
-          aos::util::ReadFileToStringOrDie(FLAGS_relative_map),
-          aos::util::ReadFileToStringOrDie(FLAGS_target_map));
+          aos::util::ReadFileToStringOrDie(absl::GetFlag(FLAGS_relative_map)),
+          aos::util::ReadFileToStringOrDie(absl::GetFlag(FLAGS_target_map)));
   aos::util::WriteStringToFileOrDie(
-      FLAGS_output,
+      absl::GetFlag(FLAGS_output),
       aos::FlatbufferToJson(map, {.multi_line = true, .max_multi_line = true}));
   return EXIT_SUCCESS;
 }