Use environment variable $TOP to determine full path to hardware/interfaces.
diff --git a/AST.cpp b/AST.cpp
index b0819e2..7c02f1d 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -67,7 +67,7 @@
// LOG(INFO) << "importing " << fqName.string();
if (fqName.name().empty()) {
- const std::string packagePath = Coordinator::GetPackagePath(fqName);
+ const std::string packagePath = mCoordinator->getPackagePath(fqName);
DIR *dir = opendir(packagePath.c_str());
if (dir == NULL) {
diff --git a/Coordinator.cpp b/Coordinator.cpp
index 6b9b1ee..f981b42 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -9,7 +9,10 @@
namespace android {
-Coordinator::Coordinator() {}
+Coordinator::Coordinator(const std::string &interfacesPath)
+ : mInterfacesPath(interfacesPath) {
+}
+
Coordinator::~Coordinator() {}
AST *Coordinator::parse(const FQName &fqName) {
@@ -25,7 +28,7 @@
// Add this to the cache immediately, so we can discover circular imports.
mCache.add(fqName, NULL);
- const std::string packagePath = GetPackagePath(fqName);
+ const std::string packagePath = getPackagePath(fqName);
if (fqName.name() != "types") {
// Any interface file implicitly imports its package's types.hal.
@@ -95,8 +98,7 @@
return ast;
}
-// static
-std::string Coordinator::GetPackagePath(const FQName &fqName) {
+std::string Coordinator::getPackagePath(const FQName &fqName) const {
CHECK(!fqName.package().empty());
CHECK(!fqName.version().empty());
const char *const kPrefix = "android.hardware.";
@@ -104,8 +106,7 @@
const std::string packageSuffix = fqName.package().substr(strlen(kPrefix));
- std::string packagePath =
- "/Volumes/Source/nyc-mr1-dev-lego/hardware/interfaces/";
+ std::string packagePath = mInterfacesPath;
size_t startPos = 0;
size_t dotPos;
diff --git a/Coordinator.h b/Coordinator.h
index 00e7f0b..0594d5b 100644
--- a/Coordinator.h
+++ b/Coordinator.h
@@ -13,16 +13,17 @@
struct Type;
struct Coordinator {
- Coordinator();
+ Coordinator(const std::string &interfacesPath);
~Coordinator();
AST *parse(const FQName &fqName);
Type *lookupType(const FQName &fqName) const;
- static std::string GetPackagePath(const FQName &fqName);
+ std::string getPackagePath(const FQName &fqName) const;
private:
+ std::string mInterfacesPath;
KeyedVector<FQName, AST *> mCache;
DISALLOW_COPY_AND_ASSIGN(Coordinator);
diff --git a/main.cpp b/main.cpp
index 7fa34b9..0bada61 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,7 +9,16 @@
using namespace android;
int main(int argc, const char *const argv[]) {
- Coordinator coordinator;
+ const char *TOP = getenv("TOP");
+ if (TOP == NULL) {
+ LOG(ERROR) << "Your environment does not define $TOP.";
+ return 1;
+ }
+
+ std::string interfacesPath = TOP;
+ interfacesPath.append("/hardware/interfaces/");
+
+ Coordinator coordinator(interfacesPath);
for (int i = 1; i < argc; ++i) {
FQName fqName(argv[i]);