Skip to content

Commit 9920184

Browse files
author
Samat Gaynutdinov
committed
change to relative in TestMakefilesPrinter
1 parent ecf8e27 commit 9920184

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,22 @@ namespace printer {
148148
Paths::getUTBotRootDir(), Paths::getAccessPrivateLibPath()));
149149
declareVariable("asanLib", Paths::getAsanLibraryPath());
150150

151-
declareVariable("clang", getRelativePathWithShellVariable(
151+
declareVariableIfNotDefined("clang", getRelativePathWithShellVariable(
152152
Paths::getUTBotInstallDir(), Paths::getUTBotClang()));
153-
declareVariable("clangpp", stringFormat("%s/bin/clang++", pathToShellVariable.at(Paths::getUTBotInstallDir())));
153+
declareVariableIfNotDefined("clangpp", stringFormat("%s/bin/clang++", pathToShellVariable.at(Paths::getUTBotInstallDir())));
154154
// declareAction(stringFormat("clangpp = %s", getRelativePathWithShellVariable(
155155
// Paths::getUTBotInstallDir(), Paths::getUTBotClangPP())));
156-
declareVariable("gcc", Paths::getGcc());
157-
declareVariable("gpp", Paths::getGpp());
156+
declareVariableIfNotDefined("gcc", Paths::getGcc());
157+
declareVariableIfNotDefined("gpp", Paths::getGpp());
158+
//
159+
// declareVariableIfNotDefined("CC", getShellByCompiler(primaryCompiler));
160+
// declareVariableIfNotDefined("CXX", getShellByCompiler(primaryCxxCompiler));
158161

159-
declareVariableIfNotDefined("CC", getShellByCompiler(primaryCompiler));
160-
declareVariableIfNotDefined("CXX", getShellByCompiler(primaryCxxCompiler));
162+
declareVariableIfNotDefined("ar", Paths::getAr());
163+
declareVariableIfNotDefined("ld", Paths::getLd());
164+
declareVariableIfNotDefined("ldGold", Paths::getLdGold());
161165

162-
declareVariable("ar", Paths::getAr());
163-
declareVariable("ld", Paths::getLd());
164-
declareVariable("ldGold", Paths::getLdGold());
165-
166-
declareVariableIfNotDefined("CxxLinker", getShellByLinker(cxxLinker));
166+
// declareVariableIfNotDefined("CxxLinker", getShellByLinker(cxxLinker));
167167

168168
// here we possibly erase mapping of someLinker -> shellVar but we don't care since we only use
169169
// cxxLinker, primaryCompiler and primaryCxxCompiler later on for reference
@@ -175,7 +175,7 @@ namespace printer {
175175

176176
declareVariable("asanLib", Paths::getAsanLibraryPath());
177177

178-
declareVariable("gtest", getRelativePathWithShellVariable(
178+
declareVariableIfNotDefined("gtest", getRelativePathWithShellVariable(
179179
Paths::getUTBotRootDir(), Paths::getGtestLibPath()));
180180

181181
declareVariable("project_dir", stringFormat("%s/%s", "$(makefile_dir)", "$(project_dir_relative_to_makefile)"));
@@ -242,7 +242,7 @@ namespace printer {
242242

243243
declareTarget(gtestAllObjectFile, {gtestCompilationArguments.getSourcePath() },
244244
{ gtestCompilationArguments.toStringWithChangingDirectory() });
245-
declareVariableIfNotDefined("GTEST_ALL", gtestAllObjectFile);
245+
declareVariable("GTEST_ALL", gtestAllObjectFile);
246246

247247
artifacts.push_back(gtestAllObjectFile);
248248
}
@@ -261,7 +261,7 @@ namespace printer {
261261
gtestCompilationArguments.setOutput(gtestMainObjectFile);
262262
declareTarget(gtestMainObjectFile, { gtestCompilationArguments.getSourcePath() },
263263
{ gtestCompilationArguments.toStringWithChangingDirectory() });
264-
declareVariableIfNotDefined("GTEST_MAIN", gtestMainObjectFile);
264+
declareVariable("GTEST_MAIN", gtestMainObjectFile);
265265

266266
artifacts.push_back(gtestMainObjectFile);
267267
}

server/src/printers/NativeMakefilePrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace printer {
1616
static const std::string FORCE = ".FORCE";
1717

1818
class NativeMakefilePrinter : public DefaultMakefilePrinter {
19+
friend class TestMakefilesPrinter;
1920
private:
2021
const utbot::ProjectContext projectContext;
2122
shared_ptr<BuildDatabase> buildDatabase;

server/src/printers/TestMakefilesPrinter.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
#include <utility>
99
#include <utils/MakefileUtils.h>
10+
#include "utils/StringUtils.h"
1011

1112
namespace printer {
13+
using StringUtils::stringFormat;
14+
1215
fs::path getMakefilePathForShared(fs::path path) {
1316
return Paths::addSuffix(Paths::addPrefix(path, "__"), "_shared");
1417
}
@@ -66,36 +69,52 @@ namespace printer {
6669
fs::path sharedMakefilePath = getMakefilePathForShared(generalMakefilePath);
6770
fs::path objMakefilePath = getMakefilePathForObject(generalMakefilePath);
6871

72+
generalMakefilePrinter.declareVariable("project_dir_relative_to_makefile",
73+
fs::relative(projectContext.projectPath, path));
74+
generalMakefilePrinter.declareVariable("makefile_dir", "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))");
75+
generalMakefilePrinter.declareVariable("project_dir",
76+
stringFormat("%s/%s", "$(makefile_dir)", "$(project_dir_relative_to_makefile)"));
77+
generalMakefilePrinter.declareVariable("build_relative", objMakefilePrinter.buildDirectoryRelative);
78+
generalMakefilePrinter.declareVariable("build_dir", stringFormat("%s/%s",
79+
objMakefilePrinter.pathToShellVariable.at(projectContext.projectPath),
80+
objMakefilePrinter.pathToShellVariable.at(objMakefilePrinter.buildDirectoryRelative)));
81+
82+
6983
generalMakefilePrinter.declareTarget(FORCE, {}, {});
7084

85+
const std::string sharedMakefilePathRelative =
86+
sharedMakefilePrinter.getRelativePathWithShellVariableForProjectDirOrBuildDirOrRootDir(sharedMakefilePath);
87+
const std::string objMakefilePathRelative =
88+
objMakefilePrinter.getRelativePathWithShellVariableForProjectDirOrBuildDirOrRootDir(objMakefilePath);
7189
generalMakefilePrinter.declareTarget("bin", {FORCE}, {
7290
StringUtils::joinWith(
73-
MakefileUtils::getMakeCommand(sharedMakefilePath.string(), "bin", true),
91+
MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "bin", true),
7492
" ")
7593
});
7694
generalMakefilePrinter.declareTarget("build", {FORCE}, {
7795
StringUtils::stringFormat("%s || %s",
7896
StringUtils::joinWith(MakefileUtils::getMakeCommand(
79-
sharedMakefilePath.string(), "build", true), " "),
97+
sharedMakefilePathRelative, "build", true), " "),
8098
StringUtils::joinWith(MakefileUtils::getMakeCommand(
81-
objMakefilePath.string(), "build", true), " "))
99+
objMakefilePathRelative, "build", true), " "))
82100
});
101+
83102
generalMakefilePrinter.declareTarget("run", {FORCE}, {
84103
StringUtils::stringFormat("%s && { %s; exit $$?; } || { %s && { %s; exit $$?; } }",
85104
StringUtils::joinWith(MakefileUtils::getMakeCommand(
86-
sharedMakefilePath.string(), "build", true), " "),
105+
sharedMakefilePathRelative, "build", true), " "),
87106
StringUtils::joinWith(MakefileUtils::getMakeCommand(
88-
sharedMakefilePath.string(), "run", true), " "),
107+
sharedMakefilePathRelative, "run", true), " "),
89108
StringUtils::joinWith(MakefileUtils::getMakeCommand(
90-
objMakefilePath.string(), "build", true), " "),
109+
objMakefilePathRelative, "build", true), " "),
91110
StringUtils::joinWith(MakefileUtils::getMakeCommand(
92-
objMakefilePath.string(), "run", true), " "))
111+
objMakefilePathRelative, "run", true), " "))
93112
});
94113
generalMakefilePrinter.declareTarget("clean", {FORCE}, {
95114
StringUtils::joinWith(
96-
MakefileUtils::getMakeCommand(sharedMakefilePath.string(), "clean", true), " "),
115+
MakefileUtils::getMakeCommand(sharedMakefilePathRelative, "clean", true), " "),
97116
StringUtils::joinWith(
98-
MakefileUtils::getMakeCommand(objMakefilePath.string(), "clean", true), " ")
117+
MakefileUtils::getMakeCommand(objMakefilePathRelative, "clean", true), " ")
99118
});
100119

101120
return {generalMakefilePath,

0 commit comments

Comments
 (0)