}
/// \brief Compile a module file for the given module, using the options
-/// provided by the importing compiler instance.
-static void compileModuleImpl(CompilerInstance &ImportingInstance,
- SourceLocation ImportLoc,
- Module *Module,
- StringRef ModuleFileName) {
+/// provided by the importing compiler instance. Returns true if the module
+/// was built without errors.
+static bool compileModuleImpl(CompilerInstance &ImportingInstance,
+ SourceLocation ImportLoc,
+ Module *Module,
+ StringRef ModuleFileName) {
ModuleMap &ModMap
= ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
if (ImportingInstance.getFrontendOpts().GenerateGlobalModuleIndex) {
ImportingInstance.setBuildGlobalModuleIndex(true);
}
+
+ return !Instance.getDiagnostics().hasErrorOccurred();
}
static bool compileAndLoadModule(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc,
- SourceLocation ModuleNameLoc,
- Module *Module,
+ SourceLocation ModuleNameLoc, Module *Module,
StringRef ModuleFileName) {
+ auto diagnoseBuildFailure = [&] {
+ ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
+ diag::err_module_not_built)
+ << Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
+ };
+
// FIXME: have LockFileManager return an error_code so that we can
// avoid the mkdir when the directory already exists.
StringRef Dir = llvm::sys::path::parent_path(ModuleFileName);
case llvm::LockFileManager::LFS_Owned:
// We're responsible for building the module ourselves.
- // FIXME: if there are errors, don't attempt to load the module.
- compileModuleImpl(ImportingInstance, ModuleNameLoc, Module,
- ModuleFileName);
+ if (!compileModuleImpl(ImportingInstance, ModuleNameLoc, Module,
+ ModuleFileName)) {
+ diagnoseBuildFailure();
+ return false;
+ }
break;
case llvm::LockFileManager::LFS_Shared:
// consistent with this ImportingInstance. Try again...
continue;
} else if (ReadResult == ASTReader::Missing) {
- ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
- diag::err_module_not_built)
- << Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
+ diagnoseBuildFailure();
}
return ReadResult == ASTReader::Success;
}