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

Side by Side Diff: tools/gn/value_extractors.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 (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/value_extractors.h" 5 #include "tools/gn/value_extractors.h"
6 6
7 #include "tools/gn/build_settings.h" 7 #include "tools/gn/build_settings.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/label.h" 9 #include "tools/gn/label.h"
10 #include "tools/gn/source_dir.h" 10 #include "tools/gn/source_dir.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 *err = Err(item, "Duplicate item in list"); 51 *err = Err(item, "Duplicate item in list");
52 size_t previous_index = dest->IndexOf(new_one); 52 size_t previous_index = dest->IndexOf(new_one);
53 err->AppendSubErr(Err(input_list[previous_index], 53 err->AppendSubErr(Err(input_list[previous_index],
54 "This was the previous definition.")); 54 "This was the previous definition."));
55 return false; 55 return false;
56 } 56 }
57 } 57 }
58 return true; 58 return true;
59 } 59 }
60 60
61 // This extractor rejects files with system-absolute file paths. If we need
62 // that in the future, we'll have to add some flag to control this.
63 struct RelativeFileConverter { 61 struct RelativeFileConverter {
64 RelativeFileConverter(const BuildSettings* build_settings_in, 62 RelativeFileConverter(const BuildSettings* build_settings_in,
65 const SourceDir& current_dir_in) 63 const SourceDir& current_dir_in)
66 : build_settings(build_settings_in), 64 : build_settings(build_settings_in),
67 current_dir(current_dir_in) { 65 current_dir(current_dir_in) {
68 } 66 }
69 bool operator()(const Value& v, SourceFile* out, Err* err) const { 67 bool operator()(const Value& v, SourceFile* out, Err* err) const {
70 if (!v.VerifyTypeIs(Value::STRING, err)) 68 if (!v.VerifyTypeIs(Value::STRING, err))
71 return false; 69 return false;
72 *out = current_dir.ResolveRelativeFile(v.string_value(), 70 *out = current_dir.ResolveRelativeFile(v.string_value(),
73 build_settings->root_path_utf8()); 71 build_settings->root_path());
74 if (out->is_system_absolute()) {
75 *err = Err(v, "System-absolute file path.",
76 "You can't list a system-absolute file path here. Please include "
77 "only files in\nthe source tree. Maybe you meant to begin with two "
78 "slashes to indicate an\nabsolute path in the source tree?");
79 return false;
80 }
81 return true; 72 return true;
82 } 73 }
83 const BuildSettings* build_settings; 74 const BuildSettings* build_settings;
84 const SourceDir& current_dir; 75 const SourceDir& current_dir;
85 }; 76 };
86 77
87 struct RelativeDirConverter { 78 struct RelativeDirConverter {
88 RelativeDirConverter(const BuildSettings* build_settings_in, 79 RelativeDirConverter(const BuildSettings* build_settings_in,
89 const SourceDir& current_dir_in) 80 const SourceDir& current_dir_in)
90 : build_settings(build_settings_in), 81 : build_settings(build_settings_in),
91 current_dir(current_dir_in) { 82 current_dir(current_dir_in) {
92 } 83 }
93 bool operator()(const Value& v, SourceDir* out, Err* err) const { 84 bool operator()(const Value& v, SourceDir* out, Err* err) const {
94 if (!v.VerifyTypeIs(Value::STRING, err)) 85 if (!v.VerifyTypeIs(Value::STRING, err))
95 return false; 86 return false;
96 *out = current_dir.ResolveRelativeDir(v.string_value(), 87 *out = current_dir.ResolveRelativeDir(v.string_value(),
97 build_settings->root_path_utf8()); 88 build_settings->root_path());
98 return true; 89 return true;
99 } 90 }
100 const BuildSettings* build_settings; 91 const BuildSettings* build_settings;
101 const SourceDir& current_dir; 92 const SourceDir& current_dir;
102 }; 93 };
103 94
104 // Fills in a label. 95 // Fills in a label.
105 template<typename T> struct LabelResolver { 96 template<typename T> struct LabelResolver {
106 LabelResolver(const SourceDir& current_dir_in, 97 LabelResolver(const SourceDir& current_dir_in,
107 const Label& current_toolchain_in) 98 const Label& current_toolchain_in,
99 const base::FilePath& source_root_in)
108 : current_dir(current_dir_in), 100 : current_dir(current_dir_in),
109 current_toolchain(current_toolchain_in) {} 101 current_toolchain(current_toolchain_in),
102 source_root(source_root_in) {}
110 bool operator()(const Value& v, Label* out, Err* err) const { 103 bool operator()(const Value& v, Label* out, Err* err) const {
111 if (!v.VerifyTypeIs(Value::STRING, err)) 104 if (!v.VerifyTypeIs(Value::STRING, err))
112 return false; 105 return false;
113 *out = Label::Resolve(current_dir, current_toolchain, v, err); 106 *out = Label::Resolve(current_dir, current_toolchain, v, source_root, err);
114 return !err->has_error(); 107 return !err->has_error();
115 } 108 }
116 const SourceDir& current_dir; 109 const SourceDir& current_dir;
117 const Label& current_toolchain; 110 const Label& current_toolchain;
111 const base::FilePath& source_root;
118 }; 112 };
119 113
120 // Fills the label part of a LabelPtrPair, leaving the pointer null. 114 // Fills the label part of a LabelPtrPair, leaving the pointer null.
121 template<typename T> struct LabelPtrResolver { 115 template<typename T> struct LabelPtrResolver {
122 LabelPtrResolver(const SourceDir& current_dir_in, 116 LabelPtrResolver(const SourceDir& current_dir_in,
123 const Label& current_toolchain_in) 117 const Label& current_toolchain_in,
118 const base::FilePath& source_root_in)
124 : current_dir(current_dir_in), 119 : current_dir(current_dir_in),
125 current_toolchain(current_toolchain_in) {} 120 current_toolchain(current_toolchain_in),
121 source_root(source_root_in) {}
126 bool operator()(const Value& v, LabelPtrPair<T>* out, Err* err) const { 122 bool operator()(const Value& v, LabelPtrPair<T>* out, Err* err) const {
127 if (!v.VerifyTypeIs(Value::STRING, err)) 123 if (!v.VerifyTypeIs(Value::STRING, err))
128 return false; 124 return false;
129 out->label = Label::Resolve(current_dir, current_toolchain, v, err); 125 out->label = Label::Resolve(current_dir, current_toolchain, v, source_root,
126 err);
130 out->origin = v.origin(); 127 out->origin = v.origin();
131 return !err->has_error(); 128 return !err->has_error();
132 } 129 }
133 const SourceDir& current_dir; 130 const SourceDir& current_dir;
134 const Label& current_toolchain; 131 const Label& current_toolchain;
132 const base::FilePath& source_root;
135 }; 133 };
136 134
137 } // namespace 135 } // namespace
138 136
139 bool ExtractListOfStringValues(const Value& value, 137 bool ExtractListOfStringValues(const Value& value,
140 std::vector<std::string>* dest, 138 std::vector<std::string>* dest,
141 Err* err) { 139 Err* err) {
142 if (!value.VerifyTypeIs(Value::LIST, err)) 140 if (!value.VerifyTypeIs(Value::LIST, err))
143 return false; 141 return false;
144 const std::vector<Value>& input_list = value.list_value(); 142 const std::vector<Value>& input_list = value.list_value();
(...skipping 17 matching lines...) Expand all
162 160
163 bool ExtractListOfRelativeDirs(const BuildSettings* build_settings, 161 bool ExtractListOfRelativeDirs(const BuildSettings* build_settings,
164 const Value& value, 162 const Value& value,
165 const SourceDir& current_dir, 163 const SourceDir& current_dir,
166 std::vector<SourceDir>* dest, 164 std::vector<SourceDir>* dest,
167 Err* err) { 165 Err* err) {
168 return ListValueExtractor(value, dest, err, 166 return ListValueExtractor(value, dest, err,
169 RelativeDirConverter(build_settings, current_dir)); 167 RelativeDirConverter(build_settings, current_dir));
170 } 168 }
171 169
172 bool ExtractListOfLabels(const Value& value, 170 bool ExtractListOfLabels(const BuildSettings* build_settings,
171 const Value& value,
173 const SourceDir& current_dir, 172 const SourceDir& current_dir,
174 const Label& current_toolchain, 173 const Label& current_toolchain,
175 LabelTargetVector* dest, 174 LabelTargetVector* dest,
176 Err* err) { 175 Err* err) {
177 return ListValueExtractor(value, dest, err, 176 return ListValueExtractor(value, dest, err,
178 LabelPtrResolver<Target>(current_dir, 177 LabelPtrResolver<Target>(
179 current_toolchain)); 178 current_dir, current_toolchain,
179 build_settings->root_path()));
180 } 180 }
181 181
182 bool ExtractListOfUniqueLabels(const Value& value, 182 bool ExtractListOfUniqueLabels(const BuildSettings* build_settings,
183 const Value& value,
183 const SourceDir& current_dir, 184 const SourceDir& current_dir,
184 const Label& current_toolchain, 185 const Label& current_toolchain,
185 UniqueVector<Label>* dest, 186 UniqueVector<Label>* dest,
186 Err* err) { 187 Err* err) {
187 return ListValueUniqueExtractor(value, dest, err, 188 return ListValueUniqueExtractor(value, dest, err,
188 LabelResolver<Config>(current_dir, 189 LabelResolver<Config>(
189 current_toolchain)); 190 current_dir, current_toolchain,
191 build_settings->root_path()));
190 } 192 }
191 193
192 bool ExtractListOfUniqueLabels(const Value& value, 194 bool ExtractListOfUniqueLabels(const BuildSettings* build_settings,
195 const Value& value,
193 const SourceDir& current_dir, 196 const SourceDir& current_dir,
194 const Label& current_toolchain, 197 const Label& current_toolchain,
195 UniqueVector<LabelConfigPair>* dest, 198 UniqueVector<LabelConfigPair>* dest,
196 Err* err) { 199 Err* err) {
197 return ListValueUniqueExtractor(value, dest, err, 200 return ListValueUniqueExtractor(value, dest, err,
198 LabelPtrResolver<Config>(current_dir, 201 LabelPtrResolver<Config>(
199 current_toolchain)); 202 current_dir, current_toolchain,
203 build_settings->root_path()));
200 } 204 }
201 205
202 bool ExtractListOfUniqueLabels(const Value& value, 206 bool ExtractListOfUniqueLabels(const BuildSettings* build_settings,
207 const Value& value,
203 const SourceDir& current_dir, 208 const SourceDir& current_dir,
204 const Label& current_toolchain, 209 const Label& current_toolchain,
205 UniqueVector<LabelTargetPair>* dest, 210 UniqueVector<LabelTargetPair>* dest,
206 Err* err) { 211 Err* err) {
207 return ListValueUniqueExtractor(value, dest, err, 212 return ListValueUniqueExtractor(value, dest, err,
208 LabelPtrResolver<Target>(current_dir, 213 LabelPtrResolver<Target>(
209 current_toolchain)); 214 current_dir, current_toolchain,
215 build_settings->root_path()));
210 } 216 }
211 217
212 bool ExtractRelativeFile(const BuildSettings* build_settings, 218 bool ExtractRelativeFile(const BuildSettings* build_settings,
213 const Value& value, 219 const Value& value,
214 const SourceDir& current_dir, 220 const SourceDir& current_dir,
215 SourceFile* file, 221 SourceFile* file,
216 Err* err) { 222 Err* err) {
217 RelativeFileConverter converter(build_settings, current_dir); 223 RelativeFileConverter converter(build_settings, current_dir);
218 return converter(value, file, err); 224 return converter(value, file, err);
219 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698