Skip to content

Commit 3139781

Browse files
committed
mrdox-test uses command line parser
fix #39, fix #51, fix #69
1 parent 9af8c48 commit 3139781

22 files changed

+831
-537
lines changed

CMakeLists.txt

+18-18
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,24 @@ file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS
8484
source/lib/*.cpp
8585
source/lib/*.natvis)
8686

87-
add_library(mrdox_lib ${LIB_INCLUDES} ${LIB_SOURCES})
88-
target_compile_features(mrdox_lib PUBLIC cxx_std_20)
89-
target_include_directories(mrdox_lib
87+
add_library(mrdox-api ${LIB_INCLUDES} ${LIB_SOURCES})
88+
target_compile_features(mrdox-api PUBLIC cxx_std_20)
89+
target_include_directories(mrdox-api
9090
PUBLIC
9191
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
9292
PRIVATE
9393
"${PROJECT_SOURCE_DIR}/source/lib/"
9494
)
9595

9696
# LLVM
97-
target_link_libraries(mrdox_lib PUBLIC ${llvm_libs})
98-
target_include_directories(mrdox_lib SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
97+
target_link_libraries(mrdox-api PUBLIC ${llvm_libs})
98+
target_include_directories(mrdox-api SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
9999

100100
# Clang
101101
if (CLANG_SIMPLE_LIBS)
102-
target_link_libraries(mrdox_lib PUBLIC LLVM clang clang-cpp)
102+
target_link_libraries(mrdox-api PUBLIC LLVM clang clang-cpp)
103103
else()
104-
target_link_libraries(mrdox_lib
104+
target_link_libraries(mrdox-api
105105
PUBLIC
106106
clangAST
107107
clangBasic
@@ -111,25 +111,25 @@ else()
111111
clangToolingCore
112112
clangToolingInclusions)
113113
endif()
114-
target_include_directories(mrdox_lib SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
114+
target_include_directories(mrdox-api SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
115115

116116
# Windows, Win64
117117
if (WIN32)
118118
target_compile_definitions(
119-
mrdox_lib
119+
mrdox-api
120120
PUBLIC
121121
-D_WIN32_WINNT=0x0601
122122
-D_CRT_SECURE_NO_WARNINGS
123123
-D_SILENCE_CXX20_CISO646_REMOVED_WARNING
124124
)
125125
get_target_property(LLVM_CONFIGURATION_TYPE LLVMCore IMPORTED_CONFIGURATIONS)
126126
if (LLVM_CONFIGURATION_TYPE STREQUAL RELWITHDEBINFO)
127-
target_compile_definitions(mrdox_lib PUBLIC -D_ITERATOR_DEBUG_LEVEL=0)
128-
target_compile_options(mrdox_lib PUBLIC /MD)
127+
target_compile_definitions(mrdox-api PUBLIC -D_ITERATOR_DEBUG_LEVEL=0)
128+
target_compile_options(mrdox-api PUBLIC /MD)
129129
endif()
130130
if(MSVC)
131131
target_compile_options(
132-
mrdox_lib
132+
mrdox-api
133133
PUBLIC
134134
/permissive- # strict C++
135135
/W4 # enable all warnings
@@ -141,7 +141,7 @@ endif ()
141141

142142
if (MRDOX_CLANG)
143143
target_compile_options(
144-
mrdox_lib
144+
mrdox-api
145145
PUBLIC
146146
-Wno-unused-private-field
147147
-Wno-unused-value
@@ -162,7 +162,7 @@ source_group(TREE ${PROJECT_SOURCE_DIR}/source/lib PREFIX "source" FILES ${LIB_S
162162

163163
file(GLOB_RECURSE TOOL_SOURCES CONFIGURE_DEPENDS source/tool/*.cpp source/tool/*.hpp)
164164
add_executable(mrdox ${TOOL_SOURCES})
165-
target_link_libraries(mrdox PRIVATE mrdox_lib)
165+
target_link_libraries(mrdox PRIVATE mrdox-api)
166166
target_include_directories(mrdox PRIVATE source/tool)
167167

168168
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
@@ -177,10 +177,10 @@ source_group(TREE ${PROJECT_SOURCE_DIR}/source/tool PREFIX "source" FILES ${TOOL
177177
if (MRDOX_BUILD_TESTS)
178178
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS source/tests/*.cpp source/tests/*.hpp)
179179
enable_testing()
180-
add_executable(mrdox_tests ${TEST_SOURCES})
181-
target_link_libraries(mrdox_tests PRIVATE mrdox_lib ${llvm_libs})
182-
target_include_directories(mrdox_tests PRIVATE ${PROJECT_SOURCE_DIR}/source/tests)
183-
add_test(NAME mrdox_tests COMMAND mrdox_tests
180+
add_executable(mrdox-test ${TEST_SOURCES})
181+
target_link_libraries(mrdox-test PRIVATE mrdox-api ${llvm_libs})
182+
target_include_directories(mrdox-test PRIVATE ${PROJECT_SOURCE_DIR}/source/tests)
183+
add_test(NAME mrdox-test COMMAND mrdox-test
184184
"${PROJECT_SOURCE_DIR}/tests/decls"
185185
"${PROJECT_SOURCE_DIR}/tests/javadoc"
186186
)

include/mrdox/Config.hpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace mrdox {
4141
particular directory from which absolute paths
4242
are calculated from relative paths.
4343
*/
44-
class Config
44+
class Config : public std::enable_shared_from_this<Config>
4545
{
4646
template<class T>
4747
friend struct llvm::yaml::MappingTraits;
@@ -242,11 +242,37 @@ class Config
242242

243243
//------------------------------------------------
244244

245+
/** A group representing possibly concurrent related tasks.
246+
*/
245247
class Config::WorkGroup
246248
{
247249
public:
250+
/** Destructor.
251+
*/
252+
~WorkGroup();
253+
254+
/** Constructor.
255+
256+
Default constructed workgroups have no
257+
concurrency level. Calls to post and wait
258+
are blocking.
259+
*/
260+
WorkGroup() noexcept = default;
261+
262+
/** Constructor.
263+
*/
248264
explicit
249-
WorkGroup(Config const& config);
265+
WorkGroup(
266+
std::shared_ptr<Config const> config);
267+
268+
/** Constructor.
269+
*/
270+
WorkGroup(WorkGroup const& other);
271+
272+
/** Assignment.
273+
*/
274+
WorkGroup&
275+
operator=(WorkGroup const& other);
250276

251277
/** Post work to the work group.
252278
*/
@@ -266,7 +292,7 @@ class Config::WorkGroup
266292

267293
class Impl;
268294

269-
Config::Impl const& config_;
295+
std::shared_ptr<Config::Impl const> config_;
270296
std::unique_ptr<Base> impl_;
271297
};
272298

@@ -279,7 +305,7 @@ parallelForEach(
279305
Range&& range,
280306
UnaryFunction const& f) const
281307
{
282-
WorkGroup wg(*this);
308+
WorkGroup wg(shared_from_this());
283309
for(auto&& element : range)
284310
wg.post([&f, &element]
285311
{

include/mrdox/format/Generator.hpp renamed to include/mrdox/Generator.hpp

+52-44
Original file line numberDiff line numberDiff line change
@@ -52,94 +52,102 @@ struct Generator
5252
llvm::StringRef
5353
extension() const noexcept = 0;
5454

55-
/** Build documentation from the corpus and configuration.
56-
57-
The default implementation calls @ref buildOneFile
58-
with a suitable filename calculated from the
59-
root directory and the generator's extension.
55+
/** Build multi-page documentation from the corpus and configuration.
6056
6157
@par Thread Safety
6258
@li Different `corpus` object: may be called concurrently.
6359
@li Same `corpus` object: may not be called concurrently.
6460
65-
@return `true` upon success.
61+
@return The error, if any occurred.
6662
67-
@par outputPath The path to a directory for
68-
emitting multi-file output, or the path of
69-
a filename with the generator's extension
70-
to emit output as a single file.
63+
@param outputPath An existing directory or
64+
a filename.
7165
72-
@par corpus The symbols to emit. The
66+
@param corpus The symbols to emit. The
7367
generator may modify the contents of
7468
the object before returning.
7569
76-
@par config The configuration to use.
70+
@param config The configuration to use.
7771
78-
@par R The diagnostic reporting object to
72+
@param R The diagnostic reporting object to
7973
use for delivering errors and information.
8074
*/
8175
virtual
82-
bool
83-
build(
76+
llvm::Error
77+
buildPages(
8478
llvm::StringRef outputPath,
8579
Corpus const& corpus,
8680
Reporter& R) const;
8781

88-
/** Build single-file documentation from the corpus and configuration.
82+
/** Build the reference as a single page to an output stream.
8983
9084
@par Thread Safety
9185
@li Different `corpus` object: may be called concurrently.
9286
@li Same `corpus` object: may not be called concurrently.
9387
94-
@return `true` upon success.
88+
@return The error, if any occurred.
9589
96-
@par fileName The path to the file
97-
which will be created or reset to hold
98-
the generated results.
90+
@param os The stream to write to.
9991
100-
@par corpus The symbols to emit. The
101-
generator may modify the contents of
102-
the object before returning.
92+
@param corpus The metadata to emit.
10393
104-
@par config The configuration to use.
94+
@param R The diagnostic reporting object to use.
10595
106-
@par R The diagnostic reporting object to
107-
use for delivering errors and information.
96+
@param fd_os A pointer to an optional, file-based
97+
output stream. If this is not null, the function
98+
fd_os->error() will be called periodically and
99+
the result returend if an error is indicated.
108100
*/
109101
virtual
110-
bool
111-
buildOne(
112-
llvm::StringRef fileName,
102+
llvm::Error
103+
buildSinglePage(
104+
llvm::raw_ostream& os,
105+
Corpus const& corpus,
106+
Reporter& R,
107+
llvm::raw_fd_ostream* fd_os = nullptr) const = 0;
108+
109+
/** Build the reference as a single page to a file.
110+
111+
@par Thread Safety
112+
@li Different `corpus` object: may be called concurrently.
113+
@li Same `corpus` object: may not be called concurrently.
114+
115+
@return The error, if any occurred.
116+
117+
@param filePath The file to write. If the
118+
file already exists, it will be overwritten.
119+
120+
@param corpus The metadata to emit.
121+
122+
@param R The diagnostic reporting object to use.
123+
*/
124+
llvm::Error
125+
buildSinglePageFile(
126+
llvm::StringRef filePath,
113127
Corpus const& corpus,
114-
Reporter& R) const = 0;
128+
Reporter& R) const;
115129

116-
/** Build a string containing the single-file documentation.
130+
/** Build the reference as a single page to a string.
117131
118132
@par Thread Safety
119133
@li Different `corpus` object: may be called concurrently.
120134
@li Same `corpus` object: may not be called concurrently.
121135
122-
@return `true` upon success.
136+
@return The error, if any occurred.
123137
124-
@par dest The string to hold the result.
138+
@param dest The string to hold the result.
125139
For the duration of the call, this must
126140
not be accessed by any other threads.
127141
128-
@par corpus The symbols to emit. The
129-
generator may modify the contents of
130-
the object before returning.
131-
132-
@par config The configuration to use.
142+
@param corpus The metadata to emit.
133143
134-
@par R The diagnostic reporting object to
135-
use for delivering errors and information.
144+
@param R The diagnostic reporting object to use.
136145
*/
137-
virtual
138-
bool
139-
buildString(
146+
llvm::Error
147+
buildSinglePageString(
140148
std::string& dest,
141149
Corpus const& corpus,
142-
Reporter& R) const = 0;
150+
Reporter& R) const;
143151
};
144152

145153
extern std::unique_ptr<Generator> makeXMLGenerator();

include/mrdox/Reporter.hpp

-9
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ class Reporter
116116
void
117117
reportError();
118118

119-
/** Report a unit test failure.
120-
121-
@par Thread Safety
122-
May be called concurrently.
123-
*/
124-
void
125-
reportTestFailure();
126-
127119
private:
128120
//--------------------------------------------
129121

@@ -160,7 +152,6 @@ class Reporter
160152
private:
161153
llvm::sys::Mutex mutable m_;
162154
std::size_t errorCount_ = 0;
163-
std::size_t testFailureCount_ = 0;
164155
};
165156

166157
//------------------------------------------------

0 commit comments

Comments
 (0)