Skip to content

Commit 07dc2a9

Browse files
Merge pull request #36785 from apple/QuietMisdreavus/quiet-symbolgraph
[SymbolGraphGen] silence symbolgraph-extract output without -v flag
2 parents 9200dde + ba2b92b commit 07dc2a9

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

include/swift/Option/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def help_hidden : Flag<["-", "--"], "help-hidden">,
184184
Flags<[HelpHidden, FrontendOption]>,
185185
HelpText<"Display available options, including hidden options">;
186186

187-
def v : Flag<["-"], "v">, Flags<[DoesNotAffectIncrementalBuild]>,
187+
def v : Flag<["-"], "v">,
188+
Flags<[DoesNotAffectIncrementalBuild, SwiftSymbolGraphExtractOption]>,
188189
HelpText<"Show commands to run and use verbose output">;
189190
def version : Flag<["-", "--"], "version">, Flags<[FrontendOption]>,
190191
HelpText<"Print version information and exit">;

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ struct SymbolGraphOptions {
3535
/// Emit members gotten through class inheritance or protocol default
3636
/// implementations with compound, "SYNTHESIZED" USRs.
3737
bool EmitSynthesizedMembers;
38+
39+
/// Whether to print informational messages when rendering
40+
/// a symbol graph.
41+
bool PrintMessages;
3842
};
3943

4044
} // end namespace symbolgraphgen

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5633,6 +5633,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56335633
/* PrettyPrint */false,
56345634
AccessLevel::Public,
56355635
/*EmitSynthesizedMembers*/true,
5636+
/*PrintMessages*/false,
56365637
};
56375638
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
56385639
}

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ symbolgraphgen::emitSymbolGraphForModule(ModuleDecl *M,
7070
SmallVector<Decl *, 64> ModuleDecls;
7171
M->getDisplayDecls(ModuleDecls);
7272

73-
llvm::errs() << ModuleDecls.size()
74-
<< " top-level declarations in this module.\n";
73+
if (Options.PrintMessages)
74+
llvm::errs() << ModuleDecls.size()
75+
<< " top-level declarations in this module.\n";
7576

7677
for (auto *Decl : ModuleDecls) {
7778
Walker.walk(Decl);
7879
}
7980

80-
llvm::errs()
81-
<< "Found " << Walker.MainGraph.Nodes.size() << " symbols and "
82-
<< Walker.MainGraph.Edges.size() << " relationships.\n";
81+
if (Options.PrintMessages)
82+
llvm::errs()
83+
<< "Found " << Walker.MainGraph.Nodes.size() << " symbols and "
84+
<< Walker.MainGraph.Edges.size() << " relationships.\n";
8385

8486
int Success = EXIT_SUCCESS;
8587

test/SymbolGraph/verbose.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name verbose -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name verbose -I %t -pretty-print -output-dir %t | %FileCheck %s -check-prefix=QUIET --allow-empty
4+
// RUN: %target-swift-symbolgraph-extract -module-name verbose -I %t -pretty-print -output-dir %t -v 2>&1 | %FileCheck %s -check-prefix=VERBOSE
5+
6+
// RUN: %empty-directory(%t)
7+
// 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
8+
9+
// QUIET-NOT: Emitting symbol graph for module file
10+
// QUIET-NOT: 2 top-level declarations in this module.
11+
// QUIET-NOT: Found 1 symbols and 0 relationships.
12+
13+
// VERBOSE: Emitting symbol graph for module file
14+
// VERBOSE: 2 top-level declarations in this module.
15+
// VERBOSE: Found 1 symbols and 0 relationships.
16+
17+
// DRIVER-NOT: Emitting symbol graph for module file
18+
// DRIVER-NOT: 2 top-level declarations in this module.
19+
// DRIVER-NOT: Found 1 symbols and 0 relationships.
20+
21+
public func someFunc() {}

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
869869
/*PrettyPrint=*/false,
870870
AccessLevel::Private,
871871
/*EmitSynthesizedMembers*/ false,
872+
/*PrintMessages*/ false,
872873
};
873874

874875
symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
166166
ParsedArgs.hasArg(OPT_pretty_print),
167167
AccessLevel::Public,
168168
!ParsedArgs.hasArg(OPT_skip_synthesized_members),
169+
ParsedArgs.hasArg(OPT_v),
169170
};
170171

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

220221
const auto &MainFile = M->getMainFile(FileUnitKind::SerializedAST);
221-
llvm::errs() << "Emitting symbol graph for module file: " << MainFile.getModuleDefiningPath() << '\n';
222+
223+
if (Options.PrintMessages)
224+
llvm::errs() << "Emitting symbol graph for module file: " << MainFile.getModuleDefiningPath() << '\n';
222225

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

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

242247
Success |= symbolgraphgen::emitSymbolGraphForModule(CIM, Options);
243248
}

0 commit comments

Comments
 (0)