| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/label_pattern.h" | 5 #include "tools/gn/label_pattern.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" |
| 7 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
| 8 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
| 9 #include "tools/gn/value.h" | 10 #include "tools/gn/value.h" |
| 10 | 11 |
| 11 const char kLabelPattern_Help[] = | 12 const char kLabelPattern_Help[] = |
| 12 "Label patterns\n" | 13 "Label patterns\n" |
| 13 "\n" | 14 "\n" |
| 14 " A label pattern is a way of expressing one or more labels in a portion\n" | 15 " A label pattern is a way of expressing one or more labels in a portion\n" |
| 15 " of the source tree. They are not general regular expressions.\n" | 16 " of the source tree. They are not general regular expressions.\n" |
| 16 "\n" | 17 "\n" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (err->has_error()) | 115 if (err->has_error()) |
| 115 return LabelPattern(); | 116 return LabelPattern(); |
| 116 | 117 |
| 117 // Trim off the toolchain for the processing below. | 118 // Trim off the toolchain for the processing below. |
| 118 str = str.substr(0, open_paren); | 119 str = str.substr(0, open_paren); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Extract path and name. | 122 // Extract path and name. |
| 122 base::StringPiece path; | 123 base::StringPiece path; |
| 123 base::StringPiece name; | 124 base::StringPiece name; |
| 124 size_t colon = str.find(':'); | 125 size_t offset = 0; |
| 126 #if defined(OS_WIN) |
| 127 if (IsPathAbsolute(str)) { |
| 128 if (str[0] != '/') { |
| 129 *err = Err(value, "Bad absolute path.", |
| 130 "Absolute paths must be of the form /C:\\ but this is \"" + |
| 131 str.as_string() + "\"."); |
| 132 return LabelPattern(); |
| 133 } |
| 134 if (str.size() > 3 && str[2] == ':' && IsSlash(str[3]) && |
| 135 IsAsciiAlpha(str[1])) { |
| 136 // Skip over the drive letter colon. |
| 137 offset = 3; |
| 138 } |
| 139 } |
| 140 #endif |
| 141 size_t colon = str.find(':', offset); |
| 125 if (colon == std::string::npos) { | 142 if (colon == std::string::npos) { |
| 126 path = base::StringPiece(str); | 143 path = base::StringPiece(str); |
| 127 } else { | 144 } else { |
| 128 path = str.substr(0, colon); | 145 path = str.substr(0, colon); |
| 129 name = str.substr(colon + 1); | 146 name = str.substr(colon + 1); |
| 130 } | 147 } |
| 131 | 148 |
| 132 // The path can have these forms: | 149 // The path can have these forms: |
| 133 // 1. <empty> (use current dir) | 150 // 1. <empty> (use current dir) |
| 134 // 2. <non wildcard stuff> (send through directory resolution) | 151 // 2. <non wildcard stuff> (send through directory resolution) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 break; | 255 break; |
| 239 } | 256 } |
| 240 | 257 |
| 241 if (!toolchain_.is_null()) { | 258 if (!toolchain_.is_null()) { |
| 242 result.push_back('('); | 259 result.push_back('('); |
| 243 result.append(toolchain_.GetUserVisibleName(false)); | 260 result.append(toolchain_.GetUserVisibleName(false)); |
| 244 result.push_back(')'); | 261 result.push_back(')'); |
| 245 } | 262 } |
| 246 return result; | 263 return result; |
| 247 } | 264 } |
| OLD | NEW |