@@ -56,40 +56,15 @@ BuildDatabase::BuildDatabase(fs::path _buildCommandsJsonPath,
56
56
target = GrpcUtils::UTBOT_AUTO_TARGET_PATH;
57
57
}
58
58
59
- BuildDatabase::BuildDatabase (BuildDatabase& baseBuildDatabase,
59
+ BuildDatabase::BuildDatabase (BuildDatabase & baseBuildDatabase,
60
60
const std::string &_target) :
61
61
serverBuildDir(baseBuildDatabase.serverBuildDir),
62
62
projectContext(baseBuildDatabase.projectContext),
63
63
buildCommandsJsonPath(baseBuildDatabase.buildCommandsJsonPath),
64
64
linkCommandsJsonPath(baseBuildDatabase.linkCommandsJsonPath),
65
65
compileCommandsJsonPath(baseBuildDatabase.compileCommandsJsonPath),
66
- isAutoTarget(false ) {
67
-
68
- // BuildDatabase baseBuildDatabase(buildCommandsJsonPath, serverBuildDir, projectContext, false);
69
-
70
-
71
- // fs::path target;
72
- // TODO target incorrect name now
73
- if (Paths::isSourceFile (_target)) {
74
- fs::path root = baseBuildDatabase.getRootForSource (_target);
75
- target = root;
76
- } else if (_target == GrpcUtils::UTBOT_AUTO_TARGET_PATH || _target.empty ()) {
77
- fs::path root = baseBuildDatabase.getRootForFirstSource ();
78
- target = root;
79
- isAutoTarget = true ;
80
- } else {
81
- auto new_target = GenerationUtils::findTarget (baseBuildDatabase.getAllTargets (), _target);
82
- if (new_target.has_value ()) {
83
- target = new_target.value ();
84
- } else {
85
- throw CompilationDatabaseException (" Can't find target: " + _target);
86
- }
87
- }
88
-
89
-
90
- // CollectionUtils::MapFileTo<std::vector<std::shared_ptr<ObjectFileInfo>>> sourceFileInfos;
91
- // CollectionUtils::MapFileTo<std::shared_ptr<ObjectFileInfo>> objectFileInfos;
92
- // CollectionUtils::MapFileTo<std::vector<fs::path>> objectFileTargets;
66
+ target(_target),
67
+ isAutoTarget(_target == GrpcUtils::UTBOT_AUTO_TARGET_PATH) {
93
68
{
94
69
auto objectFilesList = baseBuildDatabase.getArchiveObjectFiles (target);
95
70
for (const auto &objectFilePath: objectFilesList) {
@@ -103,23 +78,32 @@ BuildDatabase::BuildDatabase(BuildDatabase& baseBuildDatabase,
103
78
baseBuildDatabase.objectFileTargets [objectFileInfo->getOutputFile ()];
104
79
}
105
80
}
106
- // CollectionUtils::MapFileTo<std::shared_ptr<TargetInfo>> targetInfos;
107
- // CollectionUtils::MapFileTo<CollectionUtils::FileSet> linkUnitToStubFiles;
81
+
108
82
{
109
83
auto targetFilesList = baseBuildDatabase.getArchiveTargetFiles (target);
110
84
for (const auto &objectFilePath: targetFilesList) {
111
85
targetInfos[objectFilePath] = baseBuildDatabase.targetInfos [objectFilePath];
112
- linkUnitToStubFiles[objectFilePath] = baseBuildDatabase.linkUnitToStubFiles [objectFilePath];
113
86
}
114
87
}
115
88
116
- // std::vector<std::pair<nlohmann::json, std::shared_ptr<ObjectFileInfo>>> compileCommands_temp;
117
89
compileCommands_temp = baseBuildDatabase.compileCommands_temp ;
118
-
119
90
createClangCompileCommandsJson ();
120
91
}
121
92
122
- std::shared_ptr<BuildDatabase> BuildDatabase::createBaseForTarget (const std::string &_target) {
93
+ std::shared_ptr<BuildDatabase> BuildDatabase::createBuildDatabaseForSourceOrTarget (const std::string &_targetOrSourcePath) {
94
+ fs::path _target;
95
+ if (Paths::isSourceFile (_targetOrSourcePath)) {
96
+ _target = getRootForSource (_targetOrSourcePath);
97
+ } else if (_targetOrSourcePath == GrpcUtils::UTBOT_AUTO_TARGET_PATH || _targetOrSourcePath.empty ()) {
98
+ _target = getRootForFirstSource ();
99
+ } else {
100
+ auto new_target = GenerationUtils::findTarget (getAllTargets (), _targetOrSourcePath);
101
+ if (new_target.has_value ()) {
102
+ _target = new_target.value ();
103
+ } else {
104
+ throw CompilationDatabaseException (" Can't find target: " + _targetOrSourcePath);
105
+ }
106
+ }
123
107
return std::make_shared<BuildDatabase>(std::move (BuildDatabase (*this , _target)));
124
108
}
125
109
@@ -220,8 +204,7 @@ void BuildDatabase::initObjects(const nlohmann::json &compileCommandsJson) {
220
204
sourceFileInfos[sourcePath].emplace_back (objectInfo);
221
205
}
222
206
for (auto &[sourceFile, objectInfos]: sourceFileInfos) {
223
- // Need stable sort for save order of 32 and 64 bits files
224
- std::stable_sort (objectInfos.begin (), objectInfos.end (), conflictPriorityMore);
207
+ std::sort (objectInfos.begin (), objectInfos.end (), conflictPriorityMore);
225
208
}
226
209
}
227
210
@@ -292,27 +275,6 @@ void BuildDatabase::createClangCompileCommandsJson() {
292
275
compilationDatabase = CompilationUtils::getCompilationDatabase (clangCompileCommandsJsonPath);
293
276
}
294
277
295
- // void BuildDatabase::updateTarget(const fs::path &_target) {
296
- // if (_target.string() == GrpcUtils::UTBOT_AUTO_TARGET_PATH) {
297
- // return;
298
- // }
299
- //
300
- // for (auto &[sourceFile, objectInfos]: sourceFileInfos) {
301
- // std::sort(objectInfos.begin(), objectInfos.end(), [&](const std::shared_ptr<ObjectFileInfo> &left,
302
- // const std::shared_ptr<ObjectFileInfo> &right) {
303
- // if (CollectionUtils::containsKey(targetInfos, target)) {
304
- // if (CollectionUtils::containsKey(targetInfos[target]->files, left->getOutputFile())) {
305
- // return true;
306
- // }
307
- // if (CollectionUtils::containsKey(targetInfos[target]->files, right->getOutputFile())) {
308
- // return false;
309
- // }
310
- // }
311
- // return false;
312
- // });
313
- // }
314
- // }
315
-
316
278
void BuildDatabase::mergeLibraryOptions (std::vector<std::string> &jsonArguments) const {
317
279
for (auto it = jsonArguments.begin (); it != jsonArguments.end (); it++) {
318
280
if (*it == DynamicLibraryUtils::libraryDirOption || *it == DynamicLibraryUtils::linkFlag) {
@@ -718,21 +680,6 @@ fs::path BuildDatabase::TargetInfo::getOutput() const {
718
680
return commands[0 ].getOutput ();
719
681
}
720
682
721
- // CollectionUtils::FileSet BuildDatabase::getStubFiles(
722
- // const std::shared_ptr<const BuildDatabase::TargetInfo> &linkUnitInfo) const {
723
- // auto iterator = linkUnitToStubFiles.find(linkUnitInfo->getOutput());
724
- // if (iterator != linkUnitToStubFiles.end()) {
725
- // return iterator->second;
726
- // }
727
- // return {};
728
- // }
729
-
730
- void BuildDatabase::assignStubFilesToLinkUnit (
731
- std::shared_ptr<const BuildDatabase::TargetInfo> linkUnitInfo,
732
- CollectionUtils::FileSet stubs) {
733
- linkUnitToStubFiles.emplace (linkUnitInfo->getOutput (), std::move (stubs));
734
- }
735
-
736
683
std::vector<std::shared_ptr<BuildDatabase::TargetInfo>> BuildDatabase::getRootTargets () const {
737
684
return CollectionUtils::filterOut (
738
685
CollectionUtils::getValues (targetInfos),
0 commit comments