Skip to content

Commit dec91ce

Browse files
authored
Add option for skip precompiled objects (#652)
* Add possibility to skip precompiled object files
1 parent ca9ea6a commit dec91ce

25 files changed

+172
-75
lines changed

server/proto/testgen.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ message SettingsContext {
106106
bool useStubs = 6;
107107
ErrorMode errorMode = 7;
108108
bool differentVariablesOfTheSameType = 8;
109+
bool skipObjectWithoutSource = 9;
109110
}
110111

111112
message SnippetRequest {

server/src/Server.cpp

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

589589
utbot::ProjectContext projectContext{*request};
590590
fs::path serverBuildDir = Paths::getUTBotBuildDir(projectContext);
591-
std::shared_ptr<ProjectBuildDatabase> buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
591+
std::shared_ptr<ProjectBuildDatabase> buildDatabase =
592+
std::make_shared<ProjectBuildDatabase>(projectContext, true);
592593
StubSourcesFinder(buildDatabase).printAllModules();
593594
return Status::OK;
594595
}
@@ -663,7 +664,7 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,
663664

664665
try {
665666
utbot::ProjectContext projectContext{request->projectcontext()};
666-
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
667+
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext, true);
667668
std::vector<fs::path> targets = buildDatabase->getAllTargetPaths();
668669
ProjectTargetsWriter targetsWriter(response);
669670
targetsWriter.writeResponse(projectContext, targets);
@@ -690,7 +691,7 @@ Status Server::TestsGenServiceImpl::GetFileTargets(ServerContext *context,
690691

691692
try {
692693
utbot::ProjectContext projectContext{request->projectcontext()};
693-
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
694+
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext, true);
694695
fs::path path = request->path();
695696
auto targetPaths = buildDatabase->getTargetPathsForSourceFile(path);
696697
FileTargetsWriter targetsWriter{response};

server/src/SettingsContext.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ namespace utbot {
1010
bool useDeterministicSearcher,
1111
bool useStubs,
1212
testsgen::ErrorMode errorMode,
13-
bool differentVariablesOfTheSameType)
14-
: generateForStaticFunctions(generateForStaticFunctions),
15-
verbose(verbose),
16-
timeoutPerFunction(timeoutPerFunction > 0
17-
? std::make_optional(std::chrono::seconds{ timeoutPerFunction })
13+
bool differentVariablesOfTheSameType,
14+
bool skipObjectWithoutSource)
15+
: generateForStaticFunctions(generateForStaticFunctions),
16+
verbose(verbose),
17+
timeoutPerFunction(timeoutPerFunction > 0
18+
? std::make_optional(std::chrono::seconds{timeoutPerFunction})
1819
: std::nullopt),
19-
timeoutPerTest(timeoutPerTest > 0
20-
? std::make_optional(std::chrono::seconds{ timeoutPerTest })
21-
: std::nullopt),
22-
useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs),
23-
errorMode(errorMode),
24-
differentVariablesOfTheSameType (differentVariablesOfTheSameType) {
20+
timeoutPerTest(timeoutPerTest > 0
21+
? std::make_optional(std::chrono::seconds{timeoutPerTest})
22+
: std::nullopt),
23+
useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs),
24+
errorMode(errorMode),
25+
differentVariablesOfTheSameType(differentVariablesOfTheSameType),
26+
skipObjectWithoutSource(skipObjectWithoutSource) {
2527
}
28+
2629
SettingsContext::SettingsContext(const testsgen::SettingsContext &settingsContext)
27-
: SettingsContext(settingsContext.generateforstaticfunctions(),
30+
: SettingsContext(settingsContext.generateforstaticfunctions(),
2831
settingsContext.verbose(),
2932
settingsContext.timeoutperfunction(),
3033
settingsContext.timeoutpertest(),
3134
settingsContext.usedeterministicsearcher(),
3235
settingsContext.usestubs(),
3336
settingsContext.errormode(),
34-
settingsContext.differentvariablesofthesametype()) {
37+
settingsContext.differentvariablesofthesametype(),
38+
settingsContext.skipobjectwithoutsource()) {
3539
}
3640
}

server/src/SettingsContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace utbot {
2121
bool useDeterministicSearcher,
2222
bool useStubs,
2323
testsgen::ErrorMode errorMode,
24-
bool differentVariablesOfTheSameType);
24+
bool differentVariablesOfTheSameType,
25+
bool skipObjectWithoutSource);
2526

