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/label.h" | 5 #include "tools/gn/label.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" |
8 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
| 10 #include "tools/gn/filesystem_utils.h" |
9 #include "tools/gn/parse_tree.h" | 11 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/value.h" | 12 #include "tools/gn/value.h" |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 // We print user visible label names with no trailing slash after the | 16 // We print user visible label names with no trailing slash after the |
15 // directory name. | 17 // directory name. |
16 std::string DirWithNoTrailingSlash(const SourceDir& dir) { | 18 std::string DirWithNoTrailingSlash(const SourceDir& dir) { |
17 // Be careful not to trim if the input is just "/" or "//". | 19 // Be careful not to trim if the input is just "/" or "//". |
18 if (dir.value().size() > 2) | 20 if (dir.value().size() > 2) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 const Label& current_toolchain, | 88 const Label& current_toolchain, |
87 const Value& original_value, | 89 const Value& original_value, |
88 const base::StringPiece& input, | 90 const base::StringPiece& input, |
89 SourceDir* out_dir, | 91 SourceDir* out_dir, |
90 std::string* out_name, | 92 std::string* out_name, |
91 SourceDir* out_toolchain_dir, | 93 SourceDir* out_toolchain_dir, |
92 std::string* out_toolchain_name, | 94 std::string* out_toolchain_name, |
93 Err* err) { | 95 Err* err) { |
94 // To workaround the problem that StringPiece operator[] doesn't return a ref. | 96 // To workaround the problem that StringPiece operator[] doesn't return a ref. |
95 const char* input_str = input.data(); | 97 const char* input_str = input.data(); |
96 | 98 size_t offset = 0; |
97 size_t path_separator = input.find_first_of(":("); | 99 #if defined(OS_WIN) |
| 100 if (IsPathAbsolute(input)) { |
| 101 if (input[0] != '/') { |
| 102 *err = Err(original_value, "Bad absolute path.", |
| 103 "Absolute paths must be of the form /C:\\ but this is \"" + |
| 104 input.as_string() + "\"."); |
| 105 return false; |
| 106 } |
| 107 if (input.size() > 3 && input[2] == ':' && IsSlash(input[3]) && |
| 108 IsAsciiAlpha(input[1])) { |
| 109 // Skip over the drive letter colon. |
| 110 offset = 3; |
| 111 } |
| 112 } |
| 113 #endif |
| 114 size_t path_separator = input.find_first_of(":(", offset); |
98 base::StringPiece location_piece; | 115 base::StringPiece location_piece; |
99 base::StringPiece name_piece; | 116 base::StringPiece name_piece; |
100 base::StringPiece toolchain_piece; | 117 base::StringPiece toolchain_piece; |
101 if (path_separator == std::string::npos) { | 118 if (path_separator == std::string::npos) { |
102 location_piece = input; | 119 location_piece = input; |
103 // Leave name & toolchain piece null. | 120 // Leave name & toolchain piece null. |
104 } else { | 121 } else { |
105 location_piece = base::StringPiece(&input_str[0], path_separator); | 122 location_piece = base::StringPiece(&input_str[0], path_separator); |
106 | 123 |
107 size_t toolchain_separator = input.find('(', path_separator); | 124 size_t toolchain_separator = input.find('(', path_separator); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 270 } |
254 return ret; | 271 return ret; |
255 } | 272 } |
256 | 273 |
257 std::string Label::GetUserVisibleName(const Label& default_toolchain) const { | 274 std::string Label::GetUserVisibleName(const Label& default_toolchain) const { |
258 bool include_toolchain = | 275 bool include_toolchain = |
259 default_toolchain.dir() != toolchain_dir_ || | 276 default_toolchain.dir() != toolchain_dir_ || |
260 default_toolchain.name() != toolchain_name_; | 277 default_toolchain.name() != toolchain_name_; |
261 return GetUserVisibleName(include_toolchain); | 278 return GetUserVisibleName(include_toolchain); |
262 } | 279 } |
OLD | NEW |