Skip to content

Commit 2589d25

Browse files
author
David Ungar
authored
Merge pull request #36175 from davidungar/enhance-tool
[NFC, Incremental] Add ability to decode a swiftmodule file to `swift-dependency-tool`
2 parents ac1f769 + 4c12c71 commit 2589d25

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,10 @@ class SourceFileDepGraph {
879879
}
880880

881881
/// Read a swiftdeps file at \p path and return a SourceFileDepGraph if
882-
/// successful.
883-
Optional<SourceFileDepGraph> static loadFromPath(StringRef);
882+
/// successful. If \p allowSwiftModule is true, try to load the information
883+
/// from a swiftmodule file if appropriate.
884+
Optional<SourceFileDepGraph> static loadFromPath(
885+
StringRef, bool allowSwiftModule = false);
884886

885887
/// Read a swiftdeps file from \p buffer and return a SourceFileDepGraph if
886888
/// successful.

lib/AST/FineGrainedDependencies.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ using namespace fine_grained_dependencies;
4242
// MARK: Emitting and reading SourceFileDepGraph
4343
//==============================================================================
4444

45-
Optional<SourceFileDepGraph> SourceFileDepGraph::loadFromPath(StringRef path) {
45+
Optional<SourceFileDepGraph>
46+
SourceFileDepGraph::loadFromPath(StringRef path, const bool allowSwiftModule) {
47+
const bool treatAsModule =
48+
allowSwiftModule &&
49+
path.endswith(file_types::getExtension(file_types::TY_SwiftModuleFile));
4650
auto bufferOrError = llvm::MemoryBuffer::getFile(path);
4751
if (!bufferOrError)
4852
return None;
49-
return loadFromBuffer(*bufferOrError.get());
53+
return treatAsModule ? loadFromSwiftModuleBuffer(*bufferOrError.get())
54+
: loadFromBuffer(*bufferOrError.get());
5055
}
5156

5257
Optional<SourceFileDepGraph>

tools/swift-dependency-tool/swift-dependency-tool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ int main(int argc, char *argv[]) {
216216
}
217217

218218
case ActionType::BinaryToYAML: {
219-
auto fg = SourceFileDepGraph::loadFromPath(options::InputFilename);
219+
auto fg = SourceFileDepGraph::loadFromPath(options::InputFilename, true);
220220
if (!fg) {
221221
llvm::errs() << "Failed to read dependency file\n";
222222
return 1;

0 commit comments

Comments
 (0)