OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A general interface for filtering and only acting on classes in Chromium C++ | 5 // A general interface for filtering and only acting on classes in Chromium C++ |
6 // code. | 6 // code. |
7 | 7 |
8 #include "ChromeClassTester.h" | 8 #include "ChromeClassTester.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 // things through macros that were defined due to third party libraries. | 123 // things through macros that were defined due to third party libraries. |
124 if (filename == "<scratch space>") | 124 if (filename == "<scratch space>") |
125 return true; | 125 return true; |
126 | 126 |
127 // Don't complain about autogenerated protobuf files. | 127 // Don't complain about autogenerated protobuf files. |
128 if (ends_with(filename, ".pb.h")) { | 128 if (ends_with(filename, ".pb.h")) { |
129 return true; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 #if defined(LLVM_ON_UNIX) | 132 #if defined(LLVM_ON_UNIX) |
133 // We need to munge the paths so that they are relative to the repository | 133 // Resolve the symlinktastic relative path and make it absolute. |
134 // srcroot. We first resolve the symlinktastic relative path and then | |
135 // remove our known srcroot from it if needed. | |
136 char resolvedPath[MAXPATHLEN]; | 134 char resolvedPath[MAXPATHLEN]; |
137 if (realpath(filename.c_str(), resolvedPath)) { | 135 if (realpath(filename.c_str(), resolvedPath)) { |
138 filename = resolvedPath; | 136 filename = resolvedPath; |
139 } | 137 } |
140 #endif | 138 #endif |
141 | 139 |
142 #if defined(LLVM_ON_WIN32) | 140 #if defined(LLVM_ON_WIN32) |
143 std::replace(filename.begin(), filename.end(), '\\', '/'); | 141 std::replace(filename.begin(), filename.end(), '\\', '/'); |
142 | |
143 // On Posix, realpath() has made the path absolute. On Windows, this isn't | |
144 // necessarily true, so prepend a '/' to the path to make sure the | |
145 // banned_directories_ loop below works correctly. | |
146 // This turns e.g. "gen/dir/file.cc" to "/gen/dir/file.cc" which lets the | |
147 // "/gen/" banned_dir work. | |
148 // This seems simpler than converting to utf16, calling GetFullPathNameW(), | |
149 // and converting back to utf8. | |
150 filename.insert(filename.begin(), '/'); | |
dcheng
2015/04/27 22:31:21
Would it make sense to use llvm::sys::fs::make_abs
Nico
2015/04/27 22:57:00
That'd work too I suppose. Nothing wrong with "/c:
| |
144 #endif | 151 #endif |
145 | 152 |
146 for (const std::string& banned_dir : banned_directories_) { | 153 for (const std::string& banned_dir : banned_directories_) { |
147 // If any of the banned directories occur as a component in filename, | 154 // If any of the banned directories occur as a component in filename, |
148 // this file is rejected. | 155 // this file is rejected. |
149 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); | 156 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); |
150 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); | 157 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); |
151 | 158 |
152 if (filename.find(banned_dir) != std::string::npos) | 159 if (filename.find(banned_dir) != std::string::npos) |
153 return true; | 160 return true; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); | 304 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); |
298 if (ploc.isInvalid()) { | 305 if (ploc.isInvalid()) { |
299 // If we're in an invalid location, we're looking at things that aren't | 306 // If we're in an invalid location, we're looking at things that aren't |
300 // actually stated in the source. | 307 // actually stated in the source. |
301 return false; | 308 return false; |
302 } | 309 } |
303 | 310 |
304 *filename = ploc.getFilename(); | 311 *filename = ploc.getFilename(); |
305 return true; | 312 return true; |
306 } | 313 } |
OLD | NEW |