Skip to content

Commit 0c4ee4b

Browse files
author
Vladislav Kalugin
committed
not end
1 parent 547c195 commit 0c4ee4b

12 files changed

+120
-95
lines changed

server/src/building/BuildDatabase.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ BuildDatabase::BuildDatabase(fs::path _buildCommandsJsonPath,
3939
projectContext(std::move(_projectContext)),
4040
buildCommandsJsonPath(std::move(_buildCommandsJsonPath)),
4141
linkCommandsJsonPath(fs::canonical(buildCommandsJsonPath / "link_commands.json")),
42-
compileCommandsJsonPath(fs::canonical(buildCommandsJsonPath / "compile_commands.json")) {
42+
compileCommandsJsonPath(fs::canonical(buildCommandsJsonPath / "compile_commands.json")),
43+
isAutoTarget(true) {
4344
if (!fs::exists(linkCommandsJsonPath) || !fs::exists(compileCommandsJsonPath)) {
4445
throw CompilationDatabaseException("Couldn't open link_commands.json or compile_commands.json files");
4546
}
@@ -64,7 +65,8 @@ BuildDatabase::BuildDatabase(BuildDatabase& baseBuildDatabase,
6465
projectContext(baseBuildDatabase.projectContext),
6566
buildCommandsJsonPath(baseBuildDatabase.buildCommandsJsonPath),
6667
linkCommandsJsonPath(baseBuildDatabase.linkCommandsJsonPath),
67-
compileCommandsJsonPath(baseBuildDatabase.compileCommandsJsonPath) {
68+
compileCommandsJsonPath(baseBuildDatabase.compileCommandsJsonPath),
69+
isAutoTarget(false) {
6870

6971
// BuildDatabase baseBuildDatabase(buildCommandsJsonPath, serverBuildDir, projectContext, false);
7072

@@ -77,6 +79,7 @@ BuildDatabase::BuildDatabase(BuildDatabase& baseBuildDatabase,
7779
} else if (_target == GrpcUtils::UTBOT_AUTO_TARGET_PATH || _target.empty()) {
7880
fs::path root = baseBuildDatabase.getRootForFirstSource();
7981
target = root;
82+
isAutoTarget = true;
8083
} else {
8184
auto new_target = GenerationUtils::findTarget(baseBuildDatabase.getAllTargets(), _target);
8285
if (new_target.has_value()) {
@@ -722,14 +725,14 @@ fs::path BuildDatabase::TargetInfo::getOutput() const {
722725
return commands[0].getOutput();
723726
}
724727

725-
CollectionUtils::FileSet BuildDatabase::getStubFiles(
726-
const std::shared_ptr<const BuildDatabase::TargetInfo> &linkUnitInfo) const {
727-
auto iterator = linkUnitToStubFiles.find(linkUnitInfo->getOutput());
728-
if (iterator != linkUnitToStubFiles.end()) {
729-
return iterator->second;
730-
}
731-
return {};
732-
}
728+
//CollectionUtils::FileSet BuildDatabase::getStubFiles(
729+
// const std::shared_ptr<const BuildDatabase::TargetInfo> &linkUnitInfo) const {
730+
// auto iterator = linkUnitToStubFiles.find(linkUnitInfo->getOutput());
731+
// if (iterator != linkUnitToStubFiles.end()) {
732+
// return iterator->second;
733+
// }
734+
// return {};
735+
//}
733736

734737
void BuildDatabase::assignStubFilesToLinkUnit(
735738
std::shared_ptr<const BuildDatabase::TargetInfo> linkUnitInfo,
@@ -778,9 +781,9 @@ BuildDatabase::getTargetsForSourceFile(const fs::path &sourceFilePath) const {
778781

779782
std::vector<fs::path> BuildDatabase::targetListForFile(const fs::path &sourceFilePath,
780783
const fs::path &objectFile) const {
781-
// if (!hasAutoTarget()) {
782-
// return {target};
783-
// }
784+
if (!hasAutoTarget()) {
785+
return { target };
786+
}
784787
auto result = CollectionUtils::transformTo<std::vector<fs::path>>(
785788
getTargetsForSourceFile(sourceFilePath),
786789
[&](const std::shared_ptr<const BuildDatabase::TargetInfo> &targetInfo) {
@@ -843,7 +846,7 @@ CollectionUtils::FileSet BuildDatabase::getSourceFilesForTarget(const fs::path &
843846
}
844847

845848
bool BuildDatabase::hasAutoTarget() const {
846-
return target == GrpcUtils::UTBOT_AUTO_TARGET_PATH;
849+
return isAutoTarget;
847850
}
848851

849852
fs::path BuildDatabase::getTargetPath() const {

server/src/building/BuildDatabase.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ class BuildDatabase {
197197
*/
198198
std::vector<std::shared_ptr<ObjectFileInfo>> getAllCompileCommands() const;
199199

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;
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;
209209

210210
/**
211211
* @brief Assign set of file paths to stubs to given link unit
@@ -245,6 +245,7 @@ class BuildDatabase {
245245
const fs::path linkCommandsJsonPath;
246246
const fs::path compileCommandsJsonPath;
247247
fs::path target;
248+
bool isAutoTarget;
248249
CollectionUtils::MapFileTo<std::vector<std::shared_ptr<ObjectFileInfo>>> sourceFileInfos;
249250
CollectionUtils::MapFileTo<std::shared_ptr<ObjectFileInfo>> objectFileInfos;
250251
CollectionUtils::MapFileTo<std::shared_ptr<TargetInfo>> targetInfos;

server/src/building/IRParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
bool IRParser::parseModule(const fs::path &rootBitcode, tests::TestsMap &tests) {
1919
try {
20-
LOG_S(MAX) << "Parse module: " << rootBitcode.c_str();
20+
LOG_S(DEBUG) << "Parse module: " << rootBitcode.c_str();
2121
llvm::LLVMContext context;
2222
auto module = getModule(rootBitcode, context);
2323
if (module) {

server/src/building/Linker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Result<Linker::LinkResult> Linker::linkWholeTarget(const fs::path &target) {
133133
auto requestTarget = testGen.buildDatabase->getTargetPath();
134134
LOG_IF_S(ERROR, target != GrpcUtils::UTBOT_AUTO_TARGET_PATH && requestTarget != target)
135135
<< "Try link target that not specified by user";
136-
// testGen.setTargetPath(target);
136+
testGen.setTargetPath(target);
137137

138138
auto targetUnitInfo = testGen.buildDatabase->getClientLinkUnitInfo(target);
139139
auto siblings = testGen.buildDatabase->getArchiveObjectFiles(target);
@@ -164,7 +164,7 @@ Result<Linker::LinkResult> Linker::linkWholeTarget(const fs::path &target) {
164164
kleeGenerator->buildByCDb(siblingObjectsToBuild, stubSources);
165165
auto result = link(filesToLink, target, "", std::nullopt, stubSources, false);
166166
//this is done in order to restore testGen.target in case of UTBot: auto
167-
// testGen.setTargetPath(requestTarget);
167+
testGen.setTargetPath(requestTarget);
168168
return result;
169169
}
170170

@@ -202,8 +202,8 @@ void Linker::linkForProject() {
202202
return compilationUnitInfo->getOutputFile();
203203
});
204204
addToGenerated(objectFiles, linkres.bitcodeOutput);
205-
auto &&targetUnitInfo = testGen.buildDatabase->getClientLinkUnitInfo(target);
206-
testGen.buildDatabase->assignStubFilesToLinkUnit(targetUnitInfo, linkres.stubsSet);
205+
auto &&targetUnitInfo = testGen.baseBuildDatabase->getClientLinkUnitInfo(target);
206+
testGen.baseBuildDatabase->assignStubFilesToLinkUnit(targetUnitInfo, linkres.stubsSet);
207207
break;
208208
} else {
209209
std::stringstream ss;

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,17 @@ namespace printer {
116116
}
117117

118118
NativeMakefilePrinter::NativeMakefilePrinter(
119-
utbot::ProjectContext projectContext,
120-
std::shared_ptr<BuildDatabase> buildDatabase,
119+
// utbot::ProjectContext projectContext,
120+
// std::shared_ptr<BuildDatabase> buildDatabase,
121+
const BaseTestGen& testGen,
121122
fs::path const &rootPath,
122123
fs::path primaryCompiler,
123124
CollectionUtils::FileSet const *stubSources,
124125
std::map<std::string, fs::path, std::function<bool(const std::string&, const std::string&)>> pathToShellVariable)
125126
: RelativeMakefilePrinter(pathToShellVariable),
126-
projectContext(std::move(projectContext)), buildDatabase(std::move(buildDatabase)), rootPath(std::move(rootPath)),
127+
testGen(testGen),
128+
// projectContext(std::move(projectContext)), buildDatabase(std::move(buildDatabase)),
129+
rootPath(std::move(rootPath)),
127130
primaryCompiler(std::move(primaryCompiler)),
128131
primaryCxxCompiler(CompilationUtils::toCppCompiler(this->primaryCompiler)),
129132
primaryCompilerName(CompilationUtils::getCompilerName(this->primaryCompiler)),
@@ -135,7 +138,7 @@ namespace printer {
135138
CompilationUtils::getCoverageLinkFlags(primaryCxxCompilerName), " ")),
136139
sanitizerLinkFlags(SanitizerUtils::getSanitizeLinkFlags(primaryCxxCompilerName)),
137140

138-
buildDirectory(Paths::getUtbotBuildDir(projectContext)),
141+
buildDirectory(Paths::getUtbotBuildDir(testGen.projectContext)),
139142
dependencyDirectory(buildDirectory / "dependencies"),
140143
stubSources(stubSources) {
141144

@@ -164,13 +167,13 @@ namespace printer {
164167
}
165168

166169
fs::path NativeMakefilePrinter::getTemporaryDependencyFile(fs::path const &file) {
167-
fs::path relativePath = fs::relative(file, projectContext.projectPath);
170+
fs::path relativePath = fs::relative(file, testGen.projectContext.projectPath);
168171
return getRelativePath(dependencyDirectory) /
169172
Paths::addExtension(relativePath, ".Td");
170173
}
171174

172175
fs::path NativeMakefilePrinter::getDependencyFile(fs::path const &file) {
173-
fs::path relativePath = fs::relative(file, projectContext.projectPath);
176+
fs::path relativePath = fs::relative(file, testGen.projectContext.projectPath);
174177
return getRelativePath(dependencyDirectory) /
175178
Paths::addExtension(relativePath, ".d");
176179
}
@@ -270,25 +273,25 @@ namespace printer {
270273
BuildResult NativeMakefilePrinter::addObjectFile(const fs::path &objectFile,
271274
const std::string &suffixForParentOfStubs) {
272275

273-
auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo(objectFile);
276+
auto compilationUnitInfo = testGen.buildDatabase->getClientCompilationUnitInfo(objectFile);
274277
fs::path sourcePath = compilationUnitInfo->getSourcePath();
275278

276279
fs::path pathToCompile;
277280
fs::path recompiledFile;
278281
BuildResult::Type buildResultType;
279282
BuildResult buildResult;
280283
if (CollectionUtils::contains(*stubSources, sourcePath)) {
281-
pathToCompile = Paths::sourcePathToStubPath(projectContext, sourcePath);
282-
recompiledFile = Paths::getRecompiledFile(projectContext, pathToCompile);
284+
pathToCompile = Paths::sourcePathToStubPath(testGen.projectContext, sourcePath);
285+
recompiledFile = Paths::getRecompiledFile(testGen.projectContext, pathToCompile);
283286
buildResultType = BuildResult::Type::ALL_STUBS;
284287
} else {
285288
if (Paths::isCXXFile(sourcePath)) {
286289
pathToCompile = sourcePath;
287290
} else {
288-
pathToCompile = Paths::getWrapperFilePath(projectContext, sourcePath);
291+
pathToCompile = Paths::getWrapperFilePath(testGen.projectContext, sourcePath);
289292
}
290293
recompiledFile =
291-
Paths::getRecompiledFile(projectContext, compilationUnitInfo->getOutputFile());
294+
Paths::getRecompiledFile(testGen.projectContext, compilationUnitInfo->getOutputFile());
292295
buildResultType = BuildResult::Type::NO_STUBS;
293296
}
294297

@@ -299,7 +302,7 @@ namespace printer {
299302
}
300303

301304
void NativeMakefilePrinter::addTestTarget(const fs::path &sourcePath) {
302-
auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo(sourcePath);
305+
auto compilationUnitInfo = testGen.buildDatabase->getClientCompilationUnitInfo(sourcePath);
303306
auto testCompilationCommand = compilationUnitInfo->command;
304307
testCompilationCommand.setCompiler(getRelativePathForLinker(primaryCxxCompiler));
305308
testCompilationCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
@@ -314,10 +317,10 @@ namespace printer {
314317
testCompilationCommand.addFlagToBegin(FPIC_FLAG);
315318
testCompilationCommand.addFlagsToBegin(SANITIZER_NEEDED_FLAGS);
316319

317-
fs::path testSourcePath = Paths::sourcePathToTestPath(projectContext, sourcePath);
320+
fs::path testSourcePath = Paths::sourcePathToTestPath(testGen.projectContext, sourcePath);
318321
fs::path compilationDirectory = compilationUnitInfo->getDirectory();
319-
fs::path testObjectDir = Paths::getTestObjectDir(projectContext);
320-
fs::path testSourceRelativePath = fs::relative(testSourcePath, projectContext.testDirPath);
322+
fs::path testObjectDir = Paths::getTestObjectDir(testGen.projectContext);
323+
fs::path testSourceRelativePath = fs::relative(testSourcePath, testGen.projectContext.testDirPath);
321324
fs::path testObjectPathRelative = getRelativePath(
322325
testObjectDir / Paths::addExtension(testSourceRelativePath, ".o"));
323326
testCompilationCommand.setOutput(
@@ -332,7 +335,7 @@ namespace printer {
332335

333336
artifacts.push_back(testCompilationCommand.getOutput());
334337

335-
auto rootLinkUnitInfo = buildDatabase->getClientLinkUnitInfo(rootPath);
338+
auto rootLinkUnitInfo = testGen.buildDatabase->getClientLinkUnitInfo(rootPath);
336339
fs::path testExecutablePath = getTestExecutablePath(sourcePath);
337340

338341
std::vector<std::string> filesToLink{ "$(GTEST_MAIN)", "$(GTEST_ALL)", testCompilationCommand.getOutput(),
@@ -399,14 +402,15 @@ namespace printer {
399402
}
400403
fs::path NativeMakefilePrinter::getTestExecutablePath(const fs::path &sourcePath) const {
401404
return Paths::removeExtension(
402-
Paths::removeExtension(Paths::getRecompiledFile(projectContext, sourcePath)));
405+
Paths::removeExtension(Paths::getRecompiledFile(testGen.projectContext, sourcePath)));
403406
}
404407

405408
NativeMakefilePrinter::NativeMakefilePrinter(const NativeMakefilePrinter &baseMakefilePrinter,
406409
const fs::path &sourcePath)
407410
: RelativeMakefilePrinter(baseMakefilePrinter.pathToShellVariable),
408-
projectContext(baseMakefilePrinter.projectContext),
409-
buildDatabase(baseMakefilePrinter.buildDatabase),
411+
// projectContext(baseMakefilePrinter.projectContext),
412+
// buildDatabase(baseMakefilePrinter.buildDatabase),
413+
testGen(baseMakefilePrinter.testGen),
410414
rootPath(baseMakefilePrinter.rootPath),
411415
primaryCompiler(baseMakefilePrinter.primaryCompiler),
412416
primaryCxxCompiler(baseMakefilePrinter.primaryCxxCompiler),
@@ -427,7 +431,7 @@ namespace printer {
427431

428432
fs::path testExecutablePath = getTestExecutablePath(sourcePath);
429433

430-
auto rootLinkUnitInfo = buildDatabase->getClientLinkUnitInfo(rootPath);
434+
auto rootLinkUnitInfo = testGen.buildDatabase->getClientLinkUnitInfo(rootPath);
431435

432436
fs::path coverageInfoBinary = sharedOutput.value();
433437
if (!Paths::isLibraryFile(coverageInfoBinary)) {
@@ -469,7 +473,7 @@ namespace printer {
469473
return buildResults[unitFile] = buildResult;
470474
}
471475

472-
auto linkUnitInfo = buildDatabase->getClientLinkUnitInfo(unitFile);
476+
auto linkUnitInfo = testGen.buildDatabase->getClientLinkUnitInfo(unitFile);
473477
BuildResult::Type unitType = BuildResult::Type::NONE;
474478
CollectionUtils::MapFileTo<fs::path> fileMapping;
475479
auto unitBuildResults = CollectionUtils::transformTo<std::vector<BuildResult>>(
@@ -490,7 +494,7 @@ namespace printer {
490494
bool isExecutable = !Paths::isLibraryFile(unitFile);
491495

492496
fs::path recompiledFile =
493-
Paths::getRecompiledFile(projectContext, linkUnitInfo->getOutput());
497+
Paths::getRecompiledFile(testGen.projectContext, linkUnitInfo->getOutput());
494498
if (isExecutable && !transformExeToLib) {
495499
recompiledFile = Paths::isObjectFile(recompiledFile) ?
496500
recompiledFile : Paths::addExtension(recompiledFile, ".o");
@@ -530,9 +534,9 @@ namespace printer {
530534
getLibraryAbsolutePath(argument, linkCommand.getDirectory());
531535
if (optionalLibraryAbsolutePath.has_value()) {
532536
const fs::path &absolutePath = optionalLibraryAbsolutePath.value();
533-
if (Paths::isSubPathOf(projectContext.buildDir(), absolutePath)) {
537+
if (Paths::isSubPathOf(testGen.projectContext.buildDir(), absolutePath)) {
534538
fs::path recompiledDir =
535-
Paths::getRecompiledFile(projectContext, absolutePath);
539+
Paths::getRecompiledFile(testGen.projectContext, absolutePath);
536540
std::string directoryFlag = getLibraryDirectoryFlag(recompiledDir);
537541
libraryDirectoriesFlags.push_back(directoryFlag);
538542
}
@@ -614,11 +618,11 @@ namespace printer {
614618
void NativeMakefilePrinter::addStubs(const CollectionUtils::FileSet &stubsSet) {
615619
auto stubObjectFiles = CollectionUtils::transformTo<CollectionUtils::FileSet>(
616620
Synchronizer::dropHeaders(stubsSet), [this](fs::path const &stub) {
617-
fs::path sourcePath = Paths::stubPathToSourcePath(projectContext, stub);
621+
fs::path sourcePath = Paths::stubPathToSourcePath(testGen.projectContext, stub);
618622
fs::path stubBuildFilePath =
619-
Paths::getStubBuildFilePath(projectContext, sourcePath);
620-
auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo(sourcePath);
621-
fs::path target = Paths::getRecompiledFile(projectContext, stub);
623+
Paths::getStubBuildFilePath(testGen.projectContext, sourcePath);
624+
auto compilationUnitInfo = testGen.baseBuildDatabase->getClientCompilationUnitInfo(sourcePath);
625+
fs::path target = Paths::getRecompiledFile(testGen.projectContext, stub);
622626
addCompileTarget(stub, target, *compilationUnitInfo);
623627
return target;
624628
});

server/src/printers/NativeMakefilePrinter.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ namespace printer {
1515
class NativeMakefilePrinter : public RelativeMakefilePrinter {
1616
friend class TestMakefilesPrinter;
1717
private:
18-
const utbot::ProjectContext projectContext;
19-
std::shared_ptr<BuildDatabase> buildDatabase;
18+
const BaseTestGen& testGen;
19+
// const utbot::ProjectContext projectContext;
20+
// std::shared_ptr<BuildDatabase> buildDatabase;
2021
fs::path rootPath;
2122

2223
fs::path primaryCompiler;
@@ -67,8 +68,9 @@ namespace printer {
6768
bool transformExeToLib);
6869

6970
public:
70-
NativeMakefilePrinter(utbot::ProjectContext projectContext,
71-
std::shared_ptr<BuildDatabase> buildDatabase,
71+
NativeMakefilePrinter(const BaseTestGen& testGen,
72+
// utbot::ProjectContext projectContext,
73+
// std::shared_ptr<BuildDatabase> buildDatabase,
7274
fs::path const &rootPath,
7375
fs::path primaryCompiler,
7476
CollectionUtils::FileSet const *stubSources,

0 commit comments

Comments
 (0)