Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: tools/gn/label.cc

Issue 857163002: Absolute path fixes for gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows fixes and additional tests Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 on the form /C:\\");
brettw 2015/02/06 23:08:37 "on the form" -> "of the form". Can you append to
104 return false;
105 }
106 if (input.size() > 3 && input[2] == ':' && IsSlash(input[3]) &&
107 IsAsciiAlpha(input[1])) {
108 // Skip over the drive letter colon.
109 offset = 3;
110 }
111 }
112 #endif
113 size_t path_separator = input.find_first_of(":(", offset);
98 base::StringPiece location_piece; 114 base::StringPiece location_piece;
99 base::StringPiece name_piece; 115 base::StringPiece name_piece;
100 base::StringPiece toolchain_piece; 116 base::StringPiece toolchain_piece;
101 if (path_separator == std::string::npos) { 117 if (path_separator == std::string::npos) {
102 location_piece = input; 118 location_piece = input;
103 // Leave name & toolchain piece null. 119 // Leave name & toolchain piece null.
104 } else { 120 } else {
105 location_piece = base::StringPiece(&input_str[0], path_separator); 121 location_piece = base::StringPiece(&input_str[0], path_separator);
106 122
107 size_t toolchain_separator = input.find('(', path_separator); 123 size_t toolchain_separator = input.find('(', path_separator);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 269 }
254 return ret; 270 return ret;
255 } 271 }
256 272
257 std::string Label::GetUserVisibleName(const Label& default_toolchain) const { 273 std::string Label::GetUserVisibleName(const Label& default_toolchain) const {
258 bool include_toolchain = 274 bool include_toolchain =
259 default_toolchain.dir() != toolchain_dir_ || 275 default_toolchain.dir() != toolchain_dir_ ||
260 default_toolchain.name() != toolchain_name_; 276 default_toolchain.name() != toolchain_name_;
261 return GetUserVisibleName(include_toolchain); 277 return GetUserVisibleName(include_toolchain);
262 } 278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698