Improve error handling for Clang module imports.
authorAdrian Prantl <aprantl@apple.com>
Tue, 19 Mar 2019 15:38:26 +0000 (15:38 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 19 Mar 2019 15:38:26 +0000 (15:38 +0000)
rdar://problem/48883558

Differential Revision: https://reviews.llvm.org/D59524

llvm-svn: 356462

lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h [deleted file]
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h [deleted file]
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Makefile
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/TestCXXModulesImport.py
lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap [deleted file]
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Bar.h
deleted file mode 100644 (file)
index 3d9a88c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-struct Bar { int success; };
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Foo.h
deleted file mode 100644 (file)
index 1fe02e8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-struct Foo {};
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Bar.h
new file mode 100644 (file)
index 0000000..3d9a88c
--- /dev/null
@@ -0,0 +1 @@
+struct Bar { int success; };
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/Foo.h
new file mode 100644 (file)
index 0000000..1fe02e8
--- /dev/null
@@ -0,0 +1 @@
+struct Foo {};
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/Inputs/module.modulemap
new file mode 100644 (file)
index 0000000..4221d0f
--- /dev/null
@@ -0,0 +1,7 @@
+module Foo {
+  header "Foo.h"
+}
+
+module Bar {
+  header "Bar.h"
+}
index 796b4dc5ef336f9605b4c7e1e3a0a20ab3b35044..2b8f23bcec7795b62d3c58a5253063316e1418f7 100644 (file)
@@ -1,6 +1,5 @@
 LEVEL = ../../../make
 CXX_SOURCES := main.cpp
-
-CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS)
+CFLAGS_EXTRAS = $(MANDATORY_MODULE_BUILD_CFLAGS) -I$(BUILDDIR)/include
 
 include $(LEVEL)/Makefile.rules
index 74ac40056733cb1b47858d2ed1eadd50267a0183..cee551d2bc827f18a734e313a672e8a9956a0d3b 100644 (file)
@@ -2,13 +2,9 @@
 
 from __future__ import print_function
 
-
-from distutils.version import StrictVersion
 import unittest2
-import os
-import time
 import lldb
-import platform
+import shutil
 
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -19,13 +15,32 @@ class CXXModulesImportTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
+    def build(self):
+        include = self.getBuildArtifact('include')
+        lldbutil.mkdir_p(include)
+        for f in ['Foo.h', 'Bar.h', 'module.modulemap']:
+            shutil.copyfile(self.getSourcePath(os.path.join('Inputs', f)),
+                            os.path.join(include, f))
+        super(CXXModulesImportTestCase, self).build()
+    
     @skipUnlessDarwin
     @skipIf(macos_version=["<", "10.12"])
     def test_expr(self):
         self.build()
-        exe = self.getBuildArtifact("a.out")
         target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
             self, 'break here', lldb.SBFileSpec('main.cpp'))
 
         self.expect("expr -l Objective-C++ -- @import Bar")
         self.expect("expr -- Bar()", substrs = ["success"])
+        self.expect("expr -l Objective-C++ -- @import THIS_MODULE_DOES_NOT_EXIST",
+                    error=True)
+
+    @skipUnlessDarwin
+    @skipIf(macos_version=["<", "10.12"])
+    def test_expr_failing_import(self):
+        self.build()
+        shutil.rmtree(self.getBuildArtifact('include'))
+        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+            self, 'break here', lldb.SBFileSpec('main.cpp'))
+
+        self.expect("expr -l Objective-C++ -- @import Bar", error=True)
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap b/lldb/packages/Python/lldbsuite/test/lang/cpp/modules-import/module.modulemap
deleted file mode 100644 (file)
index 4221d0f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-module Foo {
-  header "Foo.h"
-}
-
-module Bar {
-  header "Bar.h"
-}
index 78941355ba9048b47b8a4127954e40d849d73875..05294927a1594891e0d0d55df845b3609643999a 100644 (file)
@@ -229,15 +229,23 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
                             std::equal(sysroot_begin, sysroot_end, path_begin);
     // No need to inject search paths to modules in the sysroot.
     if (!is_system_module) {
+      auto error = [&]() {
+        error_stream.Printf("error: No module map file in %s\n",
+                            module.search_path.AsCString());
+        return false;
+      };
+
       bool is_system = true;
       bool is_framework = false;
       auto *dir =
           HS.getFileMgr().getDirectory(module.search_path.GetStringRef());
+      if (!dir)
+        return error();
       auto *file = HS.lookupModuleMapFile(dir, is_framework);
+      if (!file)
+        return error();
       if (!HS.loadModuleMapFile(file, is_system))
-        error_stream.Printf("error: No module map file in %s\n",
-                            module.search_path.AsCString());
-      return false;
+        return error();
     }
   }
   if (!HS.lookupModule(module.path.front().GetStringRef())) {