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

Side by Side Diff: base/base_paths_mac.mm

Issue 18309008: Fix GetNSExecutablePath for running tests with relative path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac 5 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac
6 // in base/path_service.cc. 6 // in base/path_service.cc.
7 7
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #include <mach-o/dyld.h> 10 #include <mach-o/dyld.h>
(...skipping 14 matching lines...) Expand all
25 DCHECK(path); 25 DCHECK(path);
26 // Executable path can have relative references ("..") depending on 26 // Executable path can have relative references ("..") depending on
27 // how the app was launched. 27 // how the app was launched.
28 uint32_t executable_length = 0; 28 uint32_t executable_length = 0;
29 _NSGetExecutablePath(NULL, &executable_length); 29 _NSGetExecutablePath(NULL, &executable_length);
30 DCHECK_GT(executable_length, 1u); 30 DCHECK_GT(executable_length, 1u);
31 std::string executable_path; 31 std::string executable_path;
32 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length), 32 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length),
33 &executable_length); 33 &executable_length);
34 DCHECK_EQ(rv, 0); 34 DCHECK_EQ(rv, 0);
35 *path = base::FilePath(executable_path); 35
36 // _NSGetExecutablePath may return paths containing ./ or ../ which makes
37 // FilePath::DirName() work incorrectly, convert it to absolute path so that
38 // paths such as DIR_SOURCE_ROOT can work.
39 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path));
Nico 2013/07/10 18:02:31 Hm, are you sure these paths never get persisted s
brettw 2013/08/06 04:52:06 We do want an absolute path here. We should be sur
36 } 40 }
37 41
38 // Returns true if the module for |address| is found. |path| will contain 42 // Returns true if the module for |address| is found. |path| will contain
39 // the path to the module. Note that |path| may not be absolute. 43 // the path to the module. Note that |path| may not be absolute.
40 bool GetModulePathForAddress(base::FilePath* path, 44 bool GetModulePathForAddress(base::FilePath* path,
41 const void* address) WARN_UNUSED_RESULT; 45 const void* address) WARN_UNUSED_RESULT;
42 46
43 bool GetModulePathForAddress(base::FilePath* path, const void* address) { 47 bool GetModulePathForAddress(base::FilePath* path, const void* address) {
44 Dl_info info; 48 Dl_info info;
45 if (dladdr(address, &info) == 0) 49 if (dladdr(address, &info) == 0)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return base::mac::GetUserDirectory(NSCachesDirectory, result); 107 return base::mac::GetUserDirectory(NSCachesDirectory, result);
104 case base::DIR_HOME: 108 case base::DIR_HOME:
105 *result = base::mac::NSStringToFilePath(NSHomeDirectory()); 109 *result = base::mac::NSStringToFilePath(NSHomeDirectory());
106 return true; 110 return true;
107 default: 111 default:
108 return false; 112 return false;
109 } 113 }
110 } 114 }
111 115
112 } // namespace base 116 } // namespace base
OLDNEW
« 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