@@ -116,14 +116,17 @@ namespace printer {
116
116
}
117
117
118
118
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,
121
122
fs::path const &rootPath,
122
123
fs::path primaryCompiler,
123
124
CollectionUtils::FileSet const *stubSources,
124
125
std::map<std::string, fs::path, std::function<bool (const std::string&, const std::string&)>> pathToShellVariable)
125
126
: 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)),
127
130
primaryCompiler(std::move(primaryCompiler)),
128
131
primaryCxxCompiler(CompilationUtils::toCppCompiler(this ->primaryCompiler)),
129
132
primaryCompilerName(CompilationUtils::getCompilerName(this ->primaryCompiler)),
@@ -135,7 +138,7 @@ namespace printer {
135
138
CompilationUtils::getCoverageLinkFlags (primaryCxxCompilerName), " ")),
136
139
sanitizerLinkFlags(SanitizerUtils::getSanitizeLinkFlags(primaryCxxCompilerName)),
137
140
138
- buildDirectory(Paths::getUtbotBuildDir(projectContext)),
141
+ buildDirectory(Paths::getUtbotBuildDir(testGen. projectContext)),
139
142
dependencyDirectory(buildDirectory / " dependencies" ),
140
143
stubSources(stubSources) {
141
144
@@ -164,13 +167,13 @@ namespace printer {
164
167
}
165
168
166
169
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 );
168
171
return getRelativePath (dependencyDirectory) /
169
172
Paths::addExtension (relativePath, " .Td" );
170
173
}
171
174
172
175
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 );
174
177
return getRelativePath (dependencyDirectory) /
175
178
Paths::addExtension (relativePath, " .d" );
176
179
}
@@ -270,25 +273,25 @@ namespace printer {
270
273
BuildResult NativeMakefilePrinter::addObjectFile (const fs::path &objectFile,
271
274
const std::string &suffixForParentOfStubs) {
272
275
273
- auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo (objectFile);
276
+ auto compilationUnitInfo = testGen. buildDatabase ->getClientCompilationUnitInfo (objectFile);
274
277
fs::path sourcePath = compilationUnitInfo->getSourcePath ();
275
278
276
279
fs::path pathToCompile;
277
280
fs::path recompiledFile;
278
281
BuildResult::Type buildResultType;
279
282
BuildResult buildResult;
280
283
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);
283
286
buildResultType = BuildResult::Type::ALL_STUBS;
284
287
} else {
285
288
if (Paths::isCXXFile (sourcePath)) {
286
289
pathToCompile = sourcePath;
287
290
} else {
288
- pathToCompile = Paths::getWrapperFilePath (projectContext, sourcePath);
291
+ pathToCompile = Paths::getWrapperFilePath (testGen. projectContext , sourcePath);
289
292
}
290
293
recompiledFile =
291
- Paths::getRecompiledFile (projectContext, compilationUnitInfo->getOutputFile ());
294
+ Paths::getRecompiledFile (testGen. projectContext , compilationUnitInfo->getOutputFile ());
292
295
buildResultType = BuildResult::Type::NO_STUBS;
293
296
}
294
297
@@ -299,7 +302,7 @@ namespace printer {
299
302
}
300
303
301
304
void NativeMakefilePrinter::addTestTarget (const fs::path &sourcePath) {
302
- auto compilationUnitInfo = buildDatabase->getClientCompilationUnitInfo (sourcePath);
305
+ auto compilationUnitInfo = testGen. buildDatabase ->getClientCompilationUnitInfo (sourcePath);
303
306
auto testCompilationCommand = compilationUnitInfo->command ;
304
307
testCompilationCommand.setCompiler (getRelativePathForLinker (primaryCxxCompiler));
305
308
testCompilationCommand.setOptimizationLevel (OPTIMIZATION_FLAG);
@@ -314,10 +317,10 @@ namespace printer {
314
317
testCompilationCommand.addFlagToBegin (FPIC_FLAG);
315
318
testCompilationCommand.addFlagsToBegin (SANITIZER_NEEDED_FLAGS);
316
319
317
- fs::path testSourcePath = Paths::sourcePathToTestPath (projectContext, sourcePath);
320
+ fs::path testSourcePath = Paths::sourcePathToTestPath (testGen. projectContext , sourcePath);
318
321
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 );
321
324
fs::path testObjectPathRelative = getRelativePath (
322
325
testObjectDir / Paths::addExtension (testSourceRelativePath, " .o" ));
323
326
testCompilationCommand.setOutput (
@@ -332,7 +335,7 @@ namespace printer {
332
335
333
336
artifacts.push_back (testCompilationCommand.getOutput ());
334
337
335
- auto rootLinkUnitInfo = buildDatabase->getClientLinkUnitInfo (rootPath);
338
+ auto rootLinkUnitInfo = testGen. buildDatabase ->getClientLinkUnitInfo (rootPath);
336
339
fs::path testExecutablePath = getTestExecutablePath (sourcePath);
337
340
338
341
std::vector<std::string> filesToLink{ " $(GTEST_MAIN)" , " $(GTEST_ALL)" , testCompilationCommand.getOutput (),
@@ -399,14 +402,15 @@ namespace printer {
399
402
}
400
403
fs::path NativeMakefilePrinter::getTestExecutablePath (const fs::path &sourcePath) const {
401
404
return Paths::removeExtension (
402
- Paths::removeExtension (Paths::getRecompiledFile (projectContext, sourcePath)));
405
+ Paths::removeExtension (Paths::getRecompiledFile (testGen. projectContext , sourcePath)));
403
406
}
404
407
405
408
NativeMakefilePrinter::NativeMakefilePrinter (const NativeMakefilePrinter &baseMakefilePrinter,
406
409
const fs::path &sourcePath)
407
410
: RelativeMakefilePrinter(baseMakefilePrinter.pathToShellVariable),
408
- projectContext(baseMakefilePrinter.projectContext),
409
- buildDatabase(baseMakefilePrinter.buildDatabase),
411
+ // projectContext(baseMakefilePrinter.projectContext),
412
+ // buildDatabase(baseMakefilePrinter.buildDatabase),
413
+ testGen(baseMakefilePrinter.testGen),
410
414
rootPath(baseMakefilePrinter.rootPath),
411
415
primaryCompiler(baseMakefilePrinter.primaryCompiler),
412
416
primaryCxxCompiler(baseMakefilePrinter.primaryCxxCompiler),
@@ -427,7 +431,7 @@ namespace printer {
427
431
428
432
fs::path testExecutablePath = getTestExecutablePath (sourcePath);
429
433
430
- auto rootLinkUnitInfo = buildDatabase->getClientLinkUnitInfo (rootPath);
434
+ auto rootLinkUnitInfo = testGen. buildDatabase ->getClientLinkUnitInfo (rootPath);
431
435
432
436
fs::path coverageInfoBinary = sharedOutput.value ();
433
437
if (!Paths::isLibraryFile (coverageInfoBinary)) {
@@ -469,7 +473,7 @@ namespace printer {
469
473
return buildResults[unitFile] = buildResult;
470
474
}
471
475
472
- auto linkUnitInfo = buildDatabase->getClientLinkUnitInfo (unitFile);
476
+ auto linkUnitInfo = testGen. buildDatabase ->getClientLinkUnitInfo (unitFile);
473
477
BuildResult::Type unitType = BuildResult::Type::NONE;
474
478
CollectionUtils::MapFileTo<fs::path> fileMapping;
475
479
auto unitBuildResults = CollectionUtils::transformTo<std::vector<BuildResult>>(
@@ -490,7 +494,7 @@ namespace printer {
490
494
bool isExecutable = !Paths::isLibraryFile (unitFile);
491
495
492
496
fs::path recompiledFile =
493
- Paths::getRecompiledFile (projectContext, linkUnitInfo->getOutput ());
497
+ Paths::getRecompiledFile (testGen. projectContext , linkUnitInfo->getOutput ());
494
498
if (isExecutable && !transformExeToLib) {
495
499
recompiledFile = Paths::isObjectFile (recompiledFile) ?
496
500
recompiledFile : Paths::addExtension (recompiledFile, " .o" );
@@ -530,9 +534,9 @@ namespace printer {
530
534
getLibraryAbsolutePath (argument, linkCommand.getDirectory ());
531
535
if (optionalLibraryAbsolutePath.has_value ()) {
532
536
const fs::path &absolutePath = optionalLibraryAbsolutePath.value ();
533
- if (Paths::isSubPathOf (projectContext.buildDir (), absolutePath)) {
537
+ if (Paths::isSubPathOf (testGen. projectContext .buildDir (), absolutePath)) {
534
538
fs::path recompiledDir =
535
- Paths::getRecompiledFile (projectContext, absolutePath);
539
+ Paths::getRecompiledFile (testGen. projectContext , absolutePath);
536
540
std::string directoryFlag = getLibraryDirectoryFlag (recompiledDir);
537
541
libraryDirectoriesFlags.push_back (directoryFlag);
538
542
}
@@ -614,11 +618,11 @@ namespace printer {
614
618
void NativeMakefilePrinter::addStubs (const CollectionUtils::FileSet &stubsSet) {
615
619
auto stubObjectFiles = CollectionUtils::transformTo<CollectionUtils::FileSet>(
616
620
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);
618
622
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);
622
626
addCompileTarget (stub, target, *compilationUnitInfo);
623
627
return target;
624
628
});
0 commit comments