Skip to content

Commit

Permalink
Improve error handling for Clang module imports.
Browse files Browse the repository at this point in the history
rdar://problem/48883558

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

llvm-svn: 356462
  • Loading branch information
adrian-prantl committed Mar 19, 2019
1 parent af40d43 commit da8c0e4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
@@ -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
Expand Up @@ -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 *
Expand All @@ -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)
Expand Up @@ -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())) {
Expand Down

0 comments on commit da8c0e4

Please sign in to comment.