Skip to content

[SymbolGraphGen] silence symbolgraph-extract output without -v flag #36785

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 2 commits into from
Apr 9, 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
3 changes: 2 additions & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def help_hidden : Flag<["-", "--"], "help-hidden">,
Flags<[HelpHidden, FrontendOption]>,
HelpText<"Display available options, including hidden options">;

def v : Flag<["-"], "v">, Flags<[DoesNotAffectIncrementalBuild]>,
def v : Flag<["-"], "v">,
Flags<[DoesNotAffectIncrementalBuild, SwiftSymbolGraphExtractOption]>,
HelpText<"Show commands to run and use verbose output">;
def version : Flag<["-", "--"], "version">, Flags<[FrontendOption]>,
HelpText<"Print version information and exit">;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/SymbolGraphGen/SymbolGraphOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct SymbolGraphOptions {
/// Emit members gotten through class inheritance or protocol default
/// implementations with compound, "SYNTHESIZED" USRs.
bool EmitSynthesizedMembers;

/// Whether to print informational messages when rendering
/// a symbol graph.
bool PrintMessages;
};

} // end namespace symbolgraphgen
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5633,6 +5633,7 @@ void swift::serialize(ModuleOrSourceFile DC,
/* PrettyPrint */false,
AccessLevel::Public,
/*EmitSynthesizedMembers*/true,
/*PrintMessages*/false,
};
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/SymbolGraphGen/SymbolGraphGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ symbolgraphgen::emitSymbolGraphForModule(ModuleDecl *M,
SmallVector<Decl *, 64> ModuleDecls;
M->getDisplayDecls(ModuleDecls);

llvm::errs() << ModuleDecls.size()
<< " top-level declarations in this module.\n";
if (Options.PrintMessages)
llvm::errs() << ModuleDecls.size()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to implement this would be to create a stream that forwards its input to llvm:errs() only if QuietMessages is true. That way we don't have to guard the messages around if checks. I don't really mind either way though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's some "optional stream wrapper" type that exists somewhere, this implementation feels like the "smallest diff" way to implement this. Otherwise, i'd have to implement the wrapper myself.

<< " top-level declarations in this module.\n";

for (auto *Decl : ModuleDecls) {
Walker.walk(Decl);
}

llvm::errs()
<< "Found " << Walker.MainGraph.Nodes.size() << " symbols and "
<< Walker.MainGraph.Edges.size() << " relationships.\n";
if (Options.PrintMessages)
llvm::errs()
<< "Found " << Walker.MainGraph.Nodes.size() << " symbols and "
<< Walker.MainGraph.Edges.size() << " relationships.\n";

int Success = EXIT_SUCCESS;

Expand Down
21 changes: 21 additions & 0 deletions test/SymbolGraph/verbose.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name verbose -emit-module -emit-module-path %t/
// RUN: %target-swift-symbolgraph-extract -module-name verbose -I %t -pretty-print -output-dir %t | %FileCheck %s -check-prefix=QUIET --allow-empty
// RUN: %target-swift-symbolgraph-extract -module-name verbose -I %t -pretty-print -output-dir %t -v 2>&1 | %FileCheck %s -check-prefix=VERBOSE

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name verbose -emit-module -emit-module-path %t/verbose.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t | %FileCheck %s -check-prefix=DRIVER --allow-empty

// QUIET-NOT: Emitting symbol graph for module file
// QUIET-NOT: 2 top-level declarations in this module.
// QUIET-NOT: Found 1 symbols and 0 relationships.

// VERBOSE: Emitting symbol graph for module file
// VERBOSE: 2 top-level declarations in this module.
// VERBOSE: Found 1 symbols and 0 relationships.

// DRIVER-NOT: Emitting symbol graph for module file
// DRIVER-NOT: 2 top-level declarations in this module.
// DRIVER-NOT: Found 1 symbols and 0 relationships.

public func someFunc() {}
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
/*PrettyPrint=*/false,
AccessLevel::Private,
/*EmitSynthesizedMembers*/ false,
/*PrintMessages*/ false,
};

symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,
Expand Down
11 changes: 8 additions & 3 deletions tools/driver/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
ParsedArgs.hasArg(OPT_pretty_print),
AccessLevel::Public,
!ParsedArgs.hasArg(OPT_skip_synthesized_members),
ParsedArgs.hasArg(OPT_v),
};

if (auto *A = ParsedArgs.getLastArg(OPT_minimum_access_level)) {
Expand Down Expand Up @@ -218,7 +219,9 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
}

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

if (Options.PrintMessages)
llvm::errs() << "Emitting symbol graph for module file: " << MainFile.getModuleDefiningPath() << '\n';

int Success = symbolgraphgen::emitSymbolGraphForModule(M, Options);

Expand All @@ -236,8 +239,10 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
auto CIM = CI.getASTContext().getModuleByName(OM->getNameStr());
if (CIM) {
const auto &CIMainFile = CIM->getMainFile(FileUnitKind::SerializedAST);
llvm::errs() << "Emitting symbol graph for cross-import overlay module file: "
<< CIMainFile.getModuleDefiningPath() << '\n';

if (Options.PrintMessages)
llvm::errs() << "Emitting symbol graph for cross-import overlay module file: "
<< CIMainFile.getModuleDefiningPath() << '\n';

Success |= symbolgraphgen::emitSymbolGraphForModule(CIM, Options);
}
Expand Down