michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/base_paths_mac.h" michael@0: michael@0: #import michael@0: michael@0: #include "base/file_path.h" michael@0: #include "base/file_util.h" michael@0: #include "base/logging.h" michael@0: #include "base/mac_util.h" michael@0: #include "base/path_service.h" michael@0: #include "base/string_util.h" michael@0: michael@0: namespace base { michael@0: michael@0: bool PathProviderMac(int key, FilePath* result) { michael@0: std::string cur; michael@0: switch (key) { michael@0: case base::FILE_EXE: michael@0: case base::FILE_MODULE: { michael@0: // Executable path can have relative references ("..") depending on michael@0: // how the app was launched. michael@0: NSString* path = michael@0: [[[NSBundle mainBundle] executablePath] stringByStandardizingPath]; michael@0: cur = [path fileSystemRepresentation]; michael@0: break; michael@0: } michael@0: case base::DIR_SOURCE_ROOT: { michael@0: FilePath path; michael@0: PathService::Get(base::DIR_EXE, &path); michael@0: if (mac_util::AmIBundled()) { michael@0: // The bundled app executables (Chromium, TestShell, etc) live five michael@0: // levels down, eg: michael@0: // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium. michael@0: path = path.DirName(); michael@0: path = path.DirName(); michael@0: path = path.DirName(); michael@0: path = path.DirName(); michael@0: *result = path.DirName(); michael@0: } else { michael@0: // Unit tests execute two levels deep from the source root, eg: michael@0: // src/xcodebuild/{Debug|Release}/base_unittests michael@0: path = path.DirName(); michael@0: *result = path.DirName(); michael@0: } michael@0: return true; michael@0: } michael@0: default: michael@0: return false; michael@0: } michael@0: michael@0: *result = FilePath(cur); michael@0: return true; michael@0: } michael@0: michael@0: } // namespace base