Skip to content

Commit 610f847

Browse files
author
Samat Gaynutdinov
committed
link & gtest command finished & add env vars to makefile
1 parent 6a7b771 commit 610f847

File tree

14 files changed

+179
-55
lines changed

14 files changed

+179
-55
lines changed

server/src/Paths.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,20 @@ namespace Paths {
194194
return getArtifactsRootDir(projectContext) / "tests";
195195
}
196196
fs::path getMakefileDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
197-
return getArtifactsRootDir(projectContext) / "make" / getRelativeDirPath(projectContext, sourceFilePath);
197+
// return getArtifactsRootDir(projectContext) / "make" / getRelativeDirPath(projectContext, sourceFilePath);
198+
return getGeneratedHeaderDir(projectContext, sourceFilePath);
198199
}
199200
fs::path getGeneratedHeaderDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
200201
return projectContext.testDirPath / getRelativeDirPath(projectContext, sourceFilePath);
201202
}
202203
fs::path getRecompiledDir(const utbot::ProjectContext &projectContext) {
203-
return getTmpDir(projectContext.projectName) / "recompiled";
204+
return getTmpDir(projectContext) / "recompiled";
204205
}
205206
fs::path getTestObjectDir(const utbot::ProjectContext &projectContext) {
206-
return getTmpDir(projectContext.projectName) / "test_objects";
207+
return getTmpDir(projectContext) / "test_objects";
207208
}
208209
fs::path getCoverageDir(const utbot::ProjectContext &projectContext) {
209-
return getTmpDir(projectContext.projectName) / "coverage";
210+
return getTmpDir(projectContext) / "coverage";
210211
}
211212
fs::path getClangCoverageDir(const utbot::ProjectContext &projectContext) {
212213
return getCoverageDir(projectContext) / "lcov";
@@ -249,15 +250,15 @@ namespace Paths {
249250

250251
fs::path getBuildFilePath(const utbot::ProjectContext &projectContext,
251252
const fs::path &sourceFilePath) {
252-
fs::path path = getTmpDir(projectContext.projectName) /
253+
fs::path path = getTmpDir(projectContext) /
253254
getRelativeDirPath(projectContext, sourceFilePath) /
254255
sourceFilePath.filename();
255256
return addExtension(path, ".o");
256257
}
257258

258259
fs::path getStubBuildFilePath(const utbot::ProjectContext &projectContext,
259260
const fs::path &sourceFilePath) {
260-
fs::path path = getTmpDir(projectContext.projectName) /
261+
fs::path path = getTmpDir(projectContext) /
261262
getRelativeDirPath(projectContext, sourceFilePath) /
262263
sourcePathToStubName(sourceFilePath);
263264
return addExtension(path, ".o");
@@ -359,6 +360,18 @@ namespace Paths {
359360
return fs::relative(source.parent_path(), projectContext.projectPath);
360361
}
361362

363+
std::optional<std::string> getRelativePathWithShellVariable(const string &shellVariableForBase,
364+
const fs::path &base,
365+
const fs::path &source) {
366+
367+
auto relative = fs::relative(source, base).string();
368+
if (relative.empty() || StringUtils::contains(relative, "..")) {
369+
return std::nullopt;
370+
}
371+
return std::make_optional(StringUtils::stringFormat("%s/%s", shellVariableForBase, fs::relative(source, base)));
372+
}
373+
374+
362375
fs::path stubPathToSourcePath(const utbot::ProjectContext &projectContext,
363376
const fs::path &stubPath) {
364377
fs::path sourceFilePath =
@@ -371,7 +384,13 @@ namespace Paths {
371384
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
372385
}
373386
fs::path getBuildDir(const utbot::ProjectContext &projectContext) {
374-
return getTmpDir(projectContext.projectName) / "build";
387+
return projectContext.buildDir;
388+
}
389+
390+
fs::path getTmpDir(const utbot::ProjectContext &projectContext)
391+
{
392+
fs::path mountedCCJsonDirPath = getBuildDir(projectContext) / CompilationUtils::MOUNTED_CC_JSON_DIR_NAME;
393+
return mountedCCJsonDirPath / "tmp" / RequestEnvironment::getClientId();
375394
}
376395

377396
//endregion

server/src/Paths.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,14 @@ namespace Paths {
170170
return tmpPath / "tmp" / RequestEnvironment::getClientId() / projectName;
171171
}
172172

173+
fs::path getTmpDir(const utbot::ProjectContext &projectContext);
174+
173175
fs::path getBuildDir(const utbot::ProjectContext &projectContext);
174176

177+
static inline fs::path getBuildDirRelative(const utbot::ProjectContext &projectContext) {
178+
return projectContext.buildDirRelativePath;
179+
}
180+
175181
//region json
176182
static inline fs::path getClientsJsonPath() {
177183
return tmpPath / "tmp" / "clients.json";
@@ -347,6 +353,10 @@ namespace Paths {
347353

348354
fs::path getRelativeDirPath(const utbot::ProjectContext &projectContext, const fs::path &source);
349355

356+
std::optional<std::string> getRelativePathWithShellVariable(const string& shellVariableForBase,
357+
const fs::path& base,
358+
const fs::path& source);
359+
350360
fs::path getMakefilePathFromSourceFilePath(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath,
351361
const string& suffix = "");
352362

server/src/Server.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context,
574574

575575
MEASURE_FUNCTION_EXECUTION_TIME
576576

577-
fs::path serverBuildDir = Paths::getTmpDir(request->projectname());
577+
// fs::path serverBuildDir = Paths::getTmpDir(request->projectname());
578578
utbot::ProjectContext projectContext{ *request };
579+
fs::path serverBuildDir = Paths::getTmpDir(projectContext);
579580
shared_ptr<BuildDatabase> buildDatabase = BuildDatabase::create(projectContext);
580581
StubSourcesFinder(buildDatabase).printAllModules();
581582
return Status::OK;

server/src/Synchronizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void Synchronizer::synchronizeStubs(StubSet &outdatedStubs,
155155
true);
156156

157157
fs::path ccJsonStubDirPath =
158-
Paths::getTmpDir(testGen->projectContext.projectName) / "stubs_build_files";
158+
Paths::getTmpDir(testGen->projectContext) / "stubs_build_files";
159159
auto stubsCdb = createStubsCompilationDatabase(stubFiles, ccJsonStubDirPath);
160160

161161
auto sourceToHeaderRewriter =

server/src/building/BaseCommand.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,8 @@ namespace utbot {
124124
optimizationLevel = addFlagToBegin(flag);
125125
}
126126
}
127+
128+
void BaseCommand::setDirectory(const fs::path& directory) {
129+
this->directory = directory;
130+
}
127131
}

server/src/building/BaseCommand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace utbot {
9090
size_t erase_if(std::function<bool(std::string)> f);
9191

9292
void setOptimizationLevel(const std::string &flag);
93+
94+
void setDirectory(const fs::path& directory);
9395
};
9496
}
9597

server/src/building/BuildDatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ std::shared_ptr<BuildDatabase> BuildDatabase::create(const utbot::ProjectContext
6060
fs::path compileCommandsJsonPath =
6161
CompilationUtils::substituteRemotePathToCompileCommandsJsonPath(
6262
projectContext.projectPath, projectContext.buildDirRelativePath);
63-
fs::path serverBuildDir = Paths::getTmpDir(projectContext.projectName);
63+
fs::path serverBuildDir = Paths::getTmpDir(projectContext);
6464
std::shared_ptr<BuildDatabase> buildDatabase =
6565
std::make_shared<BuildDatabase>(compileCommandsJsonPath, serverBuildDir, projectContext);
6666
return buildDatabase;

server/src/building/CompileCommand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace utbot {
111111
return *sourcePath;
112112
}
113113

114-
void CompileCommand::setSourcePath(fs::path sourcePath) {
114+
void CompileCommand::setSourcePath(std::string sourcePath) {
115115
*(this->sourcePath) = std::move(sourcePath);
116116
}
117117

@@ -131,7 +131,7 @@ namespace utbot {
131131
return false;
132132
}
133133

134-
void CompileCommand::setOutput(fs::path output) {
134+
void CompileCommand::setOutput(std::string output) {
135135
*(this->output) = std::move(output);
136136
}
137137

server/src/building/CompileCommand.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace utbot {
3939

4040
[[nodiscard]] fs::path getSourcePath() const;
4141

42-
void setSourcePath(fs::path sourcePath);
42+
void setSourcePath(std::string sourcePath);
4343

4444
[[nodiscard]] fs::path getCompiler() const;
4545

@@ -49,7 +49,7 @@ namespace utbot {
4949

5050
[[nodiscard]] bool isArchiveCommand() const override;
5151

52-
void setOutput(fs::path output);
52+
void setOutput(std::string output);
5353

5454
void removeGccFlags();
5555

server/src/environment/EnvironmentPaths.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ namespace Paths {
5050
}
5151

5252
fs::path getUTBotClang() {
53-
return getUTBotInstallDir() / "bin/clang";
53+
return getUTBotInstallDir() / "bin" / "clang";
5454
}
5555

5656
fs::path getUTBotClangPP() {
57-
return getUTBotInstallDir() / "bin/clang++";
57+
return getUTBotInstallDir() / "bin" / "clang++";
5858
}
5959

6060
fs::path getGcc() {

0 commit comments

Comments
 (0)