Skip to content

Commit 29e7ab5

Browse files
committed
Generator: Fix processing arguments when chaning absolute paths
The bug there is that it was not resetting 'previousIsDashI' back to false in the loop. As a result, some other arguments were prepended with the path which would make them ignored. This patch also chanfe a std::for_each into a normal for and fix identation.
1 parent 6fa0e7e commit 29e7ab5

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

generator/main.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,26 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
218218
// This code change all the paths to be absolute paths
219219
// FIXME: it is a bit fragile.
220220
bool previousIsDashI = false;
221-
std::for_each(command.begin(), command.end(), [&](std::string &A) {
221+
for(std::string &A : command) {
222222
if (previousIsDashI && !A.empty() && A[0] != '/') {
223223
A = Directory % "/" % A;
224-
return;
224+
previousIsDashI = false;
225+
continue;
225226
} else if (A == "-I") {
226227
previousIsDashI = true;
227-
return;
228+
continue;
228229
}
229230
previousIsDashI = false;
230-
if (A.empty()) return;
231-
if (llvm::StringRef(A).startswith("-I") && A[2] != '/') {
232-
A = "-I" % Directory % "/" % llvm::StringRef(A).substr(2);
233-
return;
234-
}
235-
if (A[0] == '-' || A[0] == '/') return;
236-
std::string PossiblePath = Directory % "/" % A;
231+
if (A.empty()) continue;
232+
if (llvm::StringRef(A).startswith("-I") && A[2] != '/') {
233+
A = "-I" % Directory % "/" % llvm::StringRef(A).substr(2);
234+
continue;
235+
}
236+
if (A[0] == '-' || A[0] == '/') continue;
237+
std::string PossiblePath = Directory % "/" % A;
237238
if (llvm::sys::fs::exists(PossiblePath))
238-
A = PossiblePath;
239-
} );
239+
A = PossiblePath;
240+
}
240241

241242
#if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR < 6
242243
auto Ajust = [&](clang::tooling::ArgumentsAdjuster &&aj) { command = aj.Adjust(command); };

0 commit comments

Comments
 (0)