Skip to content

Commit a63f708

Browse files
author
Vladislav Kalugin
committed
refactoring after review 9
1 parent 34c5870 commit a63f708

13 files changed

+39
-50
lines changed

server/src/Server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context,
578578

579579
utbot::ProjectContext projectContext{*request};
580580
fs::path serverBuildDir = Paths::getUtbotBuildDir(projectContext);
581-
std::shared_ptr<ProjectBuildDatabase> buildDatabase = ProjectBuildDatabase::create(projectContext);
581+
std::shared_ptr<ProjectBuildDatabase> buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
582582
StubSourcesFinder(buildDatabase).printAllModules();
583583
return Status::OK;
584584
}
@@ -653,7 +653,7 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,
653653

654654
try {
655655
utbot::ProjectContext projectContext{request->projectcontext()};
656-
auto buildDatabase = ProjectBuildDatabase::create(projectContext);
656+
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
657657
std::vector<fs::path> targets = buildDatabase->getAllTargetPaths();
658658
ProjectTargetsWriter targetsWriter(response);
659659
targetsWriter.writeResponse(projectContext, targets);
@@ -675,7 +675,7 @@ Status Server::TestsGenServiceImpl::GetFileTargets(ServerContext *context,
675675

676676
try {
677677
utbot::ProjectContext projectContext{request->projectcontext()};
678-
auto buildDatabase = ProjectBuildDatabase::create(projectContext);
678+
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
679679
fs::path path = request->path();
680680
auto targetPaths = buildDatabase->getTargetPathsForSourceFile(path);
681681
FileTargetsWriter targetsWriter{response};

server/src/building/ProjectBuildDatabase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class ProjectBuildDatabase : public BuildDatabase {
1616
void fillTargetInfoParents();
1717

1818
public:
19-
ProjectBuildDatabase(fs::path _buildCommandsJsonPath, fs::path _serverBuildDir,
20-
utbot::ProjectContext _projectContext);
19+
ProjectBuildDatabase(fs::path buildCommandsJsonPath, fs::path serverBuildDir,
20+
utbot::ProjectContext projectContext);
2121

22-
static std::shared_ptr<ProjectBuildDatabase> create(const utbot::ProjectContext &projectContext);
22+
ProjectBuildDatabase(utbot::ProjectContext projectContext);
2323
};
2424

2525

server/src/building/ProjectBuildDatabse.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
4343
createClangCompileCommandsJson();
4444
}
4545

46-
std::shared_ptr<ProjectBuildDatabase> ProjectBuildDatabase::create(const utbot::ProjectContext &projectContext) {
47-
fs::path compileCommandsJsonPath =
48-
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
49-
projectContext.projectPath, projectContext.buildDirRelativePath);
50-
fs::path serverBuildDir = Paths::getUtbotBuildDir(projectContext);
51-
std::shared_ptr<ProjectBuildDatabase> buildDatabase = std::make_shared<ProjectBuildDatabase>(
52-
std::move(ProjectBuildDatabase(compileCommandsJsonPath, serverBuildDir, projectContext)));
53-
return buildDatabase;
46+
ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase(
47+
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext.projectPath,
48+
projectContext.buildDirRelativePath),
49+
Paths::getUtbotBuildDir(projectContext), std::move(projectContext)) {
5450
}
5551

5652

server/src/building/TargetBuildDatabase.cpp

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

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+
1224
{
1325
auto objectFilesList = baseBuildDatabase->getArchiveObjectFiles(target);
1426
for (const auto &objectFilePath: objectFilesList) {
@@ -33,24 +45,6 @@ TargetBuildDatabase::TargetBuildDatabase(BuildDatabase *baseBuildDatabase,
3345
createClangCompileCommandsJson();
3446
}
3547

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-
5448
std::vector<std::shared_ptr<BuildDatabase::TargetInfo>> TargetBuildDatabase::getRootTargets() const {
5549
if (!hasAutoTarget()) {
5650
return {targetInfos.at(target)};

server/src/building/TargetBuildDatabase.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
class TargetBuildDatabase : public BuildDatabase {
88
private:
9-
TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const fs::path &_target);
10-
119
fs::path target;
1210
bool isAutoTarget;
11+
1312
public:
14-
static std::shared_ptr<TargetBuildDatabase> createForSourceOrTarget(BuildDatabase *baseBuildDatabase,
15-
const std::string &_targetOrSourcePath);
13+
TargetBuildDatabase(BuildDatabase *baseBuildDatabase, const std::string &targetOrSourcePath);
1614

1715
bool hasAutoTarget() const;
1816

server/src/coverage/GcovCoverageTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include "utils/MakefileUtils.h"
1414
#include "utils/StringUtils.h"
1515
#include "utils/path/FileSystemPath.h"
16+
#include "printers/DefaultMakefilePrinter.h"
1617

1718
#include "loguru.h"
1819
#include "json.hpp"
1920

2021
#include <utility>
21-
#include "printers/DefaultMakefilePrinter.h"
2222

2323
using Coverage::CoverageMap;
2424
using Coverage::FileCoverage;

server/src/coverage/TestRunner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include "printers/DefaultMakefilePrinter.h"
21
#include "TestRunner.h"
2+
3+
#include "printers/DefaultMakefilePrinter.h"
34
#include "GTestLogger.h"
45
#include "Paths.h"
56
#include "TimeExecStatistics.h"

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace printer {
116116
}
117117

118118
NativeMakefilePrinter::NativeMakefilePrinter(
119-
const BaseTestGen* testGen,
119+
const BaseTestGen *testGen,
120120
fs::path const &rootPath,
121121
fs::path primaryCompiler,
122122
CollectionUtils::FileSet const *stubSources,

server/src/printers/NativeMakefilePrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace printer {
1515
class NativeMakefilePrinter : public RelativeMakefilePrinter {
1616
friend class TestMakefilesPrinter;
1717
private:
18-
const BaseTestGen* testGen;
18+
const BaseTestGen *testGen;
1919
fs::path rootPath;
2020

2121
fs::path primaryCompiler;
@@ -66,7 +66,7 @@ namespace printer {
6666
bool transformExeToLib);
6767

6868
public:
69-
NativeMakefilePrinter(const BaseTestGen* testGen,
69+
NativeMakefilePrinter(const BaseTestGen *testGen,
7070
fs::path const &rootPath,
7171
fs::path primaryCompiler,
7272
CollectionUtils::FileSet const *stubSources,

server/src/printers/RelativeMakefilePrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef UNITTESTBOT_RELATIVEMAKEFILEPRINTER_H
22
#define UNITTESTBOT_RELATIVEMAKEFILEPRINTER_H
3+
34
#include "printers/DefaultMakefilePrinter.h"
45

56
namespace printer {

server/src/testgens/BaseTestGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ void BaseTestGen::setInitializedTestsMap() {
4848

4949
void BaseTestGen::setTargetPath(fs::path _targetPath) {
5050
if (targetBuildDatabase->hasAutoTarget() && targetBuildDatabase->getTargetPath() != _targetPath) {
51-
targetBuildDatabase = std::move(
52-
TargetBuildDatabase::createForSourceOrTarget(projectBuildDatabase.get(), _targetPath));
51+
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), _targetPath);
5352
updateTargetSources(_targetPath);
5453
}
5554
}

server/src/testgens/ProjectTestGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request,
1717
compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
1818
projectContext.projectPath, projectContext.buildDirRelativePath);
1919
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
20-
targetBuildDatabase = TargetBuildDatabase::createForSourceOrTarget(projectBuildDatabase.get(), request.targetpath());
20+
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), request.targetpath());
2121
if (autoDetect) {
2222
autoDetectSourcePathsIfNotEmpty();
2323
} else {

server/src/testgens/SnippetTestGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SnippetTestGen::SnippetTestGen(const testsgen::SnippetRequest &request,
1919
compileCommandsJsonPath = serverBuildDir;
2020
utbot::ProjectContext projectContext{request, serverBuildDir};
2121
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
22-
targetBuildDatabase = TargetBuildDatabase::createForSourceOrTarget(projectBuildDatabase.get(), serverBuildDir / SNIPPET_TARGET);
22+
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), serverBuildDir / SNIPPET_TARGET);
2323
setTargetForSource(filePath);
2424
setInitializedTestsMap();
2525
}

0 commit comments

Comments
 (0)