Skip to content

Commit b52eaac

Browse files
committed
log-level option
#feat
1 parent e2a93e4 commit b52eaac

File tree

9 files changed

+114
-43
lines changed

9 files changed

+114
-43
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ if (MRDOCS_BUILD_TESTS)
401401
"--stdlib-includes=${LIBCXX_DIR}"
402402
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
403403
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
404-
--report=3
404+
--log-level=warn
405405
)
406406
foreach (action IN ITEMS test create update)
407407
add_custom_target(
@@ -416,7 +416,7 @@ if (MRDOCS_BUILD_TESTS)
416416
"--stdlib-includes=${LIBCXX_DIR}"
417417
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
418418
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
419-
--report=3
419+
--log-level=warn
420420
DEPENDS mrdocs-test
421421
)
422422
endforeach ()

docs/mrdocs.schema.json

+17-4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@
190190
"title": "Standard Library include paths",
191191
"type": "array"
192192
},
193+
"log-level": {
194+
"default": "info",
195+
"description": "The reporting level determines the amount of information displayed during the generation of the documentation.",
196+
"enum": [
197+
"trace",
198+
"debug",
199+
"info",
200+
"warn",
201+
"error",
202+
"fatal"
203+
],
204+
"title": "The minimum reporting level"
205+
},
193206
"multipage": {
194207
"default": true,
195208
"description": "Generates a multipage documentation. The output directory must be a directory. This option acts as a hint to the generator to create a multipage documentation. Whether the hint is followed or not depends on the generator.",
@@ -237,11 +250,11 @@
237250
"type": "boolean"
238251
},
239252
"report": {
240-
"default": 1,
241-
"description": "The reporting level determines the amount of information displayed during the generation of the documentation. The levels are: 0 - no output, 1 - errors only, 2 - errors and warnings, 3 - errors, warnings, and information, 4 - errors, warnings, information, and debug information.",
253+
"default": -1,
254+
"description": "The reporting level determines the amount of information displayed during the generation of the documentation. The value `-1` delegates the decision to the `log-level` option.",
242255
"maximum": 5,
243-
"minimum": 0,
244-
"title": "The minimum reporting level: 0 to 4",
256+
"minimum": -1,
257+
"title": "The minimum reporting level",
245258
"type": "integer"
246259
},
247260
"see-below": {

include/mrdocs/Support/ScopeExit.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ScopeExit {
3535
}
3636
};
3737

38+
template <class F>
39+
ScopeExit(F) -> ScopeExit<F>;
40+
3841
template <class T>
3942
class ScopeExitRestore {
4043
T prev_;
@@ -66,9 +69,6 @@ class ScopeExitRestore {
6669
}
6770
};
6871

69-
template <class F>
70-
ScopeExit(F) -> ScopeExit<F>;
71-
7272
template <class T>
7373
ScopeExitRestore(T&) -> ScopeExitRestore<T>;
7474

