Skip to content

don't crash the symbol graph tool when a module fails to load #35923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/SymbolGraph/Module/FailedLoad.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %S/Inputs/FailedLoad/A.swift -module-name A -emit-module -emit-module-path %t/
// RUN: %target-build-swift %s -module-name FailedLoad -emit-module -I %t -emit-module-path %t/

// RUN: rm %t/A.swiftmodule

// RUN: not %target-swift-symbolgraph-extract -module-name FailedLoad -I %t -pretty-print -output-dir %t 2>&1 | %FileCheck %s

// CHECK-NOT: Emitting symbol graph for module file

import A

public struct Outer {
public var Something: A.Inner
}
3 changes: 3 additions & 0 deletions test/SymbolGraph/Module/Inputs/FailedLoad/A.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct Inner {
public var Field: String
}
8 changes: 8 additions & 0 deletions tools/driver/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
}
return EXIT_FAILURE;
}

if (M->failedToLoad()) {
llvm::errs() << "Error: Failed to load the module '" << options::ModuleName
<< "'. Are you missing build dependencies or include/framework directories?\n"
<< "See the previous error messages for details. Aborting.\n";

return EXIT_FAILURE;
}

const auto &MainFile = M->getMainFile(FileUnitKind::SerializedAST);
llvm::errs() << "Emitting symbol graph for module file: " << MainFile.getModuleDefiningPath() << '\n';
Expand Down