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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Allow passing this in the environment, for more flexibility in build | 76 // Allow passing this in the environment, for more flexibility in build |
77 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 77 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
78 scoped_ptr<base::Environment> env(base::Environment::Create()); | 78 scoped_ptr<base::Environment> env(base::Environment::Create()); |
79 std::string cr_source_root; | 79 std::string cr_source_root; |
80 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { | 80 if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { |
81 path = FilePath(cr_source_root); | 81 path = FilePath(cr_source_root); |
82 if (file_util::PathExists(path.Append(kThisSourceFile))) { | 82 if (file_util::PathExists(path.Append(kThisSourceFile))) { |
83 *result = path; | 83 *result = path; |
84 return true; | 84 return true; |
85 } else { | 85 } else { |
86 LOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " | 86 DLOG(WARNING) << "CR_SOURCE_ROOT is set, but it appears to not " |
87 << "point to the correct source root directory."; | 87 << "point to the correct source root directory."; |
88 } | 88 } |
89 } | 89 } |
90 // On POSIX, unit tests execute two levels deep from the source root. | 90 // On POSIX, unit tests execute two levels deep from the source root. |
91 // For example: out/{Debug|Release}/net_unittest | 91 // For example: out/{Debug|Release}/net_unittest |
92 if (PathService::Get(base::DIR_EXE, &path)) { | 92 if (PathService::Get(base::DIR_EXE, &path)) { |
93 path = path.DirName().DirName(); | 93 path = path.DirName().DirName(); |
94 if (file_util::PathExists(path.Append(kThisSourceFile))) { | 94 if (file_util::PathExists(path.Append(kThisSourceFile))) { |
95 *result = path; | 95 *result = path; |
96 return true; | 96 return true; |
97 } | 97 } |
98 } | 98 } |
99 // In a case of WebKit-only checkout, executable files are put into | 99 // In a case of WebKit-only checkout, executable files are put into |
100 // <root of checkout>/out/{Debug|Release}, and we should return | 100 // <root of checkout>/out/{Debug|Release}, and we should return |
101 // <root of checkout>/Source/WebKit/chromium for DIR_SOURCE_ROOT. | 101 // <root of checkout>/Source/WebKit/chromium for DIR_SOURCE_ROOT. |
102 if (PathService::Get(base::DIR_EXE, &path)) { | 102 if (PathService::Get(base::DIR_EXE, &path)) { |
103 path = path.DirName().DirName().Append("Source/WebKit/chromium"); | 103 path = path.DirName().DirName().Append("Source/WebKit/chromium"); |
104 if (file_util::PathExists(path.Append(kThisSourceFile))) { | 104 if (file_util::PathExists(path.Append(kThisSourceFile))) { |
105 *result = path; | 105 *result = path; |
106 return true; | 106 return true; |
107 } | 107 } |
108 } | 108 } |
109 // If that failed (maybe the build output is symlinked to a different | 109 // If that failed (maybe the build output is symlinked to a different |
110 // drive) try assuming the current directory is the source root. | 110 // drive) try assuming the current directory is the source root. |
111 if (file_util::GetCurrentDirectory(&path) && | 111 if (file_util::GetCurrentDirectory(&path) && |
112 file_util::PathExists(path.Append(kThisSourceFile))) { | 112 file_util::PathExists(path.Append(kThisSourceFile))) { |
113 *result = path; | 113 *result = path; |
114 return true; | 114 return true; |
115 } | 115 } |
116 LOG(ERROR) << "Couldn't find your source root. " | 116 DLOG(ERROR) << "Couldn't find your source root. " |
117 << "Try running from your chromium/src directory."; | 117 << "Try running from your chromium/src directory."; |
118 return false; | 118 return false; |
119 } | 119 } |
120 case base::DIR_CACHE: | 120 case base::DIR_CACHE: |
121 scoped_ptr<base::Environment> env(base::Environment::Create()); | 121 scoped_ptr<base::Environment> env(base::Environment::Create()); |
122 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", | 122 FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", |
123 ".cache")); | 123 ".cache")); |
124 *result = cache_dir; | 124 *result = cache_dir; |
125 return true; | 125 return true; |
126 } | 126 } |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 } // namespace base | 130 } // namespace base |
OLD | NEW |