Skip to content

Commit b0926f2

Browse files
committed
fix target selection
1 parent 25043ce commit b0926f2

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

server/src/building/TargetBuildDatabase.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
#include "utils/GrpcUtils.h"
55
#include "utils/GenerationUtils.h"
66

7-
TargetBuildDatabase::TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath) :
7+
TargetBuildDatabase::TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath,
8+
const std::optional<fs::path> &sourceFile) :
89
BuildDatabase(baseBuildDatabase) {
910
if (Paths::isSourceFile(targetOrSourcePath)) {
1011
target = baseBuildDatabase->getRootForSource(targetOrSourcePath);
1112
} else if (targetOrSourcePath == GrpcUtils::UTBOT_AUTO_TARGET_PATH || targetOrSourcePath.empty()) {
12-
target = baseBuildDatabase->getRootForFirstSource();
13+
if (sourceFile.has_value()) {
14+
target = baseBuildDatabase->getRootForSource(sourceFile.value());
15+
} else {
16+
target = baseBuildDatabase->getRootForFirstSource();
17+
}
1318
} else {
1419
auto new_target = GenerationUtils::findTarget(baseBuildDatabase->getAllTargets(), targetOrSourcePath);
1520
if (new_target.has_value()) {
@@ -19,6 +24,7 @@ TargetBuildDatabase::TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const
1924
}
2025
}
2126

27+
LOG_S(INFO) << StringUtils::stringFormat("Chosen target: %s", target);
2228
isAutoTarget = target == GrpcUtils::UTBOT_AUTO_TARGET_PATH;
2329

2430
{

server/src/building/TargetBuildDatabase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class TargetBuildDatabase : public BuildDatabase {
1010
bool isAutoTarget;
1111

1212
public:
13-
TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath);
13+
TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath,
14+
const std::optional<fs::path> &sourceFile = std::nullopt);
1415

1516
bool hasAutoTarget() const;
1617

server/src/testgens/FileTestGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FileTestGen::FileTestGen(const testsgen::FileRequest &request,
66
ProgressWriter *progressWriter,
77
bool testMode)
8-
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false),
8+
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false, fs::weakly_canonical(request.filepath())),
99
filepath(fs::weakly_canonical(request.filepath())) {
1010
testingMethodsSourcePaths = {filepath};
1111
setInitializedTestsMap();

server/src/testgens/LineTestGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
LineTestGen::LineTestGen(const testsgen::LineRequest &request,
44
ProgressWriter *progressWriter,
55
bool testMode, bool forHeader)
6-
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false) {
6+
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false, fs::weakly_canonical(request.sourceinfo().filepath())) {
77
filePath = fs::weakly_canonical(request.sourceinfo().filepath());
88
line = request.sourceinfo().line();
99
std::optional<fs::path> sourcePath = Paths::headerPathToSourcePath(filePath);

server/src/testgens/ProjectTestGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request,
99
ProgressWriter *progressWriter,
1010
bool testMode,
11-
bool autoDetect)
11+
bool autoDetect,
12+
const std::optional<fs::path> &sourceFile)
1213
: BaseTestGen(request.projectcontext(),
1314
request.settingscontext(),
1415
progressWriter,
1516
testMode), request(&request) {
1617
fs::create_directories(projectContext.testDirPath);
1718
compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext);
1819
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
19-
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), request.targetpath());
20+
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), request.targetpath(), sourceFile);
2021
if (autoDetect) {
2122
autoDetectSourcePathsIfNotEmpty();
2223
} else {

server/src/testgens/ProjectTestGen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class ProjectTestGen : public BaseTestGen {
1010
ProjectTestGen(const testsgen::ProjectRequest &request,
1111
ProgressWriter *progressWriter,
1212
bool testMode,
13-
bool autoDetect = true);
13+
bool autoDetect = true,
14+
const std::optional<fs::path> &sourceFile = std::nullopt);
1415

1516
~ProjectTestGen() override = default;
1617

0 commit comments

Comments
 (0)