Rafael Espindola | 7a231f5 | 2013-06-26 19:33:03 +0000 | [diff] [blame] | 1 | //===-- Path.cpp - Implement OS Path Concept ------------------------------===// |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Rafael Espindola | 7a231f5 | 2013-06-26 19:33:03 +0000 | [diff] [blame] | 10 | // This file implements the operating system Path API. |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Rafael Espindola | a11c3e2 | 2013-06-11 22:21:28 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Path.h" |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Endian.h" |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 18 | #include <cctype> |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 19 | #include <cstdio> |
| 20 | #include <cstring> |
Rafael Espindola | 8ee23f0 | 2013-06-18 17:01:00 +0000 | [diff] [blame] | 21 | |
| 22 | #if !defined(_MSC_VER) && !defined(__MINGW32__) |
Douglas Gregor | b0b5bde | 2013-03-21 21:46:10 +0000 | [diff] [blame] | 23 | #include <unistd.h> |
Rafael Espindola | 8ee23f0 | 2013-06-18 17:01:00 +0000 | [diff] [blame] | 24 | #else |
| 25 | #include <io.h> |
Douglas Gregor | b0b5bde | 2013-03-21 21:46:10 +0000 | [diff] [blame] | 26 | #endif |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 27 | |
| 28 | namespace { |
| 29 | using llvm::StringRef; |
Zhanyong Wan | 63cc3a8 | 2011-02-11 21:24:40 +0000 | [diff] [blame] | 30 | using llvm::sys::path::is_separator; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef LLVM_ON_WIN32 |
Benjamin Kramer | 80fd2a1 | 2012-02-08 13:13:47 +0000 | [diff] [blame] | 33 | const char *separators = "\\/"; |
| 34 | const char prefered_separator = '\\'; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 35 | #else |
Benjamin Kramer | 80fd2a1 | 2012-02-08 13:13:47 +0000 | [diff] [blame] | 36 | const char separators = '/'; |
| 37 | const char prefered_separator = '/'; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Benjamin Kramer | 7fb8666 | 2010-12-17 18:59:09 +0000 | [diff] [blame] | 40 | StringRef find_first_component(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 41 | // Look for this first component in the following order. |
| 42 | // * empty (in this case we return an empty string) |
| 43 | // * either C: or {//,\\}net. |
| 44 | // * {/,\} |
| 45 | // * {.,..} |
| 46 | // * {file,directory}name |
| 47 | |
| 48 | if (path.empty()) |
| 49 | return path; |
| 50 | |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 51 | #ifdef LLVM_ON_WIN32 |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 52 | // C: |
Guy Benyei | 87d0b9e | 2013-02-12 21:21:59 +0000 | [diff] [blame] | 53 | if (path.size() >= 2 && std::isalpha(static_cast<unsigned char>(path[0])) && |
| 54 | path[1] == ':') |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 55 | return path.substr(0, 2); |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 56 | #endif |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 57 | |
| 58 | // //net |
| 59 | if ((path.size() > 2) && |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 60 | is_separator(path[0]) && |
| 61 | path[0] == path[1] && |
| 62 | !is_separator(path[2])) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 63 | // Find the next directory separator. |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 64 | size_t end = path.find_first_of(separators, 2); |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 65 | return path.substr(0, end); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // {/,\} |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 69 | if (is_separator(path[0])) |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 70 | return path.substr(0, 1); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 71 | |
| 72 | if (path.startswith("..")) |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 73 | return path.substr(0, 2); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 74 | |
| 75 | if (path[0] == '.') |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 76 | return path.substr(0, 1); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 77 | |
| 78 | // * {file,directory}name |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 79 | size_t end = path.find_first_of(separators, 2); |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 80 | return path.substr(0, end); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 81 | } |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 82 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 83 | size_t filename_pos(StringRef str) { |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 84 | if (str.size() == 2 && |
| 85 | is_separator(str[0]) && |
Michael J. Spencer | ca3a339 | 2010-12-07 03:57:48 +0000 | [diff] [blame] | 86 | str[0] == str[1]) |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 87 | return 0; |
| 88 | |
| 89 | if (str.size() > 0 && is_separator(str[str.size() - 1])) |
| 90 | return str.size() - 1; |
| 91 | |
| 92 | size_t pos = str.find_last_of(separators, str.size() - 1); |
| 93 | |
| 94 | #ifdef LLVM_ON_WIN32 |
| 95 | if (pos == StringRef::npos) |
| 96 | pos = str.find_last_of(':', str.size() - 2); |
| 97 | #endif |
| 98 | |
| 99 | if (pos == StringRef::npos || |
| 100 | (pos == 1 && is_separator(str[0]))) |
| 101 | return 0; |
| 102 | |
| 103 | return pos + 1; |
| 104 | } |
| 105 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 106 | size_t root_dir_start(StringRef str) { |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 107 | // case "c:/" |
| 108 | #ifdef LLVM_ON_WIN32 |
| 109 | if (str.size() > 2 && |
| 110 | str[1] == ':' && |
| 111 | is_separator(str[2])) |
| 112 | return 2; |
| 113 | #endif |
| 114 | |
| 115 | // case "//" |
| 116 | if (str.size() == 2 && |
| 117 | is_separator(str[0]) && |
| 118 | str[0] == str[1]) |
| 119 | return StringRef::npos; |
| 120 | |
| 121 | // case "//net" |
| 122 | if (str.size() > 3 && |
| 123 | is_separator(str[0]) && |
| 124 | str[0] == str[1] && |
| 125 | !is_separator(str[2])) { |
| 126 | return str.find_first_of(separators, 2); |
| 127 | } |
| 128 | |
| 129 | // case "/" |
| 130 | if (str.size() > 0 && is_separator(str[0])) |
| 131 | return 0; |
| 132 | |
| 133 | return StringRef::npos; |
| 134 | } |
| 135 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 136 | size_t parent_path_end(StringRef path) { |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 137 | size_t end_pos = filename_pos(path); |
| 138 | |
| 139 | bool filename_was_sep = path.size() > 0 && is_separator(path[end_pos]); |
| 140 | |
| 141 | // Skip separators except for root dir. |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 142 | size_t root_dir_pos = root_dir_start(path.substr(0, end_pos)); |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 143 | |
| 144 | while(end_pos > 0 && |
| 145 | (end_pos - 1) != root_dir_pos && |
| 146 | is_separator(path[end_pos - 1])) |
| 147 | --end_pos; |
| 148 | |
| 149 | if (end_pos == 1 && root_dir_pos == 0 && filename_was_sep) |
| 150 | return StringRef::npos; |
| 151 | |
| 152 | return end_pos; |
| 153 | } |
Zhanyong Wan | 63cc3a8 | 2011-02-11 21:24:40 +0000 | [diff] [blame] | 154 | } // end unnamed namespace |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 155 | |
| 156 | namespace llvm { |
| 157 | namespace sys { |
| 158 | namespace path { |
| 159 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 160 | const_iterator begin(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 161 | const_iterator i; |
| 162 | i.Path = path; |
| 163 | i.Component = find_first_component(path); |
| 164 | i.Position = 0; |
| 165 | return i; |
| 166 | } |
| 167 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 168 | const_iterator end(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 169 | const_iterator i; |
| 170 | i.Path = path; |
| 171 | i.Position = path.size(); |
| 172 | return i; |
| 173 | } |
| 174 | |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 175 | const_iterator &const_iterator::operator++() { |
| 176 | assert(Position < Path.size() && "Tried to increment past end!"); |
| 177 | |
| 178 | // Increment Position to past the current component |
| 179 | Position += Component.size(); |
| 180 | |
| 181 | // Check for end. |
| 182 | if (Position == Path.size()) { |
| 183 | Component = StringRef(); |
| 184 | return *this; |
| 185 | } |
| 186 | |
| 187 | // Both POSIX and Windows treat paths that begin with exactly two separators |
| 188 | // specially. |
| 189 | bool was_net = Component.size() > 2 && |
| 190 | is_separator(Component[0]) && |
| 191 | Component[1] == Component[0] && |
| 192 | !is_separator(Component[2]); |
| 193 | |
| 194 | // Handle separators. |
| 195 | if (is_separator(Path[Position])) { |
| 196 | // Root dir. |
| 197 | if (was_net |
| 198 | #ifdef LLVM_ON_WIN32 |
| 199 | // c:/ |
| 200 | || Component.endswith(":") |
| 201 | #endif |
| 202 | ) { |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 203 | Component = Path.substr(Position, 1); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 204 | return *this; |
| 205 | } |
| 206 | |
| 207 | // Skip extra separators. |
| 208 | while (Position != Path.size() && |
| 209 | is_separator(Path[Position])) { |
| 210 | ++Position; |
| 211 | } |
| 212 | |
| 213 | // Treat trailing '/' as a '.'. |
| 214 | if (Position == Path.size()) { |
| 215 | --Position; |
| 216 | Component = "."; |
| 217 | return *this; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Find next component. |
| 222 | size_t end_pos = Path.find_first_of(separators, Position); |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 223 | Component = Path.slice(Position, end_pos); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 224 | |
| 225 | return *this; |
| 226 | } |
| 227 | |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 228 | const_iterator &const_iterator::operator--() { |
| 229 | // If we're at the end and the previous char was a '/', return '.'. |
| 230 | if (Position == Path.size() && |
| 231 | Path.size() > 1 && |
| 232 | is_separator(Path[Position - 1]) |
| 233 | #ifdef LLVM_ON_WIN32 |
| 234 | && Path[Position - 2] != ':' |
| 235 | #endif |
| 236 | ) { |
| 237 | --Position; |
| 238 | Component = "."; |
| 239 | return *this; |
| 240 | } |
| 241 | |
| 242 | // Skip separators unless it's the root directory. |
| 243 | size_t root_dir_pos = root_dir_start(Path); |
| 244 | size_t end_pos = Position; |
| 245 | |
| 246 | while(end_pos > 0 && |
| 247 | (end_pos - 1) != root_dir_pos && |
| 248 | is_separator(Path[end_pos - 1])) |
| 249 | --end_pos; |
| 250 | |
| 251 | // Find next separator. |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 252 | size_t start_pos = filename_pos(Path.substr(0, end_pos)); |
| 253 | Component = Path.slice(start_pos, end_pos); |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 254 | Position = start_pos; |
| 255 | return *this; |
| 256 | } |
| 257 | |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 258 | bool const_iterator::operator==(const const_iterator &RHS) const { |
| 259 | return Path.begin() == RHS.Path.begin() && |
| 260 | Position == RHS.Position; |
| 261 | } |
| 262 | |
| 263 | bool const_iterator::operator!=(const const_iterator &RHS) const { |
| 264 | return !(*this == RHS); |
| 265 | } |
| 266 | |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 267 | ptrdiff_t const_iterator::operator-(const const_iterator &RHS) const { |
| 268 | return Position - RHS.Position; |
| 269 | } |
| 270 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 271 | const StringRef root_path(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 272 | const_iterator b = begin(path), |
| 273 | pos = b, |
| 274 | e = end(path); |
| 275 | if (b != e) { |
| 276 | bool has_net = b->size() > 2 && is_separator((*b)[0]) && (*b)[1] == (*b)[0]; |
| 277 | bool has_drive = |
| 278 | #ifdef LLVM_ON_WIN32 |
| 279 | b->endswith(":"); |
| 280 | #else |
| 281 | false; |
| 282 | #endif |
| 283 | |
| 284 | if (has_net || has_drive) { |
| 285 | if ((++pos != e) && is_separator((*pos)[0])) { |
| 286 | // {C:/,//net/}, so get the first two components. |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 287 | return path.substr(0, b->size() + pos->size()); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 288 | } else { |
| 289 | // just {C:,//net}, return the first component. |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 290 | return *b; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | // POSIX style root directory. |
| 295 | if (is_separator((*b)[0])) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 296 | return *b; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 297 | } |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 300 | return StringRef(); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 303 | const StringRef root_name(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 304 | const_iterator b = begin(path), |
| 305 | e = end(path); |
| 306 | if (b != e) { |
| 307 | bool has_net = b->size() > 2 && is_separator((*b)[0]) && (*b)[1] == (*b)[0]; |
| 308 | bool has_drive = |
| 309 | #ifdef LLVM_ON_WIN32 |
| 310 | b->endswith(":"); |
| 311 | #else |
| 312 | false; |
| 313 | #endif |
| 314 | |
| 315 | if (has_net || has_drive) { |
| 316 | // just {C:,//net}, return the first component. |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 317 | return *b; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | // No path or no name. |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 322 | return StringRef(); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 325 | const StringRef root_directory(StringRef path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 326 | const_iterator b = begin(path), |
| 327 | pos = b, |
| 328 | e = end(path); |
| 329 | if (b != e) { |
| 330 | bool has_net = b->size() > 2 && is_separator((*b)[0]) && (*b)[1] == (*b)[0]; |
| 331 | bool has_drive = |
| 332 | #ifdef LLVM_ON_WIN32 |
| 333 | b->endswith(":"); |
| 334 | #else |
| 335 | false; |
| 336 | #endif |
| 337 | |
| 338 | if ((has_net || has_drive) && |
| 339 | // {C:,//net}, skip to the next component. |
| 340 | (++pos != e) && is_separator((*pos)[0])) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 341 | return *pos; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | // POSIX style root directory. |
| 345 | if (!has_net && is_separator((*b)[0])) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 346 | return *b; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | // No path or no root. |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 351 | return StringRef(); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 354 | const StringRef relative_path(StringRef path) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 355 | StringRef root = root_path(path); |
Michael J. Spencer | d0fff18 | 2012-02-29 00:06:24 +0000 | [diff] [blame] | 356 | return path.substr(root.size()); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 359 | void append(SmallVectorImpl<char> &path, const Twine &a, |
| 360 | const Twine &b, |
| 361 | const Twine &c, |
| 362 | const Twine &d) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 363 | SmallString<32> a_storage; |
| 364 | SmallString<32> b_storage; |
| 365 | SmallString<32> c_storage; |
| 366 | SmallString<32> d_storage; |
| 367 | |
| 368 | SmallVector<StringRef, 4> components; |
| 369 | if (!a.isTriviallyEmpty()) components.push_back(a.toStringRef(a_storage)); |
| 370 | if (!b.isTriviallyEmpty()) components.push_back(b.toStringRef(b_storage)); |
| 371 | if (!c.isTriviallyEmpty()) components.push_back(c.toStringRef(c_storage)); |
| 372 | if (!d.isTriviallyEmpty()) components.push_back(d.toStringRef(d_storage)); |
| 373 | |
| 374 | for (SmallVectorImpl<StringRef>::const_iterator i = components.begin(), |
| 375 | e = components.end(); |
| 376 | i != e; ++i) { |
| 377 | bool path_has_sep = !path.empty() && is_separator(path[path.size() - 1]); |
| 378 | bool component_has_sep = !i->empty() && is_separator((*i)[0]); |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 379 | bool is_root_name = has_root_name(*i); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 380 | |
| 381 | if (path_has_sep) { |
| 382 | // Strip separators from beginning of component. |
| 383 | size_t loc = i->find_first_not_of(separators); |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 384 | StringRef c = i->substr(loc); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 385 | |
| 386 | // Append it. |
| 387 | path.append(c.begin(), c.end()); |
| 388 | continue; |
| 389 | } |
| 390 | |
Michael J. Spencer | f150e76 | 2010-12-06 04:28:23 +0000 | [diff] [blame] | 391 | if (!component_has_sep && !(path.empty() || is_root_name)) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 392 | // Add a separator. |
| 393 | path.push_back(prefered_separator); |
| 394 | } |
| 395 | |
| 396 | path.append(i->begin(), i->end()); |
| 397 | } |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Argyrios Kyrtzidis | 6e31b9b | 2011-02-15 17:51:19 +0000 | [diff] [blame] | 400 | void append(SmallVectorImpl<char> &path, |
| 401 | const_iterator begin, const_iterator end) { |
| 402 | for (; begin != end; ++begin) |
| 403 | path::append(path, *begin); |
| 404 | } |
| 405 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 406 | const StringRef parent_path(StringRef path) { |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 407 | size_t end_pos = parent_path_end(path); |
| 408 | if (end_pos == StringRef::npos) |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 409 | return StringRef(); |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 410 | else |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 411 | return path.substr(0, end_pos); |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 414 | void remove_filename(SmallVectorImpl<char> &path) { |
Michael J. Spencer | dbfb56b | 2010-12-01 00:52:28 +0000 | [diff] [blame] | 415 | size_t end_pos = parent_path_end(StringRef(path.begin(), path.size())); |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 416 | if (end_pos != StringRef::npos) |
| 417 | path.set_size(end_pos); |
Michael J. Spencer | dbfb56b | 2010-12-01 00:52:28 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 420 | void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) { |
Michael J. Spencer | 52ed867 | 2010-12-01 00:52:55 +0000 | [diff] [blame] | 421 | StringRef p(path.begin(), path.size()); |
| 422 | SmallString<32> ext_storage; |
| 423 | StringRef ext = extension.toStringRef(ext_storage); |
| 424 | |
| 425 | // Erase existing extension. |
| 426 | size_t pos = p.find_last_of('.'); |
| 427 | if (pos != StringRef::npos && pos >= filename_pos(p)) |
| 428 | path.set_size(pos); |
| 429 | |
| 430 | // Append '.' if needed. |
| 431 | if (ext.size() > 0 && ext[0] != '.') |
| 432 | path.push_back('.'); |
| 433 | |
| 434 | // Append extension. |
| 435 | path.append(ext.begin(), ext.end()); |
Michael J. Spencer | 52ed867 | 2010-12-01 00:52:55 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 438 | void native(const Twine &path, SmallVectorImpl<char> &result) { |
Michael J. Spencer | 722d5ad | 2010-12-01 02:48:27 +0000 | [diff] [blame] | 439 | // Clear result. |
Michael J. Spencer | fbd1bbd | 2010-12-07 01:23:19 +0000 | [diff] [blame] | 440 | result.clear(); |
Michael J. Spencer | 722d5ad | 2010-12-01 02:48:27 +0000 | [diff] [blame] | 441 | #ifdef LLVM_ON_WIN32 |
| 442 | SmallString<128> path_storage; |
| 443 | StringRef p = path.toStringRef(path_storage); |
| 444 | result.reserve(p.size()); |
| 445 | for (StringRef::const_iterator i = p.begin(), |
| 446 | e = p.end(); |
| 447 | i != e; |
| 448 | ++i) { |
| 449 | if (*i == '/') |
| 450 | result.push_back('\\'); |
| 451 | else |
| 452 | result.push_back(*i); |
| 453 | } |
| 454 | #else |
| 455 | path.toVector(result); |
| 456 | #endif |
Michael J. Spencer | 722d5ad | 2010-12-01 02:48:27 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 459 | const StringRef filename(StringRef path) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 460 | return *(--end(path)); |
Michael J. Spencer | a979355 | 2010-12-01 03:18:17 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 463 | const StringRef stem(StringRef path) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 464 | StringRef fname = filename(path); |
Michael J. Spencer | 34ab1f6 | 2010-12-01 03:18:33 +0000 | [diff] [blame] | 465 | size_t pos = fname.find_last_of('.'); |
| 466 | if (pos == StringRef::npos) |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 467 | return fname; |
Michael J. Spencer | 34ab1f6 | 2010-12-01 03:18:33 +0000 | [diff] [blame] | 468 | else |
| 469 | if ((fname.size() == 1 && fname == ".") || |
| 470 | (fname.size() == 2 && fname == "..")) |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 471 | return fname; |
Michael J. Spencer | 34ab1f6 | 2010-12-01 03:18:33 +0000 | [diff] [blame] | 472 | else |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 473 | return fname.substr(0, pos); |
Michael J. Spencer | 34ab1f6 | 2010-12-01 03:18:33 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Benjamin Kramer | d53f3c8 | 2010-12-17 18:19:06 +0000 | [diff] [blame] | 476 | const StringRef extension(StringRef path) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 477 | StringRef fname = filename(path); |
Michael J. Spencer | 5265f22 | 2010-12-01 03:37:41 +0000 | [diff] [blame] | 478 | size_t pos = fname.find_last_of('.'); |
| 479 | if (pos == StringRef::npos) |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 480 | return StringRef(); |
Michael J. Spencer | 5265f22 | 2010-12-01 03:37:41 +0000 | [diff] [blame] | 481 | else |
| 482 | if ((fname.size() == 1 && fname == ".") || |
| 483 | (fname.size() == 2 && fname == "..")) |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 484 | return StringRef(); |
Michael J. Spencer | 5265f22 | 2010-12-01 03:37:41 +0000 | [diff] [blame] | 485 | else |
Benjamin Kramer | 3ce88c9 | 2010-12-17 20:27:37 +0000 | [diff] [blame] | 486 | return fname.substr(pos); |
Michael J. Spencer | 5265f22 | 2010-12-01 03:37:41 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Zhanyong Wan | 63cc3a8 | 2011-02-11 21:24:40 +0000 | [diff] [blame] | 489 | bool is_separator(char value) { |
| 490 | switch(value) { |
| 491 | #ifdef LLVM_ON_WIN32 |
| 492 | case '\\': // fall through |
| 493 | #endif |
| 494 | case '/': return true; |
| 495 | default: return false; |
| 496 | } |
| 497 | } |
| 498 | |
Douglas Gregor | 55cf815 | 2011-09-14 20:27:01 +0000 | [diff] [blame] | 499 | void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result) { |
| 500 | result.clear(); |
Michael J. Spencer | faebf11 | 2011-12-13 23:16:15 +0000 | [diff] [blame] | 501 | |
Douglas Gregor | b0b5bde | 2013-03-21 21:46:10 +0000 | [diff] [blame] | 502 | #ifdef __APPLE__ |
| 503 | // On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR. |
| 504 | int ConfName = erasedOnReboot? _CS_DARWIN_USER_TEMP_DIR |
| 505 | : _CS_DARWIN_USER_CACHE_DIR; |
| 506 | size_t ConfLen = confstr(ConfName, 0, 0); |
| 507 | if (ConfLen > 0) { |
| 508 | do { |
| 509 | result.resize(ConfLen); |
| 510 | ConfLen = confstr(ConfName, result.data(), result.size()); |
| 511 | } while (ConfLen > 0 && ConfLen != result.size()); |
| 512 | |
| 513 | if (ConfLen > 0) { |
| 514 | assert(result.back() == 0); |
| 515 | result.pop_back(); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | result.clear(); |
| 520 | } |
| 521 | #endif |
| 522 | |
Douglas Gregor | 55cf815 | 2011-09-14 20:27:01 +0000 | [diff] [blame] | 523 | // Check whether the temporary directory is specified by an environment |
| 524 | // variable. |
| 525 | const char *EnvironmentVariable; |
| 526 | #ifdef LLVM_ON_WIN32 |
| 527 | EnvironmentVariable = "TEMP"; |
| 528 | #else |
| 529 | EnvironmentVariable = "TMPDIR"; |
| 530 | #endif |
| 531 | if (char *RequestedDir = getenv(EnvironmentVariable)) { |
| 532 | result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); |
| 533 | return; |
| 534 | } |
Michael J. Spencer | faebf11 | 2011-12-13 23:16:15 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | 55cf815 | 2011-09-14 20:27:01 +0000 | [diff] [blame] | 536 | // Fall back to a system default. |
| 537 | const char *DefaultResult; |
| 538 | #ifdef LLVM_ON_WIN32 |
| 539 | (void)erasedOnReboot; |
Douglas Gregor | d26d6b6 | 2011-09-14 23:21:47 +0000 | [diff] [blame] | 540 | DefaultResult = "C:\\TEMP"; |
Douglas Gregor | 55cf815 | 2011-09-14 20:27:01 +0000 | [diff] [blame] | 541 | #else |
| 542 | if (erasedOnReboot) |
| 543 | DefaultResult = "/tmp"; |
| 544 | else |
| 545 | DefaultResult = "/var/tmp"; |
| 546 | #endif |
| 547 | result.append(DefaultResult, DefaultResult + strlen(DefaultResult)); |
| 548 | } |
Michael J. Spencer | faebf11 | 2011-12-13 23:16:15 +0000 | [diff] [blame] | 549 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 550 | bool has_root_name(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 551 | SmallString<128> path_storage; |
| 552 | StringRef p = path.toStringRef(path_storage); |
| 553 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 554 | return !root_name(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 557 | bool has_root_directory(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 558 | SmallString<128> path_storage; |
| 559 | StringRef p = path.toStringRef(path_storage); |
| 560 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 561 | return !root_directory(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 564 | bool has_root_path(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 565 | SmallString<128> path_storage; |
| 566 | StringRef p = path.toStringRef(path_storage); |
| 567 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 568 | return !root_path(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Michael J. Spencer | 2d484eb | 2010-12-20 13:30:28 +0000 | [diff] [blame] | 571 | bool has_relative_path(const Twine &path) { |
| 572 | SmallString<128> path_storage; |
| 573 | StringRef p = path.toStringRef(path_storage); |
| 574 | |
| 575 | return !relative_path(p).empty(); |
| 576 | } |
| 577 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 578 | bool has_filename(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 579 | SmallString<128> path_storage; |
| 580 | StringRef p = path.toStringRef(path_storage); |
| 581 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 582 | return !filename(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 585 | bool has_parent_path(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 586 | SmallString<128> path_storage; |
| 587 | StringRef p = path.toStringRef(path_storage); |
| 588 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 589 | return !parent_path(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 592 | bool has_stem(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 593 | SmallString<128> path_storage; |
| 594 | StringRef p = path.toStringRef(path_storage); |
| 595 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 596 | return !stem(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 599 | bool has_extension(const Twine &path) { |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 600 | SmallString<128> path_storage; |
| 601 | StringRef p = path.toStringRef(path_storage); |
| 602 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 603 | return !extension(p).empty(); |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 606 | bool is_absolute(const Twine &path) { |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 607 | SmallString<128> path_storage; |
| 608 | StringRef p = path.toStringRef(path_storage); |
| 609 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 610 | bool rootDir = has_root_directory(p), |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 611 | #ifdef LLVM_ON_WIN32 |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 612 | rootName = has_root_name(p); |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 613 | #else |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 614 | rootName = true; |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 615 | #endif |
| 616 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 617 | return rootDir && rootName; |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Michael J. Spencer | 12ccf67 | 2010-12-07 18:12:07 +0000 | [diff] [blame] | 620 | bool is_relative(const Twine &path) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 621 | return !is_absolute(path); |
Michael J. Spencer | ce2b68f | 2010-12-01 06:21:53 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Michael J. Spencer | bee0c38 | 2010-12-01 19:32:01 +0000 | [diff] [blame] | 624 | } // end namespace path |
| 625 | |
| 626 | namespace fs { |
| 627 | |
Rafael Espindola | 8ee23f0 | 2013-06-18 17:01:00 +0000 | [diff] [blame] | 628 | error_code unique_file(const Twine &Model, SmallVectorImpl<char> &ResultPath, |
| 629 | bool MakeAbsolute, unsigned Mode) { |
Rafael Espindola | 8ba825e | 2013-06-25 00:49:40 +0000 | [diff] [blame] | 630 | // FIXME: This is really inefficient. unique_path creates a path an tries to |
| 631 | // open it. We should factor the code so that we just don't create/open the |
| 632 | // file when we don't need it. |
Rafael Espindola | 8ee23f0 | 2013-06-18 17:01:00 +0000 | [diff] [blame] | 633 | int FD; |
| 634 | error_code Ret = unique_file(Model, FD, ResultPath, MakeAbsolute, Mode); |
Rafael Espindola | 8ba825e | 2013-06-25 00:49:40 +0000 | [diff] [blame] | 635 | if (Ret) |
| 636 | return Ret; |
| 637 | |
| 638 | if (close(FD)) |
| 639 | return error_code(errno, system_category()); |
| 640 | |
Rafael Espindola | fa34f42 | 2013-06-25 04:23:46 +0000 | [diff] [blame] | 641 | StringRef P(ResultPath.begin(), ResultPath.size()); |
| 642 | return fs::remove(P); |
Rafael Espindola | 8ee23f0 | 2013-06-18 17:01:00 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Rafael Espindola | 08ddd12 | 2013-06-27 03:45:31 +0000 | [diff] [blame^] | 645 | error_code createUniqueDirectory(const Twine &Prefix, |
| 646 | SmallVectorImpl<char> &ResultPath) { |
| 647 | // FIXME: This is double inefficient. We compute a unique file name, created |
| 648 | // it, delete it and keep only the directory. |
| 649 | error_code EC = unique_file(Prefix + "-%%%%%%/dummy", ResultPath); |
| 650 | if (EC) |
| 651 | return EC; |
| 652 | path::remove_filename(ResultPath); |
| 653 | return error_code::success(); |
| 654 | } |
| 655 | |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 656 | error_code make_absolute(SmallVectorImpl<char> &path) { |
| 657 | StringRef p(path.data(), path.size()); |
| 658 | |
Daniel Dunbar | d1d7216 | 2012-02-29 00:20:37 +0000 | [diff] [blame] | 659 | bool rootDirectory = path::has_root_directory(p), |
| 660 | #ifdef LLVM_ON_WIN32 |
Daniel Dunbar | 95fe7b9 | 2012-02-29 00:46:46 +0000 | [diff] [blame] | 661 | rootName = path::has_root_name(p); |
Daniel Dunbar | d1d7216 | 2012-02-29 00:20:37 +0000 | [diff] [blame] | 662 | #else |
| 663 | rootName = true; |
| 664 | #endif |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 665 | |
| 666 | // Already absolute. |
| 667 | if (rootName && rootDirectory) |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 668 | return error_code::success(); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 669 | |
| 670 | // All of the following conditions will need the current directory. |
| 671 | SmallString<128> current_dir; |
| 672 | if (error_code ec = current_path(current_dir)) return ec; |
| 673 | |
| 674 | // Relative path. Prepend the current directory. |
| 675 | if (!rootName && !rootDirectory) { |
| 676 | // Append path to the current directory. |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 677 | path::append(current_dir, p); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 678 | // Set path to the result. |
| 679 | path.swap(current_dir); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 680 | return error_code::success(); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | if (!rootName && rootDirectory) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 684 | StringRef cdrn = path::root_name(current_dir); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 685 | SmallString<128> curDirRootName(cdrn.begin(), cdrn.end()); |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 686 | path::append(curDirRootName, p); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 687 | // Set path to the result. |
| 688 | path.swap(curDirRootName); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 689 | return error_code::success(); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | if (rootName && !rootDirectory) { |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 693 | StringRef pRootName = path::root_name(p); |
| 694 | StringRef bRootDirectory = path::root_directory(current_dir); |
| 695 | StringRef bRelativePath = path::relative_path(current_dir); |
| 696 | StringRef pRelativePath = path::relative_path(p); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 697 | |
| 698 | SmallString<128> res; |
Michael J. Spencer | 936671b | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 699 | path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 700 | path.swap(res); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 701 | return error_code::success(); |
Michael J. Spencer | ee271d8 | 2010-12-07 03:57:17 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | llvm_unreachable("All rootName and rootDirectory combinations should have " |
| 705 | "occurred above!"); |
| 706 | } |
| 707 | |
Michael J. Spencer | b83769f | 2010-12-03 05:42:11 +0000 | [diff] [blame] | 708 | error_code create_directories(const Twine &path, bool &existed) { |
| 709 | SmallString<128> path_storage; |
| 710 | StringRef p = path.toStringRef(path_storage); |
| 711 | |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 712 | StringRef parent = path::parent_path(p); |
Michael J. Spencer | 55f43d6 | 2012-03-21 23:09:14 +0000 | [diff] [blame] | 713 | if (!parent.empty()) { |
| 714 | bool parent_exists; |
| 715 | if (error_code ec = fs::exists(parent, parent_exists)) return ec; |
Michael J. Spencer | 5029159 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 716 | |
Michael J. Spencer | 55f43d6 | 2012-03-21 23:09:14 +0000 | [diff] [blame] | 717 | if (!parent_exists) |
| 718 | if (error_code ec = create_directories(parent, existed)) return ec; |
| 719 | } |
Michael J. Spencer | b83769f | 2010-12-03 05:42:11 +0000 | [diff] [blame] | 720 | |
| 721 | return create_directory(p, existed); |
| 722 | } |
| 723 | |
Michael J. Spencer | 61187dd | 2010-12-09 17:37:02 +0000 | [diff] [blame] | 724 | bool exists(file_status status) { |
| 725 | return status_known(status) && status.type() != file_type::file_not_found; |
| 726 | } |
| 727 | |
| 728 | bool status_known(file_status s) { |
| 729 | return s.type() != file_type::status_error; |
| 730 | } |
| 731 | |
| 732 | bool is_directory(file_status status) { |
| 733 | return status.type() == file_type::directory_file; |
| 734 | } |
| 735 | |
Michael J. Spencer | 218dc3e | 2011-01-11 01:21:55 +0000 | [diff] [blame] | 736 | error_code is_directory(const Twine &path, bool &result) { |
| 737 | file_status st; |
| 738 | if (error_code ec = status(path, st)) |
| 739 | return ec; |
| 740 | result = is_directory(st); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 741 | return error_code::success(); |
Michael J. Spencer | 218dc3e | 2011-01-11 01:21:55 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Michael J. Spencer | 61187dd | 2010-12-09 17:37:02 +0000 | [diff] [blame] | 744 | bool is_regular_file(file_status status) { |
| 745 | return status.type() == file_type::regular_file; |
| 746 | } |
| 747 | |
Michael J. Spencer | 218dc3e | 2011-01-11 01:21:55 +0000 | [diff] [blame] | 748 | error_code is_regular_file(const Twine &path, bool &result) { |
| 749 | file_status st; |
| 750 | if (error_code ec = status(path, st)) |
| 751 | return ec; |
| 752 | result = is_regular_file(st); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 753 | return error_code::success(); |
Michael J. Spencer | 218dc3e | 2011-01-11 01:21:55 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Michael J. Spencer | 61187dd | 2010-12-09 17:37:02 +0000 | [diff] [blame] | 756 | bool is_symlink(file_status status) { |
| 757 | return status.type() == file_type::symlink_file; |
| 758 | } |
| 759 | |
Michael J. Spencer | 9df536c | 2011-01-12 23:55:06 +0000 | [diff] [blame] | 760 | error_code is_symlink(const Twine &path, bool &result) { |
| 761 | file_status st; |
| 762 | if (error_code ec = status(path, st)) |
| 763 | return ec; |
| 764 | result = is_symlink(st); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 765 | return error_code::success(); |
Michael J. Spencer | 9df536c | 2011-01-12 23:55:06 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Michael J. Spencer | 61187dd | 2010-12-09 17:37:02 +0000 | [diff] [blame] | 768 | bool is_other(file_status status) { |
| 769 | return exists(status) && |
| 770 | !is_regular_file(status) && |
| 771 | !is_directory(status) && |
| 772 | !is_symlink(status); |
| 773 | } |
| 774 | |
Benjamin Kramer | 357b571 | 2011-09-14 01:14:36 +0000 | [diff] [blame] | 775 | void directory_entry::replace_filename(const Twine &filename, file_status st) { |
Michael J. Spencer | 753cbbb | 2010-12-06 04:28:42 +0000 | [diff] [blame] | 776 | SmallString<128> path(Path.begin(), Path.end()); |
| 777 | path::remove_filename(path); |
| 778 | path::append(path, filename); |
| 779 | Path = path.str(); |
| 780 | Status = st; |
Michael J. Spencer | 753cbbb | 2010-12-06 04:28:42 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 783 | error_code has_magic(const Twine &path, const Twine &magic, bool &result) { |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 784 | SmallString<32> MagicStorage; |
Michael J. Spencer | b33594b | 2011-01-15 18:52:41 +0000 | [diff] [blame] | 785 | StringRef Magic = magic.toStringRef(MagicStorage); |
| 786 | SmallString<32> Buffer; |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 787 | |
Michael J. Spencer | b33594b | 2011-01-15 18:52:41 +0000 | [diff] [blame] | 788 | if (error_code ec = get_magic(path, Magic.size(), Buffer)) { |
| 789 | if (ec == errc::value_too_large) { |
| 790 | // Magic.size() > file_size(Path). |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 791 | result = false; |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 792 | return error_code::success(); |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 793 | } |
Michael J. Spencer | b33594b | 2011-01-15 18:52:41 +0000 | [diff] [blame] | 794 | return ec; |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 795 | } |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 796 | |
Michael J. Spencer | b33594b | 2011-01-15 18:52:41 +0000 | [diff] [blame] | 797 | result = Magic == Buffer; |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 798 | return error_code::success(); |
Michael J. Spencer | 628467e | 2010-12-28 01:49:01 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 801 | /// @brief Identify the magic in magic. |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 802 | file_magic identify_magic(StringRef Magic) { |
| 803 | if (Magic.size() < 4) |
Michael J. Spencer | b51c8e9 | 2012-06-19 05:29:57 +0000 | [diff] [blame] | 804 | return file_magic::unknown; |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 805 | switch ((unsigned char)Magic[0]) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 806 | case 0xDE: // 0x0B17C0DE = BC wraper |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 807 | if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 && |
| 808 | Magic[3] == (char)0x0B) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 809 | return file_magic::bitcode; |
| 810 | break; |
| 811 | case 'B': |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 812 | if (Magic[1] == 'C' && Magic[2] == (char)0xC0 && Magic[3] == (char)0xDE) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 813 | return file_magic::bitcode; |
| 814 | break; |
| 815 | case '!': |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 816 | if (Magic.size() >= 8) |
| 817 | if (memcmp(Magic.data(),"!<arch>\n",8) == 0) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 818 | return file_magic::archive; |
| 819 | break; |
| 820 | |
| 821 | case '\177': |
Rafael Espindola | 0179706 | 2013-06-11 17:25:45 +0000 | [diff] [blame] | 822 | if (Magic.size() >= 18 && Magic[1] == 'E' && Magic[2] == 'L' && |
| 823 | Magic[3] == 'F') { |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 824 | bool Data2MSB = Magic[5] == 2; |
Michael J. Spencer | c0a74e2 | 2013-04-05 20:10:04 +0000 | [diff] [blame] | 825 | unsigned high = Data2MSB ? 16 : 17; |
| 826 | unsigned low = Data2MSB ? 17 : 16; |
Rafael Espindola | 0179706 | 2013-06-11 17:25:45 +0000 | [diff] [blame] | 827 | if (Magic[high] == 0) |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 828 | switch (Magic[low]) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 829 | default: break; |
| 830 | case 1: return file_magic::elf_relocatable; |
| 831 | case 2: return file_magic::elf_executable; |
| 832 | case 3: return file_magic::elf_shared_object; |
| 833 | case 4: return file_magic::elf_core; |
| 834 | } |
| 835 | } |
| 836 | break; |
| 837 | |
| 838 | case 0xCA: |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 839 | if (Magic[1] == char(0xFE) && Magic[2] == char(0xBA) && |
| 840 | Magic[3] == char(0xBE)) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 841 | // This is complicated by an overlap with Java class files. |
| 842 | // See the Mach-O section in /usr/share/file/magic for details. |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 843 | if (Magic.size() >= 8 && Magic[7] < 43) |
Alexey Samsonov | 9c22f87 | 2013-06-18 15:03:28 +0000 | [diff] [blame] | 844 | return file_magic::macho_universal_binary; |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 845 | } |
| 846 | break; |
| 847 | |
| 848 | // The two magic numbers for mach-o are: |
| 849 | // 0xfeedface - 32-bit mach-o |
| 850 | // 0xfeedfacf - 64-bit mach-o |
| 851 | case 0xFE: |
| 852 | case 0xCE: |
| 853 | case 0xCF: { |
| 854 | uint16_t type = 0; |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 855 | if (Magic[0] == char(0xFE) && Magic[1] == char(0xED) && |
| 856 | Magic[2] == char(0xFA) && |
| 857 | (Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 858 | /* Native endian */ |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 859 | if (Magic.size() >= 16) type = Magic[14] << 8 | Magic[15]; |
| 860 | } else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) && |
| 861 | Magic[1] == char(0xFA) && Magic[2] == char(0xED) && |
| 862 | Magic[3] == char(0xFE)) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 863 | /* Reverse endian */ |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 864 | if (Magic.size() >= 14) type = Magic[13] << 8 | Magic[12]; |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 865 | } |
| 866 | switch (type) { |
| 867 | default: break; |
| 868 | case 1: return file_magic::macho_object; |
| 869 | case 2: return file_magic::macho_executable; |
| 870 | case 3: return file_magic::macho_fixed_virtual_memory_shared_lib; |
| 871 | case 4: return file_magic::macho_core; |
Rafael Espindola | 6d315c6 | 2013-06-10 20:32:27 +0000 | [diff] [blame] | 872 | case 5: return file_magic::macho_preload_executable; |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 873 | case 6: return file_magic::macho_dynamically_linked_shared_lib; |
| 874 | case 7: return file_magic::macho_dynamic_linker; |
| 875 | case 8: return file_magic::macho_bundle; |
| 876 | case 9: return file_magic::macho_dynamic_linker; |
| 877 | case 10: return file_magic::macho_dsym_companion; |
| 878 | } |
| 879 | break; |
| 880 | } |
| 881 | case 0xF0: // PowerPC Windows |
| 882 | case 0x83: // Alpha 32-bit |
| 883 | case 0x84: // Alpha 64-bit |
| 884 | case 0x66: // MPS R4000 Windows |
| 885 | case 0x50: // mc68K |
| 886 | case 0x4c: // 80386 Windows |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 887 | if (Magic[1] == 0x01) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 888 | return file_magic::coff_object; |
| 889 | |
| 890 | case 0x90: // PA-RISC Windows |
| 891 | case 0x68: // mc68K Windows |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 892 | if (Magic[1] == 0x02) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 893 | return file_magic::coff_object; |
| 894 | break; |
| 895 | |
| 896 | case 0x4d: // Possible MS-DOS stub on Windows PE file |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 897 | if (Magic[1] == 0x5a) { |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 898 | uint32_t off = |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 899 | *reinterpret_cast<const support::ulittle32_t*>(Magic.data() + 0x3c); |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 900 | // PE/COFF file, either EXE or DLL. |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 901 | if (off < Magic.size() && memcmp(Magic.data() + off, "PE\0\0",4) == 0) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 902 | return file_magic::pecoff_executable; |
| 903 | } |
| 904 | break; |
| 905 | |
| 906 | case 0x64: // x86-64 Windows. |
Rafael Espindola | 9bd9f8e | 2013-06-11 17:22:12 +0000 | [diff] [blame] | 907 | if (Magic[1] == char(0x86)) |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 908 | return file_magic::coff_object; |
| 909 | break; |
| 910 | |
| 911 | default: |
| 912 | break; |
| 913 | } |
| 914 | return file_magic::unknown; |
| 915 | } |
| 916 | |
| 917 | error_code identify_magic(const Twine &path, file_magic &result) { |
Michael J. Spencer | 28f0ed5 | 2011-01-15 20:39:36 +0000 | [diff] [blame] | 918 | SmallString<32> Magic; |
| 919 | error_code ec = get_magic(path, Magic.capacity(), Magic); |
| 920 | if (ec && ec != errc::value_too_large) |
| 921 | return ec; |
| 922 | |
Michael J. Spencer | 5b08230 | 2011-12-13 23:17:12 +0000 | [diff] [blame] | 923 | result = identify_magic(Magic); |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 924 | return error_code::success(); |
Michael J. Spencer | 28f0ed5 | 2011-01-15 20:39:36 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Michael J. Spencer | 7fd682a | 2011-01-05 16:39:38 +0000 | [diff] [blame] | 927 | namespace { |
| 928 | error_code remove_all_r(StringRef path, file_type ft, uint32_t &count) { |
| 929 | if (ft == file_type::directory_file) { |
| 930 | // This code would be a lot better with exceptions ;/. |
| 931 | error_code ec; |
Michael J. Spencer | 1dd2ee7 | 2011-12-12 06:03:33 +0000 | [diff] [blame] | 932 | directory_iterator i(path, ec); |
| 933 | if (ec) return ec; |
| 934 | for (directory_iterator e; i != e; i.increment(ec)) { |
Michael J. Spencer | 7fd682a | 2011-01-05 16:39:38 +0000 | [diff] [blame] | 935 | if (ec) return ec; |
| 936 | file_status st; |
| 937 | if (error_code ec = i->status(st)) return ec; |
| 938 | if (error_code ec = remove_all_r(i->path(), st.type(), count)) return ec; |
| 939 | } |
| 940 | bool obviously_this_exists; |
| 941 | if (error_code ec = remove(path, obviously_this_exists)) return ec; |
| 942 | assert(obviously_this_exists); |
| 943 | ++count; // Include the directory itself in the items removed. |
| 944 | } else { |
| 945 | bool obviously_this_exists; |
| 946 | if (error_code ec = remove(path, obviously_this_exists)) return ec; |
| 947 | assert(obviously_this_exists); |
| 948 | ++count; |
| 949 | } |
| 950 | |
David Blaikie | 58604cd | 2012-02-09 19:24:12 +0000 | [diff] [blame] | 951 | return error_code::success(); |
Michael J. Spencer | 7fd682a | 2011-01-05 16:39:38 +0000 | [diff] [blame] | 952 | } |
Zhanyong Wan | 63cc3a8 | 2011-02-11 21:24:40 +0000 | [diff] [blame] | 953 | } // end unnamed namespace |
Michael J. Spencer | 7fd682a | 2011-01-05 16:39:38 +0000 | [diff] [blame] | 954 | |
| 955 | error_code remove_all(const Twine &path, uint32_t &num_removed) { |
| 956 | SmallString<128> path_storage; |
| 957 | StringRef p = path.toStringRef(path_storage); |
| 958 | |
| 959 | file_status fs; |
| 960 | if (error_code ec = status(path, fs)) |
| 961 | return ec; |
| 962 | num_removed = 0; |
| 963 | return remove_all_r(p, fs.type(), num_removed); |
| 964 | } |
| 965 | |
Michael J. Spencer | 5bcdc7f | 2011-01-05 16:39:13 +0000 | [diff] [blame] | 966 | error_code directory_entry::status(file_status &result) const { |
| 967 | return fs::status(Path, result); |
| 968 | } |
| 969 | |
Michael J. Spencer | bee0c38 | 2010-12-01 19:32:01 +0000 | [diff] [blame] | 970 | } // end namespace fs |
| 971 | } // end namespace sys |
| 972 | } // end namespace llvm |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 973 | |
| 974 | // Include the truly platform-specific parts. |
| 975 | #if defined(LLVM_ON_UNIX) |
Rafael Espindola | 7a231f5 | 2013-06-26 19:33:03 +0000 | [diff] [blame] | 976 | #include "Unix/Path.inc" |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 977 | #endif |
| 978 | #if defined(LLVM_ON_WIN32) |
Rafael Espindola | 7a231f5 | 2013-06-26 19:33:03 +0000 | [diff] [blame] | 979 | #include "Windows/Path.inc" |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 980 | #endif |