4
4
#include " utils/GrpcUtils.h"
5
5
#include " utils/GenerationUtils.h"
6
6
7
- TargetBuildDatabase::TargetBuildDatabase (BuildDatabase *baseBuildDatabase,
8
- const fs::path &_target) :
9
- BuildDatabase(baseBuildDatabase),
10
- target(_target),
11
- isAutoTarget(_target == GrpcUtils::UTBOT_AUTO_TARGET_PATH) {
7
+ TargetBuildDatabase::TargetBuildDatabase (BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath) :
8
+ BuildDatabase(baseBuildDatabase) {
9
+ if (Paths::isSourceFile (targetOrSourcePath)) {
10
+ target = baseBuildDatabase->getRootForSource (targetOrSourcePath);
11
+ } else if (targetOrSourcePath == GrpcUtils::UTBOT_AUTO_TARGET_PATH || targetOrSourcePath.empty ()) {
12
+ target = baseBuildDatabase->getRootForFirstSource ();
13
+ } else {
14
+ auto new_target = GenerationUtils::findTarget (baseBuildDatabase->getAllTargets (), targetOrSourcePath);
15
+ if (new_target.has_value ()) {
16
+ target = new_target.value ();
17
+ } else {
18
+ throw CompilationDatabaseException (" Can't find target: " + targetOrSourcePath);
19
+ }
20
+ }
21
+
22
+ isAutoTarget = target == GrpcUtils::UTBOT_AUTO_TARGET_PATH;
23
+
12
24
{
13
25
auto objectFilesList = baseBuildDatabase->getArchiveObjectFiles (target);
14
26
for (const auto &objectFilePath: objectFilesList) {
@@ -33,24 +45,6 @@ TargetBuildDatabase::TargetBuildDatabase(BuildDatabase *baseBuildDatabase,
33
45
createClangCompileCommandsJson ();
34
46
}
35
47
36
- std::shared_ptr<TargetBuildDatabase> TargetBuildDatabase::createForSourceOrTarget (BuildDatabase *baseBuildDatabase,
37
- const std::string &_targetOrSourcePath) {
38
- fs::path _target;
39
- if (Paths::isSourceFile (_targetOrSourcePath)) {
40
- _target = baseBuildDatabase->getRootForSource (_targetOrSourcePath);
41
- } else if (_targetOrSourcePath == GrpcUtils::UTBOT_AUTO_TARGET_PATH || _targetOrSourcePath.empty ()) {
42
- _target = baseBuildDatabase->getRootForFirstSource ();
43
- } else {
44
- auto new_target = GenerationUtils::findTarget (baseBuildDatabase->getAllTargets (), _targetOrSourcePath);
45
- if (new_target.has_value ()) {
46
- _target = new_target.value ();
47
- } else {
48
- throw CompilationDatabaseException (" Can't find target: " + _targetOrSourcePath);
49
- }
50
- }
51
- return std::make_shared<TargetBuildDatabase>(std::move (TargetBuildDatabase (baseBuildDatabase, _target)));
52
- }
53
-
54
48
std::vector<std::shared_ptr<BuildDatabase::TargetInfo>> TargetBuildDatabase::getRootTargets () const {
55
49
if (!hasAutoTarget ()) {
56
50
return {targetInfos.at (target)};
0 commit comments