Cleanup codes
am: 803bfb8ffa

Change-Id: I725e4ce3283d48bc58723d4894eb5d9128056959
diff --git a/Android.bp b/Android.bp
index 8f26ddc..a45eec6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -21,6 +21,7 @@
     proto: {
         type: "full",
     },
+    local_include_dirs: ["include"],
 }
 
 cc_binary_host {
diff --git a/CppGen.cpp b/CppGen.cpp
index 9b8f345..473fb36 100644
--- a/CppGen.cpp
+++ b/CppGen.cpp
@@ -179,21 +179,14 @@
 const std::regex kRegexDot{"\\."};
 const std::regex kRegexUnderscore{"_"};
 
-std::string GetHeaderIncludeGuardName(const sysprop::Properties& props);
 std::string GetCppEnumName(const sysprop::Property& prop);
 std::string GetCppPropTypeName(const sysprop::Property& prop);
 std::string GetCppNamespace(const sysprop::Properties& props);
 
-bool GenerateHeader(const sysprop::Properties& props, sysprop::Scope scope,
-                    std::string* header_result, std::string* err);
-bool GenerateSource(const sysprop::Properties& props,
-                    const std::string& include_name, std::string* source_result,
-                    std::string* err);
-
-std::string GetHeaderIncludeGuardName(const sysprop::Properties& props) {
-  return "SYSPROPGEN_" + std::regex_replace(props.module(), kRegexDot, "_") +
-         "_H_";
-}
+std::string GenerateHeader(const sysprop::Properties& props,
+                           sysprop::Scope scope);
+std::string GenerateSource(const sysprop::Properties& props,
+                           const std::string& include_name);
 
 std::string GetCppEnumName(const sysprop::Property& prop) {
   return ApiNameToIdentifier(prop.api_name()) + "_values";
@@ -234,16 +227,13 @@
   return std::regex_replace(props.module(), kRegexDot, "::");
 }
 
-bool GenerateHeader(const sysprop::Properties& props, sysprop::Scope scope,
-                    std::string* header_result,
-                    [[maybe_unused]] std::string* err) {
+std::string GenerateHeader(const sysprop::Properties& props,
+                           sysprop::Scope scope) {
   CodeWriter writer(kIndent);
 
   writer.Write("%s", kGeneratedFileFooterComments);
 
-  std::string include_guard_name = GetHeaderIncludeGuardName(props);
-  writer.Write("#ifndef %s\n#define %s\n\n", include_guard_name.c_str(),
-               include_guard_name.c_str());
+  writer.Write("#pragma once\n\n");
   writer.Write("%s", kCppHeaderIncludes);
 
   std::string cpp_namespace = GetCppNamespace(props);
@@ -284,17 +274,13 @@
     }
   }
 
-  writer.Write("\n}  // namespace %s\n\n", cpp_namespace.c_str());
+  writer.Write("\n}  // namespace %s\n", cpp_namespace.c_str());
 
-  writer.Write("#endif  // %s\n", include_guard_name.c_str());
-
-  *header_result = writer.Code();
-  return true;
+  return writer.Code();
 }
 
-bool GenerateSource(const sysprop::Properties& props,
-                    const std::string& include_name, std::string* source_result,
-                    [[maybe_unused]] std::string* err) {
+std::string GenerateSource(const sysprop::Properties& props,
+                           const std::string& include_name) {
   CodeWriter writer(kIndent);
   writer.Write("%s", kGeneratedFileFooterComments);
   writer.Write("#include <%s>\n\n", include_name.c_str());
@@ -404,9 +390,7 @@
 
   writer.Write("\n}  // namespace %s\n", cpp_namespace.c_str());
 
-  *source_result = writer.Code();
-
-  return true;
+  return writer.Code();
 }
 
 }  // namespace
@@ -428,17 +412,13 @@
            std::pair(sysprop::Internal, header_dir),
            std::pair(sysprop::System, system_header_dir),
        }) {
-    std::string result;
-    if (!GenerateHeader(props, scope, &result, err)) {
-      return false;
-    }
-
     if (!IsDirectory(dir) && !CreateDirectories(dir)) {
       *err = "Creating directory to " + dir + " failed: " + strerror(errno);
       return false;
     }
 
     std::string path = dir + "/" + output_basename + ".h";
+    std::string result = GenerateHeader(props, scope);
 
     if (!android::base::WriteStringToFile(result, path)) {
       *err =
@@ -448,11 +428,7 @@
   }
 
   std::string source_path = source_output_dir + "/" + output_basename + ".cpp";
-  std::string source_result;
-
-  if (!GenerateSource(props, include_name, &source_result, err)) {
-    return false;
-  }
+  std::string source_result = GenerateSource(props, include_name);
 
   if (!android::base::WriteStringToFile(source_result, source_path)) {
     *err = "Writing generated source to " + source_path +
diff --git a/CodeWriter.h b/include/CodeWriter.h
similarity index 100%
rename from CodeWriter.h
rename to include/CodeWriter.h
diff --git a/Common.h b/include/Common.h
similarity index 100%
rename from Common.h
rename to include/Common.h
diff --git a/CppGen.h b/include/CppGen.h
similarity index 100%
rename from CppGen.h
rename to include/CppGen.h
diff --git a/JavaGen.h b/include/JavaGen.h
similarity index 100%
rename from JavaGen.h
rename to include/JavaGen.h
diff --git a/tests/CppGenTest.cpp b/tests/CppGenTest.cpp
index 365b93e..8dbd38e 100644
--- a/tests/CppGenTest.cpp
+++ b/tests/CppGenTest.cpp
@@ -105,8 +105,7 @@
 constexpr const char* kExpectedHeaderOutput =
     R"(// Generated by the sysprop generator. DO NOT EDIT!
 
-#ifndef SYSPROPGEN_android_sysprop_PlatformProperties_H_
-#define SYSPROPGEN_android_sysprop_PlatformProperties_H_
+#pragma once
 
 #include <cstdint>
 #include <optional>
@@ -162,15 +161,12 @@
 bool el(const std::vector<std::optional<el_values>>& value);
 
 }  // namespace android::sysprop::PlatformProperties
-
-#endif  // SYSPROPGEN_android_sysprop_PlatformProperties_H_
 )";
 
 constexpr const char* kExpectedSystemHeaderOutput =
     R"(// Generated by the sysprop generator. DO NOT EDIT!
 
-#ifndef SYSPROPGEN_android_sysprop_PlatformProperties_H_
-#define SYSPROPGEN_android_sysprop_PlatformProperties_H_
+#pragma once
 
 #include <cstdint>
 #include <optional>
@@ -192,8 +188,6 @@
 std::vector<std::optional<std::string>> test_strlist();
 
 }  // namespace android::sysprop::PlatformProperties
-
-#endif  // SYSPROPGEN_android_sysprop_PlatformProperties_H_
 )";
 
 constexpr const char* kExpectedSourceOutput =