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

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

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 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 "tools/gn/err.h" 7 #include "tools/gn/err.h"
8 #include "tools/gn/filesystem_utils.h" 8 #include "tools/gn/filesystem_utils.h"
9 #include "tools/gn/value.h" 9 #include "tools/gn/value.h"
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 : toolchain_(toolchain_label), 54 : toolchain_(toolchain_label),
55 type_(type), 55 type_(type),
56 dir_(dir) { 56 dir_(dir) {
57 name.CopyToString(&name_); 57 name.CopyToString(&name_);
58 } 58 }
59 59
60 LabelPattern::~LabelPattern() { 60 LabelPattern::~LabelPattern() {
61 } 61 }
62 62
63 // static 63 // static
64 LabelPattern LabelPattern::GetPattern(const SourceDir& current_dir, 64 LabelPattern LabelPattern::GetPattern(const base::FilePath& source_root,
65 const SourceDir& current_dir,
65 const Value& value, 66 const Value& value,
66 Err* err) { 67 Err* err) {
67 if (!value.VerifyTypeIs(Value::STRING, err)) 68 if (!value.VerifyTypeIs(Value::STRING, err))
68 return LabelPattern(); 69 return LabelPattern();
69 70
70 base::StringPiece str(value.string_value()); 71 base::StringPiece str(value.string_value());
71 if (str.empty()) { 72 if (str.empty()) {
72 *err = Err(value, "Label pattern must not be empty."); 73 *err = Err(value, "Label pattern must not be empty.");
73 return LabelPattern(); 74 return LabelPattern();
74 } 75 }
75 76
76 // If there's no wildcard, this is specifying an exact label, use the 77 // If there's no wildcard, this is specifying an exact label, use the
77 // label resolution code to get all the implicit name stuff. 78 // label resolution code to get all the implicit name stuff.
78 size_t star = str.find('*'); 79 size_t star = str.find('*');
79 if (star == std::string::npos) { 80 if (star == std::string::npos) {
80 Label label = Label::Resolve(current_dir, Label(), value, err); 81 Label label = Label::Resolve(current_dir, Label(), value, source_root, err);
81 if (err->has_error()) 82 if (err->has_error())
82 return LabelPattern(); 83 return LabelPattern();
83 84
84 // Toolchain. 85 // Toolchain.
85 Label toolchain_label; 86 Label toolchain_label;
86 if (!label.toolchain_dir().is_null() || !label.toolchain_name().empty()) 87 if (!label.toolchain_dir().is_null() || !label.toolchain_name().empty())
87 toolchain_label = label.GetToolchainLabel(); 88 toolchain_label = label.GetToolchainLabel();
88 89
89 return LabelPattern(MATCH, label.dir(), label.name(), toolchain_label); 90 return LabelPattern(MATCH, label.dir(), label.name(), toolchain_label);
90 } 91 }
(...skipping 12 matching lines...) Expand all
103 std::string toolchain_string = 104 std::string toolchain_string =
104 str.substr(open_paren + 1, close_paren - open_paren - 1).as_string(); 105 str.substr(open_paren + 1, close_paren - open_paren - 1).as_string();
105 if (toolchain_string.find('*') != std::string::npos) { 106 if (toolchain_string.find('*') != std::string::npos) {
106 *err = Err(value, "Can't have a wildcard in the toolchain."); 107 *err = Err(value, "Can't have a wildcard in the toolchain.");
107 return LabelPattern(); 108 return LabelPattern();
108 } 109 }
109 110
110 // Parse the inside of the parens as a label for a toolchain. 111 // Parse the inside of the parens as a label for a toolchain.
111 Value value_for_toolchain(value.origin(), toolchain_string); 112 Value value_for_toolchain(value.origin(), toolchain_string);
112 toolchain_label = 113 toolchain_label =
113 Label::Resolve(current_dir, Label(), value_for_toolchain, err); 114 Label::Resolve(current_dir, Label(), value_for_toolchain, source_root,
115 err);
114 if (err->has_error()) 116 if (err->has_error())
115 return LabelPattern(); 117 return LabelPattern();
116 118
117 // Trim off the toolchain for the processing below. 119 // Trim off the toolchain for the processing below.
118 str = str.substr(0, open_paren); 120 str = str.substr(0, open_paren);
119 } 121 }
120 122
121 // Extract path and name. 123 // Extract path and name.
122 base::StringPiece path; 124 base::StringPiece path;
123 base::StringPiece name; 125 base::StringPiece name;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // Resolve the part of the path that's not the wildcard. 161 // Resolve the part of the path that's not the wildcard.
160 if (!path.empty()) { 162 if (!path.empty()) {
161 // The non-wildcard stuff better not have a wildcard. 163 // The non-wildcard stuff better not have a wildcard.
162 if (path.find('*') != base::StringPiece::npos) { 164 if (path.find('*') != base::StringPiece::npos) {
163 *err = Err(value, "Label patterns only support wildcard suffixes.", 165 *err = Err(value, "Label patterns only support wildcard suffixes.",
164 "The pattern contained a '*' that wasn't at tne end."); 166 "The pattern contained a '*' that wasn't at tne end.");
165 return LabelPattern(); 167 return LabelPattern();
166 } 168 }
167 169
168 // Resolve the non-wildcard stuff. 170 // Resolve the non-wildcard stuff.
169 dir = current_dir.ResolveRelativeDir(path); 171 dir = current_dir.ResolveRelativeDir(path, source_root);
170 if (dir.is_null()) { 172 if (dir.is_null()) {
171 *err = Err(value, "Label pattern didn't resolve to a dir.", 173 *err = Err(value, "Label pattern didn't resolve to a dir.",
172 "The directory name \"" + path.as_string() + "\" didn't\n" 174 "The directory name \"" + path.as_string() + "\" didn't\n"
173 "resolve to a directory."); 175 "resolve to a directory.");
174 return LabelPattern(); 176 return LabelPattern();
175 } 177 }
176 } 178 }
177 179
178 // Resolve the name. At this point, we're doing wildcard matches so the 180 // Resolve the name. At this point, we're doing wildcard matches so the
179 // name should either be empty ("foo/*") or a wildcard ("foo:*"); 181 // name should either be empty ("foo/*") or a wildcard ("foo:*");
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 break; 240 break;
239 } 241 }
240 242
241 if (!toolchain_.is_null()) { 243 if (!toolchain_.is_null()) {
242 result.push_back('('); 244 result.push_back('(');
243 result.append(toolchain_.GetUserVisibleName(false)); 245 result.append(toolchain_.GetUserVisibleName(false));
244 result.push_back(')'); 246 result.push_back(')');
245 } 247 }
246 return result; 248 return result;
247 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698