@@ -59,20 +59,17 @@ fs::path BuildDatabase::createExplicitObjectFileCompilationCommand(const std::sh
59
59
}
60
60
61
61
void BuildDatabase::createClangCompileCommandsJson () {
62
- CollectionUtils::MapFileTo<std::pair<nlohmann::json, std::shared_ptr<ObjectFileInfo>>> fileCompileCommands;
63
- for (const auto &[compileCommand, objectInfo]: compileCommands_temp) {
64
- const fs::path &sourcePath = objectInfo->getSourcePath ();
65
- if (CollectionUtils::contains (fileCompileCommands, sourcePath)) {
66
- LOG_S (WARNING) << " Multiple compile commands for file \" " << sourcePath
67
- << " \" use command for \" " << objectInfo->getOutputFile () << " \" " ;
68
- } else if (CollectionUtils::contains (objectFileInfos, objectInfo->getOutputFile ())) {
69
- fileCompileCommands[sourcePath] = {compileCommand, objectInfo};
70
- }
62
+ CollectionUtils::MapFileTo<nlohmann::json> fileCompileCommands;
63
+ for (const auto &[sourcePath, objectInfos]: sourceFileInfos) {
64
+ const std::shared_ptr<ObjectFileInfo> &objectInfo = objectInfos.front ();
65
+ fileCompileCommands[sourcePath] = {{" directory" , objectInfo->command .getDirectory ()},
66
+ {" command" , objectInfo->command .toString ()},
67
+ {" file" , objectInfo->command .getSourcePath ()}};
71
68
}
72
69
73
70
nlohmann::json compileCommandsSingleFilesJson;
74
71
for (const auto &compileCommand: fileCompileCommands) {
75
- compileCommandsSingleFilesJson.push_back (compileCommand.second . first );
72
+ compileCommandsSingleFilesJson.push_back (compileCommand.second );
76
73
}
77
74
78
75
fs::path clangCompileCommandsJsonPath = CompilationUtils::getClangCompileCommandsJsonPath (buildCommandsJsonPath);
@@ -334,6 +331,11 @@ BuildDatabase::getClientCompilationUnitInfo(const fs::path &filepath) const {
334
331
throw CompilationDatabaseException (" File is not a compilation unit or an object file: " + filepath.string ());
335
332
}
336
333
334
+
335
+ [[nodiscard]] bool BuildDatabase::hasUnitInfo (const fs::path &filepath) const {
336
+ return CollectionUtils::contains (sourceFileInfos, filepath) || CollectionUtils::contains (objectFileInfos, filepath);
337
+ }
338
+
337
339
std::shared_ptr<const BuildDatabase::TargetInfo> BuildDatabase::getClientLinkUnitInfo (const fs::path &filepath) const {
338
340
if (Paths::isSourceFile (filepath)) {
339
341
auto compilationInfo = getClientCompilationUnitInfo (filepath);
@@ -543,7 +545,3 @@ CollectionUtils::FileSet BuildDatabase::getSourceFilesForTarget(const fs::path &
543
545
std::shared_ptr<BuildDatabase::TargetInfo> BuildDatabase::getTargetInfo (const fs::path &_target) {
544
546
return targetInfos[_target];
545
547
}
546
-
547
- std::vector<std::pair<nlohmann::json, std::shared_ptr<BuildDatabase::ObjectFileInfo>>> BuildDatabase::getCompileCommands_temp () {
548
- return compileCommands_temp;
549
- }
0 commit comments