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

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: Patch that compiles and passes unit tests on both Windows and Linux Created 6 years, 1 month 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
« no previous file with comments | « tools/gn/substitution_writer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_utf8());
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),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 201 }
211 202
212 bool ExtractRelativeFile(const BuildSettings* build_settings, 203 bool ExtractRelativeFile(const BuildSettings* build_settings,
213 const Value& value, 204 const Value& value,
214 const SourceDir& current_dir, 205 const SourceDir& current_dir,
215 SourceFile* file, 206 SourceFile* file,
216 Err* err) { 207 Err* err) {
217 RelativeFileConverter converter(build_settings, current_dir); 208 RelativeFileConverter converter(build_settings, current_dir);
218 return converter(value, file, err); 209 return converter(value, file, err);
219 } 210 }
OLDNEW
« no previous file with comments | « tools/gn/substitution_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698