Fix C++ reflection so that -p works.

The C++ reflection code was missing support for the -p option, which allows
the developer to place the .cpp/.h files into a different directory than the
bitcode. It was also missing directory creation (and path separators) for that
option.

Change-Id: I5b16a6d109c6df8ca3e1542e0c5345691037bf85
(cherry picked from commit c7888b0c7c648b8e3987d9ff277e10e0551e203b)
diff --git a/llvm-rs-cc.cpp b/llvm-rs-cc.cpp
index e2c9599..1736c0b 100644
--- a/llvm-rs-cc.cpp
+++ b/llvm-rs-cc.cpp
@@ -291,10 +291,11 @@
 
     if (Args->hasArg(OPT_reflect_cpp)) {
       Opts.mBitcodeStorage = slang::BCST_CPP_CODE;
-      // mJavaReflectionPathBase isn't set for C++ reflected builds
-      // set it to mOutputDir so we can use the path sanely from
-      // RSReflectionBase later on
-      Opts.mJavaReflectionPathBase = Opts.mOutputDir;
+      // mJavaReflectionPathBase can be set for C++ reflected builds.
+      // Set it to the standard mOutputDir (via -o) by default.
+      if (Opts.mJavaReflectionPathBase.empty()) {
+        Opts.mJavaReflectionPathBase = Opts.mOutputDir;
+      }
     }
 
     Opts.mOutputDepDir =
diff --git a/slang_rs_reflection_cpp.cpp b/slang_rs_reflection_cpp.cpp
index f583148..adc05b7 100644
--- a/slang_rs_reflection_cpp.cpp
+++ b/slang_rs_reflection_cpp.cpp
@@ -122,10 +122,20 @@
                               const string &InputFileName,
                               const string &OutputBCFileName) {
   mInputFileName = InputFileName;
-  mOutputPath = OutputPathBase;
+  mOutputPath = OutputPathBase + OS_PATH_SEPARATOR_STR;
   mOutputBCFileName = OutputBCFileName;
   mClassName = string("ScriptC_") + stripRS(InputFileName);
 
+  std::string Path =
+      RSSlangReflectUtils::ComputePackagedPath(OutputPathBase.c_str(), "");
+
+  std::string ErrorMsg;
+  if (!SlangUtils::CreateDirectoryWithParents(Path, &ErrorMsg)) {
+    fprintf(stderr, "Error: Could not create path %s - %s\n",
+            Path.c_str(), ErrorMsg.c_str());
+    return false;
+  }
+
   makeHeader("android::RSC::ScriptC");
   std::vector< std::string > header(mText);
   mText.clear();