|
10 | 10 | //
|
11 | 11 |
|
12 | 12 | #include "ToolExecutor.hpp"
|
| 13 | +#include <mrdox/Support/Report.hpp> |
13 | 14 | #include <mrdox/Support/ThreadPool.hpp>
|
14 | 15 | #include <clang/Tooling/ToolExecutorPluginRegistry.h>
|
15 | 16 | #include <llvm/Support/Regex.h>
|
@@ -112,49 +113,75 @@ execute(
|
112 | 113 | llvm::errs() << Msg.str() << "\n";
|
113 | 114 | };
|
114 | 115 |
|
115 |
| - auto Files = Compilations.getAllFiles(); |
| 116 | + // Get a copy of the filename strings |
| 117 | + std::vector<std::string> Files = Compilations.getAllFiles(); |
116 | 118 |
|
117 | 119 | // Add a counter to track the progress.
|
118 |
| - const std::string TotalNumStr = std::to_string(Files.size()); |
| 120 | + auto const TotalNumStr = std::to_string(Files.size()); |
119 | 121 | unsigned Counter = 0;
|
120 | 122 | auto Count = [&]()
|
121 | 123 | {
|
122 | 124 | std::unique_lock<std::mutex> LockGuard(TUMutex);
|
123 | 125 | return ++Counter;
|
124 | 126 | };
|
125 | 127 |
|
126 |
| - auto& Action = Actions.front(); |
| 128 | + auto const& Action = Actions.front(); |
127 | 129 |
|
128 |
| - TaskGroup taskGroup(config_.threadPool()); |
| 130 | + auto const processFile = |
| 131 | + [&](std::string Path) |
| 132 | + { |
| 133 | + if(config_.verboseOutput) |
| 134 | + Log("[" + std::to_string(Count()) + "/" + TotalNumStr + "] Processing file " + Path); |
| 135 | + |
| 136 | + // Each thread gets an independent copy of a VFS to allow different |
| 137 | + // concurrent working directories. |
| 138 | + IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = |
| 139 | + llvm::vfs::createPhysicalFileSystem(); |
| 140 | + |
| 141 | + tooling::ClangTool Tool( Compilations, { Path }, |
| 142 | + std::make_shared<PCHContainerOperations>(), FS); |
| 143 | + Tool.appendArgumentsAdjuster(Action.second); |
| 144 | + Tool.appendArgumentsAdjuster(getDefaultArgumentsAdjusters()); |
| 145 | + |
| 146 | + for (const auto& FileAndContent : OverlayFiles) |
| 147 | + Tool.mapVirtualFile(FileAndContent.first(), |
| 148 | + FileAndContent.second); |
| 149 | + |
| 150 | + // VFALCO This needs to be tested |
| 151 | + if (Tool.run(Action.first.get())) |
| 152 | + AppendError(llvm::Twine("Failed to run action on ") + Path + "\n"); |
| 153 | + }; |
129 | 154 |
|
130 |
| - for (std::string File : Files) |
| 155 | + // Run the action on all files in the database |
| 156 | + std::vector<Error> errors; |
| 157 | + if(Files.size() > 1) |
| 158 | + { |
| 159 | + TaskGroup taskGroup(config_.threadPool()); |
| 160 | + // VFALCO is File move-constructed? |
| 161 | + for(std::string File : std::move(Files)) |
| 162 | + { |
| 163 | + taskGroup.async( |
| 164 | + [&, Path = std::move(File)]() |
| 165 | + { |
| 166 | + processFile(std::move(Path)); |
| 167 | + }); |
| 168 | + } |
| 169 | + errors = taskGroup.wait(); |
| 170 | + } |
| 171 | + else |
131 | 172 | {
|
132 |
| - taskGroup.async( |
133 |
| - [&, Path = std::move(File)]() |
| 173 | + try |
| 174 | + { |
| 175 | + processFile(std::move(Files.front())); |
| 176 | + } |
| 177 | + catch(Exception const& ex) |
134 | 178 | {
|
135 |
| - if(config_.verboseOutput) |
136 |
| - Log("[" + std::to_string(Count()) + "/" + TotalNumStr + "] Processing file " + Path); |
137 |
| - |
138 |
| - // Each thread gets an independent copy of a VFS to allow different |
139 |
| - // concurrent working directories. |
140 |
| - IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = |
141 |
| - llvm::vfs::createPhysicalFileSystem(); |
142 |
| - |
143 |
| - tooling::ClangTool Tool( Compilations, { Path }, |
144 |
| - std::make_shared<PCHContainerOperations>(), FS); |
145 |
| - Tool.appendArgumentsAdjuster(Action.second); |
146 |
| - Tool.appendArgumentsAdjuster(getDefaultArgumentsAdjusters()); |
147 |
| - |
148 |
| - for (const auto& FileAndContent : OverlayFiles) |
149 |
| - Tool.mapVirtualFile(FileAndContent.first(), |
150 |
| - FileAndContent.second); |
151 |
| - |
152 |
| - if (Tool.run(Action.first.get())) |
153 |
| - AppendError(llvm::Twine("Failed to run action on ") + Path + "\n"); |
154 |
| - }); |
| 179 | + errors.push_back(ex.error()); |
| 180 | + } |
155 | 181 | }
|
156 | 182 |
|
157 |
| - auto errors = taskGroup.wait(); |
| 183 | + if(! errors.empty()) |
| 184 | + reportError(errors, "Could not run the tool executor"); |
158 | 185 |
|
159 | 186 | if (!ErrorMsg.empty())
|
160 | 187 | return make_string_error(ErrorMsg);
|
|
0 commit comments