Skip to content

Commit

Permalink
Add option for skip precompiled objects (#652)
Browse files Browse the repository at this point in the history
* Add possibility to skip precompiled object files
  • Loading branch information
ladisgin authored Nov 17, 2023
1 parent ca9ea6a commit dec91ce
Show file tree
Hide file tree
Showing 25 changed files with 172 additions and 75 deletions.
1 change: 1 addition & 0 deletions server/proto/testgen.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ message SettingsContext {
bool useStubs = 6;
ErrorMode errorMode = 7;
bool differentVariablesOfTheSameType = 8;
bool skipObjectWithoutSource = 9;
}

message SnippetRequest {
Expand Down
7 changes: 4 additions & 3 deletions server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context,

utbot::ProjectContext projectContext{*request};
fs::path serverBuildDir = Paths::getUTBotBuildDir(projectContext);
std::shared_ptr<ProjectBuildDatabase> buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
std::shared_ptr<ProjectBuildDatabase> buildDatabase =
std::make_shared<ProjectBuildDatabase>(projectContext, true);
StubSourcesFinder(buildDatabase).printAllModules();
return Status::OK;
}
Expand Down Expand Up @@ -663,7 +664,7 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,

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

try {
utbot::ProjectContext projectContext{request->projectcontext()};
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
auto buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext, true);
fs::path path = request->path();
auto targetPaths = buildDatabase->getTargetPathsForSourceFile(path);
FileTargetsWriter targetsWriter{response};
Expand Down
30 changes: 17 additions & 13 deletions server/src/SettingsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ namespace utbot {
bool useDeterministicSearcher,
bool useStubs,
testsgen::ErrorMode errorMode,
bool differentVariablesOfTheSameType)
: generateForStaticFunctions(generateForStaticFunctions),
verbose(verbose),
timeoutPerFunction(timeoutPerFunction > 0
? std::make_optional(std::chrono::seconds{ timeoutPerFunction })
bool differentVariablesOfTheSameType,
bool skipObjectWithoutSource)
: generateForStaticFunctions(generateForStaticFunctions),
verbose(verbose),
timeoutPerFunction(timeoutPerFunction > 0
? std::make_optional(std::chrono::seconds{timeoutPerFunction})
: std::nullopt),
timeoutPerTest(timeoutPerTest > 0
? std::make_optional(std::chrono::seconds{ timeoutPerTest })
: std::nullopt),
useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs),
errorMode(errorMode),
differentVariablesOfTheSameType (differentVariablesOfTheSameType) {
timeoutPerTest(timeoutPerTest > 0
? std::make_optional(std::chrono::seconds{timeoutPerTest})
: std::nullopt),
useDeterministicSearcher(useDeterministicSearcher), useStubs(useStubs),
errorMode(errorMode),
differentVariablesOfTheSameType(differentVariablesOfTheSameType),
skipObjectWithoutSource(skipObjectWithoutSource) {
}

SettingsContext::SettingsContext(const testsgen::SettingsContext &settingsContext)
: SettingsContext(settingsContext.generateforstaticfunctions(),
: SettingsContext(settingsContext.generateforstaticfunctions(),
settingsContext.verbose(),
settingsContext.timeoutperfunction(),
settingsContext.timeoutpertest(),
settingsContext.usedeterministicsearcher(),
settingsContext.usestubs(),
settingsContext.errormode(),
settingsContext.differentvariablesofthesametype()) {
settingsContext.differentvariablesofthesametype(),
settingsContext.skipobjectwithoutsource()) {
}
}
4 changes: 3 additions & 1 deletion server/src/SettingsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace utbot {
bool useDeterministicSearcher,
bool useStubs,
testsgen::ErrorMode errorMode,
bool differentVariablesOfTheSameType);
bool differentVariablesOfTheSameType,
bool skipObjectWithoutSource);

