Skip to content

[lldb] Fix ApplyWorkingDir not properly handling . includes when working dir is . #7061

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

Merged
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
4 changes: 4 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,10 @@ void SwiftASTContext::ApplyWorkingDir(
llvm::SmallString<128> joined_path;
llvm::sys::path::append(joined_path, cur_working_dir, arg);
llvm::sys::path::remove_dots(joined_path);
// remove_dots can return an empty string if given a . or chain of ./.
if (joined_path.empty())
joined_path = ".";

clang_argument.resize(prefix.size());
clang_argument.append(joined_path.begin(), joined_path.end());
}
Expand Down
11 changes: 11 additions & 0 deletions lldb/unittests/Symbol/TestSwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TEST_F(TestSwiftASTContext, SwiftFriendlyTriple) {
TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
std::string abs_working_dir = "/abs/dir";
std::string rel_working_dir = "rel/dir";
std::string dot_working_dir = ".";

// non-include option should not apply working dir
llvm::SmallString<128> non_include_flag("-non-include-flag");
Expand Down Expand Up @@ -154,6 +155,16 @@ TEST_F(TestSwiftASTContext, ApplyWorkingDir) {
EXPECT_EQ(module_file_with_name_rel_path,
llvm::SmallString<128>(
"-fmodule-file=modulename=/abs/dir/relpath/module.pcm"));

// include path arg with cwd = .
llvm::SmallString<128> dot_rel_path("-iquoterel/path");
SwiftASTContext::ApplyWorkingDir(dot_rel_path, dot_working_dir);
EXPECT_EQ(dot_rel_path, llvm::SmallString<128>("-iquoterel/path"));

// . include path arg with cwd = . should stay as .
llvm::SmallString<128> dot_dot_path("-iquote.");
SwiftASTContext::ApplyWorkingDir(dot_dot_path, dot_working_dir);
EXPECT_EQ(dot_dot_path, llvm::SmallString<128>("-iquote."));
}

namespace {
Expand Down