aboutsummaryrefslogtreecommitdiff
path: root/generateCppAdapter.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2017-09-25 18:44:43 -0700
committerSteven Moreland <smoreland@google.com>2017-09-26 13:02:49 -0700
commita885d256232623361209801c854e39f4bca2247e (patch)
tree2415eae1b87f53a5bbe8c4744f4c85af1ca3707b /generateCppAdapter.cpp
parentf78c44db648a1f7dd38fed110b8e53cc04f96516 (diff)
downloadhidl-a885d256232623361209801c854e39f4bca2247e.tar.gz
Use getFormatter everywhere.
This brings hidl-gen closer to only opening files in one place. It will allow for debug printing of all paths that are open and also opens the door for build system consistency changes which are tracked in b/62807497. Fixes: 65738957 Test: update-base-files.sh Test: run_all_host_tests.sh Change-Id: Ib706fa0479a8e5bf51ff9243330fb0dcd615c789
Diffstat (limited to 'generateCppAdapter.cpp')
-rw-r--r--generateCppAdapter.cpp32
1 files changed, 8 insertions, 24 deletions
diff --git a/generateCppAdapter.cpp b/generateCppAdapter.cpp
index 77416117..5e41edc3 100644
--- a/generateCppAdapter.cpp
+++ b/generateCppAdapter.cpp
@@ -51,21 +51,13 @@ status_t AST::generateCppAdapterHeader(const std::string& outputPath) const {
const std::string klassName = getInterface()->getAdapterName();
- std::string path = outputPath;
- path.append(mCoordinator->convertPackageRootToPath(mPackage));
- path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
- path.append(klassName);
- path.append(".h");
+ Formatter out = mCoordinator->getFormatter(outputPath, mPackage,
+ Coordinator::Location::GEN_OUTPUT, klassName + ".h");
- CHECK(Coordinator::MakeParentHierarchy(path));
- FILE* file = fopen(path.c_str(), "w");
-
- if (file == NULL) {
- return -errno;
+ if (!out.isValid()) {
+ return UNKNOWN_ERROR;
}
- Formatter out(file);
-
const std::string guard = makeHeaderGuard(klassName, true /* indicateGenerated */);
out << "#ifndef " << guard << "\n";
@@ -115,21 +107,13 @@ status_t AST::generateCppAdapterSource(const std::string& outputPath) const {
const std::string klassName = getInterface()->getAdapterName();
- std::string path = outputPath;
- path.append(mCoordinator->convertPackageRootToPath(mPackage));
- path.append(mCoordinator->getPackagePath(mPackage, true /* relative */));
- path.append(klassName);
- path.append(".cpp");
+ Formatter out = mCoordinator->getFormatter(
+ outputPath, mPackage, Coordinator::Location::GEN_OUTPUT, klassName + ".cpp");
- CHECK(Coordinator::MakeParentHierarchy(path));
- FILE* file = fopen(path.c_str(), "w");
-
- if (file == NULL) {
- return -errno;
+ if (!out.isValid()) {
+ return UNKNOWN_ERROR;
}
- Formatter out(file);
-
out << "#include <hidladapter/HidlBinderAdapter.h>\n";
generateCppPackageInclude(out, mPackage, getInterface()->localName());