Skip to content
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

Reformat build structure #457

Merged
merged 5 commits into from
Sep 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/build-utbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ jobs:
- name: Check test portability
run: |
rm -r /home/runner/work/UTBotCpp/UTBotCpp/c-example/build
env make -f /home/runner/work/UTBotCpp/UTBotCpp/c-example/tests/lib/floats/floating_point_plain.mk run GTEST_FLAGS="--gtest_filter=*.plain_isnan_test_1" CLANG="/usr/bin/clang-10" CLANGXX="/usr/bin/clang++-10" GTEST="/gtest"
env make -f /home/runner/work/UTBotCpp/UTBotCpp/c-example/tests/makefiles/lib/floats/floating_point_plain.mk run GTEST_FLAGS="--gtest_filter=*.plain_isnan_test_1" CLANG="/usr/bin/clang-10" CLANGXX="/usr/bin/clang++-10" GTEST="/gtest"
13 changes: 5 additions & 8 deletions server/src/KleeRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ namespace {
}

KleeRunner::KleeRunner(utbot::ProjectContext projectContext,
utbot::SettingsContext settingsContext,
fs::path serverBuildDir)
: projectContext(std::move(projectContext)), settingsContext(std::move(settingsContext)),
projectTmpPath(std::move(serverBuildDir)) {
utbot::SettingsContext settingsContext)
: projectContext(std::move(projectContext)), settingsContext(std::move(settingsContext)) {
}

void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
Expand All @@ -59,7 +57,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
StatsUtils::TestsGenerationStatsFileMap &generationStats) {
LOG_SCOPE_FUNCTION(DEBUG);

fs::path kleeOutDir = Paths::getKleeOutDir(projectTmpPath);
fs::path kleeOutDir = Paths::getKleeOutDir(projectContext);
if (fs::exists(kleeOutDir)) {
FileSystemUtils::removeAll(kleeOutDir);
}
Expand Down Expand Up @@ -105,7 +103,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
} else {
processBatchWithoutInteractive(batch, tests, ktests);
}
auto kleeStats = writeKleeStats(Paths::kleeOutDirForFilePath(projectContext, projectTmpPath, filePath));
auto kleeStats = writeKleeStats(Paths::kleeOutDirForFilePath(projectContext, filePath));
generator->parseKTestsToFinalCode(tests, methodNameToReturnTypeMap, ktests, lineInfo,
settingsContext.verbose);
generationStats.addFileStats(kleeStats, tests);
Expand All @@ -116,7 +114,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
std::function<void()> prepareTotal = [&]() {
testsWriter->writeReport(sarif::sarifPackResults(sarifResults),
"Sarif Report was created",
projectContext.projectPath / sarif::SARIF_DIR_NAME / sarif::SARIF_FILE_NAME);
Paths::getUTBotReportDir(projectContext) / sarif::SARIF_FILE_NAME);
};

