Skip to content

Commit c312f4d

Browse files
Vladislav Kaluginladisgin
Vladislav Kalugin
authored andcommitted
Fix incorrect work with relative paths in include flags
1 parent 6cc816c commit c312f4d

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

server/src/building/ProjectBuildDatabse.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
#include "ProjectBuildDatabase.h"
2+
23
#include "utils/GrpcUtils.h"
34
#include "exceptions/CompilationDatabaseException.h"
45
#include "utils/JsonUtils.h"
56
#include "loguru.h"
67
#include "utils/StringUtils.h"
8+
#include "utils/CompilationUtils.h"
79

10+
static std::string tryConvertToFullPath(const std::string &possibleFilePath, const fs::path &dirPath) {
11+
fs::path fullFilePath = Paths::getCCJsonFileFullPath(possibleFilePath, dirPath);
12+
return fs::exists(fullFilePath) ? fullFilePath.string() : possibleFilePath;
13+
}
814

9-
static std::string tryConvertOptionToPath(const std::string &possibleFilePath,
10-
const fs::path &dirPath) {
11-
if (StringUtils::startsWith(possibleFilePath, "-")) {
12-
return possibleFilePath;
13-
}
14-
fs::path fullFilePath;
15+
static std::string tryConvertOptionToPath(const std::string &possibleFilePath, const fs::path &dirPath) {
16+
std::string resOption;
1517
try {
16-
fullFilePath = Paths::getCCJsonFileFullPath(possibleFilePath, dirPath);
18+
if (StringUtils::startsWith(possibleFilePath, "-I")) {
19+
resOption = CompilationUtils::getIncludePath(tryConvertToFullPath(possibleFilePath.substr(2), dirPath));
20+
} else if (!StringUtils::startsWith(possibleFilePath, "-")) {
21+
resOption = tryConvertToFullPath(possibleFilePath, dirPath);
22+
} else {
23+
resOption = possibleFilePath;
24+
}
1725
} catch (...) {
1826
return possibleFilePath;
1927
}
20-
return fs::exists(fullFilePath) ? fullFilePath.string() : possibleFilePath;
28+
return resOption;
2129
}
2230

2331
ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ namespace printer {
653653
return;
654654
}
655655
// if in -I flag
656-
if (argument.length() >= 3 && StringUtils::startsWith(argument, "-I")) {
656+
if (StringUtils::startsWith(argument, "-I/")) {
657657
argument = CompilationUtils::getIncludePath(getRelativePath(argument.substr(2)).string());
658658
}
659659
}

server/src/printers/RelativeMakefilePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ RelativeMakefilePrinter::RelativeMakefilePrinter(
2727
initializePathsToShellVariables();
2828
}
2929

30-
fs::path RelativeMakefilePrinter::getRelativePath(fs::path source) const {
30+
fs::path RelativeMakefilePrinter::getRelativePath(const fs::path &source) const {
3131
return getRelativePath(source, true);
3232
}
3333

server/src/printers/RelativeMakefilePrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RelativeMakefilePrinter : public DefaultMakefilePrinter {
2727

2828
// map variable with absolute path to $(someVar)
2929
std::map<std::string, fs::path, std::function<bool(const std::string&, const std::string&)>> pathToShellVariable;
30-
fs::path getRelativePath(fs::path source) const;
30+
fs::path getRelativePath(const fs::path &source) const;
3131
void declareShellVariable(const std::string& variableName, fs::path path,
3232
std::function<void(const std::string&, const std::string&)> shellVariableDeclarationFunction,
3333
bool shouldWriteToMap = true, bool isCanonical = true);

0 commit comments

Comments
 (0)