From 160ba18af20c76ca08e8a11e3ea70cb854c82346 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Mon, 8 Sep 2025 11:02:16 +0200 Subject: [PATCH 01/25] Run tests using clang-cl on windows --- src/lib/SingleFileDB.hpp | 18 +++++++++++++----- src/test/TestRunner.cpp | 8 +++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lib/SingleFileDB.hpp b/src/lib/SingleFileDB.hpp index 16af01ed5..59797357d 100644 --- a/src/lib/SingleFileDB.hpp +++ b/src/lib/SingleFileDB.hpp @@ -30,17 +30,25 @@ class SingleFileDB public: explicit SingleFileDB( - llvm::StringRef pathName) + llvm::StringRef pathName, bool is_clang_cl = false) { auto fileName = files::getFileName(pathName); auto parentDir = files::getParentDir(pathName); std::vector cmds; - cmds.emplace_back("clang"); + if (is_clang_cl) { + cmds.emplace_back("clang-cl"); + cmds.emplace_back("/std:c++latest"); + cmds.emplace_back("/permissive-"); + cmds.emplace_back("/WX"); + } + else { + cmds.emplace_back("clang"); + cmds.emplace_back("-std=c++23"); + cmds.emplace_back("-pedantic-errors"); + cmds.emplace_back("-Werror"); + } cmds.emplace_back("-fsyntax-only"); - cmds.emplace_back("-std=c++23"); - cmds.emplace_back("-pedantic-errors"); - cmds.emplace_back("-Werror"); cmds.emplace_back(fileName); cc_.emplace_back( parentDir, diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 31ea0e38d..ae25192af 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -114,9 +114,15 @@ handleFile( // Create an adjusted MrDocsDatabase auto parentDir = files::getParentDir(filePath); + bool const is_clang_cl = +#if defined(WIN32) + true; +#else + false; +#endif std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( - llvm::StringRef(parentDir), SingleFileDB(filePath), config, defaultIncludePaths); + llvm::StringRef(parentDir), SingleFileDB(filePath, is_clang_cl), config, defaultIncludePaths); report::debug("Building Corpus", filePath); auto corpus = CorpusImpl::build(config, compilations); From c148e0249174f4dd4571faf723c07dccd918e9f3 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Mon, 8 Sep 2025 11:04:40 +0200 Subject: [PATCH 02/25] Use clang-cl system includes syntax --- src/lib/MrDocsCompilationDatabase.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index e565db784..2dbb1ce38 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -448,8 +448,8 @@ adjustCommandLine( it != implicitIncludeDirectories.end()) { for (auto const& inc : it->second) { - new_cmdline.emplace_back(std::format("-isystem{}", inc)); - } + new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); + } } } @@ -467,7 +467,7 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdlib++"); for (auto const& inc : (*config)->stdlibIncludes) { - new_cmdline.emplace_back(std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); } } @@ -476,7 +476,7 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdinc"); for (auto const& inc : (*config)->libcIncludes) { - new_cmdline.emplace_back(std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); } } @@ -485,7 +485,7 @@ adjustCommandLine( // ------------------------------------------------------ for (auto const& inc : (*config)->systemIncludes) { - new_cmdline.emplace_back(std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); } for (auto const& inc : (*config)->includes) { From 754f590ff7ed23fdeaec8bf524653642fee7c0f4 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Mon, 8 Sep 2025 14:30:33 +0200 Subject: [PATCH 03/25] Use clang-cl nostdlibinc option --- src/lib/MrDocsCompilationDatabase.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 2dbb1ce38..1511b5295 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -463,8 +463,7 @@ adjustCommandLine( // implicit include paths and add the standard library // and system includes manually. That gives MrDocs // access to libc++ in a portable way. - new_cmdline.emplace_back("-nostdinc++"); - new_cmdline.emplace_back("-nostdlib++"); + new_cmdline.emplace_back(is_clang_cl ? "/X" : "-nostdinc++"); for (auto const& inc : (*config)->stdlibIncludes) { new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); From 6f020d23efa63858d3f42985c62a4dbb41af067c Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Fri, 19 Sep 2025 08:56:27 +0200 Subject: [PATCH 04/25] - --- src/lib/SingleFileDB.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/SingleFileDB.hpp b/src/lib/SingleFileDB.hpp index 59797357d..5eddbca45 100644 --- a/src/lib/SingleFileDB.hpp +++ b/src/lib/SingleFileDB.hpp @@ -48,7 +48,6 @@ class SingleFileDB cmds.emplace_back("-pedantic-errors"); cmds.emplace_back("-Werror"); } - cmds.emplace_back("-fsyntax-only"); cmds.emplace_back(fileName); cc_.emplace_back( parentDir, From 9ed7c65047869db615818babe76e6817626ec8a6 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 10:42:26 +0200 Subject: [PATCH 05/25] refactor SingleFileDB --- src/lib/SingleFileDB.hpp | 65 ++++++++++++++++++++++------------------ src/test/TestRunner.cpp | 8 ++--- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/lib/SingleFileDB.hpp b/src/lib/SingleFileDB.hpp index 5eddbca45..8ec64b635 100644 --- a/src/lib/SingleFileDB.hpp +++ b/src/lib/SingleFileDB.hpp @@ -20,62 +20,69 @@ namespace clang { namespace mrdocs { -/** Compilation database for a single .cpp file. +/** Compilation database for a single file. */ class SingleFileDB : public tooling::CompilationDatabase { - std::vector cc_; + tooling::CompileCommand cc_; public: - explicit - SingleFileDB( - llvm::StringRef pathName, bool is_clang_cl = false) + explicit SingleFileDB(tooling::CompileCommand cc) + : cc_(std::move(cc)) + {} + + static SingleFileDB makeForClang(llvm::StringRef pathName) + { + auto fileName = files::getFileName(pathName); + auto parentDir = files::getParentDir(pathName); + + std::vector cmds = {"clang", + "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; + tooling::CompileCommand cc( + parentDir, + fileName, + std::move(cmds), + parentDir); + cc.Heuristic = "unit test"; + return SingleFileDB(std::move(cc)); + } + + static SingleFileDB makeForClangCL(llvm::StringRef pathName) { auto fileName = files::getFileName(pathName); auto parentDir = files::getParentDir(pathName); - std::vector cmds; - if (is_clang_cl) { - cmds.emplace_back("clang-cl"); - cmds.emplace_back("/std:c++latest"); - cmds.emplace_back("/permissive-"); - cmds.emplace_back("/WX"); - } - else { - cmds.emplace_back("clang"); - cmds.emplace_back("-std=c++23"); - cmds.emplace_back("-pedantic-errors"); - cmds.emplace_back("-Werror"); - } - cmds.emplace_back(fileName); - cc_.emplace_back( + std::vector cmds = {"clang-cl", + "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; + tooling::CompileCommand cc( parentDir, fileName, std::move(cmds), parentDir); - cc_.back().Heuristic = "unit test"; + cc.Heuristic = "unit test"; + return SingleFileDB(std::move(cc)); } std::vector - getCompileCommands( - llvm::StringRef FilePath) const override + getCompileCommands( + llvm::StringRef FilePath) const override { - if (FilePath != cc_.front().Filename) + if (FilePath != cc_.Filename) return {}; - return { cc_.front() }; + return { cc_ }; } std::vector - getAllFiles() const override + getAllFiles() const override { - return { cc_.front().Filename }; + return { cc_.Filename }; } std::vector - getAllCompileCommands() const override + getAllCompileCommands() const override { - return { cc_.front() }; + return { cc_ }; } }; diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index ae25192af..542e043cd 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -114,15 +114,15 @@ handleFile( // Create an adjusted MrDocsDatabase auto parentDir = files::getParentDir(filePath); - bool const is_clang_cl = + SingleFileDB const db = #if defined(WIN32) - true; + SingleFileDB::makeForClangCL(filePath); #else - false; + SingleFileDB::makeForClang(filePath); #endif std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( - llvm::StringRef(parentDir), SingleFileDB(filePath, is_clang_cl), config, defaultIncludePaths); + llvm::StringRef(parentDir), db, config, defaultIncludePaths); report::debug("Building Corpus", filePath); auto corpus = CorpusImpl::build(config, compilations); From 13cc376c7824a02482ca0b353fc2cc02799c2df7 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 11:13:00 +0200 Subject: [PATCH 06/25] -include for clang-cl is spelled /FI --- src/lib/CorpusImpl.cpp | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/lib/CorpusImpl.cpp b/src/lib/CorpusImpl.cpp index 258c4c8e6..67314e628 100644 --- a/src/lib/CorpusImpl.cpp +++ b/src/lib/CorpusImpl.cpp @@ -23,6 +23,8 @@ #include "lib/Metadata/Finalizers/SortMembersFinalizer.hpp" #include "lib/Support/Chrono.hpp" #include "lib/Support/Report.hpp" +#include +#include #include #include #include @@ -711,6 +713,41 @@ lookupCacheSet( //------------------------------------------------ +namespace { +// FIXME(k-ballo): MrDocsCompilationDatabase already figured this out, but we lost that information. +// do we want to have to recompute it here? if so, dedup this query +bool +isClangCL(tooling::CompilationDatabase const& compilations) +{ + auto const& commands = compilations.getAllCompileCommands(); + if (commands.empty()) return false; + + auto const& cmdline = commands.front().CommandLine; + + // ------------------------------------------------------ + // Convert to InputArgList + // ------------------------------------------------------ + // InputArgList is the input format for llvm functions + auto cmdLineCStrsView = std::views::transform(cmdline, &std::string::c_str); + std::vector const cmdLineCStrs(cmdLineCStrsView.begin(), cmdLineCStrsView.end()); + llvm::opt::InputArgList const args( + cmdLineCStrs.data(), + cmdLineCStrs.data() + cmdLineCStrs.size()); + + // ------------------------------------------------------ + // Get driver mode + // ------------------------------------------------------ + // The driver mode distinguishes between clang/gcc and msvc + // command line option formats. The value is deduced from + // the `-drive-mode` option or from `progName`. + // Common values are "gcc", "g++", "cpp", "cl" and "flang". + std::string const& progName = cmdline.front(); + StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); + + return driver::IsClangCL(driver_mode); +} +} + mrdocs::Expected> CorpusImpl:: build( @@ -735,6 +772,10 @@ build( // InfoSet in the execution context. InfoExecutionContext context(*config); + // Identify if we should use "msvc/clang-cl" or "clang/gcc" format + // for options. + bool const is_clang_cl = isClangCL(compilations); + // ------------------------------------------ // "Process file" task // ------------------------------------------ @@ -795,7 +836,7 @@ build( FSConcrete->addVirtualFile(shimPath, shimContent); Tool.appendArgumentsAdjuster( tooling::combineAdjusters( - tooling::getInsertArgumentAdjuster("-include"), + tooling::getInsertArgumentAdjuster(is_clang_cl ? "/FI" : "-include"), tooling::getInsertArgumentAdjuster(shimPath.data()))); } From 5704a084535e9c817ea22a10a89e5a6585d956b6 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 11:17:46 +0200 Subject: [PATCH 07/25] revert format on save --- src/lib/SingleFileDB.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/SingleFileDB.hpp b/src/lib/SingleFileDB.hpp index 8ec64b635..e245d498b 100644 --- a/src/lib/SingleFileDB.hpp +++ b/src/lib/SingleFileDB.hpp @@ -65,8 +65,8 @@ class SingleFileDB } std::vector - getCompileCommands( - llvm::StringRef FilePath) const override + getCompileCommands( + llvm::StringRef FilePath) const override { if (FilePath != cc_.Filename) return {}; @@ -74,13 +74,13 @@ class SingleFileDB } std::vector - getAllFiles() const override + getAllFiles() const override { return { cc_.Filename }; } std::vector - getAllCompileCommands() const override + getAllCompileCommands() const override { return { cc_ }; } From 5a9d1d613394979eea196b2bb32e72e78e5aeddf Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 11:19:18 +0200 Subject: [PATCH 08/25] tweaks --- src/lib/MrDocsCompilationDatabase.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 1511b5295..accd529d8 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -448,7 +448,8 @@ adjustCommandLine( it != implicitIncludeDirectories.end()) { for (auto const& inc : it->second) { - new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(inc); } } } @@ -466,7 +467,8 @@ adjustCommandLine( new_cmdline.emplace_back(is_clang_cl ? "/X" : "-nostdinc++"); for (auto const& inc : (*config)->stdlibIncludes) { - new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(inc); } } @@ -475,7 +477,8 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdinc"); for (auto const& inc : (*config)->libcIncludes) { - new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(inc); } } @@ -484,7 +487,8 @@ adjustCommandLine( // ------------------------------------------------------ for (auto const& inc : (*config)->systemIncludes) { - new_cmdline.emplace_back(is_clang_cl ? std::format("-external:I{}", inc) : std::format("-isystem{}", inc)); + new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(inc); } for (auto const& inc : (*config)->includes) { From 723cfcf39b20fc027388d2bfc35e73e3c849cfef Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 12:54:12 +0200 Subject: [PATCH 09/25] salvage some tests... --- src/test/lib/MrDocsCompilationDatabase.cpp | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/test/lib/MrDocsCompilationDatabase.cpp diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp new file mode 100644 index 000000000..fed45d59b --- /dev/null +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -0,0 +1,135 @@ +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) +// +// Official repository: https://github.com/cppalliance/mrdocs +// + +#include "lib/ConfigImpl.hpp" +#include "lib/MrDocsCompilationDatabase.hpp" +#include "lib/SingleFileDB.hpp" +#include +#include +#include +#include + +namespace clang { +namespace mrdocs { + +namespace { +struct TestConfigImpl final : Config +{ + Settings settings_; + + ThreadPool& + threadPool() const noexcept override + { + static ThreadPool dummyThreadPool_; + return dummyThreadPool_; + } + + dom::Object const& object() const override + { + static dom::Object dummyObject; + return dummyObject; + + } + + Settings const& settings() const noexcept override + { + return settings_; + } +}; +} + +struct MrDocsCompilationDatabase_test +{ + Config::Settings fileSettings_; + ThreadPool threadPool_; + ReferenceDirectories dirs_; + + auto adjustCompileCommand(SingleFileDB const& db, std::shared_ptr config) const + { + // Create an adjusted MrDocsDatabase + std::unordered_map> defaultIncludePaths; + MrDocsCompilationDatabase compilations( + dirs_.cwd, db, config, defaultIncludePaths); + return compilations.getAllCompileCommands().front().CommandLine; + } + + static bool has(std::vector const& commandLine, std::string_view flag) + { + return mrdocs::contains(commandLine, flag); + } + static bool has(std::vector const& commandLine, std::initializer_list flags) + { + MRDOCS_ASSERT(flags.size() > 0); + return std::search(commandLine.begin(), commandLine.end(), flags.begin(), flags.end()) != commandLine.end(); + } + + void testClang() + { + SingleFileDB const db = SingleFileDB::makeForClang("test.cpp"); + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemStdlib = false; + config->settings_.stdlibIncludes.push_back("stdlib-path"); + + auto adjusted = adjustCompileCommand(db, config); + BOOST_TEST(has(adjusted, "-nostdinc++")); + BOOST_TEST(has(adjusted, {"-isystem", "stdlib-path"})); + } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemLibc = false; + config->settings_.libcIncludes.push_back("libc-path"); + + auto adjusted = adjustCompileCommand(db, config); + BOOST_TEST(has(adjusted, "-nostdinc")); + BOOST_TEST(has(adjusted, {"-isystem", "libc-path"})); + } + } + + void testClangCL() + { + SingleFileDB const db = SingleFileDB::makeForClangCL("test.cpp"); + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemStdlib = false; + config->settings_.stdlibIncludes.push_back("stdlib-path"); + + auto adjusted = adjustCompileCommand(db, config); + BOOST_TEST(has(adjusted, "/X")); + BOOST_TEST(has(adjusted, {"-external:I", "stdlib-path"})); + } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemLibc = false; + config->settings_.libcIncludes.push_back("libc-path"); + + auto adjusted = adjustCompileCommand(db, config); + BOOST_TEST(has(adjusted, "-nostdinc")); + BOOST_TEST(has(adjusted, {"-external:I", "libc-path"})); + } + } + + void run() + { + testClang(); + testClangCL(); + } +}; + +TEST_SUITE( + MrDocsCompilationDatabase_test, + "clang.mrdocs.MrDocsCompilationDatabase"); + +} // mrdocs +} // clang From b1275c58db8c016e5008d87411d9cda80b2840f2 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 14:07:08 +0200 Subject: [PATCH 10/25] test -std --- src/lib/MrDocsCompilationDatabase.cpp | 9 +-- src/lib/SingleFileDB.hpp | 33 --------- src/test/TestRunner.cpp | 38 ++++++++++- src/test/lib/MrDocsCompilationDatabase.cpp | 79 +++++++++++++++++----- 4 files changed, 103 insertions(+), 56 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index accd529d8..4f8b13c75 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -317,7 +317,7 @@ adjustCommandLine( // ------------------------------------------------------ // Add flags to ignore all warnings. Any options that // affect warnings will be discarded later. - new_cmdline.emplace_back(is_clang_cl ? "/w" : "-w"); + new_cmdline.emplace_back("-w"); new_cmdline.emplace_back("-fsyntax-only"); // ------------------------------------------------------ @@ -411,9 +411,10 @@ adjustCommandLine( isExplicitCCompileCommand || (!isExplicitCppCompileCommand && isImplicitCSourceFile); constexpr auto is_std_option = [](std::string_view const opt) { - return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:"); + return opt.starts_with("-std=") || opt.starts_with("--std=") || // clang options + opt.starts_with("-std:") || opt.starts_with("/std:"); // clang-cl options }; - if (std::ranges::find_if(cmdline, is_std_option) == cmdline.end()) + if (std::ranges::none_of(cmdline, is_std_option)) { if (!isCCompileCommand) { @@ -464,7 +465,7 @@ adjustCommandLine( // implicit include paths and add the standard library // and system includes manually. That gives MrDocs // access to libc++ in a portable way. - new_cmdline.emplace_back(is_clang_cl ? "/X" : "-nostdinc++"); + new_cmdline.emplace_back(is_clang_cl ? "-X" : "-nostdinc++"); for (auto const& inc : (*config)->stdlibIncludes) { new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); diff --git a/src/lib/SingleFileDB.hpp b/src/lib/SingleFileDB.hpp index e245d498b..393e7dea8 100644 --- a/src/lib/SingleFileDB.hpp +++ b/src/lib/SingleFileDB.hpp @@ -11,7 +11,6 @@ #ifndef MRDOCS_LIB_SINGLEFILEDB_HPP #define MRDOCS_LIB_SINGLEFILEDB_HPP -#include #include #include #include @@ -32,38 +31,6 @@ class SingleFileDB : cc_(std::move(cc)) {} - static SingleFileDB makeForClang(llvm::StringRef pathName) - { - auto fileName = files::getFileName(pathName); - auto parentDir = files::getParentDir(pathName); - - std::vector cmds = {"clang", - "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; - tooling::CompileCommand cc( - parentDir, - fileName, - std::move(cmds), - parentDir); - cc.Heuristic = "unit test"; - return SingleFileDB(std::move(cc)); - } - - static SingleFileDB makeForClangCL(llvm::StringRef pathName) - { - auto fileName = files::getFileName(pathName); - auto parentDir = files::getParentDir(pathName); - - std::vector cmds = {"clang-cl", - "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; - tooling::CompileCommand cc( - parentDir, - fileName, - std::move(cmds), - parentDir); - cc.Heuristic = "unit test"; - return SingleFileDB(std::move(cc)); - } - std::vector getCompileCommands( llvm::StringRef FilePath) const override diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 542e043cd..40edceac7 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -55,6 +55,7 @@ writeFile( return {}; } +namespace{ void replaceCRLFWithLF(std::string &str) { @@ -65,6 +66,39 @@ replaceCRLFWithLF(std::string &str) } } +SingleFileDB makeSingleFileDBForClang(llvm::StringRef pathName) +{ + auto fileName = files::getFileName(pathName); + auto parentDir = files::getParentDir(pathName); + + std::vector cmds = {"clang", + "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; + tooling::CompileCommand cc( + parentDir, + fileName, + std::move(cmds), + parentDir); + cc.Heuristic = "unit test"; + return SingleFileDB(std::move(cc)); +} + +SingleFileDB makeSingleFileDBForClangCL(llvm::StringRef pathName) +{ + auto fileName = files::getFileName(pathName); + auto parentDir = files::getParentDir(pathName); + + std::vector cmds = {"clang-cl", + "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; + tooling::CompileCommand cc( + parentDir, + fileName, + std::move(cmds), + parentDir); + cc.Heuristic = "unit test"; + return SingleFileDB(std::move(cc)); +} +} + void TestRunner:: handleFile( @@ -116,9 +150,9 @@ handleFile( auto parentDir = files::getParentDir(filePath); SingleFileDB const db = #if defined(WIN32) - SingleFileDB::makeForClangCL(filePath); + makeSingleFileDBForClang(filePath); #else - SingleFileDB::makeForClang(filePath); + makeSingleFileDBForClangCL(filePath); #endif std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index fed45d59b..aaddeabc5 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -25,7 +25,7 @@ struct TestConfigImpl final : Config Settings settings_; ThreadPool& - threadPool() const noexcept override + threadPool() const noexcept override { static ThreadPool dummyThreadPool_; return dummyThreadPool_; @@ -51,12 +51,19 @@ struct MrDocsCompilationDatabase_test ThreadPool threadPool_; ReferenceDirectories dirs_; - auto adjustCompileCommand(SingleFileDB const& db, std::shared_ptr config) const + auto adjustCompileCommand(std::vector commandLine, std::shared_ptr config) const { + tooling::CompileCommand cc; + cc.Directory = "."; + cc.Filename = "test.cpp"; // file does not exist + cc.CommandLine = std::move(commandLine); + cc.CommandLine.push_back(cc.Filename); + cc.Heuristic = "unit test"; + // Create an adjusted MrDocsDatabase std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( - dirs_.cwd, db, config, defaultIncludePaths); + dirs_.cwd, SingleFileDB(std::move(cc)), config, defaultIncludePaths); return compilations.getAllCompileCommands().front().CommandLine; } @@ -72,16 +79,14 @@ struct MrDocsCompilationDatabase_test void testClang() { - SingleFileDB const db = SingleFileDB::makeForClang("test.cpp"); - { - std::shared_ptr config = std::make_shared(); + std::shared_ptr const config = std::make_shared(); config->settings_.useSystemStdlib = false; config->settings_.stdlibIncludes.push_back("stdlib-path"); - auto adjusted = adjustCompileCommand(db, config); + auto adjusted = adjustCompileCommand({ "clang" }, config); BOOST_TEST(has(adjusted, "-nostdinc++")); - BOOST_TEST(has(adjusted, {"-isystem", "stdlib-path"})); + BOOST_TEST(has(adjusted, { "-isystem", "stdlib-path" })); } { @@ -89,24 +94,43 @@ struct MrDocsCompilationDatabase_test config->settings_.useSystemLibc = false; config->settings_.libcIncludes.push_back("libc-path"); - auto adjusted = adjustCompileCommand(db, config); + auto adjusted = adjustCompileCommand({ "clang" }, config); BOOST_TEST(has(adjusted, "-nostdinc")); - BOOST_TEST(has(adjusted, {"-isystem", "libc-path"})); + BOOST_TEST(has(adjusted, { "-isystem", "libc-path" })); + } + + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang" }, config); + BOOST_TEST(has(adjusted, "-std=c++23")); + } + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang", "-std=c++11" }, config); + BOOST_TEST(has(adjusted, "-std=c++11")); + BOOST_TEST_NOT(has(adjusted, "-std=c++23")); + } + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang", "--std=c++11" }, config); + BOOST_TEST(has(adjusted, "--std=c++11")); + BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } } void testClangCL() { - SingleFileDB const db = SingleFileDB::makeForClangCL("test.cpp"); - { std::shared_ptr config = std::make_shared(); config->settings_.useSystemStdlib = false; config->settings_.stdlibIncludes.push_back("stdlib-path"); - auto adjusted = adjustCompileCommand(db, config); - BOOST_TEST(has(adjusted, "/X")); - BOOST_TEST(has(adjusted, {"-external:I", "stdlib-path"})); + auto adjusted = adjustCompileCommand({ "clang-cl" }, config); + BOOST_TEST(has(adjusted, "-X")); + BOOST_TEST(has(adjusted, { "-external:I", "stdlib-path" })); } { @@ -114,9 +138,30 @@ struct MrDocsCompilationDatabase_test config->settings_.useSystemLibc = false; config->settings_.libcIncludes.push_back("libc-path"); - auto adjusted = adjustCompileCommand(db, config); + auto adjusted = adjustCompileCommand({ "clang-cl" }, config); BOOST_TEST(has(adjusted, "-nostdinc")); - BOOST_TEST(has(adjusted, {"-external:I", "libc-path"})); + BOOST_TEST(has(adjusted, { "-external:I", "libc-path" })); + } + + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang-cl" }, config); + BOOST_TEST(has(adjusted, "-std=c++23")); + } + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang-cl", "-std:c++11" }, config); + BOOST_TEST(has(adjusted, "-std:c++11")); + BOOST_TEST_NOT(has(adjusted, "-std=c++23")); + } + { + std::shared_ptr config = std::make_shared(); + + auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++11" }, config); + BOOST_TEST(has(adjusted, "/std:c++11")); + BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } } From e38fb10b4fc29fff182b82ac24e2758c8e6a7714 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 14:09:23 +0200 Subject: [PATCH 11/25] test defines --- src/test/lib/MrDocsCompilationDatabase.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index aaddeabc5..17e22440a 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -119,6 +119,17 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "--std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.defines = {"FOO", "BAR=1"}; + + auto adjusted = adjustCompileCommand({ "clang", "-DBAZ=2" }, config); + BOOST_TEST(has(adjusted, "-D__MRDOCS__")); + BOOST_TEST(has(adjusted, "-DFOO")); + BOOST_TEST(has(adjusted, "-DBAR=1")); + BOOST_TEST(has(adjusted, "-DBAZ=2")); + } } void testClangCL() @@ -163,6 +174,17 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "/std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.defines = {"FOO", "BAR=1"}; + + auto adjusted = adjustCompileCommand({ "clang-cl", "-DBAZ=2" }, config); + BOOST_TEST(has(adjusted, "-D__MRDOCS__")); + BOOST_TEST(has(adjusted, "-DFOO")); + BOOST_TEST(has(adjusted, "-DBAR=1")); + BOOST_TEST(has(adjusted, "-DBAZ=2")); + } } void run() From 635733a5fcb1f0540a91089fe3c04312883b50be Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 14:14:36 +0200 Subject: [PATCH 12/25] test systemIncludes --- src/test/lib/MrDocsCompilationDatabase.cpp | 94 +++++++++++++--------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 17e22440a..78cc27125 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -79,43 +79,25 @@ struct MrDocsCompilationDatabase_test void testClang() { - { - std::shared_ptr const config = std::make_shared(); - config->settings_.useSystemStdlib = false; - config->settings_.stdlibIncludes.push_back("stdlib-path"); - - auto adjusted = adjustCompileCommand({ "clang" }, config); - BOOST_TEST(has(adjusted, "-nostdinc++")); - BOOST_TEST(has(adjusted, { "-isystem", "stdlib-path" })); - } - - { - std::shared_ptr config = std::make_shared(); - config->settings_.useSystemLibc = false; - config->settings_.libcIncludes.push_back("libc-path"); - - auto adjusted = adjustCompileCommand({ "clang" }, config); - BOOST_TEST(has(adjusted, "-nostdinc")); - BOOST_TEST(has(adjusted, { "-isystem", "libc-path" })); - } + std::string const programName = "clang"; { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang" }, config); + auto adjusted = adjustCompileCommand({ programName }, config); BOOST_TEST(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang", "-std=c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "-std=c++11" }, config); BOOST_TEST(has(adjusted, "-std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang", "--std=c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "--std=c++11" }, config); BOOST_TEST(has(adjusted, "--std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } @@ -124,53 +106,63 @@ struct MrDocsCompilationDatabase_test std::shared_ptr config = std::make_shared(); config->settings_.defines = {"FOO", "BAR=1"}; - auto adjusted = adjustCompileCommand({ "clang", "-DBAZ=2" }, config); + auto adjusted = adjustCompileCommand({ programName, "-DBAZ=2" }, config); BOOST_TEST(has(adjusted, "-D__MRDOCS__")); BOOST_TEST(has(adjusted, "-DFOO")); BOOST_TEST(has(adjusted, "-DBAR=1")); BOOST_TEST(has(adjusted, "-DBAZ=2")); } - } - void testClangCL() - { { - std::shared_ptr config = std::make_shared(); + std::shared_ptr const config = std::make_shared(); config->settings_.useSystemStdlib = false; config->settings_.stdlibIncludes.push_back("stdlib-path"); - auto adjusted = adjustCompileCommand({ "clang-cl" }, config); - BOOST_TEST(has(adjusted, "-X")); - BOOST_TEST(has(adjusted, { "-external:I", "stdlib-path" })); + auto adjusted = adjustCompileCommand({ programName }, config); + BOOST_TEST(has(adjusted, "-nostdinc++")); + BOOST_TEST(has(adjusted, { "-isystem", "stdlib-path" })); } - + { std::shared_ptr config = std::make_shared(); config->settings_.useSystemLibc = false; config->settings_.libcIncludes.push_back("libc-path"); - auto adjusted = adjustCompileCommand({ "clang-cl" }, config); + auto adjusted = adjustCompileCommand({ programName }, config); BOOST_TEST(has(adjusted, "-nostdinc")); - BOOST_TEST(has(adjusted, { "-external:I", "libc-path" })); + BOOST_TEST(has(adjusted, { "-isystem", "libc-path" })); + } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.systemIncludes.push_back("system-path"); + + auto adjusted = adjustCompileCommand({ programName }, config); + BOOST_TEST(has(adjusted, { "-isystem", "system-path" })); } + } + + void testClangCL() + { + std::string const programName = "clang-cl"; { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang-cl" }, config); + auto adjusted = adjustCompileCommand({ programName }, config); BOOST_TEST(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang-cl", "-std:c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "-std:c++11" }, config); BOOST_TEST(has(adjusted, "-std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - auto adjusted = adjustCompileCommand({ "clang-cl", "/std:c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "/std:c++11" }, config); BOOST_TEST(has(adjusted, "/std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } @@ -179,12 +171,40 @@ struct MrDocsCompilationDatabase_test std::shared_ptr config = std::make_shared(); config->settings_.defines = {"FOO", "BAR=1"}; - auto adjusted = adjustCompileCommand({ "clang-cl", "-DBAZ=2" }, config); + auto adjusted = adjustCompileCommand({ programName, "-DBAZ=2" }, config); BOOST_TEST(has(adjusted, "-D__MRDOCS__")); BOOST_TEST(has(adjusted, "-DFOO")); BOOST_TEST(has(adjusted, "-DBAR=1")); BOOST_TEST(has(adjusted, "-DBAZ=2")); } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemStdlib = false; + config->settings_.stdlibIncludes.push_back("stdlib-path"); + + auto adjusted = adjustCompileCommand({ programName }, config); + BOOST_TEST(has(adjusted, "-X")); + BOOST_TEST(has(adjusted, { "-external:I", "stdlib-path" })); + } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.useSystemLibc = false; + config->settings_.libcIncludes.push_back("libc-path"); + + auto adjusted = adjustCompileCommand({ programName }, config); + BOOST_TEST(has(adjusted, "-nostdinc")); + BOOST_TEST(has(adjusted, { "-external:I", "libc-path" })); + } + + { + std::shared_ptr config = std::make_shared(); + config->settings_.systemIncludes.push_back("system-path"); + + auto adjusted = adjustCompileCommand({ programName }, config); + BOOST_TEST(has(adjusted, { "-external:I", "system-path" })); + } } void run() From 4913671a0e8c24d17e9bf2442533a4cb881d6e40 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 14:54:21 +0200 Subject: [PATCH 13/25] flip --- src/test/TestRunner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 40edceac7..9be08e6df 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -150,9 +150,9 @@ handleFile( auto parentDir = files::getParentDir(filePath); SingleFileDB const db = #if defined(WIN32) - makeSingleFileDBForClang(filePath); -#else makeSingleFileDBForClangCL(filePath); +#else + makeSingleFileDBForClang(filePath); #endif std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( From 873d59a1c3fcb9e7089acf7f589c15e23a5e80ff Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 15:09:42 +0200 Subject: [PATCH 14/25] unused --- src/test/lib/MrDocsCompilationDatabase.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 78cc27125..a7e19473a 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -47,10 +47,6 @@ struct TestConfigImpl final : Config struct MrDocsCompilationDatabase_test { - Config::Settings fileSettings_; - ThreadPool threadPool_; - ReferenceDirectories dirs_; - auto adjustCompileCommand(std::vector commandLine, std::shared_ptr config) const { tooling::CompileCommand cc; @@ -63,7 +59,7 @@ struct MrDocsCompilationDatabase_test // Create an adjusted MrDocsDatabase std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( - dirs_.cwd, SingleFileDB(std::move(cc)), config, defaultIncludePaths); + "", SingleFileDB(std::move(cc)), config, defaultIncludePaths); return compilations.getAllCompileCommands().front().CommandLine; } From 6f360eddbfb1195a72f76a23d03a22fcc8249265 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 15:12:32 +0200 Subject: [PATCH 15/25] default --- src/test/lib/MrDocsCompilationDatabase.cpp | 36 ++++++++-------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index a7e19473a..f00ff8e59 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -47,7 +47,9 @@ struct TestConfigImpl final : Config struct MrDocsCompilationDatabase_test { - auto adjustCompileCommand(std::vector commandLine, std::shared_ptr config) const + auto adjustCompileCommand( + std::vector commandLine, + std::shared_ptr config = std::make_shared()) const { tooling::CompileCommand cc; cc.Directory = "."; @@ -78,29 +80,23 @@ struct MrDocsCompilationDatabase_test std::string const programName = "clang"; { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName }, config); + auto adjusted = adjustCompileCommand({ programName }); BOOST_TEST(has(adjusted, "-std=c++23")); } { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName, "-std=c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "-std=c++11" }); BOOST_TEST(has(adjusted, "-std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName, "--std=c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "--std=c++11" }); BOOST_TEST(has(adjusted, "--std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - config->settings_.defines = {"FOO", "BAR=1"}; + config->settings_.defines = { "FOO", "BAR=1" }; auto adjusted = adjustCompileCommand({ programName, "-DBAZ=2" }, config); BOOST_TEST(has(adjusted, "-D__MRDOCS__")); @@ -118,7 +114,7 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-nostdinc++")); BOOST_TEST(has(adjusted, { "-isystem", "stdlib-path" })); } - + { std::shared_ptr config = std::make_shared(); config->settings_.useSystemLibc = false; @@ -143,29 +139,23 @@ struct MrDocsCompilationDatabase_test std::string const programName = "clang-cl"; { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName }, config); + auto adjusted = adjustCompileCommand({ programName }); BOOST_TEST(has(adjusted, "-std=c++23")); } { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName, "-std:c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "-std:c++11" }); BOOST_TEST(has(adjusted, "-std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { - std::shared_ptr config = std::make_shared(); - - auto adjusted = adjustCompileCommand({ programName, "/std:c++11" }, config); + auto adjusted = adjustCompileCommand({ programName, "/std:c++11" }); BOOST_TEST(has(adjusted, "/std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } { std::shared_ptr config = std::make_shared(); - config->settings_.defines = {"FOO", "BAR=1"}; + config->settings_.defines = { "FOO", "BAR=1" }; auto adjusted = adjustCompileCommand({ programName, "-DBAZ=2" }, config); BOOST_TEST(has(adjusted, "-D__MRDOCS__")); @@ -193,7 +183,7 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-nostdinc")); BOOST_TEST(has(adjusted, { "-external:I", "libc-path" })); } - + { std::shared_ptr config = std::make_shared(); config->settings_.systemIncludes.push_back("system-path"); From cee45622c6a853e1f2bab939717f1d0d49bc8f0f Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Wed, 1 Oct 2025 15:24:17 +0200 Subject: [PATCH 16/25] test std more --- src/lib/MrDocsCompilationDatabase.cpp | 4 +-- src/test/lib/MrDocsCompilationDatabase.cpp | 36 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 4f8b13c75..0e2776392 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -418,11 +418,11 @@ adjustCommandLine( { if (!isCCompileCommand) { - new_cmdline.emplace_back("-std=c++23"); + new_cmdline.emplace_back(is_clang_cl ? "-std:c++latest" : "-std=c++23"); } else { - new_cmdline.emplace_back("-std=c23"); + new_cmdline.emplace_back(is_clang_cl ? "-std:clatest" : "-std=c23"); } } diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index f00ff8e59..0a3bdff8e 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -94,6 +94,21 @@ struct MrDocsCompilationDatabase_test BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c" }); + BOOST_TEST(has(adjusted, "-std=c23")); + } + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c", "-std=c11" }); + BOOST_TEST(has(adjusted, "-std=c11")); + BOOST_TEST_NOT(has(adjusted, "-std=c23")); + } + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c", "--std=c11" }); + BOOST_TEST(has(adjusted, "--std=c11")); + BOOST_TEST_NOT(has(adjusted, "-std=c23")); + } + { std::shared_ptr config = std::make_shared(); config->settings_.defines = { "FOO", "BAR=1" }; @@ -140,17 +155,32 @@ struct MrDocsCompilationDatabase_test { auto adjusted = adjustCompileCommand({ programName }); - BOOST_TEST(has(adjusted, "-std=c++23")); + BOOST_TEST(has(adjusted, "-std:c++latest")); } { auto adjusted = adjustCompileCommand({ programName, "-std:c++11" }); BOOST_TEST(has(adjusted, "-std:c++11")); - BOOST_TEST_NOT(has(adjusted, "-std=c++23")); + BOOST_TEST_NOT(has(adjusted, "-std:c++latest")); } { auto adjusted = adjustCompileCommand({ programName, "/std:c++11" }); BOOST_TEST(has(adjusted, "/std:c++11")); - BOOST_TEST_NOT(has(adjusted, "-std=c++23")); + BOOST_TEST_NOT(has(adjusted, "-std:c++latest")); + } + + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c" }); + BOOST_TEST(has(adjusted, "-std:clatest")); + } + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c", "-std:c11" }); + BOOST_TEST(has(adjusted, "-std:c11")); + BOOST_TEST_NOT(has(adjusted, "-std:clatest")); + } + { + auto adjusted = adjustCompileCommand({ programName, "-x", "c", "/std:c11" }); + BOOST_TEST(has(adjusted, "/std:c11")); + BOOST_TEST_NOT(has(adjusted, "-std:clatest")); } { From 89fc4632f3b2427ab8c8687bbd0c1d5577ee8aee Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 2 Oct 2025 14:48:24 +0200 Subject: [PATCH 17/25] separate cases --- src/test/lib/MrDocsCompilationDatabase.cpp | 74 +++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 0a3bdff8e..8d4164d83 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -75,7 +75,7 @@ struct MrDocsCompilationDatabase_test return std::search(commandLine.begin(), commandLine.end(), flags.begin(), flags.end()) != commandLine.end(); } - void testClang() + void testClang_stdCxx() { std::string const programName = "clang"; @@ -93,6 +93,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "--std=c++11")); BOOST_TEST_NOT(has(adjusted, "-std=c++23")); } + } + + void testClang_stdC() + { + std::string const programName = "clang"; { auto adjusted = adjustCompileCommand({ programName, "-x", "c" }); @@ -108,6 +113,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "--std=c11")); BOOST_TEST_NOT(has(adjusted, "-std=c23")); } + } + + void testClang_defines() + { + std::string const programName = "clang"; { std::shared_ptr config = std::make_shared(); @@ -119,6 +129,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-DBAR=1")); BOOST_TEST(has(adjusted, "-DBAZ=2")); } + } + + void testClang_stdlib() + { + std::string const programName = "clang"; { std::shared_ptr const config = std::make_shared(); @@ -129,6 +144,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-nostdinc++")); BOOST_TEST(has(adjusted, { "-isystem", "stdlib-path" })); } + } + + void testClang_libc() + { + std::string const programName = "clang"; { std::shared_ptr config = std::make_shared(); @@ -139,6 +159,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-nostdinc")); BOOST_TEST(has(adjusted, { "-isystem", "libc-path" })); } + } + + void testClang_systemIncludes() + { + std::string const programName = "clang"; { std::shared_ptr config = std::make_shared(); @@ -149,7 +174,17 @@ struct MrDocsCompilationDatabase_test } } - void testClangCL() + void testClang() + { + testClang_stdCxx(); + testClang_stdC(); + testClang_defines(); + testClang_stdlib(); + testClang_libc(); + testClang_systemIncludes(); + } + + void testClangCL_stdCxx() { std::string const programName = "clang-cl"; @@ -167,6 +202,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "/std:c++11")); BOOST_TEST_NOT(has(adjusted, "-std:c++latest")); } + } + + void testClangCL_stdC() + { + std::string const programName = "clang-cl"; { auto adjusted = adjustCompileCommand({ programName, "-x", "c" }); @@ -182,6 +222,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "/std:c11")); BOOST_TEST_NOT(has(adjusted, "-std:clatest")); } + } + + void testClangCL_defines() + { + std::string const programName = "clang-cl"; { std::shared_ptr config = std::make_shared(); @@ -193,6 +238,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-DBAR=1")); BOOST_TEST(has(adjusted, "-DBAZ=2")); } + } + + void testClangCL_stdlib() + { + std::string const programName = "clang-cl"; { std::shared_ptr config = std::make_shared(); @@ -203,6 +253,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-X")); BOOST_TEST(has(adjusted, { "-external:I", "stdlib-path" })); } + } + + void testClangCL_libc() + { + std::string const programName = "clang-cl"; { std::shared_ptr config = std::make_shared(); @@ -213,6 +268,11 @@ struct MrDocsCompilationDatabase_test BOOST_TEST(has(adjusted, "-nostdinc")); BOOST_TEST(has(adjusted, { "-external:I", "libc-path" })); } + } + + void testClangCL_systemIncludes() + { + std::string const programName = "clang-cl"; { std::shared_ptr config = std::make_shared(); @@ -223,6 +283,16 @@ struct MrDocsCompilationDatabase_test } } + void testClangCL() + { + testClangCL_stdCxx(); + testClangCL_stdC(); + testClangCL_defines(); + testClangCL_stdlib(); + testClangCL_libc(); + testClangCL_systemIncludes(); + } + void run() { testClang(); From b190535f6427dadf3e5ccc36452d6e2026121602 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 2 Oct 2025 14:49:57 +0200 Subject: [PATCH 18/25] decide flag spelling once --- src/lib/MrDocsCompilationDatabase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 0e2776392..60ecec50d 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -312,6 +312,8 @@ adjustCommandLine( // for options. bool const is_clang_cl = driver::IsClangCL(driver_mode); + auto const systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem"; + // ------------------------------------------------------ // Supress all warnings // ------------------------------------------------------ @@ -449,7 +451,7 @@ adjustCommandLine( it != implicitIncludeDirectories.end()) { for (auto const& inc : it->second) { - new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(systemIncludeFlag); new_cmdline.emplace_back(inc); } } @@ -468,7 +470,7 @@ adjustCommandLine( new_cmdline.emplace_back(is_clang_cl ? "-X" : "-nostdinc++"); for (auto const& inc : (*config)->stdlibIncludes) { - new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(systemIncludeFlag); new_cmdline.emplace_back(inc); } } @@ -478,7 +480,7 @@ adjustCommandLine( new_cmdline.emplace_back("-nostdinc"); for (auto const& inc : (*config)->libcIncludes) { - new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(systemIncludeFlag); new_cmdline.emplace_back(inc); } } @@ -488,7 +490,7 @@ adjustCommandLine( // ------------------------------------------------------ for (auto const& inc : (*config)->systemIncludes) { - new_cmdline.emplace_back(is_clang_cl ? "-external:I" : "-isystem"); + new_cmdline.emplace_back(systemIncludeFlag); new_cmdline.emplace_back(inc); } for (auto const& inc : (*config)->includes) From baef4b68b9298724d78d880f62e432d0c91bca4f Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 2 Oct 2025 15:10:26 +0200 Subject: [PATCH 19/25] isClangCL --- src/lib/AST/ClangHelpers.cpp | 30 ++++++++++++++++++++ src/lib/AST/ClangHelpers.hpp | 8 ++++++ src/lib/CorpusImpl.cpp | 41 ++------------------------- src/lib/CorpusImpl.hpp | 9 +++--- src/lib/MrDocsCompilationDatabase.cpp | 18 ++++-------- src/lib/MrDocsCompilationDatabase.hpp | 8 ++++++ 6 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/lib/AST/ClangHelpers.cpp b/src/lib/AST/ClangHelpers.cpp index 8de956239..5be852238 100644 --- a/src/lib/AST/ClangHelpers.cpp +++ b/src/lib/AST/ClangHelpers.cpp @@ -13,8 +13,10 @@ #include "lib/AST/ClangHelpers.hpp" #include #include +#include #include #include +#include #include namespace clang::mrdocs { @@ -454,4 +456,32 @@ isDocumented(Decl const* D) return getDocumentation(D) != nullptr; } +bool +isClangCL(tooling::CompileCommand const& cc) +{ + auto const& cmdline = cc.CommandLine; + + // ------------------------------------------------------ + // Convert to InputArgList + // ------------------------------------------------------ + // InputArgList is the input format for llvm functions + auto cmdLineCStrsView = std::views::transform(cmdline, &std::string::c_str); + std::vector const cmdLineCStrs(cmdLineCStrsView.begin(), cmdLineCStrsView.end()); + llvm::opt::InputArgList const args( + cmdLineCStrs.data(), + cmdLineCStrs.data() + cmdLineCStrs.size()); + + // ------------------------------------------------------ + // Get driver mode + // ------------------------------------------------------ + // The driver mode distinguishes between clang/gcc and msvc + // command line option formats. The value is deduced from + // the `-drive-mode` option or from `progName`. + // Common values are "gcc", "g++", "cpp", "cl" and "flang". + std::string const& progName = cmdline.front(); + StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); + + return driver::IsClangCL(driver_mode); +} + } // clang::mrdocs diff --git a/src/lib/AST/ClangHelpers.hpp b/src/lib/AST/ClangHelpers.hpp index 2cd2cbf0e..d04360b9d 100644 --- a/src/lib/AST/ClangHelpers.hpp +++ b/src/lib/AST/ClangHelpers.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1081,6 +1082,13 @@ namespace detail { report::trace("{}", MRDOCS_SYMBOL_TRACE_UNIQUE_NAME) #endif +/** Determine whether the driver mode is ClangCL. + + @param cc The compilation command to insepct. + */ +bool +isClangCL(tooling::CompileCommand const& cc); + } // clang::mrdocs #endif diff --git a/src/lib/CorpusImpl.cpp b/src/lib/CorpusImpl.cpp index 67314e628..ccf7000ad 100644 --- a/src/lib/CorpusImpl.cpp +++ b/src/lib/CorpusImpl.cpp @@ -23,8 +23,6 @@ #include "lib/Metadata/Finalizers/SortMembersFinalizer.hpp" #include "lib/Support/Chrono.hpp" #include "lib/Support/Report.hpp" -#include -#include #include #include #include @@ -713,46 +711,11 @@ lookupCacheSet( //------------------------------------------------ -namespace { -// FIXME(k-ballo): MrDocsCompilationDatabase already figured this out, but we lost that information. -// do we want to have to recompute it here? if so, dedup this query -bool -isClangCL(tooling::CompilationDatabase const& compilations) -{ - auto const& commands = compilations.getAllCompileCommands(); - if (commands.empty()) return false; - - auto const& cmdline = commands.front().CommandLine; - - // ------------------------------------------------------ - // Convert to InputArgList - // ------------------------------------------------------ - // InputArgList is the input format for llvm functions - auto cmdLineCStrsView = std::views::transform(cmdline, &std::string::c_str); - std::vector const cmdLineCStrs(cmdLineCStrsView.begin(), cmdLineCStrsView.end()); - llvm::opt::InputArgList const args( - cmdLineCStrs.data(), - cmdLineCStrs.data() + cmdLineCStrs.size()); - - // ------------------------------------------------------ - // Get driver mode - // ------------------------------------------------------ - // The driver mode distinguishes between clang/gcc and msvc - // command line option formats. The value is deduced from - // the `-drive-mode` option or from `progName`. - // Common values are "gcc", "g++", "cpp", "cl" and "flang". - std::string const& progName = cmdline.front(); - StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); - - return driver::IsClangCL(driver_mode); -} -} - mrdocs::Expected> CorpusImpl:: build( std::shared_ptr const& config, - tooling::CompilationDatabase const& compilations) + MrDocsCompilationDatabase const& compilations) { using clock_type = std::chrono::steady_clock; auto start_time = clock_type::now(); @@ -774,7 +737,7 @@ build( // Identify if we should use "msvc/clang-cl" or "clang/gcc" format // for options. - bool const is_clang_cl = isClangCL(compilations); + bool const is_clang_cl = compilations.isClangCL(); // ------------------------------------------ // "Process file" task diff --git a/src/lib/CorpusImpl.hpp b/src/lib/CorpusImpl.hpp index c8d70d0cf..0a3f56dae 100644 --- a/src/lib/CorpusImpl.hpp +++ b/src/lib/CorpusImpl.hpp @@ -12,9 +12,10 @@ #ifndef MRDOCS_LIB_CORPUSIMPL_HPP #define MRDOCS_LIB_CORPUSIMPL_HPP -#include "lib/AST/ParseRef.hpp" #include "ConfigImpl.hpp" +#include "lib/AST/ParseRef.hpp" #include "lib/Metadata/InfoSet.hpp" +#include "lib/MrDocsCompilationDatabase.hpp" #include "lib/Support/Debug.hpp" #include #include @@ -22,11 +23,11 @@ #include #include #include +#include #include #include #include #include -#include namespace clang::mrdocs { @@ -161,7 +162,7 @@ class CorpusImpl final : public Corpus not need to call this function directly. @param config A shared pointer to the configuration. - @param compilations A compilations database for the input files. + @param compilations A MrDocs compilations database for the input files. */ // MRDOCS_DECL [[nodiscard]] @@ -169,7 +170,7 @@ class CorpusImpl final : public Corpus mrdocs::Expected> build( std::shared_ptr const& config, - tooling::CompilationDatabase const& compilations); + MrDocsCompilationDatabase const& compilations); void qualifiedName( diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 60ecec50d..3025817f6 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -11,6 +11,7 @@ #include "MrDocsCompilationDatabase.hpp" #include "lib/ConfigImpl.hpp" +#include "lib/AST/ClangHelpers.hpp" #include "lib/Support/Debug.hpp" #include "lib/Support/ExecuteAndWaitWithLogging.hpp" #include "lib/Support/Path.hpp" @@ -275,6 +276,7 @@ std::vector adjustCommandLine( StringRef const workingDir, std::vector const& cmdline, + bool is_clang_cl, std::shared_ptr const& config, std::unordered_map> const& implicitIncludeDirectories, std::string_view filename) @@ -300,18 +302,6 @@ adjustCommandLine( cmdLineCStrs.data(), cmdLineCStrs.data() + cmdLineCStrs.size()); - // ------------------------------------------------------ - // Get driver mode - // ------------------------------------------------------ - // The driver mode distinguishes between clang/gcc and msvc - // command line option formats. The value is deduced from - // the `-drive-mode` option or from `progName`. - // Common values are "gcc", "g++", "cpp", "cl" and "flang". - StringRef const driver_mode = driver::getDriverMode(progName, cmdLineCStrs); - // Identify if we should use "msvc/clang-cl" or "clang/gcc" format - // for options. - bool const is_clang_cl = driver::IsClangCL(driver_mode); - auto const systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem"; // ------------------------------------------------------ @@ -562,6 +552,9 @@ MrDocsCompilationDatabase( using tooling::CompileCommand; std::vector allCommands = inner.getAllCompileCommands(); + if (allCommands.empty()) return; + + isClangCL_ = mrdocs::isClangCL(allCommands.front()); AllCommands_.reserve(allCommands.size()); SmallPathString temp; for (CompileCommand const& cmd0 : allCommands) @@ -573,6 +566,7 @@ MrDocsCompilationDatabase( cmd.CommandLine = adjustCommandLine( workingDir, cmd0.CommandLine, + isClangCL_, config, implicitIncludeDirectories, cmd0.Filename); diff --git a/src/lib/MrDocsCompilationDatabase.hpp b/src/lib/MrDocsCompilationDatabase.hpp index 490955ad2..8dc7d2acd 100644 --- a/src/lib/MrDocsCompilationDatabase.hpp +++ b/src/lib/MrDocsCompilationDatabase.hpp @@ -38,6 +38,7 @@ class MrDocsCompilationDatabase { std::vector AllCommands_; llvm::StringMap IndexByFile_; + bool isClangCL_{}; public: /** @@ -80,6 +81,13 @@ class MrDocsCompilationDatabase */ std::vector getAllCompileCommands() const override; + + /** Whether the driver mode for the compilation database is ClangCL */ + bool + isClangCL() const noexcept + { + return isClangCL_; + } }; } // mrdocs From c3fa9b73381746ffe61029db80d8076a32e49797 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Thu, 2 Oct 2025 15:14:05 +0200 Subject: [PATCH 20/25] silence warning --- src/test/TestRunner.cpp | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 9be08e6df..a35c94c7f 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -66,29 +66,17 @@ replaceCRLFWithLF(std::string &str) } } -SingleFileDB makeSingleFileDBForClang(llvm::StringRef pathName) +SingleFileDB makeSingleFileDB(llvm::StringRef pathName) { auto fileName = files::getFileName(pathName); auto parentDir = files::getParentDir(pathName); - std::vector cmds = {"clang", - "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; - tooling::CompileCommand cc( - parentDir, - fileName, - std::move(cmds), - parentDir); - cc.Heuristic = "unit test"; - return SingleFileDB(std::move(cc)); -} - -SingleFileDB makeSingleFileDBForClangCL(llvm::StringRef pathName) -{ - auto fileName = files::getFileName(pathName); - auto parentDir = files::getParentDir(pathName); - - std::vector cmds = {"clang-cl", - "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; + std::vector cmds = +#if defined(WIN32) + {"clang-cl", "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; +#else + {"clang", "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; +#endif tooling::CompileCommand cc( parentDir, fileName, @@ -148,12 +136,7 @@ handleFile( // Create an adjusted MrDocsDatabase auto parentDir = files::getParentDir(filePath); - SingleFileDB const db = -#if defined(WIN32) - makeSingleFileDBForClangCL(filePath); -#else - makeSingleFileDBForClang(filePath); -#endif + SingleFileDB const db = makeSingleFileDB(filePath); std::unordered_map> defaultIncludePaths; MrDocsCompilationDatabase compilations( llvm::StringRef(parentDir), db, config, defaultIncludePaths); From 4835c4c84a2b1105ec63d30a67155236107eaa2f Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Fri, 3 Oct 2025 12:47:32 +0200 Subject: [PATCH 21/25] test both clang and clang-cl modes --- src/test/TestRunner.cpp | 53 +++++++++++++++++++++++++++++------------ src/test/TestRunner.hpp | 8 +++++++ 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index a35c94c7f..447ff1414 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -66,17 +66,13 @@ replaceCRLFWithLF(std::string &str) } } -SingleFileDB makeSingleFileDB(llvm::StringRef pathName) +SingleFileDB makeSingleFileDB(llvm::StringRef pathName, std::vector cmds) { auto fileName = files::getFileName(pathName); auto parentDir = files::getParentDir(pathName); - std::vector cmds = -#if defined(WIN32) - {"clang-cl", "/std:c++latest", "/permissive-", "/WX", std::string{fileName}}; -#else - {"clang", "-std=c++23", "-pedantic-errors", "-Werror", std::string{fileName}}; -#endif + cmds.push_back(std::string{fileName}); + tooling::CompileCommand cc( parentDir, fileName, @@ -95,7 +91,6 @@ handleFile( { report::debug("Handling {}", filePath); - namespace fs = llvm::sys::fs; namespace path = llvm::sys::path; MRDOCS_ASSERT(path::extension(filePath).compare_insensitive(".cpp") == 0); @@ -130,17 +125,45 @@ handleFile( std::shared_ptr config = ConfigImpl::load(fileSettings, dirs_, threadPool_).value(); + auto parentDir = files::getParentDir(filePath); + std::unordered_map> defaultIncludePaths; + + // Test normally + { + auto const db = makeSingleFileDB(filePath, + {"clang", "-std=c++23", "-pedantic-errors", "-Werror"}); + + // Create an adjusted MrDocsDatabase + MrDocsCompilationDatabase compilations( + llvm::StringRef(parentDir), db, config, defaultIncludePaths); + handleCompilationDatabase(filePath, compilations, config); + } + + // Test again in clang-cl mode + { + auto const db = makeSingleFileDB(filePath, + {"clang-cl", "/std:c++latest", "/permissive-", "/WX"}); + + // Create an adjusted MrDocsDatabase + MrDocsCompilationDatabase compilations( + llvm::StringRef(parentDir), db, config, defaultIncludePaths); + handleCompilationDatabase(filePath, compilations, config); + } +} + +void +TestRunner:: +handleCompilationDatabase( + llvm::StringRef filePath, + MrDocsCompilationDatabase const& compilations, + std::shared_ptr const& config) +{ + namespace path = llvm::sys::path; + // Path with the expected results SmallPathString expectedPath = filePath; path::replace_extension(expectedPath, gen_->fileExtension()); - // Create an adjusted MrDocsDatabase - auto parentDir = files::getParentDir(filePath); - SingleFileDB const db = makeSingleFileDB(filePath); - std::unordered_map> defaultIncludePaths; - MrDocsCompilationDatabase compilations( - llvm::StringRef(parentDir), db, config, defaultIncludePaths); - report::debug("Building Corpus", filePath); auto corpus = CorpusImpl::build(config, compilations); if (!corpus) diff --git a/src/test/TestRunner.hpp b/src/test/TestRunner.hpp index 2642a2262..0f7d9afd5 100644 --- a/src/test/TestRunner.hpp +++ b/src/test/TestRunner.hpp @@ -12,8 +12,10 @@ #define MRDOCS_TEST_TESTRUNNER_HPP #include "lib/ConfigImpl.hpp" +#include "lib/MrDocsCompilationDatabase.hpp" #include #include +#include #include #include #include @@ -75,6 +77,12 @@ class TestRunner TestRunner(std::string_view generator); + void + handleCompilationDatabase( + llvm::StringRef filePath, + MrDocsCompilationDatabase const& compilations, + std::shared_ptr const& config); + /** Check a single file, or a directory recursively. This function checks the specified path From c2b61adecb21a93334a0e2d4a5d5150ca3b1b1d3 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Fri, 3 Oct 2025 13:29:13 +0200 Subject: [PATCH 22/25] uh? --- src/test/TestRunner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 447ff1414..65abda30b 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -139,6 +139,7 @@ handleFile( handleCompilationDatabase(filePath, compilations, config); } +#if defined(_MSC_VER) // Test again in clang-cl mode { auto const db = makeSingleFileDB(filePath, @@ -149,6 +150,7 @@ handleFile( llvm::StringRef(parentDir), db, config, defaultIncludePaths); handleCompilationDatabase(filePath, compilations, config); } +#endif } void From 382b764e2785ed0123d2ad0f33d2c8487ad3c601 Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 7 Oct 2025 08:36:41 +0200 Subject: [PATCH 23/25] fix clang-cl default std flags --- src/lib/MrDocsCompilationDatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MrDocsCompilationDatabase.cpp b/src/lib/MrDocsCompilationDatabase.cpp index 3025817f6..cbe2b0c56 100644 --- a/src/lib/MrDocsCompilationDatabase.cpp +++ b/src/lib/MrDocsCompilationDatabase.cpp @@ -410,11 +410,11 @@ adjustCommandLine( { if (!isCCompileCommand) { - new_cmdline.emplace_back(is_clang_cl ? "-std:c++latest" : "-std=c++23"); + new_cmdline.emplace_back(is_clang_cl ? "-std:c++23preview" : "-std=c++23"); } else { - new_cmdline.emplace_back(is_clang_cl ? "-std:clatest" : "-std=c23"); + new_cmdline.emplace_back(is_clang_cl ? "-std:c17" : "-std=c23"); } } From 2ab662802e4f2e4594e5270bae36caf42183af3e Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 7 Oct 2025 16:37:54 +0200 Subject: [PATCH 24/25] adjust -std: test --- src/test/lib/MrDocsCompilationDatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/lib/MrDocsCompilationDatabase.cpp b/src/test/lib/MrDocsCompilationDatabase.cpp index 8d4164d83..26731347f 100644 --- a/src/test/lib/MrDocsCompilationDatabase.cpp +++ b/src/test/lib/MrDocsCompilationDatabase.cpp @@ -190,7 +190,7 @@ struct MrDocsCompilationDatabase_test { auto adjusted = adjustCompileCommand({ programName }); - BOOST_TEST(has(adjusted, "-std:c++latest")); + BOOST_TEST(has(adjusted, "-std:c++23preview")); } { auto adjusted = adjustCompileCommand({ programName, "-std:c++11" }); @@ -210,7 +210,7 @@ struct MrDocsCompilationDatabase_test { auto adjusted = adjustCompileCommand({ programName, "-x", "c" }); - BOOST_TEST(has(adjusted, "-std:clatest")); + BOOST_TEST(has(adjusted, "-std:c17")); } { auto adjusted = adjustCompileCommand({ programName, "-x", "c", "-std:c11" }); From 5bcc0c1c8beff47a4a5f5d7c0dbf6222b0e238ed Mon Sep 17 00:00:00 2001 From: Agustin Berge Date: Tue, 7 Oct 2025 17:03:01 +0200 Subject: [PATCH 25/25] adjust more --- src/test/TestRunner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 65abda30b..3a451b707 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -131,7 +131,7 @@ handleFile( // Test normally { auto const db = makeSingleFileDB(filePath, - {"clang", "-std=c++23", "-pedantic-errors", "-Werror"}); + {"clang", "-std=c++23"}); // Create an adjusted MrDocsDatabase MrDocsCompilationDatabase compilations( @@ -143,7 +143,7 @@ handleFile( // Test again in clang-cl mode { auto const db = makeSingleFileDB(filePath, - {"clang-cl", "/std:c++latest", "/permissive-", "/WX"}); + {"clang-cl", "/std:c++23preview"}); // Create an adjusted MrDocsDatabase MrDocsCompilationDatabase compilations(