src/lib/Lib/Config.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct PublicSettingsVisitor {
100100
}
101101
else if constexpr (std::same_as<DT, int> || std::same_as<DT, unsigned>)
102102
{
103-
return normalizeInteger(name, value, opts);
103+
return normalizeInteger(self, name, value, opts);
104104
}
105105
else
106106
{
@@ -328,15 +328,11 @@ struct PublicSettingsVisitor {
328328
template <std::integral T>
329329
Expected<void>
330330
normalizeInteger(
331+
PublicSettings& self,
331332
std::string_view name,
332333
T& value,
333334
PublicSettings::OptionProperties const& opts) const
334335
{
335-
if (name == "concurrency" && std::cmp_equal(value, 0))
336-
{
337-
value = std::thread::hardware_concurrency();
338-
return {};
339-
}
340336
MRDOCS_CHECK(
341337
!opts.minValue || std::cmp_greater_equal(value, *opts.minValue),
342338
formatError(
@@ -351,6 +347,30 @@ struct PublicSettingsVisitor {
351347
name,
352348
value,
353349
*opts.maxValue));
350+
351+
if (name == "concurrency" && std::cmp_equal(value, 0))
352+
{
353+
value = std::thread::hardware_concurrency();
354+
return {};
355+
}
356+
357+
if (name == "report" && std::cmp_not_equal(value, static_cast<unsigned>(-1)))
358+
{
359+
static_assert(
360+
static_cast<unsigned>(PublicSettings::LogLevel::Trace) ==
361+
static_cast<unsigned>(report::Level::trace));
362+
static_assert(
363+
static_cast<unsigned>(PublicSettings::LogLevel::Fatal) ==
364+
static_cast<unsigned>(report::Level::fatal));
365+
MRDOCS_ASSERT(opts.deprecated);
366+
report::warn(
367+
"`report` option is deprecated, use `log-level` instead");
368+
auto const logLevel = static_cast<PublicSettings::LogLevel>(value);
369+
auto logLevelStr = PublicSettings::toString(logLevel);
370+
report::warn("`report` option: setting `log-level` to \"{}\"", logLevelStr);
371+
self.logLevel = logLevel;
372+
return {};
373+
}
354374
return {};
355375
}
356376

src/lib/Lib/ConfigOptions.json

+22-8
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@
350350
"details": "The desired level of concurrency: 0 for hardware-suggested.",
351351
"type": "unsigned",
352352
"default": 0,
353-
"value-mapping": {
354-
"0": "std::thread::hardware_concurrency()"
355-
}
353+
"min-value": 0
356354
},
357355
{
358356
"name": "verbose",
@@ -363,12 +361,28 @@
363361
},
364362
{
365363
"name": "report",
366-
"brief": "The minimum reporting level: 0 to 4",
367-
"details": "The reporting level determines the amount of information displayed during the generation of the documentation. The levels are: 0 - no output, 1 - errors only, 2 - errors and warnings, 3 - errors, warnings, and information, 4 - errors, warnings, information, and debug information.",
364+
"brief": "The minimum reporting level",
365+
"details": "The reporting level determines the amount of information displayed during the generation of the documentation. The value `-1` delegates the decision to the `log-level` option.",
368366
"type": "unsigned",
369-
"default": 1,
370-
"min-value": 0,
371-
"max-value": 5
367+
"default": -1,
368+
"min-value": -1,
369+
"max-value": 5,
370+
"deprecated": "Use `log-level` instead"
371+
},
372+
{
373+
"name": "log-level",
374+
"brief": "The minimum reporting level",
375+
"details": "The reporting level determines the amount of information displayed during the generation of the documentation.",
376+
"type": "enum",
377+
"values": [
378+
"trace",
379+
"debug",
380+
"info",
381+
"warn",
382+
"error",
383+
"fatal"
384+
],
385+
"default": "info"
372386
},
373387
{
374388
"name": "ignore-map-errors",

src/test/TestMain.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ int test_main(int argc, char const** argv)
9494
return EXIT_FAILURE;
9595
}
9696

97-
// Apply reportLevel
98-
report::setMinimumLevel(report::getLevel(
99-
testArgs.report.getValue()));
100-
97+
// Apply log-level
98+
auto ll = PublicSettings::LogLevel::Info;
99+
PublicSettings::fromString(testArgs.logLevel.getValue(), ll);
100+
report::setMinimumLevel(static_cast<report::Level>(ll));
101101
report::setSourceLocationWarnings(false);
102102

103103
if (!testArgs.cmdLineInputs.empty())

src/tool/GenerateAction.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
// Copyright (c) 2024 Alan de Freitas ([email protected])
89
//
910
// Official repository: https://github.com/cppalliance/mrdocs
1011
//
@@ -25,8 +26,7 @@
2526

2627
#include <cstdlib>
2728

28-
namespace clang {
29-
namespace mrdocs {
29+
namespace clang::mrdocs {
3030

3131
namespace {
3232

@@ -101,6 +101,7 @@ DoGenerateAction(
101101
MRDOCS_TRY(Config::Settings::load_file(publicSettings, configPath, dirs));
102102
MRDOCS_TRY(toolArgs.apply(publicSettings, dirs, argv));
103103
MRDOCS_TRY(publicSettings.normalize(dirs));
104+
report::setMinimumLevel(static_cast<report::Level>(publicSettings.logLevel));
104105
ThreadPool threadPool(publicSettings.concurrency);
105106
MRDOCS_TRY(
106107
std::shared_ptr<ConfigImpl const> config,
@@ -213,5 +214,4 @@ DoGenerateAction(
213214
return {};
214215
}
215216

216-
} // mrdocs
217-
} // clang
217+
} // clang::mrdocs

src/tool/ToolMain.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ mrdocs_main(int argc, char const** argv)
108108
return EXIT_FAILURE;
109109
}
110110

111-
// Apply report level
112-
report::setMinimumLevel(report::getLevel(
113-
toolArgs.report.getValue()));
114-
115111
// Set up addons directory
116112
#ifdef __GNUC__
117113
#pragma GCC diagnostic push
@@ -124,6 +120,10 @@ mrdocs_main(int argc, char const** argv)
124120
#endif
125121
std::string execPath = llvm::sys::fs::getMainExecutable(argv[0], addressOfMain);
126122

123+
// Before `DoGenerateAction`, we use an error reporting level.
124+
// DoGenerateAction will set the level to whatever is specified in
125+
// the command line or the configuration file
126+
report::setMinimumLevel(report::Level::error);
127127
auto res = getReferenceDirectories(execPath);
128128
if (!res)
129129
{
@@ -141,8 +141,7 @@ mrdocs_main(int argc, char const** argv)
141141
auto configPath = *std::move(expConfigPath);
142142

143143
// Generate
144-
auto exp = DoGenerateAction(configPath, dirs, argv);
145-
if (!exp)
144+
if (auto exp = DoGenerateAction(configPath, dirs, argv); !exp)
146145
{
147146
report::error("Generating reference failed: {}", exp.error());
148147
}

util/generate-config-info.py

+31-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def get_flat_suboptions(option_name, options):
6363

6464
def get_valid_enum_categories():
6565
valid_enum_cats = {
66-
'generator': ["adoc", "html", "xml"]
66+
'generator': ["adoc", "html", "xml"],
67+
'log-level': ["trace", "debug", "info", "warn", "error", "fatal"]
6768
}
6869
return valid_enum_cats
6970

@@ -310,6 +311,7 @@ def generate_public_settings_hpp(config):
310311
contents += ' //--------------------------------------------\n'
311312
contents += ' // Enums\n'
312313
contents += ' //--------------------------------------------\n\n'
314+
313315
for [enum_name, enum_values] in get_valid_enum_categories().items():
314316
options_that_use_it = []
315317
for category in config:
@@ -331,6 +333,31 @@ def generate_public_settings_hpp(config):
331333
contents += f' {to_pascal_case(enum_value)},\n'
332334
contents += ' };\n\n'
333335

336+
contents += f' static\n'
337+
contents += f' constexpr\n'
338+
contents += f' std::string_view\n'
339+
contents += f' toString({to_pascal_case(enum_name)} const e) {{\n'
340+
contents += f' switch (e) {{\n'
341+
for enum_value in enum_values:
342+
contents += f' case {to_pascal_case(enum_name)}::{to_pascal_case(enum_value)}:\n'
343+
contents += f' return "{enum_value}";\n'
344+
contents += f' }}\n'
345+
contents += f' return "";\n'
346+
contents += ' }\n\n'
347+
348+
contents += f' static\n'
349+
contents += f' constexpr\n'
350+
contents += f' bool\n'
351+
contents += f' fromString(std::string_view const str, {to_pascal_case(enum_name)}& e) {{\n'
352+
for enum_value in enum_values:
353+
contents += f' if (str == "{enum_value}")\n'
354+
contents += f' {{\n'
355+
contents += f' e = {to_pascal_case(enum_name)}::{to_pascal_case(enum_value)};\n'
356+
contents += f' return true;\n'
357+
contents += f' }}\n'
358+
contents += f' return false;\n'
359+
contents += ' }\n\n'
360+
334361
for category in config:
335362
category_name = category['category']
336363
category_brief = category['brief']
@@ -437,7 +464,7 @@ def generate_public_settings_hpp(config):
437464
# print the default in cpp
438465
if cpp_default_value is not None:
439466
cpp_type = to_cpp_type(option)
440-
if cpp_type in ['bool', 'unsigned', 'int']:
467+
if cpp_type in ['bool', 'unsigned', 'int', 'enum']:
441468
cpp_type = f'static_cast<{cpp_type}>'
442469
contents += f'{pad}.{to_camel_case("default")}Value = {cpp_type}({cpp_default_value}),\n'
443470
if 'relative-to' in option:
@@ -910,8 +937,7 @@ def generate_public_toolargs_cpp(config):
910937
contents += f'#include {header}\n'
911938
contents += '\n'
912939

913-
contents += 'namespace clang {\n'
914-
contents += 'namespace mrdocs {\n\n'
940+
contents += 'namespace clang::mrdocs {\n\n'
915941

916942
# Main constructor that initializes all options
917943
contents += 'PublicToolArgs::\n'
@@ -1020,8 +1046,7 @@ def generate_public_toolargs_cpp(config):
10201046
contents += ' return {};\n'
10211047
contents += '}\n'
10221048

1023-
contents += '} // namespace mrdocs\n'
1024-
contents += '} // namespace clang\n\n'
1049+
contents += '} // namespace clang::mrdocs\n'
10251050
return contents
10261051

10271052

0 commit comments

Comments
 (0)