am a5e349fc: am cf9a73a4: Fix teardown bug for multiple files without pragma.

* commit 'a5e349fcef0ae262d8a5d8d26b0aabe3fa8b6b0b':
  Fix teardown bug for multiple files without pragma.
diff --git a/slang_rs.cpp b/slang_rs.cpp
index 18858b2..af86e78 100644
--- a/slang_rs.cpp
+++ b/slang_rs.cpp
@@ -324,6 +324,11 @@
     if (!setOutput(OutputFile))
       return false;
 
+    if (!JavaReflectionPackageName.empty()) {
+      mRSContext->setReflectJavaPackageName(
+          JavaReflectionPackageName);
+    }
+
     if (Slang::compile() > 0)
       return false;
 
diff --git a/slang_rs_backend.cpp b/slang_rs_backend.cpp
index d0b067e..a1efad1 100644
--- a/slang_rs_backend.cpp
+++ b/slang_rs_backend.cpp
@@ -184,6 +184,16 @@
     slangAssert(version == 1);
   }
 
+  if (mContext->getReflectJavaPackageName().empty()) {
+    mDiagEngine.Report(
+        mSourceMgr.getLocForEndOfFile(mSourceMgr.getMainFileID()),
+        mDiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error,
+                                    "missing \"#pragma rs "
+                                    "java_package_name(com.foo.bar)\" "
+                                    "in source file"));
+    return;
+  }
+
   // Create a static global destructor if necessary (to handle RS object
   // runtime cleanup).
   clang::FunctionDecl *FD = mRefCount.CreateStaticGlobalDtor();
diff --git a/slang_rs_context.cpp b/slang_rs_context.cpp
index 4ed7e40..a400b12 100644
--- a/slang_rs_context.cpp
+++ b/slang_rs_context.cpp
@@ -293,17 +293,7 @@
   const std::string &PackageName =
       ((OutputPackageName.empty()) ? mReflectJavaPackageName :
                                      OutputPackageName);
-  if (PackageName.empty()) {
-    clang::DiagnosticsEngine *DiagEngine = getDiagnostics();
-    const clang::SourceManager *SM = getSourceManager();
-    DiagEngine->Report(
-        SM->getLocForEndOfFile(SM->getMainFileID()),
-        DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error,
-                                    "missing \"#pragma rs "
-                                    "java_package_name(com.foo.bar)\" "
-                                    "in source file"));
-    return false;
-  }
+  slangAssert(!PackageName.empty());
 
   // Copy back the really applied package name
   RealPackageName->assign(PackageName);
diff --git a/tests/F_no_pragma/first.rs b/tests/F_no_pragma/first.rs
new file mode 100644
index 0000000..a53bf90
--- /dev/null
+++ b/tests/F_no_pragma/first.rs
@@ -0,0 +1,3 @@
+#pragma version(1)
+#pragma rs java_package_name(foo)
+
diff --git a/tests/F_no_pragma/second.rs b/tests/F_no_pragma/second.rs
new file mode 100644
index 0000000..a746ce1
--- /dev/null
+++ b/tests/F_no_pragma/second.rs
@@ -0,0 +1,2 @@
+#pragma version(1)
+
diff --git a/tests/F_no_pragma/stderr.txt.expect b/tests/F_no_pragma/stderr.txt.expect
new file mode 100644
index 0000000..8b4c80e
--- /dev/null
+++ b/tests/F_no_pragma/stderr.txt.expect
@@ -0,0 +1 @@
+second.rs:2:1: error: missing "#pragma rs java_package_name(com.foo.bar)" in source file
diff --git a/tests/F_no_pragma/stdout.txt.expect b/tests/F_no_pragma/stdout.txt.expect
new file mode 100644
index 0000000..1a30d53
--- /dev/null
+++ b/tests/F_no_pragma/stdout.txt.expect
@@ -0,0 +1 @@
+Generating ScriptC_first.java ...