Skip to content

Commit d947525

Browse files
committed
style: version printer mimics clang
1 parent 8834acb commit d947525

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/tool/ToolMain.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#include <mrdocs/Version.hpp>
1717
#include <llvm/Support/FileSystem.h>
1818
#include <llvm/Support/PrettyStackTrace.h>
19-
#include <llvm/Support/Signals.h>
2019
#include <llvm/Support/raw_ostream.h>
20+
#include <llvm/Support/Signals.h>
21+
#include <llvm/TargetParser/Host.h>
2122
#include <cstdlib>
2223
#include <ranges>
2324

@@ -36,16 +37,6 @@ DoGenerateAction(
3637
ReferenceDirectories const& dirs,
3738
char const** argv);
3839

39-
void
40-
print_version(llvm::raw_ostream& os)
41-
{
42-
os << project_name
43-
<< "\n " << project_description
44-
<< "\n version: " << project_version_with_build
45-
<< "\n build: " << project_version_build
46-
<< "\n built with LLVM " << LLVM_VERSION_STRING
47-
<< "\n";
48-
}
4940

5041
Expected<ReferenceDirectories>
5142
getReferenceDirectories(std::string const& execPath)
@@ -99,26 +90,35 @@ mrdocs_main(int argc, char const** argv)
9990
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
10091
llvm::setBugReportMsg("PLEASE submit a bug report to https://github.com/cppalliance/mrdocs/issues/ and include the crash backtrace.\n");
10192

93+
// Set up addons directory
94+
#ifdef __GNUC__
95+
# pragma GCC diagnostic push
96+
# pragma GCC diagnostic ignored "-Wpedantic"
97+
// error: ISO C++ forbids taking address of function ‘::main’
98+
#endif
99+
void* addressOfMain = reinterpret_cast<void*>(&main);
100+
#ifdef __GNUC__
101+
# pragma GCC diagnostic pop
102+
#endif
103+
std::string execPath = llvm::sys::fs::
104+
getMainExecutable(argv[0], addressOfMain);
105+
102106
// Parse command line options
103-
llvm::cl::SetVersionPrinter(&print_version);
107+
llvm::cl::SetVersionPrinter([execPath](llvm::raw_ostream& os) {
108+
os << project_name << " version " << project_version_with_build << "\n";
109+
os << "Built with LLVM " << LLVM_VERSION_STRING << "\n";
110+
os << "Build SHA: " << project_version_build << "\n";
111+
os << "Target: " << llvm::sys::getDefaultTargetTriple() << "\n";
112+
os << "InstalledDir: " << files::getParentDir(execPath) << "\n";
113+
});
114+
104115
toolArgs.hideForeignOptions();
105116
if (!llvm::cl::ParseCommandLineOptions(
106117
argc, argv, toolArgs.usageText))
107118
{
108119
return EXIT_FAILURE;
109120
}
110121

111-
// Set up addons directory
112-
#ifdef __GNUC__
113-
#pragma GCC diagnostic push
114-
#pragma GCC diagnostic ignored "-Wpedantic"
115-
// error: ISO C++ forbids taking address of function ‘::main’
116-
#endif
117-
void* addressOfMain = reinterpret_cast<void*>(&main);
118-
#ifdef __GNUC__
119-
#pragma GCC diagnostic pop
120-
#endif
121-
std::string execPath = llvm::sys::fs::getMainExecutable(argv[0], addressOfMain);
122122

123123
// Before `DoGenerateAction`, we use an error reporting level.
124124
// DoGenerateAction will set the level to whatever is specified in

0 commit comments

Comments
 (0)