Skip to content

Commit e9eeb2d

Browse files
author
Vladislav Kalugin
committed
refactoring after review 3
1 parent b43371e commit e9eeb2d

28 files changed

+534
-403
lines changed

server/src/KleeGenerator.cpp

Lines changed: 148 additions & 146 deletions
Large diffs are not rendered by default.

server/src/KleeGenerator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class KleeGenerator {
4343
* @throws fs::filesystem_error Thrown if it can't create tmp folder for some
4444
* reasons.
4545
*/
46-
KleeGenerator(BaseTestGen &_testGen, types::TypesHandler &typesHandler,
46+
KleeGenerator(BaseTestGen *_testGen, types::TypesHandler &typesHandler,
4747
PathSubstitution filePathsSubstitution);
4848

4949
struct BuildFileInfo {
@@ -144,17 +144,17 @@ class KleeGenerator {
144144
const CollectionUtils::FileSet &stubSources) const;
145145

146146
private:
147-
BaseTestGen &testGen;
147+
BaseTestGen *testGen;
148148
types::TypesHandler typesHandler;
149149
PathSubstitution pathSubstitution;
150150

151151
CollectionUtils::MapFileTo<std::vector<std::string>> failedFunctions;
152152

153153
fs::path writeKleeFile(
154-
printer::KleePrinter &kleePrinter,
155-
Tests const &tests,
156-
const std::shared_ptr<LineInfo> &lineInfo,
157-
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
154+
printer::KleePrinter &kleePrinter,
155+
Tests const &tests,
156+
const std::shared_ptr<LineInfo> &lineInfo,
157+
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
158158
[](tests::Tests::MethodDescription const &) { return true; });
159159
};
160160

server/src/ReturnTypesFetcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void ReturnTypesFetcher::fetch(ProgressWriter *const progressWriter,
1010
testsMap[filePath];
1111
}
1212
Fetcher(Fetcher::Options::Value::RETURN_TYPE_NAMES_ONLY,
13-
testGen->getBuildDatabase(false)->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
13+
testGen->getTargetBuildDatabase()->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
1414
testGen->compileCommandsJsonPath, false)
1515
.fetchWithProgress(progressWriter, "Fetching return types for functions", true);
1616
for (auto const &[sourceFilePath, test] : testsMap) {

server/src/Server.cpp

Lines changed: 76 additions & 72 deletions
Large diffs are not rendered by default.

server/src/Synchronizer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void Synchronizer::synchronizeStubs(StubSet &outdatedStubs,
153153
auto options = Fetcher::Options::Value::FUNCTION | Fetcher::Options::Value::INCLUDE | Fetcher::Options::Value::TYPE;
154154

155155
auto stubFetcher =
156-
Fetcher(options, testGen->getBuildDatabase(true)->compilationDatabase, sourceFilesMap, &testGen->types,
156+
Fetcher(options, testGen->getProjectBuildDatabase()->compilationDatabase, sourceFilesMap, &testGen->types,
157157
&sizeContext->pointerSize, &sizeContext->maximumAlignment,
158158
testGen->compileCommandsJsonPath, false);
159159

@@ -165,7 +165,7 @@ void Synchronizer::synchronizeStubs(StubSet &outdatedStubs,
165165
auto stubsCdb = createStubsCompilationDatabase(stubFiles, ccJsonStubDirPath);
166166

167167
auto sourceToHeaderRewriter =
168-
SourceToHeaderRewriter(testGen->projectContext, testGen->getBuildDatabase(true)->compilationDatabase,
168+
SourceToHeaderRewriter(testGen->projectContext, testGen->getProjectBuildDatabase()->compilationDatabase,
169169
stubFetcher.getStructsToDeclare(), testGen->serverBuildDir);
170170

171171
for (const StubOperator &outdatedStub : outdatedStubs) {
@@ -211,19 +211,19 @@ void Synchronizer::synchronizeWrappers(const CollectionUtils::FileSet &outdatedS
211211
sourceFilesNeedToRegenerateWrappers, testGen->progressWriter,
212212
"Generating wrappers", [this](fs::path const &sourceFilePath) {
213213
SourceToHeaderRewriter sourceToHeaderRewriter(testGen->projectContext,
214-
testGen->getBuildDatabase(true)->compilationDatabase, nullptr,
214+
testGen->getProjectBuildDatabase()->compilationDatabase, nullptr,
215215
testGen->serverBuildDir);
216216
std::string wrapper = sourceToHeaderRewriter.generateWrapper(sourceFilePath);
217217
printer::SourceWrapperPrinter(Paths::getSourceLanguage(sourceFilePath)).print(testGen->projectContext, sourceFilePath, wrapper);
218218
});
219219
}
220220

221221
const CollectionUtils::FileSet &Synchronizer::getSourceFiles() const {
222-
return testGen->getBuildDatabase(false)->compilationDatabase->getAllFiles();
222+
return testGen->getTargetBuildDatabase()->compilationDatabase->getAllFiles();
223223
}
224224

225225
StubSet Synchronizer::getStubsFiles() const {
226-
return getStubSetFromSources(testGen->getBuildDatabase(true)->compilationDatabase->getAllFiles());
226+
return getStubSetFromSources(testGen->getProjectBuildDatabase()->compilationDatabase->getAllFiles());
227227
}
228228

229229
void Synchronizer::prepareDirectory(const fs::path &stubDirectory) {

server/src/building/BuildDatabase.cpp

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616
#include <functional>
1717
#include <queue>
1818
#include <unordered_map>
19+
#include <utility>
1920

20-
static std::string tryConvertOptionToPath(const std::string &possibleFilePath,
21-
const fs::path &dirPath) {
22-
if (StringUtils::startsWith(possibleFilePath, "-")) {
23-
return possibleFilePath;
24-
}
25-
fs::path fullFilePath;
26-
try {
27-
fullFilePath = Paths::getCCJsonFileFullPath(possibleFilePath, dirPath);
28-
} catch (...) {
29-
return possibleFilePath;
30-
}
31-
return fs::exists(fullFilePath) ? fullFilePath.string() : possibleFilePath;
21+
BuildDatabase::BuildDatabase(
22+
fs::path serverBuildDir,
23+
fs::path buildCommandsJsonPath,
24+
fs::path linkCommandsJsonPath,
25+
fs::path compileCommandsJsonPath,
26+
utbot::ProjectContext projectContext
27+
) : serverBuildDir(std::move(serverBuildDir)),
28+
buildCommandsJsonPath(std::move(buildCommandsJsonPath)),
29+
linkCommandsJsonPath(std::move(linkCommandsJsonPath)),
30+
compileCommandsJsonPath(std::move(compileCommandsJsonPath)),
31+
projectContext(std::move(projectContext)) {
32+
}
33+
34+
BuildDatabase::BuildDatabase(BuildDatabase *baseBuildDatabase) :
35+
serverBuildDir(baseBuildDatabase->serverBuildDir),
36+
projectContext(baseBuildDatabase->projectContext),
37+
buildCommandsJsonPath(baseBuildDatabase->buildCommandsJsonPath),
38+
linkCommandsJsonPath(baseBuildDatabase->linkCommandsJsonPath),
39+
compileCommandsJsonPath(baseBuildDatabase->compileCommandsJsonPath) {
3240
}
3341

3442
fs::path BuildDatabase::createExplicitObjectFileCompilationCommand(const std::shared_ptr<ObjectFileInfo> &objectInfo) {
@@ -435,10 +443,18 @@ std::vector<std::shared_ptr<BuildDatabase::TargetInfo>> BuildDatabase::getAllTar
435443
return CollectionUtils::getValues(targetInfos);
436444
}
437445

446+
std::vector<fs::path> BuildDatabase::getAllTargetPaths() const {
447+
return CollectionUtils::transformTo<std::vector<fs::path>>(CollectionUtils::getValues(targetInfos),
448+
[](const std::shared_ptr<TargetInfo> &targetInfo) {
449+
return targetInfo->getOutput();
450+
});
451+
}
452+
438453
std::vector<std::shared_ptr<BuildDatabase::TargetInfo>>
439454
BuildDatabase::getTargetsForSourceFile(const fs::path &sourceFilePath) const {
440455
CollectionUtils::MapFileTo<bool> cache;
441-
std::function<bool(fs::path const &)> containsSourceFilePath = [&](fs::path const &unitFile) {
456+
std::function<
457+
bool(fs::path const &)> containsSourceFilePath = [&](fs::path const &unitFile) {
442458
if (CollectionUtils::containsKey(cache, unitFile)) {
443459
return cache[unitFile];
444460
}
@@ -483,7 +499,8 @@ std::vector<fs::path> BuildDatabase::getTargetPathsForObjectFile(const fs::path
483499

484500
std::shared_ptr<BuildDatabase::TargetInfo> BuildDatabase::getPriorityTarget() const {
485501
CollectionUtils::MapFileTo<int> cache;
486-
std::function<int(fs::path const &)> numberOfSources = [&](fs::path const &unitFile) {
502+
std::function<
503+
int(fs::path const &)> numberOfSources = [&](fs::path const &unitFile) {
487504
if (CollectionUtils::containsKey(cache, unitFile)) {
488505
return cache[unitFile];
489506
}
@@ -515,18 +532,18 @@ fs::path BuildDatabase::newDirForFile(const fs::path &file) const {
515532
}
516533

517534
CollectionUtils::FileSet BuildDatabase::getSourceFilesForTarget(const fs::path &_target) {
518-
LOG_IF_S(WARNING, !hasAutoTarget() && target != _target.c_str()) << "Try get sources for different target";
535+
LOG_IF_S(WARNING, !hasAutoTarget() && getTargetPath() != _target.c_str()) << "Try get sources for different target";
519536
return CollectionUtils::transformTo<CollectionUtils::FileSet>(
520537
getArchiveObjectFiles(_target),
521538
[this](fs::path const &objectPath) {
522539
return getClientCompilationUnitInfo(objectPath)->getSourcePath();
523540
});
524541
}
525542

526-
bool BuildDatabase::hasAutoTarget() const {
527-
return isAutoTarget;
543+
std::shared_ptr<BuildDatabase::TargetInfo> BuildDatabase::getTargetInfo(const fs::path &_target) {
544+
return targetInfos[_target];
528545
}
529546

530-
fs::path BuildDatabase::getTargetPath() const {
531-
return target;
547+
std::vector<std::pair<nlohmann::json, std::shared_ptr<BuildDatabase::ObjectFileInfo>>> BuildDatabase::getCompileCommands_temp() {
548+
return compileCommands_temp;
532549
}

server/src/building/BuildDatabase.h

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ class BuildDatabase {
2222
explicit KleeFilesInfo(fs::path kleeFile);
2323

2424
void setCorrectMethods(std::unordered_set<std::string> correctMethods);
25+
2526
void setAllAreCorrect(bool allAreCorrect);
2627

2728
bool isCorrectMethod(const std::string &method);
29+
2830
fs::path getKleeFile();
31+
2932
fs::path getKleeBitcodeFile();
33+
3034
fs::path getKleeFile(const std::string &methodName);
35+
3136
fs::path getKleeBitcodeFile(const std::string &methodName);
3237

3338
private:
@@ -67,8 +72,10 @@ class BuildDatabase {
6772

6873
// Directory from where to execute the command
6974
[[nodiscard]] fs::path const &getDirectory() const;
75+
7076
// User source file
7177
[[nodiscard]] fs::path getSourcePath() const;
78+
7279
// User object file
7380
[[nodiscard]] fs::path getOutputFile() const;
7481

@@ -99,6 +106,7 @@ class BuildDatabase {
99106

100107
public:
101108
const fs::path &getCompileCommandsJson();
109+
102110
const fs::path &getLinkCommandsJson();
103111

104112
/**
@@ -158,6 +166,7 @@ class BuildDatabase {
158166
* @throws CompilationDatabaseException if files are wrong
159167
*/
160168
[[nodiscard]] std::shared_ptr<const TargetInfo> getClientLinkUnitInfo(const fs::path &filepath) const;
169+
161170
[[nodiscard]] fs::path getObjectFile(const fs::path &sourceFile) const;
162171

163172
/**
@@ -168,8 +177,11 @@ class BuildDatabase {
168177
* @throws CompilationDatabaseException if file is wrong
169178
*/
170179
[[nodiscard]] fs::path getRootForSource(const fs::path &path) const;
180+
171181
[[nodiscard]] fs::path getRootForFirstSource() const;
182+
172183
[[nodiscard]] fs::path getBitcodeForSource(const fs::path &sourceFile) const;
184+
173185
[[nodiscard]] fs::path getBitcodeFile(const fs::path &filepath) const;
174186

175187
/**
@@ -193,41 +205,62 @@ class BuildDatabase {
193205
std::vector<std::shared_ptr<ObjectFileInfo>> getAllCompileCommands() const;
194206

195207
std::vector<std::shared_ptr<TargetInfo>> getRootTargets() const;
196-
virtual std::vector<std::shared_ptr<TargetInfo>> getAllTargets() const = 0;
197208

198-
virtual std::vector<fs::path>
199-
getTargetPathsForSourceFile(const fs::path &sourceFilePath) const;
200-
virtual std::vector<fs::path>
201-
getTargetPathsForObjectFile(const fs::path &objectFile) const;
209+
std::vector<std::shared_ptr<TargetInfo>> getAllTargets() const;
210+
211+
std::vector<fs::path> getAllTargetPaths() const;
212+
213+
virtual std::vector<fs::path> getTargetPathsForSourceFile(const fs::path &sourceFilePath) const;
214+
215+
virtual std::vector<fs::path> getTargetPathsForObjectFile(const fs::path &objectFile) const;
202216

203217
std::shared_ptr<TargetInfo> getPriorityTarget() const;
204218

205219
CollectionUtils::FileSet getSourceFilesForTarget(const fs::path &_target);
206220

221+
std::shared_ptr<TargetInfo> getTargetInfo(const fs::path &_target);
222+
223+
//TODO change
224+
std::vector<std::pair<nlohmann::json, std::shared_ptr<ObjectFileInfo>>> getCompileCommands_temp();
225+
207226
virtual bool hasAutoTarget() const = 0;
208227

209-
fs::path getTargetPath() const;
228+
virtual fs::path getTargetPath() const = 0;
210229

211230
std::shared_ptr<CompilationDatabase> compilationDatabase;
212-
protected:
213-
BuildDatabase() ;
214231

232+
protected:
215233
const fs::path serverBuildDir;
216-
const utbot::ProjectContext projectContext;
217234
const fs::path buildCommandsJsonPath;
218235
const fs::path linkCommandsJsonPath;
219236
const fs::path compileCommandsJsonPath;
237+
const utbot::ProjectContext projectContext;
220238
CollectionUtils::MapFileTo<std::vector<std::shared_ptr<ObjectFileInfo>>> sourceFileInfos;
221239
CollectionUtils::MapFileTo<std::shared_ptr<ObjectFileInfo>> objectFileInfos;
222240
CollectionUtils::MapFileTo<std::shared_ptr<TargetInfo>> targetInfos;
223241
CollectionUtils::MapFileTo<std::vector<fs::path>> objectFileTargets;
224242

243+
//TODO change
225244
std::vector<std::pair<nlohmann::json, std::shared_ptr<ObjectFileInfo>>> compileCommands_temp;
226245

246+
BuildDatabase(
247+
fs::path serverBuildDir,
248+
fs::path buildCommandsJsonPath,
249+
fs::path linkCommandsJsonPath,
250+
fs::path compileCommandsJsonPath,
251+
utbot::ProjectContext projectContext
252+
);
253+
254+
BuildDatabase(BuildDatabase *baseBuildDatabase);
255+
227256
static fs::path getCorrespondingBitcodeFile(const fs::path &filepath);
257+
228258
void createClangCompileCommandsJson();
259+
229260
void mergeLibraryOptions(std::vector<std::string> &jsonArguments) const;
230-
fs::path newDirForFile(fs::path const& file) const;
261+
262+
fs::path newDirForFile(fs::path const &file) const;
263+
231264
fs::path createExplicitObjectFileCompilationCommand(const std::shared_ptr<ObjectFileInfo> &objectInfo);
232265

233266
std::vector<std::shared_ptr<TargetInfo>> getTargetsForSourceFile(fs::path const &sourceFilePath) const;

0 commit comments

Comments
 (0)