This is an archive of the discontinued LLVM Phabricator instance.

Fix replacements for files with relative paths are not applied.
ClosedPublic

Authored by arielbernal on Oct 1 2013, 1:30 PM.

Details

Summary

D1771 was supposed to fix this but it didn't, make_absolute can't be use to check if a file is virtual. I didn't break anything either.
This patch exposes virtual entries in the FileManager to check if a filepath is a virtual file that has already been allocated.

Diff Detail

Event Timeline

I don't understand that yet. Why wouldn't make_absolute just do nothing for virtual files anyway?

A better look at make_absolute showed me that it doesn't check for the filepath to exists it just gets the current path (PWD) and then uses the current path for getting the root and relative paths, and append them to the file name. So you can actually get an absolute path to a virtual file :).
I think virtual files shouldn't be made absolute unless someone explicitly create them that way.

The test I created in D1771 is irrelevant to the patch, it doesn't hurt and in fact there should be a test to exercise the use of relative paths in a compilation database but clang-check is not creating any replacement. I'm now adding another test for this patch.

arielbernal updated this revision to Unknown Object (????).Oct 3 2013, 1:57 PM

Added unittest

klimek added inline comments.Oct 5 2013, 2:06 AM
include/clang/Basic/FileManager.h
278 ↗(On Diff #4641)

If we decided we need this (see further down), this'll need approval from Doug...

lib/Tooling/Refactoring.cpp
108

I'd always use {} if there's a more complex statement inside.

122

Can't we instead just check whether the relative file exists?
If the file is relative, and it can be accessed via the filesystem, use make_absolute; otherwise, simply use the entry name.

arielbernal added inline comments.Oct 5 2013, 9:23 PM
include/clang/Basic/FileManager.h
278 ↗(On Diff #4641)

if I use exists on the relative file then this won't be needed anymore.

lib/Tooling/Refactoring.cpp
108

yes sure

122

no problem I'll check that and upload another patch.

arielbernal updated this revision to Unknown Object (????).Oct 7 2013, 8:02 AM

Addressed comments and used exists instead of isVirtualFile.

klimek accepted this revision.Oct 8 2013, 5:30 AM

Apart from my remaining nits, LG. Thanks!

lib/Tooling/Refactoring.cpp
120

Did you change files to file on purpose? I think this makes the sentence incorrect ;)

unittests/Tooling/RefactoringTest.cpp
290

I'd EXPECT_EQ(0, chdir(...)), as the type of the chdir is not bool, and EXPECT_FALSE reads like we'd expect the command to fail.

arielbernal updated this revision to Unknown Object (????).Oct 17 2013, 10:22 AM

Fixed test since it broke OSx build.

arielbernal added inline comments.Oct 17 2013, 10:27 AM
unittests/Tooling/RefactoringTest.cpp
290

Disregard this line, it should't be here

klimek added inline comments.Oct 17 2013, 10:29 AM
unittests/Tooling/RefactoringTest.cpp
290

It's still in the updated patch, though :)

arielbernal updated this revision to Unknown Object (????).Oct 17 2013, 11:12 AM

Removed wrong setting of the current path

klimek closed this revision.May 25 2014, 1:38 AM