| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #elif defined(OS_SOLARIS) | 22 #elif defined(OS_SOLARIS) |
| 23 #include <stdlib.h> | 23 #include <stdlib.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 | 27 |
| 28 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
| 29 const char kSelfExe[] = "/proc/self/exe"; | 29 const char kSelfExe[] = "/proc/self/exe"; |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 // The name of this file relative to the source root. This is used for checking | |
| 33 // that the source checkout is in the correct place. | |
| 34 static const char kThisSourceFile[] = "base/base_paths_posix.cc"; | |
| 35 | |
| 36 bool PathProviderPosix(int key, FilePath* result) { | 32 bool PathProviderPosix(int key, FilePath* result) { |
| 37 FilePath path; | 33 FilePath path; |
| 38 switch (key) { | 34 switch (key) { |
| 39 case base::FILE_EXE: | 35 case base::FILE_EXE: |
| 40 case base::FILE_MODULE: { // TODO(evanm): is this correct? | 36 case base::FILE_MODULE: { // TODO(evanm): is this correct? |
| 41 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
| 42 FilePath bin_dir; | 38 FilePath bin_dir; |
| 43 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { | 39 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { |
| 44 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 40 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; |
| 45 return false; | 41 return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return true; | 73 return true; |
| 78 #endif | 74 #endif |
| 79 } | 75 } |
| 80 case base::DIR_SOURCE_ROOT: { | 76 case base::DIR_SOURCE_ROOT: { |
| 81 // Allow passing this in the environment, for more flexibility in build | 77 // Allow passing this in the environment, for more flexibility in build |
| 82 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 78 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
| 83 scoped_ptr<base::Environment> env(base::Environment::Create()); | 79 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 84 std::string cr_source_root; | 80 std::string cr_source_root; |
| 85 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { | 81 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { |
| 86 path = FilePath(cr_source_root); | 82 path = FilePath(cr_source_root); |
| 87 if (file_util::PathExists(path.Append(kThisSourceFile))) { | 83 if (file_util::PathExists(path)) { |
| 88 *result = path; | 84 *result = path; |
| 89 return true; | 85 return true; |
| 90 } else { | 86 } else { |
| 91 DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " | 87 DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " |
| 92 << "point to the correct source root directory."; | 88 << "point to a directory."; |
| 93 } | 89 } |
| 94 } | 90 } |
| 95 // On POSIX, unit tests execute two levels deep from the source root. | 91 // On POSIX, unit tests execute two levels deep from the source root. |
| 96 // For example: out/{Debug|Release}/net_unittest | 92 // For example: out/{Debug|Release}/net_unittest |
| 97 if (PathService::Get(base::DIR_EXE, &path)) { | 93 if (PathService::Get(base::DIR_EXE, &path)) { |
| 98 path = path.DirName().DirName(); | 94 *result = path.DirName().DirName(); |
| 99 if (file_util::PathExists(path.Append(kThisSourceFile))) { | |
| 100 *result = path; | |
| 101 return true; | |
| 102 } | |
| 103 } | |
| 104 // In a case of WebKit-only checkout, executable files are put into | |
| 105 // <root of checkout>/out/{Debug|Release}, and we should return | |
| 106 // <root of checkout>/Source/WebKit/chromium for DIR_SOURCE_ROOT. | |
| 107 if (PathService::Get(base::DIR_EXE, &path)) { | |
| 108 path = path.DirName().DirName().Append("Source/WebKit/chromium"); | |
| 109 if (file_util::PathExists(path.Append(kThisSourceFile))) { | |
| 110 *result = path; | |
| 111 return true; | |
| 112 } | |
| 113 } | |
| 114 // If that failed (maybe the build output is symlinked to a different | |
| 115 // drive) try assuming the current directory is the source root. | |
| 116 if (file_util::GetCurrentDirectory(&path) && | |
| 117 file_util::PathExists(path.Append(kThisSourceFile))) { | |
| 118 *result = path; | |
| 119 return true; | 95 return true; |
| 120 } | 96 } |
| 97 |
| 121 DLOG(ERROR) << "Couldn't find your source root. " | 98 DLOG(ERROR) << "Couldn't find your source root. " |
| 122 << "Try running from your chromium/src directory."; | 99 << "Try running from your chromium/src directory."; |
| 123 return false; | 100 return false; |
| 124 } | 101 } |
| 125 case base::DIR_CACHE: | 102 case base::DIR_CACHE: |
| 126 scoped_ptr<base::Environment> env(base::Environment::Create()); | 103 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 127 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 104 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
| 128 ".cache")); | 105 ".cache")); |
| 129 *result = cache_dir; | 106 *result = cache_dir; |
| 130 return true; | 107 return true; |
| 131 } | 108 } |
| 132 return false; | 109 return false; |
| 133 } | 110 } |
| 134 | 111 |
| 135 } // namespace base | 112 } // namespace base |
| OLD | NEW |