2627
const bool generateForStaticFunctions;
2728
const bool verbose;
@@ -30,6 +31,7 @@ namespace utbot {
3031
const bool useStubs;
3132
testsgen::ErrorMode errorMode;
3233
const bool differentVariablesOfTheSameType;
34+
const bool skipObjectWithoutSource;
3335
};
3436
}
3537

server/src/building/ProjectBuildDatabase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ProjectBuildDatabase : public BuildDatabase {
77
private:
88
void initObjects(const nlohmann::json &compileCommandsJson);
99

10-
void initInfo(const nlohmann::json &linkCommandsJson);
10+
void initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource);
1111

1212
void filterInstalledFiles();
1313

@@ -17,9 +17,9 @@ class ProjectBuildDatabase : public BuildDatabase {
1717

1818
public:
1919
ProjectBuildDatabase(fs::path buildCommandsJsonPath, fs::path serverBuildDir,
20-
utbot::ProjectContext projectContext);
20+
utbot::ProjectContext projectContext, bool skipObjectWithoutSource);
2121

22-
explicit ProjectBuildDatabase(utbot::ProjectContext projectContext);
22+
explicit ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource);
2323
};
2424

2525

server/src/building/ProjectBuildDatabse.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static std::string tryConvertOptionToPath(const std::string &possibleFilePath, c
3131

3232
ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
3333
fs::path _serverBuildDir,
34-
utbot::ProjectContext _projectContext) :
34+
utbot::ProjectContext _projectContext,
35+
bool skipObjectWithoutSource) :
3536
BuildDatabase(_serverBuildDir,
3637
_buildCommandsJsonPath,
3738
fs::canonical(_buildCommandsJsonPath / "link_commands.json"),
@@ -47,7 +48,7 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
4748
auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
4849
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);
4950
initObjects(compileCommandsJson);
50-
initInfo(linkCommandsJson);
51+
initInfo(linkCommandsJson, skipObjectWithoutSource);
5152
filterInstalledFiles();
5253
addLocalSharedLibraries();
5354
fillTargetInfoParents();
@@ -58,9 +59,10 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
5859
}
5960
}
6061

61-
ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase(
62+
ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource)
63+
: ProjectBuildDatabase(
6264
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext),
63-
Paths::getUTBotBuildDir(projectContext), std::move(projectContext)) {
65+
Paths::getUTBotBuildDir(projectContext), std::move(projectContext), skipObjectWithoutSource) {
6466
}
6567

6668

@@ -154,7 +156,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
154156
}
155157
}
156158

157-
void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
159+
void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource) {
158160
for (nlohmann::json const &linkCommand: linkCommandsJson) {
159161
fs::path directory = linkCommand.at("directory").get<std::string>();
160162
std::vector<std::string> jsonArguments;
@@ -189,14 +191,17 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
189191
if (ignoredOutput.count(currentFile)) {
190192
continue;
191193
}
192-
targetInfo->addFile(currentFile);
193194
if (Paths::isObjectFile(currentFile)) {
194195
if (!CollectionUtils::containsKey(objectFileInfos, currentFile) &&
195196
!CollectionUtils::containsKey(objectFileInfos,
196197
relative(currentFile, directory))) {
197198
std::string message =
198199
"compile_commands.json doesn't contain a command for object file " +
199200
currentFile.string();
201+
if (skipObjectWithoutSource) {
202+
LOG_S(WARNING) << message;
203+
continue;
204+
}
200205
LOG_S(ERROR) << message;
201206
throw CompilationDatabaseException(message);
202207
}
@@ -207,6 +212,7 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
207212
objectFileInfos[relative(currentFile, directory)]->linkUnit = output;
208213
}
209214
}
215+
targetInfo->addFile(currentFile);
210216
}
211217
targetInfo->commands.emplace_back(command);
212218
}

server/src/commands/Commands.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ bool Commands::SettingsContextOptionGroup::doDifferentVariablesOfTheSameType() c
416416
return differentVariablesOfTheSameType;
417417
}
418418

