[PATCH] D19842: In openFileForRead, attempt to fetch the actual name of the file on disk -- including case -- so that clang can later warn about non-portable #include and #import directives.

Bruno Cardoso Lopes via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 17:56:49 PDT 2016


bruno added a comment.

Hi Eric,

Sorry for the delay

> Ah, we're talking about 2 different things. You want to: (a) get the absolute path(?), (b) resolve symlinks, and (c) eliminate "." and ".." components from the path. That is precisely `realpath`'s purpose.


Right.

> I want to get the proper case for a path. `realpath` doesn't (necessarily) do that, so I have to fart around doing platform-specific-y things that are likely to succeed. I have no data to suggest that those platform-specific-y things are better at `realpath`'s job than `realpath` is.


What I'm suggesting here is that you abstract everything that guarantees returning the realpath (as in absolute, etc) into a separate function, lets call it `canonical_path`, even if that means that the only reliable option is calling the `realpath` function itself. Since on windows it's a different function, I see much value in having that abstracted out into a OS independent function. Additionally, I believe some of the magic you are current doing could be used as a fast path to obtain the absolute path as well, right? The more you could use that magic in `canonical_path` the better, It would be awesome to have fast paths for that.

> If I factored this code out into an API, I wouldn't call it `canonicalize` or `realpath`; I'd call it something like `try_get_real_case` or some such. Do you think something like that would be generally useful?


Something along the lines of a `getPathRealCase` returning a bool seems fine to me. This function can do any necessary magic but also call `canonical_path` whenever it needs OS independent `realpath` fallback. Does that make sense?


================
Comment at: lib/Support/Unix/Path.inc:522
@@ +521,3 @@
+  // Attempt to get the real name of the file, if the user asked
+  if(!RealPath)
+    return std::error_code();
----------------
space between "if" and "("


http://reviews.llvm.org/D19842





More information about the llvm-commits mailing list