Skip to content

Commit 97facef

Browse files
committed
ToolArgs include no default strings
#fix
1 parent dd76a20 commit 97facef

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

src/lib/Lib/Config.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ struct PublicSettingsVisitor {
150150
std::string& value,
151151
ReferenceDirectories const& dirs,
152152
PublicSettings::OptionProperties const& opts,
153-
bool const usingDefault) {
153+
bool const usingDefault)
154+
{
154155
// If the path is not absolute, we need to expand it
155156
if (!files::isAbsolute(value))
156157
{
@@ -258,7 +259,7 @@ struct PublicSettingsVisitor {
258259
{
259260
for (auto& value : values)
260261
{
261-
MRDOCS_DECL(normalizeStringPath(self, name, value, dirs, opts, usingDefault));
262+
MRDOCS_TRY(normalizeStringPath(self, name, value, dirs, opts, usingDefault));
262263
}
263264

264265
// Move command line sink values to appropriate destinations

src/tool/ToolMain.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <llvm/Support/PrettyStackTrace.h>
2020
#include <llvm/Support/Signals.h>
2121
#include <cstdlib>
22+
#include <ranges>
2223

2324
extern int main(int argc, char const** argv);
2425

25-
namespace clang {
26-
namespace mrdocs {
26+
namespace clang::mrdocs {
2727

2828
extern
2929
int
@@ -47,7 +47,7 @@ print_version(llvm::raw_ostream& os)
4747
<< "\n";
4848
}
4949

50-
Expected<std::pair<std::string, ReferenceDirectories>>
50+
Expected<ReferenceDirectories>
5151
getReferenceDirectories(std::string const& execPath)
5252
{
5353
ReferenceDirectories dirs;
@@ -58,36 +58,37 @@ getReferenceDirectories(std::string const& execPath)
5858
return Unexpected(formatError("Unable to determine current working directory: {}", ec.message()));
5959
}
6060
dirs.cwd = std::string(cwd.data(), cwd.size());
61+
return dirs;
62+
}
63+
64+
Expected<std::string>
65+
getConfigPath(ReferenceDirectories const& dirs)
66+
{
6167
std::string configPath;
62-
if (toolArgs.config.getValue() != "")
68+
auto cmdLineFilenames = std::ranges::views::transform(
69+
toolArgs.cmdLineInputs, files::getFileName);
70+
if (!toolArgs.config.getValue().empty())
6371
{
72+
// From explicit --config argument
6473
configPath = toolArgs.config.getValue();
6574
}
66-
else
75+
else if (auto const it = std::ranges::find(cmdLineFilenames, "mrdocs.yml");
76+
it != cmdLineFilenames.end())
6777
{
68-
llvm::cl::list<std::string>& inputs = toolArgs.cmdLineInputs;
69-
for (auto& input: inputs)
70-
{
71-
if (files::getFileName(input) == "mrdocs.yml")
72-
{
73-
configPath = input;
74-
break;
75-
}
76-
}
78+
// From implicit command line inputs
79+
configPath = *(it.base());
7780
}
78-
if (configPath.empty())
81+
else if (files::exists("./mrdocs.yml"))
7982
{
80-
if (files::exists("./mrdocs.yml"))
81-
{
82-
configPath = "./mrdocs.yml";
83-
}
83+
// From current directory
84+
configPath = "./mrdocs.yml";
8485
}
85-
if (configPath.empty())
86+
else
8687
{
8788
return Unexpected(formatError("The config path is missing"));
8889
}
8990
configPath = files::makeAbsolute(configPath, dirs.cwd);
90-
return std::make_pair(configPath, dirs);
91+
return configPath;
9192
}
9293

9394
int
@@ -129,7 +130,15 @@ mrdocs_main(int argc, char const** argv)
129130
report::fatal("Failed to determine reference directories: {}", res.error().message());
130131
return EXIT_FAILURE;
131132
}
132-
auto [configPath, dirs] = *res;
133+
auto dirs = *std::move(res);
134+
135+
auto expConfigPath = getConfigPath(dirs);
136+
if (!expConfigPath)
137+
{
138+
report::fatal("Failed to determine config path: {}", expConfigPath.error().message());
139+
return EXIT_FAILURE;
140+
}
141+
auto configPath = *std::move(expConfigPath);
133142

134143
// Generate
135144
auto exp = DoGenerateAction(configPath, dirs, argv);
@@ -156,8 +165,7 @@ reportUnhandledException(
156165
sys::PrintStackTrace(llvm::errs());
157166
}
158167

159-
} // mrdocs
160-
} // clang
168+
} // clang::mrdocs
161169

162170
int
163171
main(int argc, char const** argv)

util/generate-config-info.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,11 @@ def generate_toolargs_final_option_initializer(option, category_str, parents=Non
839839
if option['command-line-sink']:
840840
constructor_args.append('llvm::cl::Sink')
841841
if 'default' in option:
842-
if option["type"] in ['string', 'enum']:
843-
constructor_args.append(f'llvm::cl::init("{option["default"]}")')
844-
elif option["type"] in ['path', 'file-path', 'dir-path']:
845-
constructor_args.append(f'llvm::cl::init("{remove_reference_dir_from_path(option["default"])}")')
846-
elif option['type'] in ['unsigned', 'int']:
842+
# if option["type"] in ['string', 'enum']:
843+
# constructor_args.append(f'llvm::cl::init("{option["default"]}")')
844+
# elif option["type"] in ['path', 'file-path', 'dir-path']:
845+
# constructor_args.append(f'llvm::cl::init("{remove_reference_dir_from_path(option["default"])}")')
846+
if option['type'] in ['unsigned', 'int']:
847847
constructor_args.append(f'llvm::cl::init({option["default"]})')
848848
elif option['type'] == 'bool':
849849
bool_str = 'true' if option['default'] else 'false'

0 commit comments

Comments
 (0)