419+
bool Commands::SettingsContextOptionGroup::getSkipObjectWithoutSource() const {
420+
return skipObjectWithoutSource;
421+
}
422+
419423
Commands::RunTestsCommands::RunTestsCommands(Commands::MainCommands &commands) {
420424
runCommand = commands.getRunTestsCommand();
421425

server/src/commands/Commands.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ namespace Commands {
246246
[[nodiscard]] ErrorMode getErrorMode() const;
247247

248248
[[nodiscard]] bool doDifferentVariablesOfTheSameType() const;
249+
[[nodiscard]] bool getSkipObjectWithoutSource() const;
249250

250251
private:
251252
CLI::Option_group *settingsContextOptions;
@@ -257,6 +258,7 @@ namespace Commands {
257258
bool noStubs = false;
258259
ErrorMode errorMode = ErrorMode::FAILING;
259260
bool differentVariablesOfTheSameType = false;
261+
bool skipObjectWithoutSource = false;
260262
};
261263
};
262264

server/src/testgens/ProjectTestGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request,
1616
testMode), request(&request) {
1717
fs::create_directories(projectContext.testDirPath);
1818
compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext);
19-
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
19+
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir,
20+
projectContext,
21+
settingsContext.skipObjectWithoutSource);
2022
if (sourceFile.has_value() && Paths::isSourceFile(sourceFile.value()) &&
21-
(request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) {
23+
(request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) {
2224
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), sourceFile.value());
2325
} else {
2426
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), request.targetpath());

server/src/testgens/SnippetTestGen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ SnippetTestGen::SnippetTestGen(const testsgen::SnippetRequest &request,
1818
printer::CCJsonPrinter::createDummyBuildDB(sourcePaths, serverBuildDir);
1919
compileCommandsJsonPath = serverBuildDir;
2020
utbot::ProjectContext projectContext{request, serverBuildDir};
21-
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
22-
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), serverBuildDir / SNIPPET_TARGET);
21+
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir,
22+
projectContext,
23+
settingsContext.skipObjectWithoutSource);
24+
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(),
25+
serverBuildDir / SNIPPET_TARGET);
2326
setTargetForSource(filePath);
2427
setInitializedTestsMap();
2528
}

server/src/utils/CLIUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ createSettingsContextByOptions(const SettingsContextOptionGroup &settingsContext
6363
settingsContextOptionGroup.isDeterministicSearcherUsed(),
6464
settingsContextOptionGroup.withStubs(),
6565
settingsContextOptionGroup.getErrorMode(),
66-
settingsContextOptionGroup.doDifferentVariablesOfTheSameType());
66+
settingsContextOptionGroup.doDifferentVariablesOfTheSameType(),
67+
settingsContextOptionGroup.getSkipObjectWithoutSource());
6768
}
6869

6970
std::vector<fs::path> getSourcePaths(const ProjectContextOptionGroup &projectContextOptions,

server/src/utils/GrpcUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace GrpcUtils {
3737
bool useDeterministicSearcher,
3838
bool useStubs,
3939
ErrorMode errorMode,
40-
bool differentVariablesOfTheSameType) {
40+
bool differentVariablesOfTheSameType,
41+
bool skipObjectWithoutSource) {
4142
auto result = std::make_unique<testsgen::SettingsContext>();
4243
result->set_generateforstaticfunctions(generateForStaticFunctions);
4344
result->set_verbose(verbose);
@@ -47,6 +48,7 @@ namespace GrpcUtils {
4748
result->set_usestubs(useStubs);
4849
result->set_errormode(errorMode);
4950
result->set_differentvariablesofthesametype(differentVariablesOfTheSameType);
51+
result->set_skipobjectwithoutsource(skipObjectWithoutSource);
5052
return result;
5153
}
5254

server/src/utils/GrpcUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace GrpcUtils {
2929
bool useDeterministicSearcher,
3030
bool useStubs,
3131
ErrorMode errorMode,
32-
bool differentVariablesOfTheSameType);
32+
bool differentVariablesOfTheSameType,
33+
bool skipObjectWithoutSource);
3334

3435
std::unique_ptr<testsgen::SnippetRequest>
3536
createSnippetRequest(std::unique_ptr<testsgen::ProjectContext> projectContext,

0 commit comments

Comments
 (0)