Skip to content

Commit 32c0298

Browse files
authored
Fixing generations for files that included in two targets (#258)
Use subset of compilation database for generation with chosen target
1 parent ca3734f commit 32c0298

File tree

83 files changed

+1852
-1342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1852
-1342
lines changed

server/src/BordersFinder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ BordersFinder::BordersFinder(const fs::path &filePath,
1717
const std::shared_ptr<CompilationDatabase> &compilationDatabase,
1818
const fs::path &compileCommandsJsonPath)
1919
: line(line), classBorder(std::nullopt), clangToolRunner(compilationDatabase) {
20-
buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
2120
lineInfo.filePath = filePath;
2221
}
2322

server/src/BordersFinder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class BordersFinder : public clang::ast_matchers::MatchFinder::MatchCallback {
3131
private:
3232
unsigned line;
3333
LineInfo lineInfo{};
34-
fs::path buildRootPath;
3534
struct Borders {
3635
struct Position {
3736
unsigned line;

server/src/KleeGenerator.cpp

Lines changed: 169 additions & 168 deletions
Large diffs are not rendered by default.

server/src/KleeGenerator.h

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#include "streams/tests/TestsWriter.h"
1616
#include "types/Types.h"
1717
#include "utils/ExecUtils.h"
18-
1918
#include "utils/path/FileSystemPath.h"
19+
#include "testgens/BaseTestGen.h"
20+
2021
#include <optional>
2122
#include <sstream>
2223
#include <string>
2324

25+
2426
using json = nlohmann::json;
2527

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

5949
struct BuildFileInfo {
6050
fs::path outFilePath;
@@ -128,7 +118,7 @@ class KleeGenerator {
128118
const std::shared_ptr<LineInfo> &lineInfo = nullptr,
129119
bool verbose = false);
130120

131-
[[nodiscard]] std::shared_ptr<BuildDatabase> getBuildDatabase() const;
121+
[[nodiscard]] fs::path getBitcodeFile(const fs::path &sourcePath) const;
132122

133123
void handleFailedFunctions(tests::TestsMap &testsMap);
134124

@@ -146,29 +136,25 @@ class KleeGenerator {
146136
std::optional<utbot::CompileCommand>
147137
getCompileCommandForKlee(const fs::path &hintPath,
148138
const CollectionUtils::FileSet &stubSources,
149-
const std::vector<std::string> &flags) const;
139+
const std::vector<std::string> &flags,
140+
bool forStub) const;
150141

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

155146
private:
156-
const utbot::ProjectContext projectContext;
157-
const utbot::SettingsContext settingsContext;
158-
fs::path projectTmpPath;
159-
std::shared_ptr<CompilationDatabase> compilationDatabase;
147+
BaseTestGen *testGen;
160148
types::TypesHandler typesHandler;
161149
PathSubstitution pathSubstitution;
162-
std::shared_ptr<BuildDatabase> buildDatabase;
163-
const ProgressWriter *progressWriter;
164150

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

167153
fs::path writeKleeFile(
168-
printer::KleePrinter &kleePrinter,
169-
Tests const &tests,
170-
const std::shared_ptr<LineInfo> &lineInfo,
171-
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
154+
printer::KleePrinter &kleePrinter,
155+
Tests const &tests,
156+
const std::shared_ptr<LineInfo> &lineInfo,
157+
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter =
172158
[](tests::Tests::MethodDescription const &) { return true; });
173159
};
174160

server/src/Paths.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Paths {
2727
CollectionUtils::FileSet filtered =
2828
CollectionUtils::filterOut(paths, [&dirPaths, &filter](const fs::path &path) {
2929
return !std::any_of(dirPaths.begin(), dirPaths.end(), [&](const fs::path &dirPath) {
30-
return path.parent_path() == dirPath && fs::exists(path) && filter(path);
30+
return isSubPathOf(dirPath, path) && fs::exists(path) && filter(path);
3131
});
3232
});
3333
return filtered;

server/src/ProjectTarget.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

server/src/ProjectTarget.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

server/src/ReturnTypesFetcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void ReturnTypesFetcher::fetch(ProgressWriter *const progressWriter,
1010
testsMap[filePath];
1111
}
1212
Fetcher(Fetcher::Options::Value::RETURN_TYPE_NAMES_ONLY,
13-
testGen->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
13+
testGen->getTargetBuildDatabase()->compilationDatabase, testsMap, nullptr, nullptr, nullptr,
1414
testGen->compileCommandsJsonPath, false)
1515
.fetchWithProgress(progressWriter, "Fetching return types for functions", true);
1616
for (auto const &[sourceFilePath, test] : testsMap) {

0 commit comments

Comments
 (0)