| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "tools/gn/setup.h" | 5 #include "tools/gn/setup.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return try_this_file; | 92 return try_this_file; |
| 93 | 93 |
| 94 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); | 94 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); |
| 95 base::FilePath up_one_dir = with_no_slash.DirName(); | 95 base::FilePath up_one_dir = with_no_slash.DirName(); |
| 96 if (up_one_dir == current_dir) | 96 if (up_one_dir == current_dir) |
| 97 return base::FilePath(); // Got to the top. | 97 return base::FilePath(); // Got to the top. |
| 98 | 98 |
| 99 return FindDotFile(up_one_dir); | 99 return FindDotFile(up_one_dir); |
| 100 } | 100 } |
| 101 | 101 |
| 102 #if defined(OS_WIN) |
| 102 // Searches the list of strings, and returns the FilePat corresponding to the | 103 // Searches the list of strings, and returns the FilePat corresponding to the |
| 103 // one ending in the given substring, or the empty path if none match. | 104 // one ending in the given substring, or the empty path if none match. |
| 104 base::FilePath GetPathEndingIn( | 105 base::FilePath GetPathEndingIn( |
| 105 const std::vector<base::FilePath::StringType>& list, | 106 const std::vector<base::FilePath::StringType>& list, |
| 106 const base::FilePath::StringType ending_in) { | 107 const base::FilePath::StringType ending_in) { |
| 107 for (size_t i = 0; i < list.size(); i++) { | 108 for (size_t i = 0; i < list.size(); i++) { |
| 108 if (EndsWith(list[i], ending_in, true)) | 109 if (EndsWith(list[i], ending_in, true)) |
| 109 return base::FilePath(list[i]); | 110 return base::FilePath(list[i]); |
| 110 } | 111 } |
| 111 return base::FilePath(); | 112 return base::FilePath(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 // Fins the depot tools directory in the path environment variable and returns | 115 // Finds the depot tools directory in the path environment variable and returns |
| 115 // its value. Returns an empty file path if not found. | 116 // its value. Returns an empty file path if not found. |
| 116 // | 117 // |
| 117 // We detect the depot_tools path by looking for a directory with depot_tools | 118 // We detect the depot_tools path by looking for a directory with depot_tools |
| 118 // at the end (optionally followed by a separator). | 119 // at the end (optionally followed by a separator). |
| 119 base::FilePath ExtractDepotToolsFromPath() { | 120 base::FilePath ExtractDepotToolsFromPath() { |
| 120 #if defined(OS_WIN) | |
| 121 static const wchar_t kPathVarName[] = L"Path"; | 121 static const wchar_t kPathVarName[] = L"Path"; |
| 122 DWORD env_buf_size = GetEnvironmentVariable(kPathVarName, NULL, 0); | 122 DWORD env_buf_size = GetEnvironmentVariable(kPathVarName, NULL, 0); |
| 123 if (env_buf_size == 0) | 123 if (env_buf_size == 0) |
| 124 return base::FilePath(); | 124 return base::FilePath(); |
| 125 base::string16 path; | 125 base::string16 path; |
| 126 path.resize(env_buf_size); | 126 path.resize(env_buf_size); |
| 127 GetEnvironmentVariable(kPathVarName, &path[0], | 127 GetEnvironmentVariable(kPathVarName, &path[0], |
| 128 static_cast<DWORD>(path.size())); | 128 static_cast<DWORD>(path.size())); |
| 129 path.resize(path.size() - 1); // Trim off null. | 129 path.resize(path.size() - 1); // Trim off null. |
| 130 | 130 |
| 131 std::vector<base::string16> components; | 131 std::vector<base::string16> components; |
| 132 base::SplitString(path, ';', &components); | 132 base::SplitString(path, ';', &components); |
| 133 | 133 |
| 134 base::string16 ending_in1 = L"depot_tools\\"; | 134 base::string16 ending_in1 = L"depot_tools\\"; |
| 135 #else | |
| 136 static const char kPathVarName[] = "PATH"; | |
| 137 const char* path = getenv(kPathVarName); | |
| 138 if (!path) | |
| 139 return base::FilePath(); | |
| 140 | |
| 141 std::vector<std::string> components; | |
| 142 base::SplitString(path, ':', &components); | |
| 143 | |
| 144 std::string ending_in1 = "depot_tools/"; | |
| 145 #endif | |
| 146 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools"); | 135 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools"); |
| 147 | 136 |
| 148 base::FilePath found = GetPathEndingIn(components, ending_in1); | 137 base::FilePath found = GetPathEndingIn(components, ending_in1); |
| 149 if (!found.empty()) | 138 if (!found.empty()) |
| 150 return found; | 139 return found; |
| 151 return GetPathEndingIn(components, ending_in2); | 140 return GetPathEndingIn(components, ending_in2); |
| 152 } | 141 } |
| 142 #endif |
| 153 | 143 |
| 154 } // namespace | 144 } // namespace |
| 155 | 145 |
| 156 // CommonSetup ----------------------------------------------------------------- | 146 // CommonSetup ----------------------------------------------------------------- |
| 157 | 147 |
| 158 CommonSetup::CommonSetup() | 148 CommonSetup::CommonSetup() |
| 159 : check_for_bad_items_(true) { | 149 : check_for_bad_items_(true) { |
| 160 } | 150 } |
| 161 | 151 |
| 162 CommonSetup::CommonSetup(const CommonSetup& other) | 152 CommonSetup::CommonSetup(const CommonSetup& other) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 419 } |
| 430 | 420 |
| 431 void DependentSetup::RunPreMessageLoop() { | 421 void DependentSetup::RunPreMessageLoop() { |
| 432 CommonSetup::RunPreMessageLoop(); | 422 CommonSetup::RunPreMessageLoop(); |
| 433 } | 423 } |
| 434 | 424 |
| 435 bool DependentSetup::RunPostMessageLoop() { | 425 bool DependentSetup::RunPostMessageLoop() { |
| 436 return CommonSetup::RunPostMessageLoop(); | 426 return CommonSetup::RunPostMessageLoop(); |
| 437 } | 427 } |
| 438 | 428 |
| OLD | NEW |