const bool generateForStaticFunctions;
const bool verbose;
Expand All @@ -30,6 +31,7 @@ namespace utbot {
const bool useStubs;
testsgen::ErrorMode errorMode;
const bool differentVariablesOfTheSameType;
const bool skipObjectWithoutSource;
};
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/building/ProjectBuildDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ProjectBuildDatabase : public BuildDatabase {
private:
void initObjects(const nlohmann::json &compileCommandsJson);

void initInfo(const nlohmann::json &linkCommandsJson);
void initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource);

void filterInstalledFiles();

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

public:
ProjectBuildDatabase(fs::path buildCommandsJsonPath, fs::path serverBuildDir,
utbot::ProjectContext projectContext);
utbot::ProjectContext projectContext, bool skipObjectWithoutSource);

explicit ProjectBuildDatabase(utbot::ProjectContext projectContext);
explicit ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource);
};


Expand Down
18 changes: 12 additions & 6 deletions server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static std::string tryConvertOptionToPath(const std::string &possibleFilePath, c

ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
fs::path _serverBuildDir,
utbot::ProjectContext _projectContext) :
utbot::ProjectContext _projectContext,
bool skipObjectWithoutSource) :
BuildDatabase(_serverBuildDir,
_buildCommandsJsonPath,
fs::canonical(_buildCommandsJsonPath / "link_commands.json"),
Expand All @@ -47,7 +48,7 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);
initObjects(compileCommandsJson);
initInfo(linkCommandsJson);
initInfo(linkCommandsJson, skipObjectWithoutSource);
filterInstalledFiles();
addLocalSharedLibraries();
fillTargetInfoParents();
Expand All @@ -58,9 +59,10 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
}
}

ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase(
ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext, bool skipObjectWithoutSource)
: ProjectBuildDatabase(
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext),
Paths::getUTBotBuildDir(projectContext), std::move(projectContext)) {
Paths::getUTBotBuildDir(projectContext), std::move(projectContext), skipObjectWithoutSource) {
}


Expand Down Expand Up @@ -154,7 +156,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
}
}

void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool skipObjectWithoutSource) {
for (nlohmann::json const &linkCommand: linkCommandsJson) {
fs::path directory = linkCommand.at("directory").get<std::string>();
std::vector<std::string> jsonArguments;
Expand Down Expand Up @@ -189,14 +191,17 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
if (ignoredOutput.count(currentFile)) {
continue;
}
targetInfo->addFile(currentFile);
if (Paths::isObjectFile(currentFile)) {
if (!CollectionUtils::containsKey(objectFileInfos, currentFile) &&
!CollectionUtils::containsKey(objectFileInfos,
relative(currentFile, directory))) {
std::string message =
"compile_commands.json doesn't contain a command for object file " +
currentFile.string();
if (skipObjectWithoutSource) {
LOG_S(WARNING) << message;
continue;
}
LOG_S(ERROR) << message;
throw CompilationDatabaseException(message);
}
Expand All @@ -207,6 +212,7 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
objectFileInfos[relative(currentFile, directory)]->linkUnit = output;
}
}
targetInfo->addFile(currentFile);
}
targetInfo->commands.emplace_back(command);
}
Expand Down
4 changes: 4 additions & 0 deletions server/src/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ bool Commands::SettingsContextOptionGroup::doDifferentVariablesOfTheSameType() c
return differentVariablesOfTheSameType;
}

bool Commands::SettingsContextOptionGroup::getSkipObjectWithoutSource() const {
return skipObjectWithoutSource;
}

