Skip to content

Fixing generations for files that included in two targets #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion server/src/BordersFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ BordersFinder::BordersFinder(const fs::path &filePath,
const std::shared_ptr<CompilationDatabase> &compilationDatabase,
const fs::path &compileCommandsJsonPath)
: line(line), classBorder(std::nullopt), clangToolRunner(compilationDatabase) {
buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
lineInfo.filePath = filePath;
}

Expand Down
1 change: 0 additions & 1 deletion server/src/BordersFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BordersFinder : public clang::ast_matchers::MatchFinder::MatchCallback {
private:
unsigned line;
LineInfo lineInfo{};
fs::path buildRootPath;
struct Borders {
struct Position {
unsigned line;
Expand Down
337 changes: 169 additions & 168 deletions server/src/KleeGenerator.cpp

Large diffs are not rendered by default.

42 changes: 14 additions & 28 deletions server/src/KleeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include "streams/tests/TestsWriter.h"
#include "types/Types.h"
#include "utils/ExecUtils.h"

#include "utils/path/FileSystemPath.h"
#include "testgens/BaseTestGen.h"

#include <optional>
#include <sstream>
#include <string>


using json = nlohmann::json;

/**
Expand All @@ -33,28 +35,16 @@ class KleeGenerator {
public:
/**
* @brief Also creates tmp directories for build files.
* @param projectContext contains context about current project.
* @param settingsContext contains context about settings applied for current request.
* @param serverBuildDir Path to folder on server machine where project build dirs are located.
* @param sourcesFilePaths Paths to project files. Files which are listed in
* [compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html), filtered
* by them.
* @param compilationDatabase Pointer to compile_commands.json object.
* @param testGen contains request and build information.
* @param typesHandler provides additional information about types.
* @param filePathsSubstitution Mapping from source file path to modified file. Required for
* line test generation requests.
* @param buildDatabase Instance of BuildDatabase which handles link and compile commands
* @throws fs::filesystem_error Thrown if it can't create tmp folder for some
* reasons.
*/
KleeGenerator(utbot::ProjectContext projectContext,
utbot::SettingsContext settingsContext,
fs::path serverBuildDir,
std::shared_ptr<CompilationDatabase> compilationDatabase,
types::TypesHandler &typesHandler,
PathSubstitution filePathsSubstitution,
std::shared_ptr<BuildDatabase> buildDatabase = nullptr,
const ProgressWriter *progressWriter = DummyStreamWriter::getInstance());
KleeGenerator(BaseTestGen *testGen, types::TypesHandler &typesHandler,
PathSubstitution filePathsSubstitution);

struct BuildFileInfo {
fs::path outFilePath;
Expand Down Expand Up @@ -128,7 +118,7 @@ class KleeGenerator {
const std::shared_ptr<LineInfo> &lineInfo = nullptr,
bool verbose = false);

[[nodiscard]] std::shared_ptr<BuildDatabase> getBuildDatabase() const;
[[nodiscard]] fs::path getBitcodeFile(const fs::path &sourcePath) const;

void handleFailedFunctions(tests::TestsMap &testsMap);

Expand All @@ -146,29 +136,25 @@ class KleeGenerator {
std::optional<utbot::CompileCommand>
getCompileCommandForKlee(const fs::path &hintPath,
const CollectionUtils::FileSet &stubSources,
const std::vector<std::string> &flags) const;
const std::vector<std::string> &flags,
bool forStub) const;

std::vector<utbot::CompileCommand>
getCompileCommandsForKlee(const CollectionUtils::MapFileTo<fs::path> &filesToBuild,
const CollectionUtils::FileSet &stubSources) const;

private:
const utbot::ProjectContext projectContext;
const utbot::SettingsContext settingsContext;
fs::path projectTmpPath;
std::shared_ptr<CompilationDatabase> compilationDatabase;
BaseTestGen *testGen;
types::TypesHandler typesHandler;
PathSubstitution pathSubstitution;
std::shared_ptr<BuildDatabase> buildDatabase;
const ProgressWriter *progressWriter;

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

fs::path writeKleeFile(
printer::KleePrinter &kleePrinter,
Tests const &tests,
const std::shared_ptr<LineInfo> &lineInfo,
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
printer::KleePrinter &kleePrinter,
Tests const &tests,
const std::shared_ptr<LineInfo> &lineInfo,
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
[](tests::Tests::MethodDescription const &) { return true; });
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Paths {
CollectionUtils::FileSet filtered =
CollectionUtils::filterOut(paths, [&dirPaths, &filter](const fs::path &path) {
return !std::any_of(dirPaths.begin(), dirPaths.end(), [&](const fs::path &dirPath) {
return path.parent_path() == dirPath && fs::exists(path) && filter(path);
return isSubPathOf(dirPath, path) && fs::exists(path) && filter(path);
});
});
return filtered;
Expand Down
21 changes: 0 additions & 21 deletions server/src/ProjectTarget.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions server/src/ProjectTarget.h

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/ReturnTypesFetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void ReturnTypesFetcher::fetch(ProgressWriter *const progressWriter,
testsMap[filePath];
}
Fetcher(Fetcher::Options::Value::RETURN_TYPE_NAMES_ONLY,
testGen->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
testGen->getTargetBuildDatabase()->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
testGen->compileCommandsJsonPath, false)
.fetchWithProgress(progressWriter, "Fetching return types for functions", true);
for (auto const &[sourceFilePath, test] : testsMap) {
Expand Down
Loading