hidl-gen: allow specifying root

Also, default root to $ANDROID_BUILD_TOP or pwd if that isn't defined.

Now hidl-gen can be run from anywhere, not just croot.

Test: manual
Change-Id: I8a8ef57612ff4235772fb0a24e543ffd8c7a78c1
Bugs: me
diff --git a/Coordinator.cpp b/Coordinator.cpp
index 2a4d5d0..d0ef37f 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -44,9 +44,11 @@
 
 Coordinator::Coordinator(
         const std::vector<std::string> &packageRootPaths,
-        const std::vector<std::string> &packageRoots)
+        const std::vector<std::string> &packageRoots,
+        const std::string &rootPath)
     : mPackageRootPaths(packageRootPaths),
-      mPackageRoots(packageRoots) {
+      mPackageRoots(packageRoots),
+      mRootPath(rootPath) {
     // empty
 }
 
@@ -82,7 +84,7 @@
         // fall through.
     }
 
-    std::string path = getPackagePath(fqName);
+    std::string path = mRootPath + getPackagePath(fqName);
 
     path.append(fqName.name());
     path.append(".hal");
@@ -274,7 +276,7 @@
         std::vector<std::string> *fileNames) const {
     fileNames->clear();
 
-    const std::string packagePath = getPackagePath(package);
+    const std::string packagePath = mRootPath + getPackagePath(package);
 
     DIR *dir = opendir(packagePath.c_str());
 
@@ -411,7 +413,7 @@
     FQName prevPacakge = currentPackage;
     while (prevPacakge.getPackageMinorVersion() > 0) {
         prevPacakge = prevPacakge.downRev();
-        if (existdir(getPackagePath(prevPacakge).c_str())) {
+        if (existdir((mRootPath + getPackagePath(prevPacakge)).c_str())) {
             hasPrevPackage = true;
             break;
         }