Remove libbase dependency of sysprop_library
libbase dependency is not really needed, but it has been causing build
failure while linking with static variant of sysprop_library. This cuts
the dependency and only depend on libbase_headers and liblog.
Bug: 129301987
Test: 1) flash and boot walleye
Test: 2) try to build various properties with sysprop_library.
Test: 3) sysprop_test
Change-Id: Ieb0554471cf44e938b69793afa491ccaf77e70f0
diff --git a/CppGen.cpp b/CppGen.cpp
index 484fee1..299be1e 100644
--- a/CppGen.cpp
+++ b/CppGen.cpp
@@ -43,18 +43,18 @@
)";
constexpr const char* kCppSourceIncludes =
- R"(#include <cstring>
-#include <iterator>
-#include <type_traits>
+ R"(#include <cctype>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
+#include <limits>
#include <utility>
#include <strings.h>
#include <sys/system_properties.h>
-#include <android-base/logging.h>
#include <android-base/parseint.h>
-#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
+#include <log/log.h>
)";
@@ -80,14 +80,12 @@
template <> [[maybe_unused]] std::optional<std::int32_t> DoParse(const char* str) {
std::int32_t ret;
- bool success = android::base::ParseInt(str, &ret);
- return success ? std::make_optional(ret) : std::nullopt;
+ return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
}
template <> [[maybe_unused]] std::optional<std::int64_t> DoParse(const char* str) {
std::int64_t ret;
- bool success = android::base::ParseInt(str, &ret);
- return success ? std::make_optional(ret) : std::nullopt;
+ return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
}
template <> [[maybe_unused]] std::optional<double> DoParse(const char* str) {
@@ -99,7 +97,7 @@
return std::nullopt;
}
if (str == end || *end != '\0') {
- errno = old_errno;
+ errno = EINVAL;
return std::nullopt;
}
errno = old_errno;
@@ -112,8 +110,16 @@
template <typename Vec> [[maybe_unused]] Vec DoParseList(const char* str) {
Vec ret;
- for (auto&& element : android::base::Split(str, ",")) {
- ret.emplace_back(DoParse<typename Vec::value_type>(element.c_str()));
+ const char* p = str;
+ for (;;) {
+ const char* found = p;
+ while (*found != '\0' && *found != ',') {
+ ++found;
+ }
+ std::string value(p, found);
+ ret.emplace_back(DoParse<typename Vec::value_type>(value.c_str()));
+ if (*found == '\0') break;
+ p = found + 1;
}
return ret;
}
@@ -135,9 +141,10 @@
}
[[maybe_unused]] std::string FormatValue(const std::optional<double>& value) {
- return value
- ? android::base::StringPrintf("%.*g", std::numeric_limits<double>::max_digits10, *value)
- : "";
+ if (!value) return "";
+ char buf[1024];
+ std::sprintf(buf, "%.*g", std::numeric_limits<double>::max_digits10, *value);
+ return buf;
}
[[maybe_unused]] std::string FormatValue(const std::optional<bool>& value) {
@@ -347,9 +354,8 @@
writer.Write("}\n");
writer.Write(
- "LOG(FATAL) << \"Invalid value \" << "
- "static_cast<std::int32_t>(*value) << "
- "\" for property \" << \"%s\";\n",
+ "LOG_ALWAYS_FATAL(\"Invalid value %%d for property %s\", "
+ "static_cast<std::int32_t>(*value));\n",
prop.prop_name().c_str());
writer.Write("__builtin_unreachable();\n");
diff --git a/tests/CppGenTest.cpp b/tests/CppGenTest.cpp
index 559ba18..f4de6e4 100644
--- a/tests/CppGenTest.cpp
+++ b/tests/CppGenTest.cpp
@@ -195,18 +195,18 @@
#include <properties/PlatformProperties.sysprop.h>
+#include <cctype>
+#include <cerrno>
+#include <cstdio>
#include <cstring>
-#include <iterator>
-#include <type_traits>
+#include <limits>
#include <utility>
#include <strings.h>
#include <sys/system_properties.h>
-#include <android-base/logging.h>
#include <android-base/parseint.h>
-#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
+#include <log/log.h>
namespace {
@@ -241,7 +241,7 @@
return name;
}
}
- LOG(FATAL) << "Invalid value " << static_cast<std::int32_t>(*value) << " for property " << "android.test.enum";
+ LOG_ALWAYS_FATAL("Invalid value %d for property android.test.enum", static_cast<std::int32_t>(*value));
__builtin_unreachable();
}
@@ -268,7 +268,7 @@
return name;
}
}
- LOG(FATAL) << "Invalid value " << static_cast<std::int32_t>(*value) << " for property " << "el";
+ LOG_ALWAYS_FATAL("Invalid value %d for property el", static_cast<std::int32_t>(*value));
__builtin_unreachable();
}
@@ -293,14 +293,12 @@
template <> [[maybe_unused]] std::optional<std::int32_t> DoParse(const char* str) {
std::int32_t ret;
- bool success = android::base::ParseInt(str, &ret);
- return success ? std::make_optional(ret) : std::nullopt;
+ return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
}
template <> [[maybe_unused]] std::optional<std::int64_t> DoParse(const char* str) {
std::int64_t ret;
- bool success = android::base::ParseInt(str, &ret);
- return success ? std::make_optional(ret) : std::nullopt;
+ return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
}
template <> [[maybe_unused]] std::optional<double> DoParse(const char* str) {
@@ -312,7 +310,7 @@
return std::nullopt;
}
if (str == end || *end != '\0') {
- errno = old_errno;
+ errno = EINVAL;
return std::nullopt;
}
errno = old_errno;
@@ -325,8 +323,16 @@
template <typename Vec> [[maybe_unused]] Vec DoParseList(const char* str) {
Vec ret;
- for (auto&& element : android::base::Split(str, ",")) {
- ret.emplace_back(DoParse<typename Vec::value_type>(element.c_str()));
+ const char* p = str;
+ for (;;) {
+ const char* found = p;
+ while (*found != '\0' && *found != ',') {
+ ++found;
+ }
+ std::string value(p, found);
+ ret.emplace_back(DoParse<typename Vec::value_type>(value.c_str()));
+ if (*found == '\0') break;
+ p = found + 1;
}
return ret;
}
@@ -348,9 +354,10 @@
}
[[maybe_unused]] std::string FormatValue(const std::optional<double>& value) {
- return value
- ? android::base::StringPrintf("%.*g", std::numeric_limits<double>::max_digits10, *value)
- : "";
+ if (!value) return "";
+ char buf[1024];
+ std::sprintf(buf, "%.*g", std::numeric_limits<double>::max_digits10, *value);
+ return buf;
}
[[maybe_unused]] std::string FormatValue(const std::optional<bool>& value) {