Commands::RunTestsCommands::RunTestsCommands(Commands::MainCommands &commands) {
runCommand = commands.getRunTestsCommand();

Expand Down
2 changes: 2 additions & 0 deletions server/src/commands/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ namespace Commands {
[[nodiscard]] ErrorMode getErrorMode() const;

[[nodiscard]] bool doDifferentVariablesOfTheSameType() const;
[[nodiscard]] bool getSkipObjectWithoutSource() const;

private:
CLI::Option_group *settingsContextOptions;
Expand All @@ -257,6 +258,7 @@ namespace Commands {
bool noStubs = false;
ErrorMode errorMode = ErrorMode::FAILING;
bool differentVariablesOfTheSameType = false;
bool skipObjectWithoutSource = false;
};
};

Expand Down
6 changes: 4 additions & 2 deletions server/src/testgens/ProjectTestGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ ProjectTestGen::ProjectTestGen(const testsgen::ProjectRequest &request,
testMode), request(&request) {
fs::create_directories(projectContext.testDirPath);
compileCommandsJsonPath = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext);
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir,
projectContext,
settingsContext.skipObjectWithoutSource);
if (sourceFile.has_value() && Paths::isSourceFile(sourceFile.value()) &&
(request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) {
(request.targetpath() == GrpcUtils::UTBOT_AUTO_TARGET_PATH || request.targetpath().empty())) {
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), sourceFile.value());
} else {
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), request.targetpath());
Expand Down
7 changes: 5 additions & 2 deletions server/src/testgens/SnippetTestGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ SnippetTestGen::SnippetTestGen(const testsgen::SnippetRequest &request,
printer::CCJsonPrinter::createDummyBuildDB(sourcePaths, serverBuildDir);
compileCommandsJsonPath = serverBuildDir;
utbot::ProjectContext projectContext{request, serverBuildDir};
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(), serverBuildDir / SNIPPET_TARGET);
projectBuildDatabase = std::make_shared<ProjectBuildDatabase>(compileCommandsJsonPath, serverBuildDir,
projectContext,
settingsContext.skipObjectWithoutSource);
targetBuildDatabase = std::make_shared<TargetBuildDatabase>(projectBuildDatabase.get(),
serverBuildDir / SNIPPET_TARGET);
setTargetForSource(filePath);
setInitializedTestsMap();
}
Expand Down
3 changes: 2 additions & 1 deletion server/src/utils/CLIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ createSettingsContextByOptions(const SettingsContextOptionGroup &settingsContext
settingsContextOptionGroup.isDeterministicSearcherUsed(),
settingsContextOptionGroup.withStubs(),
settingsContextOptionGroup.getErrorMode(),
settingsContextOptionGroup.doDifferentVariablesOfTheSameType());
settingsContextOptionGroup.doDifferentVariablesOfTheSameType(),
settingsContextOptionGroup.getSkipObjectWithoutSource());
}

std::vector<fs::path> getSourcePaths(const ProjectContextOptionGroup &projectContextOptions,
Expand Down
4 changes: 3 additions & 1 deletion server/src/utils/GrpcUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace GrpcUtils {
bool useDeterministicSearcher,
bool useStubs,
ErrorMode errorMode,
bool differentVariablesOfTheSameType) {
bool differentVariablesOfTheSameType,
bool skipObjectWithoutSource) {
auto result = std::make_unique<testsgen::SettingsContext>();
result->set_generateforstaticfunctions(generateForStaticFunctions);
result->set_verbose(verbose);
Expand All @@ -47,6 +48,7 @@ namespace GrpcUtils {
result->set_usestubs(useStubs);
result->set_errormode(errorMode);
result->set_differentvariablesofthesametype(differentVariablesOfTheSameType);
result->set_skipobjectwithoutsource(skipObjectWithoutSource);
return result;
}

Expand Down
3 changes: 2 additions & 1 deletion server/src/utils/GrpcUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace GrpcUtils {
bool useDeterministicSearcher,
bool useStubs,
ErrorMode errorMode,
bool differentVariablesOfTheSameType);
bool differentVariablesOfTheSameType,
bool skipObjectWithoutSource);

std::unique_ptr<testsgen::SnippetRequest>
createSnippetRequest(std::unique_ptr<testsgen::ProjectContext> projectContext,
Expand Down
Loading

0 comments on commit dec91ce

Please sign in to comment.