Skip to content

Commit 3faf936

Browse files
committed
add verbose config option
1 parent 309b16d commit 3faf936

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

include/mrdox/Config.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Config
5050
llvm::SmallString<0> configDir_;
5151
std::string sourceRoot_;
5252
std::vector<std::string> inputFileFilter_;
53+
bool verbose_ = true;
5354

5455
explicit Config(llvm::StringRef configDir);
5556

@@ -106,6 +107,14 @@ class Config
106107
//
107108
//--------------------------------------------
108109

110+
/** Return true if tools should show progress.
111+
*/
112+
bool
113+
verbose() const noexcept
114+
{
115+
return verbose_;
116+
}
117+
109118
/** Return the full path to the configuration directory.
110119
111120
The returned path will always be POSIX
@@ -151,6 +160,15 @@ class Config
151160
//
152161
//--------------------------------------------
153162

163+
/** Set whether tools should show progress.
164+
*/
165+
void
166+
setVerbose(
167+
bool verbose) noexcept
168+
{
169+
verbose_ = verbose;
170+
}
171+
154172
/** Set the directory where the input files are stored.
155173
156174
Symbol documentation will not be emitted unless

include/mrdox/Corpus.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ struct TypedefInfo;
3636
*/
3737
class Corpus
3838
{
39+
Config const& config_;
40+
41+
explicit
42+
Corpus(
43+
Config const& config) noexcept
44+
: config_(config)
45+
{
46+
}
47+
3948
public:
4049
/** Index of all emitted symbols.
4150
*/
@@ -58,7 +67,10 @@ class Corpus
5867

5968
/** Build the intermediate representation of the code being documented.
6069
61-
@par R The diagnostic reporting object to
70+
@param config The configuration, whose lifetime
71+
must extend until the corpus is destroyed.
72+
73+
@param R The diagnostic reporting object to
6274
use for delivering errors and information.
6375
*/
6476
[[nodiscard]]
@@ -73,7 +85,7 @@ class Corpus
7385
7486
@return true upon success.
7587
76-
@par R The diagnostic reporting object to
88+
@param R The diagnostic reporting object to
7789
use for delivering errors and information.
7890
*/
7991
[[nodiscard]]
@@ -173,14 +185,14 @@ class Corpus
173185

174186
/** Insert this element and all its children into the Corpus.
175187
176-
@par Thread Safety
188+
@param Thread Safety
177189
May be called concurrently.
178190
*/
179191
void insert(std::unique_ptr<Info> Ip);
180192

181193
/** Insert Info into the index
182194
183-
@par Thread Safety
195+
@param Thread Safety
184196
May be called concurrently.
185197
*/
186198
void insertIntoIndex(Info const& I);
@@ -197,8 +209,6 @@ class Corpus
197209

198210

199211
private:
200-
Corpus() = default;
201-
202212
llvm::sys::Mutex infoMutex;
203213
llvm::sys::Mutex allSymbolsMutex;
204214
bool isCanonical_ = false;

source/lib/Config.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct Config::Options
2828

2929
std::string source_root;
3030
std::vector<std::string> input_include;
31+
bool verbose = true;
3132
};
3233

3334
} // mrdox
@@ -53,6 +54,7 @@ struct llvm::yaml::MappingTraits<
5354
static void mapping(
5455
IO& io, clang::mrdox::Config::Options& opt)
5556
{
57+
io.mapOptional("verbose", opt.verbose);
5658
io.mapOptional("source-root", opt.source_root);
5759
io.mapOptional("input", opt.input_include);
5860
}
@@ -121,6 +123,7 @@ loadFromFile(
121123
}
122124

123125
// apply opt to Config
126+
(*config)->setVerbose(opt.verbose);
124127
if(auto err = (*config)->setSourceRoot(opt.source_root))
125128
return err;
126129

@@ -166,7 +169,7 @@ setSourceRoot(
166169
namespace path = llvm::sys::path;
167170

168171
llvm::SmallString<0> temp(dirPath);
169-
if(! path::is_absolute(sourceRoot_))
172+
if(! path::is_absolute(sourceRoot_, path::Style::posix))
170173
{
171174
std::error_code ec = fs::make_absolute(temp);
172175
if(ec)

source/lib/Corpus.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ build(
4242
Config const& config,
4343
Reporter& R)
4444
{
45-
auto up = std::unique_ptr<Corpus>(new Corpus);
45+
auto up = std::unique_ptr<Corpus>(new Corpus(config));
4646
Corpus& corpus = *up;
4747

4848
// Traverse the AST for all translation units
4949
// and emit serializd bitcode into tool results.
5050
// This operation happens ona thread pool.
5151

52-
llvm::outs() << "Mapping declarations\n";
52+
if(config.verbose())
53+
llvm::outs() << "Mapping declarations\n";
5354
llvm::Error err = ex.execute(
5455
makeToolFactory(*ex.getExecutionContext(), config, R),
5556
config.ArgAdjuster);
@@ -72,7 +73,8 @@ build(
7273
// a vector of one or more bitcodes. These will
7374
// be merged later.
7475

75-
llvm::outs() << "Collecting symbols\n";
76+
if(config.verbose())
77+
llvm::outs() << "Collecting symbols\n";
7678
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
7779
ex.getToolResults()->forEachResult(
7880
[&](StringRef Key, StringRef Value)
@@ -82,7 +84,8 @@ build(
8284
});
8385

8486
// First reducing phase (reduce all decls into one info per decl).
85-
llvm::outs() << "Reducing " << USRToBitcode.size() << " declarations\n";
87+
if(config.verbose())
88+
llvm::outs() << "Reducing " << USRToBitcode.size() << " declarations\n";
8689
std::atomic<bool> GotFailure;
8790
GotFailure = false;
8891
// VFALCO Should this concurrency be a command line option?
@@ -127,8 +130,9 @@ build(
127130

128131
Pool.wait();
129132

130-
llvm::outs() <<
131-
"Collected " << corpus.InfoMap.size() << " symbols.\n";
133+
if(config.verbose())
134+
llvm::outs() << "Collected " <<
135+
corpus.InfoMap.size() << " symbols.\n";
132136

133137
if(GotFailure)
134138
{
@@ -172,7 +176,8 @@ canonicalize(
172176
}
173177

174178
Temps t;
175-
R.print("Canonicalizing...");
179+
if(config_.verbose())
180+
R.print("Canonicalizing...");
176181
if(! canonicalize(*p, t, R))
177182
return false;
178183
isCanonical_ = true;

source/tests/TestMain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ testMain(
3535
if(auto err = (*config)->setSourceRoot((*config)->configDir()))
3636
return (void)R.error(err, "set source root to '", (*config)->configDir(), "'");
3737

38+
(*config)->setVerbose(false);
39+
3840
// We need a different config for each directory
3941
// passed on the command line, and thus each must
4042
// also have a separate Tester.

0 commit comments

Comments
 (0)