testsWriter->writeTestsWithProgress(
Expand Down Expand Up @@ -212,7 +210,6 @@ KleeRunner::createKleeParams(const tests::TestMethod &testMethod,
const tests::Tests &tests,
const std::string &methodNameOrEmptyForFolder) {
fs::path kleeOut = Paths::kleeOutDirForEntrypoints(projectContext,
projectTmpPath,
tests.sourceFilePath,
methodNameOrEmptyForFolder);
fs::create_directories(kleeOut.parent_path());
Expand Down
4 changes: 1 addition & 3 deletions server/src/KleeRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class KleeRunner {
public:
KleeRunner(utbot::ProjectContext projectContext,
utbot::SettingsContext settingsContext,
fs::path serverBuildDir);
utbot::SettingsContext settingsContext);
/**
* @brief Passes arguments to `run_klee.cpp` and executes it.
*
Expand All @@ -39,7 +38,6 @@ class KleeRunner {
private:
const utbot::ProjectContext projectContext;
const utbot::SettingsContext settingsContext;
fs::path projectTmpPath;

void processBatchWithoutInteractive(const std::vector<tests::TestMethod> &testMethods,
tests::Tests &tests,
Expand Down
23 changes: 9 additions & 14 deletions server/src/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ namespace Paths {
return errFiles;
}

fs::path kleeOutDirForFilePath(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
const fs::path &filePath) {
fs::path kleeOutDir = getKleeOutDir(projectTmpPath);
fs::path kleeOutDirForFilePath(const utbot::ProjectContext &projectContext, const fs::path &filePath) {
fs::path kleeOutDir = getKleeOutDir(projectContext);
fs::path relative = fs::relative(addOrigExtensionAsSuffixAndAddNew(filePath, ""), projectContext.projectPath);
return kleeOutDir / relative;
}

fs::path kleeOutDirForEntrypoints(const utbot::ProjectContext &projectContext,
const fs::path &projectTmpPath,
const fs::path &srcFilePath,
const std::string &methodNameOrEmptyForFolder) {
auto kleeOutDirForFile = kleeOutDirForFilePath(projectContext, projectTmpPath, srcFilePath);
auto kleeOutDirForFile = kleeOutDirForFilePath(projectContext, srcFilePath);
std::string suffix = methodNameOrEmptyForFolder.empty()
? addOrigExtensionAsSuffixAndAddNew(srcFilePath, "").filename().string()
: methodNameOrEmptyForFolder;
Expand Down Expand Up @@ -218,7 +216,7 @@ namespace Paths {
return getArtifactsRootDir(projectContext) / "tests";
}
fs::path getMakefileDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
return projectContext.testDirPath / "makefiles" / getRelativeDirPath(projectContext, sourceFilePath);
}
fs::path getGeneratedHeaderDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
Expand All @@ -229,13 +227,13 @@ namespace Paths {
}

fs::path getRecompiledDir(const utbot::ProjectContext &projectContext) {
return getUtbotBuildDir(projectContext) / "recompiled";
return getUTBotBuildDir(projectContext) / "recompiled";
}
fs::path getTestObjectDir(const utbot::ProjectContext &projectContext) {
return getUtbotBuildDir(projectContext) / "test_objects";
return getUTBotBuildDir(projectContext) / "test_objects";
}
fs::path getCoverageDir(const utbot::ProjectContext &projectContext) {
return getUtbotBuildDir(projectContext) / "coverage";
return getUTBotBuildDir(projectContext) / "coverage";
}
fs::path getClangCoverageDir(const utbot::ProjectContext &projectContext) {
return getCoverageDir(projectContext) / "lcov";
Expand Down Expand Up @@ -278,15 +276,15 @@ namespace Paths {

fs::path getBuildFilePath(const utbot::ProjectContext &projectContext,
const fs::path &sourceFilePath) {
fs::path path = getUtbotBuildDir(projectContext) /
fs::path path = getUTBotBuildDir(projectContext) /
getRelativeDirPath(projectContext, sourceFilePath) /
sourceFilePath.filename();
return addExtension(path, ".o");
}

fs::path getStubBuildFilePath(const utbot::ProjectContext &projectContext,
const fs::path &sourceFilePath) {
fs::path path = getUtbotBuildDir(projectContext) /
fs::path path = getUTBotBuildDir(projectContext) /
getRelativeDirPath(projectContext, sourceFilePath) /
sourcePathToStubName(sourceFilePath);
return addExtension(path, ".o");
Expand Down Expand Up @@ -410,9 +408,6 @@ namespace Paths {
bool isHeadersEqual(const fs::path &srcPath, const fs::path &headerPath) {
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
}
fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext) {
return projectContext.buildDir() / CompilationUtils::UTBOT_BUILD_DIR_NAME;
}

//endregion

Expand Down
24 changes: 15 additions & 9 deletions server/src/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,16 @@ namespace Paths {

//endregion

fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext);
static inline fs::path getUTBotFiles(const utbot::ProjectContext &projectContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return thsi function to cpp file

return projectContext.buildDir() / CompilationUtils::UTBOT_FILES_DIR_NAME;
}

static inline fs::path getUTBotBuildDir(const utbot::ProjectContext &projectContext) {
return getUTBotFiles(projectContext) / CompilationUtils::UTBOT_BUILD_DIR_NAME;
}

static inline fs::path getRelativeUtbotBuildDir(const utbot::ProjectContext &projectContext) {
return fs::relative(getUtbotBuildDir(projectContext), projectContext.projectPath);
return fs::relative(getUTBotBuildDir(projectContext), projectContext.projectPath);
}

//region json
Expand All @@ -218,8 +224,8 @@ namespace Paths {
return getBaseLogDir() / "klee_tmp_log.txt";
}

static inline fs::path getKleeOutDir(const fs::path &projectTmpPath) {
return projectTmpPath / "klee_out";
static inline fs::path getKleeOutDir(const utbot::ProjectContext &projectContext) {
return getUTBotFiles(projectContext) / "klee_out";
}

static inline bool isKtest(fs::path const &path) {
Expand All @@ -239,11 +245,9 @@ namespace Paths {

std::vector<fs::path> getErrorDescriptors(fs::path const &path);

fs::path kleeOutDirForFilePath(const utbot::ProjectContext &projectContext, const fs::path &projectTmpPath,
const fs::path &filePath);
fs::path kleeOutDirForFilePath(const utbot::ProjectContext &projectContext, const fs::path &filePath);

fs::path kleeOutDirForEntrypoints(const utbot::ProjectContext &projectContext,
const fs::path &projectTmpPath,
const fs::path &srcFilePath,
const std::string &methodNameOrEmptyForFolder);

Expand Down Expand Up @@ -417,10 +421,12 @@ namespace Paths {

//endregion

//region utbot-report
//region utbot_report

const std::string UTBOT_REPORT = "utbot_report";

inline fs::path getUTBotReportDir(const utbot::ProjectContext &projectContext) {
return projectContext.projectPath / "utbot-report";
return projectContext.projectPath / UTBOT_REPORT;
}

inline fs::path getGenerationStatsCSVPath(const utbot::ProjectContext &projectContext) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/SARIFGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace sarif {
const fs::path &srcPath = fs::path(stack_match[3]);
const fs::path &relPathInProject = getInProjectPath(projectContext.projectPath, srcPath);
const fs::path &fullPathInProject = projectContext.projectPath / relPathInProject;
if (Paths::isSubPathOf(Paths::getUtbotBuildDir(projectContext), fullPathInProject)) {
if (Paths::isSubPathOf(Paths::getUTBotBuildDir(projectContext), fullPathInProject)) {
LOG_S(WARNING) << "Full path " << fullPathInProject << " is in build - skip it";
continue;
}
Expand Down
1 change: 0 additions & 1 deletion server/src/SARIFGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace sarif {
const std::string TEST_NAME_KEY = "TestName";
const std::string ERROR_ID_KEY = "ErrorId";

const std::string SARIF_DIR_NAME = "codeAnalysis";
const std::string SARIF_FILE_NAME = "project_code_analysis.sarif";

void sarifAddTestsToResults(const utbot::ProjectContext &projectContext,
Expand Down
5 changes: 2 additions & 3 deletions server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
Linker linker{testGen, stubGen, lineInfo, generator};
linker.prepareArtifacts();
auto testMethods = linker.getTestMethods();
KleeRunner kleeRunner{testGen.projectContext, testGen.settingsContext,
testGen.serverBuildDir};
KleeRunner kleeRunner{testGen.projectContext, testGen.settingsContext};
bool interactiveMode = (dynamic_cast<ProjectTestGen *>(&testGen) != nullptr);
auto generationStartTime = std::chrono::steady_clock::now();
StatsUtils::TestsGenerationStatsFileMap generationStatsMap(testGen.projectContext,
Expand Down Expand Up @@ -578,7 +577,7 @@ Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context,
MEASURE_FUNCTION_EXECUTION_TIME

utbot::ProjectContext projectContext{*request};
fs::path serverBuildDir = Paths::getUtbotBuildDir(projectContext);
fs::path serverBuildDir = Paths::getUTBotBuildDir(projectContext);
std::shared_ptr<ProjectBuildDatabase> buildDatabase = std::make_shared<ProjectBuildDatabase>(projectContext);
StubSourcesFinder(buildDatabase).printAllModules();
return Status::OK;
Expand Down
2 changes: 1 addition & 1 deletion server/src/Synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void Synchronizer::synchronizeStubs(StubSet &outdatedStubs,
stubFetcher.fetchWithProgress(testGen->progressWriter, "Finding source files required for stubs", true);

fs::path ccJsonStubDirPath =
Paths::getUtbotBuildDir(testGen->projectContext) / "stubs_build_files";
Paths::getUTBotBuildDir(testGen->projectContext) / "stubs_build_files";
auto stubsCdb = createStubsCompilationDatabase(stubFiles, ccJsonStubDirPath);

auto sourceToHeaderRewriter =
Expand Down
9 changes: 4 additions & 5 deletions server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
}

ProjectBuildDatabase::ProjectBuildDatabase(utbot::ProjectContext projectContext) : ProjectBuildDatabase(
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext.projectPath,
projectContext.buildDirRelativePath),
Paths::getUtbotBuildDir(projectContext), std::move(projectContext)) {
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext),
Paths::getUTBotBuildDir(projectContext), std::move(projectContext)) {
}


Expand All @@ -80,8 +79,8 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
objectInfo->command = utbot::CompileCommand(jsonArguments, directory, sourceFile);
objectInfo->command.removeWerror();
fs::path outputFile = objectInfo->getOutputFile();
fs::path kleeFilePathTemplate =
Paths::createNewDirForFile(sourceFile, projectContext.buildDir(), serverBuildDir);
fs::path kleeFilePathTemplate = Paths::createNewDirForFile(sourceFile, projectContext.projectPath,
Paths::getUTBotFiles(projectContext));
fs::path kleeFile = Paths::addSuffix(kleeFilePathTemplate, "_klee");
objectInfo->kleeFilesInfo = std::make_shared<KleeFilesInfo>(kleeFile);

Expand Down
2 changes: 1 addition & 1 deletion server/src/building/UserProjectConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void UserProjectConfiguration::RunProjectConfigurationCommand(const fs::path &bu
const ProjectConfigWriter &writer) {
auto[out, status, _] = ShellExecTask::runShellCommandTask(params, buildDirPath, projectContext.projectName, true, true);
if (status != 0) {
auto logFilePath = LogUtils::writeLog(out, Paths::getUtbotBuildDir(projectContext), "project-import");
auto logFilePath = LogUtils::writeLog(out, Paths::getUTBotBuildDir(projectContext), "project-import");
std::string message = StringUtils::stringFormat(
"Running command \"%s\" failed. See more info in logs.", params.toString());
throw std::runtime_error(message);
Expand Down
3 changes: 1 addition & 2 deletions server/src/coverage/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ grpc::Status TestRunner::runTests(bool withCoverage, const std::optional<std::ch

void TestRunner::init(bool withCoverage) {
MEASURE_FUNCTION_EXECUTION_TIME
fs::path ccJson = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
projectContext.projectPath, projectContext.buildDirRelativePath);
fs::path ccJson = CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(projectContext);
coverageTool = getCoverageTool(ccJson, projectContext, progressWriter);
if (withCoverage) {
cleanCoverage();
Expand Down
2 changes: 1 addition & 1 deletion server/src/printers/NativeMakefilePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace printer {
CompilationUtils::getCoverageLinkFlags(primaryCxxCompilerName), " ")),
sanitizerLinkFlags(SanitizerUtils::getSanitizeLinkFlags(primaryCxxCompilerName)),

buildDirectory(Paths::getUtbotBuildDir(testGen->projectContext)),
buildDirectory(Paths::getUTBotBuildDir(testGen->projectContext)),
dependencyDirectory(buildDirectory / "dependencies"),
stubSources(stubSources) {

Expand Down
5 changes: 3 additions & 2 deletions server/src/printers/RelativeMakefilePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ void RelativeMakefilePrinter::declareShellVariable(const std::string& variableNa
}
}

std::string RelativeMakefilePrinter::getProjectStructureRelativeTo(fs::path path) const {
std::string RelativeMakefilePrinter::getProjectStructureRelativeTo(const fs::path &makefilePath) const {
DefaultMakefilePrinter printer;
printer.declareVariable("export PROJECT_DIR_RELATIVE_TO_MAKEFILE", fs::relative(projectPath, path));
printer.declareVariable("export PROJECT_DIR_RELATIVE_TO_MAKEFILE",
fs::relative(projectPath, makefilePath.parent_path()));
// magic spell from https://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile
printer.declareVariable("export MAKEFILE_DIR", "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))");
printer.declareVariable("export PROJECT_DIR", "$(MAKEFILE_DIR)/$(PROJECT_DIR_RELATIVE_TO_MAKEFILE)");
Expand Down
2 changes: 1 addition & 1 deletion server/src/printers/RelativeMakefilePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RelativeMakefilePrinter : public DefaultMakefilePrinter {
std::function<void(const std::string&, const std::string&)> shellVariableDeclarationFunction,
bool shouldWriteToMap = true, bool isCanonical = true);
fs::path getRelativePathForLinker(fs::path path) const;
std::string getProjectStructureRelativeTo(fs::path path) const;
std::string getProjectStructureRelativeTo(const fs::path &makefilePath) const;
};
}

Expand Down
12 changes: 6 additions & 6 deletions server/src/printers/TestMakefilesPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace printer {
fs::path const &rootPath,
fs::path primaryCompiler,
CollectionUtils::FileSet const *stubSources) :
RelativeMakefilePrinter(Paths::getUtbotBuildDir(testGen->projectContext),
RelativeMakefilePrinter(Paths::getUTBotBuildDir(testGen->projectContext),
Paths::getRelativeUtbotBuildDir(testGen->projectContext),
testGen->projectContext.projectPath),
projectContext(testGen->projectContext),
Expand All @@ -69,13 +69,13 @@ namespace printer {
objMakefilePrinter.addStubs(stubsSet);
}

TestMakefilesContent TestMakefilesPrinter::GetMakefiles(const fs::path &path) {
TestMakefilesContent TestMakefilesPrinter::GetMakefiles(const fs::path &sourcePath) {
printer::DefaultMakefilePrinter generalMakefilePrinter;
fs::path generalMakefilePath = Paths::getMakefilePathFromSourceFilePath(projectContext, path);
fs::path generalMakefilePath = Paths::getMakefilePathFromSourceFilePath(projectContext, sourcePath);
fs::path sharedMakefilePath = getMakefilePathForShared(generalMakefilePath);
fs::path objMakefilePath = getMakefilePathForObject(generalMakefilePath);

generalMakefilePrinter.ss << getProjectStructureRelativeTo(path);
generalMakefilePrinter.ss << getProjectStructureRelativeTo(generalMakefilePath);
generalMakefilePrinter.ss << ss.str();

generalMakefilePrinter.declareTarget(FORCE, {}, {});
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace printer {

return {generalMakefilePath,
generalMakefilePrinter.ss.str(),
NativeMakefilePrinter(sharedMakefilePrinter, path).ss.str(),
NativeMakefilePrinter(objMakefilePrinter, path).ss.str()};
NativeMakefilePrinter(sharedMakefilePrinter, sourcePath).ss.str(),
NativeMakefilePrinter(objMakefilePrinter, sourcePath).ss.str()};
}
}
Loading