OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/test/testsupport/fileutils.h" | 11 #include "webrtc/test/testsupport/fileutils.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #ifdef WIN32 | 15 #ifdef WIN32 |
16 #include <direct.h> | 16 #include <direct.h> |
17 #include <tchar.h> | 17 #include <tchar.h> |
18 #include <windows.h> | 18 #include <windows.h> |
19 #include <algorithm> | 19 #include <algorithm> |
20 | 20 |
| 21 #include "Shlwapi.h" |
| 22 |
21 #include "webrtc/system_wrappers/include/utf_util_win.h" | 23 #include "webrtc/system_wrappers/include/utf_util_win.h" |
22 #define GET_CURRENT_DIR _getcwd | 24 #define GET_CURRENT_DIR _getcwd |
23 #else | 25 #else |
24 #include <unistd.h> | 26 #include <unistd.h> |
25 | 27 |
26 #define GET_CURRENT_DIR getcwd | 28 #define GET_CURRENT_DIR getcwd |
27 #endif | 29 #endif |
28 | 30 |
29 #include <sys/stat.h> // To check for directory existence. | 31 #include <sys/stat.h> // To check for directory existence. |
30 #ifndef S_ISDIR // Not defined in stat.h on Windows. | 32 #ifndef S_ISDIR // Not defined in stat.h on Windows. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 #else // WEBRTC_ANDROID | 122 #else // WEBRTC_ANDROID |
121 | 123 |
122 std::string ProjectRootPath() { | 124 std::string ProjectRootPath() { |
123 #if defined(WEBRTC_IOS) | 125 #if defined(WEBRTC_IOS) |
124 return IOSRootPath(); | 126 return IOSRootPath(); |
125 #else | 127 #else |
126 std::string path = WorkingDir(); | 128 std::string path = WorkingDir(); |
127 if (path == kFallbackPath) { | 129 if (path == kFallbackPath) { |
128 return kCannotFindProjectRootDir; | 130 return kCannotFindProjectRootDir; |
129 } | 131 } |
130 if (relative_dir_path_set && strcmp(relative_dir_path, ".") != 0) { | 132 if (relative_dir_path_set) { |
131 path = path + kPathDelimiter + relative_dir_path; | 133 path = path + kPathDelimiter + relative_dir_path; |
132 } | 134 } |
133 // Remove two directory levels from the path, i.e. a path like | 135 path = path + kPathDelimiter + ".." + kPathDelimiter + ".."; |
134 // /absolute/path/src/out/Debug will become /absolute/path/src/ | 136 char canonical_path[FILENAME_MAX]; |
135 size_t path_delimiter_index = path.find_last_of(kPathDelimiter); | 137 #ifdef WIN32 |
136 if (path_delimiter_index != std::string::npos) { | 138 bool succeeded = PathCanonicalizeA(canonical_path, path.c_str()); |
137 // Move up one directory in the directory tree. | 139 #else |
138 path = path.substr(0, path_delimiter_index); | 140 bool succeeded = realpath(path.c_str(), canonical_path) != NULL; |
139 path_delimiter_index = path.find_last_of(kPathDelimiter); | 141 #endif |
140 if (path_delimiter_index != std::string::npos) { | 142 if (succeeded) { |
141 // Move up another directory in the directory tree. We should now be at | 143 path = std::string(canonical_path) + kPathDelimiter; |
142 // the project root. | 144 return path; |
143 return path.substr(0, path_delimiter_index) + kPathDelimiter; | 145 } else { |
144 } | 146 fprintf(stderr, "Cannot find project root directory!\n"); |
| 147 return kCannotFindProjectRootDir; |
145 } | 148 } |
146 fprintf(stderr, "Cannot find project root directory!\n"); | |
147 return kCannotFindProjectRootDir; | |
148 #endif | 149 #endif |
149 } | 150 } |
150 | 151 |
151 std::string OutputPath() { | 152 std::string OutputPath() { |
152 #if defined(WEBRTC_IOS) | 153 #if defined(WEBRTC_IOS) |
153 return IOSOutputPath(); | 154 return IOSOutputPath(); |
154 #else | 155 #else |
155 std::string path = ProjectRootPath(); | 156 std::string path = ProjectRootPath(); |
156 if (path == kCannotFindProjectRootDir) { | 157 if (path == kCannotFindProjectRootDir) { |
157 return kFallbackPath; | 158 return kFallbackPath; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (fseek(f, 0, SEEK_END) == 0) { | 276 if (fseek(f, 0, SEEK_END) == 0) { |
276 size = ftell(f); | 277 size = ftell(f); |
277 } | 278 } |
278 fclose(f); | 279 fclose(f); |
279 } | 280 } |
280 return size; | 281 return size; |
281 } | 282 } |
282 | 283 |
283 } // namespace test | 284 } // namespace test |
284 } // namespace webrtc | 285 } // namespace webrtc |
OLD | NEW |