Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: tools/clang/plugins/ChromeClassTester.cpp

Issue 2318733002: clang plugin: Compute absolute paths on Windows as well. (Closed)
Patch Set: compile Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/ChromeClassTester.cpp
diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp
index cd508068e111399c0319dbebc49e707bd94fcea4..080cb96514a75c2afb7e93c4eacfbcd1b1af275b 100644
--- a/tools/clang/plugins/ChromeClassTester.cpp
+++ b/tools/clang/plugins/ChromeClassTester.cpp
@@ -16,6 +16,9 @@
#ifdef LLVM_ON_UNIX
#include <sys/param.h>
#endif
+#if defined(LLVM_ON_WIN32)
+#include <windows.h>
+#endif
using namespace clang;
using chrome_checker::Options;
@@ -119,27 +122,46 @@ bool ChromeClassTester::InBannedDirectory(SourceLocation loc) {
#if defined(LLVM_ON_UNIX)
// Resolve the symlinktastic relative path and make it absolute.
- char resolvedPath[MAXPATHLEN];
if (options_.no_realpath) {
// Same reason as windows below, but we don't need to do
// the '\\' manipulation on linux.
filename.insert(filename.begin(), '/');
} else if (realpath(filename.c_str(), resolvedPath)) {
+ char resolvedPath[MAXPATHLEN];
filename = resolvedPath;
}
#endif
#if defined(LLVM_ON_WIN32)
- std::replace(filename.begin(), filename.end(), '\\', '/');
+ // Make path absolute.
+ if (options_.no_realpath) {
+ // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the
+ // "/gen/" banned_dir work.
+ filename.insert(filename.begin(), '/');
+ } else {
+ // The Windows dance: Convert to UTF-16, call GetFullPathNameW, convert back
+ // Use vector instead of string because string doesn't guarantee continuous
dcheng 2016/09/09 17:20:57 According to my thorough scientific research of Go
Nico 2016/09/09 17:52:14 Done. (Why didn't the make data() return non-const
+ // storage in theory.
+ DWORD size_needed =
+ MultiByteToWideChar(CP_UTF8, 0, filename.data(), -1, nullptr, 0);
+ std::vector<WCHAR> utf16(size_needed);
+ MultiByteToWideChar(CP_UTF8, 0, filename.data(), -1,
+ utf16.data(), size_needed);
+
+ size_needed = GetFullPathName(utf16.data(), 0, nullptr, nullptr) + 1; // nul
+ std::vector<WCHAR> full_utf16(size_needed, 0);
+ GetFullPathNameW(utf16.data(), full_utf16.size(), full_utf16.data(),
+ nullptr);
+
+ size_needed = WideCharToMultiByte(CP_UTF8, 0, full_utf16.data(), -1,
+ nullptr, 0, nullptr, nullptr);
+ std::vector<char> utf8(size_needed);
+ WideCharToMultiByte(CP_UTF8, 0, full_utf16.data(), -1, utf8.data(),
+ size_needed, nullptr, nullptr);
+ filename.assign(utf8.begin(), utf8.end());
+ }
- // On Posix, realpath() has made the path absolute. On Windows, this isn't
- // necessarily true, so prepend a '/' to the path to make sure the
- // banned_directories_ loop below works correctly.
- // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the
- // "/gen/" banned_dir work.
- // This seems simpler than converting to utf16, calling GetFullPathNameW(),
- // and converting back to utf8.
- filename.insert(filename.begin(), '/');
+ std::replace(filename.begin(), filename.end(), '\\', '/');
#endif
for (const std::string& allowed_dir : allowed_directories_) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698