Skip to content

Commit 1329d88

Browse files
author
Vladislav Kalugin
committed
start refactoring
1 parent c21e0d6 commit 1329d88

26 files changed

+71
-223
lines changed

server/src/BordersFinder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ BordersFinder::BordersFinder(const fs::path &filePath,
1717
const std::shared_ptr<CompilationDatabase> &compilationDatabase,
1818
const fs::path &compileCommandsJsonPath)
1919
: line(line), classBorder(std::nullopt), clangToolRunner(compilationDatabase) {
20-
// buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
2120
lineInfo.filePath = filePath;
2221
}
2322

server/src/BordersFinder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class BordersFinder : public clang::ast_matchers::MatchFinder::MatchCallback {
3131
private:
3232
unsigned line;
3333
LineInfo lineInfo{};
34-
// fs::path buildRootPath;
3534
struct Borders {
3635
struct Position {
3736
unsigned line;

server/src/KleeGenerator.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,6 @@
1616

1717
using namespace tests;
1818

19-
//KleeGenerator::KleeGenerator(
20-
// utbot::testGen.projectContext testGen.projectContext,
21-
// utbot::SettingsContext settingsContext,
22-
// fs::path serverBuildDir,
23-
// std::shared_ptr<CompilationDatabase> compilationDatabase,
24-
// types::TypesHandler &typesHandler,
25-
// PathSubstitution filePathsSubstitution,
26-
// std::shared_ptr<testGen.buildDatabase> testGen.buildDatabase,
27-
// ProgressWriter const *progressWriter)
28-
// : testGen.projectContext(std::move(testGen.projectContext)),
29-
// settingsContext(std::move(settingsContext)),
30-
// testGen.serverBuildDir(std::move(serverBuildDir)),
31-
// compilationDatabase(std::move(compilationDatabase)),
32-
// typesHandler(typesHandler),
33-
// pathSubstitution(std::move(filePathsSubstitution)),
34-
// testGen.buildDatabase(std::move(testGen.buildDatabase)),
35-
// progressWriter(progressWriter) {
36-
// try {
37-
// fs::create_directories(this->testGen.serverBuildDir);
38-
// fs::create_directories(Paths::getLogDir(this->testGen.projectContext.projectName));
39-
// } catch (const fs::filesystem_error &e) {
40-
// throw FileSystemException("create_directories failed", e);
41-
// }
42-
//}
43-
//
44-
//auto generator = std::make_shared<KleeGenerator>(
45-
// testGen.testGen.projectContext, testGen.settingsContext,
46-
// testGen.serverBuildDir, testGen.testGen.buildDatabase->compilationDatabase, typesHandler,
47-
// pathSubstitution, testGen.testGen.buildDatabase, testGen.progressWriter);
48-
4919
KleeGenerator::KleeGenerator(BaseTestGen &_testGen, types::TypesHandler &typesHandler,
5020
PathSubstitution filePathsSubstitution)
5121
: testGen(_testGen), typesHandler(typesHandler),

server/src/KleeGenerator.h

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,16 @@ class KleeGenerator {
3333
using TestsMap = tests::TestsMap;
3434

3535
public:
36-
// /**
37-
// * @brief Also creates tmp directories for build files.
38-
// * @param projectContext contains context about current project.
39-
// * @param settingsContext contains context about settings applied for current request.
40-
// * @param serverBuildDir Path to folder on server machine where project build dirs are located.
41-
// * @param sourcesFilePaths Paths to project files. Files which are listed in
42-
// * [compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html), filtered
43-
// * by them.
44-
// * @param compilationDatabase Pointer to compile_commands.json object.
45-
// * @param typesHandler provides additional information about types.
46-
// * @param filePathsSubstitution Mapping from source file path to modified file. Required for
47-
// * line test generation requests.
48-
// * @param buildDatabase Instance of BuildDatabase which handles link and compile commands
49-
// * @throws fs::filesystem_error Thrown if it can't create tmp folder for some
50-
// * reasons.
51-
// */
52-
// KleeGenerator(utbot::ProjectContext projectContext,
53-
// utbot::SettingsContext settingsContext,
54-
// fs::path serverBuildDir,
55-
// std::shared_ptr<CompilationDatabase> compilationDatabase,
56-
// types::TypesHandler &typesHandler,
57-
// PathSubstitution filePathsSubstitution,
58-
// std::shared_ptr<BuildDatabase> buildDatabase = nullptr,
59-
// const ProgressWriter *progressWriter = DummyStreamWriter::getInstance());
60-
36+
/**
37+
* @brief Also creates tmp directories for build files.
38+
* @param _testGen contains context.
39+
* @param typesHandler provides additional information about types.
40+
* @param filePathsSubstitution Mapping from source file path to modified file. Required for
41+
* line test generation requests.
42+
* @param buildDatabase Instance of BuildDatabase which handles link and compile commands
43+
* @throws fs::filesystem_error Thrown if it can't create tmp folder for some
44+
* reasons.
45+
*/
6146
KleeGenerator(BaseTestGen &_testGen, types::TypesHandler &typesHandler,
6247
PathSubstitution filePathsSubstitution);
6348

@@ -161,15 +146,9 @@ class KleeGenerator {
161146
const CollectionUtils::FileSet &stubSources) const;
162147

163148
private:
164-
// const utbot::ProjectContext projectContext;
165-
// const utbot::SettingsContext settingsContext;
166-
BaseTestGen &testGen;;
167-
// fs::path projectTmpPath;
168-
// std::shared_ptr<CompilationDatabase> compilationDatabase;
149+
BaseTestGen &testGen;
169150
types::TypesHandler typesHandler;
170151
PathSubstitution pathSubstitution;
171-
// std::shared_ptr<BuildDatabase> buildDatabase;
172-
// const ProgressWriter *progressWriter;
173152

174153
CollectionUtils::MapFileTo<std::vector<std::string>> failedFunctions;
175154

server/src/building/BuildDatabase.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ static std::string tryConvertOptionToPath(const std::string &possibleFilePath,
3333

3434
BuildDatabase::BuildDatabase(fs::path _buildCommandsJsonPath,
3535
fs::path _serverBuildDir,
36-
utbot::ProjectContext _projectContext,
37-
bool createClangCC) :
36+
utbot::ProjectContext _projectContext) :
3837
serverBuildDir(std::move(_serverBuildDir)),
3938
projectContext(std::move(_projectContext)),
4039
buildCommandsJsonPath(std::move(_buildCommandsJsonPath)),
@@ -53,9 +52,7 @@ BuildDatabase::BuildDatabase(fs::path _buildCommandsJsonPath,
5352
filterInstalledFiles();
5453
addLocalSharedLibraries();
5554
fillTargetInfoParents();
56-
// if (createClangCC) {
57-
createClangCompileCommandsJson();
58-
// }
55+
createClangCompileCommandsJson();
5956
target = GrpcUtils::UTBOT_AUTO_TARGET_PATH;
6057
}
6158

@@ -131,7 +128,7 @@ std::shared_ptr<BuildDatabase> BuildDatabase::create(const utbot::ProjectContext
131128
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
132129
projectContext.projectPath, projectContext.buildDirRelativePath);
133130
fs::path serverBuildDir = Paths::getUtbotBuildDir(projectContext);
134-
std::shared_ptr<BuildDatabase> buildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext, true);
131+
std::shared_ptr<BuildDatabase> buildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
135132
return buildDatabase;
136133
}
137134

server/src/building/BuildDatabase.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class BuildDatabase {
9797
public:
9898
BuildDatabase(fs::path _buildCommandsJsonPath,
9999
fs::path _serverBuildDir,
100-
utbot::ProjectContext _projectContext,
101-
bool createClangCC);
100+
utbot::ProjectContext _projectContext);
102101

103102
static std::shared_ptr<BuildDatabase> create(const utbot::ProjectContext &projectContext);
104103
std::shared_ptr<BuildDatabase> createBaseForTarget(const std::string &target);
@@ -197,16 +196,6 @@ class BuildDatabase {
197196
*/
198197
std::vector<std::shared_ptr<ObjectFileInfo>> getAllCompileCommands() const;
199198

200-
// /**
201-
// * @brief Gets all stub files associated with given link unit
202-
// *
203-
// * @param linkUnitInfo link unit info (preferably library)
204-
// *
205-
// * @return set of file paths to stubs
206-
// */
207-
// CollectionUtils::FileSet
208-
// getStubFiles(const std::shared_ptr<const BuildDatabase::TargetInfo> &linkUnitInfo) const;
209-
210199
/**
211200
* @brief Assign set of file paths to stubs to given link unit
212201
*

server/src/building/Linker.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fs::path Linker::getSourceFilePath() {
5454
Result<Linker::LinkResult> Linker::linkForTarget(const fs::path &target, const fs::path &sourceFilePath,
5555
const std::shared_ptr<const BuildDatabase::ObjectFileInfo> &compilationUnitInfo,
5656
const fs::path &objectFile) {
57-
// testGen.setTargetPath(target);
57+
testGen.setTargetPath(target);
5858

5959
auto siblings = testGen.buildDatabase->getArchiveObjectFiles(target);
6060
auto stubSources = stubGen.getStubSources(target);
@@ -84,14 +84,6 @@ Result<Linker::LinkResult> Linker::linkForTarget(const fs::path &target, const f
8484
return stubsSetResult;
8585
}
8686

87-
//std::vector<fs::path> Linker::getTargetList(const fs::path &sourceFile, const fs::path &objectFile) const {
88-
// if (testGen.hasAutoTarget()) {
89-
// return testGen.buildDatabase->targetListForFile(sourceFile, objectFile);
90-
// } else {
91-
// return {testGen.buildDatabase->getTargetPath()};
92-
// }
93-
//}
94-
9587
void Linker::linkForOneFile(const fs::path &sourceFilePath) {
9688
ExecUtils::throwIfCancelled();
9789

@@ -104,7 +96,6 @@ void Linker::linkForOneFile(const fs::path &sourceFilePath) {
10496
if (!testGen.buildDatabase->isFirstObjectFileForSource(objectFile)) {
10597
return;
10698
}
107-
// std::vector <fs::path> targets = getTargetList(sourceFilePath, objectFile);
10899
std::vector <fs::path> targets = testGen.buildDatabase->targetListForFile(sourceFilePath, objectFile);
109100
LOG_S(DEBUG) << "Linking bitcode for file " << sourceFilePath.filename();
110101
for (size_t i = 0; i < targets.size(); i++) {
@@ -131,7 +122,7 @@ void Linker::linkForOneFile(const fs::path &sourceFilePath) {
131122

132123
Result<Linker::LinkResult> Linker::linkWholeTarget(const fs::path &target) {
133124
auto requestTarget = testGen.buildDatabase->getTargetPath();
134-
LOG_IF_S(ERROR, target != GrpcUtils::UTBOT_AUTO_TARGET_PATH && requestTarget != target)
125+
LOG_IF_S(WARNING, !testGen.buildDatabase->hasAutoTarget() && requestTarget != target)
135126
<< "Try link target that not specified by user";
136127
testGen.setTargetPath(target);
137128

@@ -153,11 +144,11 @@ Result<Linker::LinkResult> Linker::linkWholeTarget(const fs::path &target) {
153144
}
154145
if (!CollectionUtils::contains(testedFiles, objectInfo->getSourcePath()) && insideFolder) {
155146
fs::path bitcodeFile = objectInfo->kleeFilesInfo->getKleeBitcodeFile();
156-
filesToLink.emplace(objectFile, std::move(bitcodeFile));
147+
filesToLink.emplace(objectFile, bitcodeFile);
157148
} else {
158149
fs::path bitcodeFile = testGen.buildDatabase->getBitcodeForSource(objectInfo->getSourcePath());
159150
siblingObjectsToBuild.insert(objectInfo->getOutputFile());
160-
filesToLink.emplace(objectFile, std::move(bitcodeFile));
151+
filesToLink.emplace(objectFile, bitcodeFile);
161152
}
162153
}
163154

@@ -184,7 +175,6 @@ void Linker::linkForProject() {
184175
<< sourceFile;
185176
return;
186177
}
187-
// std::vector <fs::path> targets = getTargetList(sourceFile, objectFile);
188178
std::vector <fs::path> targets = testGen.buildDatabase->targetListForFile(sourceFile, objectFile);
189179
bool success = false;
190180
for (const auto &target : targets) {

server/src/building/Linker.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class Linker {
6262

6363
bool isForOneFile();
6464

65-
// std::vector<fs::path> getTargetList(const fs::path &sourceFile, const fs::path &objectFile) const;
66-
6765
Result<Linker::LinkResult> linkForTarget(const fs::path &target, const fs::path &sourceFilePath,
6866
const std::shared_ptr<const BuildDatabase::ObjectFileInfo> &compilationUnitInfo,
6967
const fs::path &objectFile);

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,13 @@ namespace printer {
116116
}
117117

118118
NativeMakefilePrinter::NativeMakefilePrinter(
119-
// utbot::ProjectContext projectContext,
120-
// std::shared_ptr<BuildDatabase> buildDatabase,
121119
const BaseTestGen& testGen,
122120
fs::path const &rootPath,
123121
fs::path primaryCompiler,
124122
CollectionUtils::FileSet const *stubSources,
125123
std::map<std::string, fs::path, std::function<bool(const std::string&, const std::string&)>> pathToShellVariable)
126124
: RelativeMakefilePrinter(pathToShellVariable),
127125
testGen(testGen),
128-
// projectContext(std::move(projectContext)), buildDatabase(std::move(buildDatabase)),
129126
rootPath(std::move(rootPath)),
130127
primaryCompiler(std::move(primaryCompiler)),
131128
primaryCxxCompiler(CompilationUtils::toCppCompiler(this->primaryCompiler)),
@@ -408,8 +405,6 @@ namespace printer {
408405
NativeMakefilePrinter::NativeMakefilePrinter(const NativeMakefilePrinter &baseMakefilePrinter,
409406
const fs::path &sourcePath)
410407
: RelativeMakefilePrinter(baseMakefilePrinter.pathToShellVariable),
411-
// projectContext(baseMakefilePrinter.projectContext),
412-
// buildDatabase(baseMakefilePrinter.buildDatabase),
413408
testGen(baseMakefilePrinter.testGen),
414409
rootPath(baseMakefilePrinter.rootPath),
415410
primaryCompiler(baseMakefilePrinter.primaryCompiler),

server/src/printers/NativeMakefilePrinter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace printer {
1616
friend class TestMakefilesPrinter;
1717
private:
1818
const BaseTestGen& testGen;
19-
// const utbot::ProjectContext projectContext;
20-
// std::shared_ptr<BuildDatabase> buildDatabase;
2119
fs::path rootPath;
2220

2321
fs::path primaryCompiler;
@@ -69,8 +67,6 @@ namespace printer {
6967

7068
public:
7169
NativeMakefilePrinter(const BaseTestGen& testGen,
72-
// utbot::ProjectContext projectContext,
73-
// std::shared_ptr<BuildDatabase> buildDatabase,
7470
fs::path const &rootPath,
7571
fs::path primaryCompiler,
7672
CollectionUtils::FileSet const *stubSources,

server/src/printers/TestMakefilesPrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ namespace printer {
4242

4343
TestMakefilesPrinter::TestMakefilesPrinter(
4444
const BaseTestGen &testGen,
45-
// utbot::ProjectContext projectContext,
46-
// std::shared_ptr<BuildDatabase> buildDatabase,
4745
fs::path const &rootPath,
4846
fs::path primaryCompiler,
4947
CollectionUtils::FileSet const *stubSources) :

server/src/printers/TestMakefilesPrinter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace printer {
3131

3232
TestMakefilesPrinter(
3333
const BaseTestGen &testGen,
34-
// utbot::ProjectContext projectContext,
35-
// std::shared_ptr<BuildDatabase> buildDatabase,
3634
fs::path const &rootPath,
3735
fs::path primaryCompiler,
3836
CollectionUtils::FileSet const *stubSources);

server/src/testgens/BaseTestGen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class BaseTestGen {
2323
fs::path serverBuildDir;
2424

2525
fs::path compileCommandsJsonPath;
26-
// std::shared_ptr<CompilationDatabase> compilationDatabase;
2726
std::shared_ptr<BuildDatabase> baseBuildDatabase;
2827
std::shared_ptr<BuildDatabase> buildDatabase;
2928

server/src/testgens/FileTestGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
FileTestGen::FileTestGen(const testsgen::FileRequest &request,
66
ProgressWriter *progressWriter,
77
bool testMode)
8-
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false),
9-
filepath(fs::weakly_canonical(request.filepath())) {
10-
testingMethodsSourcePaths = { filepath };
8+
: ProjectTestGen(request.projectrequest(), progressWriter, testMode, false),
9+
filepath(fs::weakly_canonical(request.filepath())) {
10+
testingMethodsSourcePaths = {filepath};
1111
setInitializedTestsMap();
1212
}
1313

server/src/testgens/ProjectTestGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request,
1616
fs::create_directories(projectContext.testDirPath);
1717
compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
1818
projectContext.projectPath, projectContext.buildDirRelativePath);
19-
baseBuildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext, false);
19+
baseBuildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
2020
buildDatabase = baseBuildDatabase->createBaseForTarget(request.targetpath());
21-
// compilationDatabase = CompilationUtils::getCompilationDatabase(compileCommandsJsonPath);
2221
if (autoSrcPaths) {
2322
autoDetectSourcePathsIfNotEmpty();
2423
} else {

server/src/testgens/SnippetTestGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ SnippetTestGen::SnippetTestGen(const testsgen::SnippetRequest &request,
1818
printer::CCJsonPrinter::createDummyBuildDB(sourcePaths, serverBuildDir);
1919
compileCommandsJsonPath = serverBuildDir;
2020
utbot::ProjectContext projectContext{request, serverBuildDir};
21-
baseBuildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext, false);
21+
baseBuildDatabase = std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
2222
buildDatabase = baseBuildDatabase->createBaseForTarget(serverBuildDir / SNIPPET_TARGET);
23-
// compilationDatabase = CompilationUtils::getCompilationDatabase(serverBuildDir);
2423
setTargetForSource(filePath);
2524
setInitializedTestsMap();
2625
}

server/src/utils/GenerationUtils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ namespace GenerationUtils {
3838
ServerUtils::setThreadOptions(ctx, true);
3939
auto testsWriter = std::make_unique<CLITestsWriter>();
4040
auto testGen = std::make_unique<TestGenT>(request, testsWriter.get(), true);
41-
// if constexpr (std::is_base_of_v<ProjectTestGen, TestGenT>) {
42-
// auto targetPath = findTarget(*testGen, testGen->getRequest()->targetpath());
43-
// if (!targetPath.has_value()) {
44-
// auto status = grpc::Status(grpc::INVALID_ARGUMENT, "Couldn't find appropriate target");
45-
// return std::make_pair(std::move(testGen), status);
46-
// }
47-
// testGen->setTargetPath(targetPath.value());
48-
// }
4941
Status status =
5042
Server::TestsGenServiceImpl::ProcessBaseTestRequest(*testGen, testsWriter.get());
5143
if (status.error_code() == grpc::FAILED_PRECONDITION) {

0 commit comments

Comments
 (0)