@@ -31,7 +31,8 @@ static std::string tryConvertOptionToPath(const std::string &possibleFilePath, c
3131
3232ProjectBuildDatabase::ProjectBuildDatabase (fs::path _buildCommandsJsonPath,
3333 fs::path _serverBuildDir,
34- utbot::ProjectContext _projectContext) :
34+ utbot::ProjectContext _projectContext,
35+ bool skipObjectWithoutSource) :
3536 BuildDatabase(_serverBuildDir,
3637 _buildCommandsJsonPath,
3738 fs::canonical (_buildCommandsJsonPath / " link_commands.json" ),
@@ -47,7 +48,7 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
4748 auto linkCommandsJson = JsonUtils::getJsonFromFile (linkCommandsJsonPath);
4849 auto compileCommandsJson = JsonUtils::getJsonFromFile (compileCommandsJsonPath);
4950 initObjects (compileCommandsJson);
50- initInfo (linkCommandsJson);
51+ initInfo (linkCommandsJson, skipObjectWithoutSource );
5152 filterInstalledFiles ();
5253 addLocalSharedLibraries ();
5354 fillTargetInfoParents ();
@@ -58,9 +59,10 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
5859 }
5960}
6061
61- ProjectBuildDatabase::ProjectBuildDatabase (utbot::ProjectContext projectContext) : ProjectBuildDatabase(
62+ ProjectBuildDatabase::ProjectBuildDatabase (utbot::ProjectContext projectContext, bool skipObjectWithoutSource)
63+ : ProjectBuildDatabase(
6264 CompilationUtils::substituteRemotePathToCompileCommandsJsonPath (projectContext),
63- Paths::getUTBotBuildDir(projectContext), std::move(projectContext)) {
65+ Paths::getUTBotBuildDir(projectContext), std::move(projectContext), skipObjectWithoutSource ) {
6466}
6567
6668
@@ -154,7 +156,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
154156 }
155157}
156158
157- void ProjectBuildDatabase::initInfo (const nlohmann::json &linkCommandsJson) {
159+ void ProjectBuildDatabase::initInfo (const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource ) {
158160 for (nlohmann::json const &linkCommand: linkCommandsJson) {
159161 fs::path directory = linkCommand.at (" directory" ).get <std::string>();
160162 std::vector<std::string> jsonArguments;
@@ -189,14 +191,17 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
189191 if (ignoredOutput.count (currentFile)) {
190192 continue ;
191193 }
192- targetInfo->addFile (currentFile);
193194 if (Paths::isObjectFile (currentFile)) {
194195 if (!CollectionUtils::containsKey (objectFileInfos, currentFile) &&
195196 !CollectionUtils::containsKey (objectFileInfos,
196197 relative (currentFile, directory))) {
197198 std::string message =
198199 " compile_commands.json doesn't contain a command for object file " +
199200 currentFile.string ();
201+ if (skipObjectWithoutSource) {
202+ LOG_S (WARNING) << message;
203+ continue ;
204+ }
200205 LOG_S (ERROR) << message;
201206 throw CompilationDatabaseException (message);
202207 }
@@ -207,6 +212,7 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
207212 objectFileInfos[relative (currentFile, directory)]->linkUnit = output;
208213 }
209214 }
215+ targetInfo->addFile (currentFile);
210216 }
211217 targetInfo->commands .emplace_back (command);
212218 }
0 commit comments