Skip to content

Commit b472583

Browse files
klemens-morgensternvinniefalco
authored andcommitted
mrdox.yml file
1 parent 7a27e5b commit b472583

File tree

3 files changed

+117
-4
lines changed

3 files changed

+117
-4
lines changed

include/mrdox/Config.hpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
#define MRDOX_CONFIG_HPP
1414

1515
#include <clang/Tooling/ArgumentsAdjusters.h>
16+
#include <clang/Tooling/Execution.h>
1617
#include <llvm/ADT/Optional.h>
18+
#include <llvm/ADT/SmallVector.h>
19+
#include <llvm/ADT/StringRef.h>
20+
#include <memory>
21+
#include <source_location>
1722
#include <string>
1823

1924
namespace clang {
@@ -26,10 +31,6 @@ namespace mrdox {
2631
*/
2732
struct Config
2833
{
29-
Config() = default;
30-
Config(Config&&) = delete;
31-
Config& operator=(Config&&) = delete;
32-
3334
/** Adjustments to tool command line, applied during execute.
3435
*/
3536
tooling::ArgumentsAdjuster ArgAdjuster;
@@ -49,11 +50,27 @@ struct Config
4950
// the file is in this dir.
5051
std::string SourceRoot;
5152

53+
5254
// URL of repository that hosts code used
5355
// for links to definition locations.
5456
llvm::Optional<std::string> RepositoryUrl;
5557

5658
bool IgnoreMappingFailures = false;
59+
60+
Config();
61+
Config(Config&&) = delete;
62+
Config& operator=(Config&&) = delete;
63+
64+
public:
65+
struct filter { std::vector<std::string> include, exclude; };
66+
67+
filter namespaces, files, entities;
68+
69+
std::error_code
70+
load(
71+
const std::string & name,
72+
const std::source_location & loc =
73+
std::source_location::current());
5774
};
5875

5976
} // mrdox

source/lib/Config.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,78 @@
1010
//
1111

1212
#include <mrdox/Config.hpp>
13+
#include <llvm/Support/YAMLParser.h>
14+
#include <llvm/Support/YAMLTraits.h>
15+
16+
template<>
17+
struct llvm::yaml::MappingTraits<
18+
clang::mrdox::Config::filter>
19+
{
20+
static void mapping(
21+
IO &io, clang::mrdox::Config::filter &f)
22+
{
23+
io.mapOptional("include", f.include);
24+
io.mapOptional("exclude", f.exclude);
25+
}
26+
};
27+
28+
template<>
29+
struct llvm::yaml::MappingTraits<
30+
clang::mrdox::Config>
31+
{
32+
static void mapping(
33+
IO &io, clang::mrdox::Config &f)
34+
{
35+
io.mapOptional("namespaces", f.namespaces);
36+
io.mapOptional("files", f.files);
37+
io.mapOptional("entities", f.entities);
38+
io.mapOptional("project-name", f.ProjectName);
39+
io.mapOptional("public-only", f.PublicOnly);
40+
io.mapOptional("output-dir", f.OutDirectory);
41+
}
42+
};
43+
44+
//------------------------------------------------
1345

1446
namespace clang {
1547
namespace mrdox {
1648

49+
Config::
50+
Config()
51+
{
52+
if (auto p = ::getenv("MRDOX_SOURCE_ROOT"))
53+
SourceRoot = p;
54+
else
55+
{
56+
llvm::SmallString<128> SourceRootDir;
57+
llvm::sys::fs::current_path(SourceRootDir);
58+
SourceRoot = SourceRootDir.c_str();
59+
}
60+
61+
if (auto p = ::getenv("MRDOX_REPOSITORY_URL"))
62+
RepositoryUrl.emplace(p);
63+
else if (auto q = ::getenv("DRONE_REMOTE_URL"))
64+
RepositoryUrl.emplace(q);
65+
}
66+
67+
std::error_code
68+
Config::
69+
load(
70+
const std::string & name,
71+
const std::source_location & loc)
72+
{
73+
auto ct = llvm::MemoryBuffer::getFile(SourceRoot + "/" + name);
74+
if (!ct)
75+
return ct.getError();
76+
77+
llvm::yaml::Input yin{**ct};
78+
79+
yin >> *this;
80+
if ( yin.error() )
81+
return yin.error();
82+
83+
return {};
84+
}
85+
1786
} // mrdox
1887
} // clang

source/tool/ToolMain.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,31 @@ OutDirectory(
6969
llvm::cl::init("."),
7070
llvm::cl::cat(ToolCategory));
7171

72+
static
73+
llvm::cl::opt<std::string>
74+
SourceRoot(
75+
"source-root", llvm::cl::desc(R"(
76+
Directory where processed files are stored.
77+
Links to definition locations will only be
78+
generated if the file is in this dir.)"),
79+
llvm::cl::cat(ToolCategory));
80+
81+
static
82+
llvm::cl::opt<std::string>
83+
RepositoryUrl(
84+
"repository", llvm::cl::desc(R"(
85+
URL of repository that hosts code.
86+
Used for links to definition locations.)"),
87+
llvm::cl::cat(ToolCategory));
88+
89+
static
90+
llvm::cl::opt<std::string>
91+
ConfigPath(
92+
"config-file",
93+
llvm::cl::desc(R"(The config filename relative to the repository root)"),
94+
llvm::cl::init("mrdox.yaml"),
95+
llvm::cl::cat(ToolCategory));
96+
7297
static
7398
llvm::cl::opt<std::string>
7499
FormatType(
@@ -110,6 +135,8 @@ toolMain(int argc, const char** argv)
110135
cfg.OutDirectory = OutDirectory;
111136
cfg.IgnoreMappingFailures = IgnoreMappingFailures;
112137

138+
cfg.load(ConfigPath);
139+
113140
// create the executor
114141
auto ex = std::make_unique<tooling::AllTUsToolExecutor>(
115142
optionsResult->getCompilations(), 0);

0 commit comments

Comments
 (0)