Report all errors with hidden API flags not just the first one

Previously, if an error in a flag was found the process (hiddenapi or
veridex) would exit immediately. That made it necessary to iteratively
fix the source of the error, rerun the build, wait to see if it fails
again, if it does repeat.

This change logs all errors with flags found while parsing a specific
file and only then exits.

Bug: 253335210
Test: build/soong/soong_ui.bash --make-mode TARGET_PRODUCT=aosp_cf_x86_64_phone TARGET_BUILD_VARIANT=userdebug droid dist
Change-Id: Ie13bcc2362ce9986c9958d8f31d72999f4559c06
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index aee3f9a..644ec72 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -1057,6 +1057,7 @@
     std::map<std::string, ApiList> api_flag_map;
 
     size_t line_number = 1;
+    bool errors = false;
     for (std::string line; std::getline(api_file, line); line_number++) {
       // Every line contains a comma separated list with the signature as the
       // first element and the api flags as the rest
@@ -1074,13 +1075,21 @@
       std::vector<std::string>::iterator apiListBegin = values.begin() + 1;
       std::vector<std::string>::iterator apiListEnd = values.end();
       bool success = ApiList::FromNames(apiListBegin, apiListEnd, &membership);
-      CHECK(success) << path << ":" << line_number
-          << ": Some flags were not recognized: " << line << kErrorHelp;
-      CHECK(membership.IsValid()) << path << ":" << line_number
-          << ": Invalid combination of flags: " << line << kErrorHelp;
+      if (!success) {
+        LOG(ERROR) << path << ":" << line_number
+            << ": Some flags were not recognized: " << line << kErrorHelp;
+        errors = true;
+        continue;
+      } else if (!membership.IsValid()) {
+        LOG(ERROR) << path << ":" << line_number
+            << ": Invalid combination of flags: " << line << kErrorHelp;
+        errors = true;
+        continue;
+      }
 
       api_flag_map.emplace(signature, membership);
     }
+    CHECK(!errors) << "Errors encountered while parsing file " << path;
 
     api_file.close();
     return api_flag_map;
diff --git a/tools/veridex/hidden_api.cc b/tools/veridex/hidden_api.cc
index 71ea56b5..69e6fe4 100644
--- a/tools/veridex/hidden_api.cc
+++ b/tools/veridex/hidden_api.cc
@@ -29,14 +29,22 @@
   CHECK(filename != nullptr);
 
   std::ifstream in(filename);
+  bool errors = false;
   for (std::string str; std::getline(in, str);) {
     std::vector<std::string> values = android::base::Split(str, ",");
     const std::string& signature = values[0];
 
     hiddenapi::ApiList membership;
     bool success = hiddenapi::ApiList::FromNames(values.begin() + 1, values.end(), &membership);
-    CHECK(success) << "Unknown ApiList flag: " << str;
-    CHECK(membership.IsValid()) << "Invalid ApiList: " << membership;
+    if (!success) {
+      LOG(ERROR) << "Unknown ApiList flag: " << str;
+      errors = true;
+      continue;
+    } else if (!membership.IsValid()) {
+      LOG(ERROR) << "Invalid ApiList: " << membership;
+      errors = true;
+      continue;
+    }
 
     AddSignatureToApiList(signature, membership);
     size_t pos = signature.find("->");
@@ -55,6 +63,7 @@
       }
     }
   }
+  CHECK(!errors) << "Errors encountered while parsing file " << filename;
 }
 
 void HiddenApi::AddSignatureToApiList(const std::string& signature, hiddenapi::ApiList membership) {