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

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

Issue 1943583002: GN: forward_variables_from shouldn't clobber vars. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/err.h" 5 #include "tools/gn/err.h"
6 #include "tools/gn/functions.h" 6 #include "tools/gn/functions.h"
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 9
10 namespace functions { 10 namespace functions {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // expect a persistent StringPiece (it won't copy). Not doing this will 47 // expect a persistent StringPiece (it won't copy). Not doing this will
48 // lead the scope's key to point to invalid memory after this returns. 48 // lead the scope's key to point to invalid memory after this returns.
49 base::StringPiece storage_key = source->GetStorageKey(cur.string_value()); 49 base::StringPiece storage_key = source->GetStorageKey(cur.string_value());
50 if (storage_key.empty()) { 50 if (storage_key.empty()) {
51 // Programmatic value, don't allow copying. 51 // Programmatic value, don't allow copying.
52 *err = Err(cur, "This value can't be forwarded.", 52 *err = Err(cur, "This value can't be forwarded.",
53 "The variable \"" + cur.string_value() + "\" is a built-in."); 53 "The variable \"" + cur.string_value() + "\" is a built-in.");
54 return; 54 return;
55 } 55 }
56 56
57 // Don't allow clobbering existing values.
58 const Value* existing_value = dest->GetValue(storage_key);
59 if (existing_value) {
60 *err = Err(cur, "Clobbering existing value.",
61 "The current scope already defines a value \"" +
62 cur.string_value() + "\".\nforward_variables_from() won't clobber "
63 "existing values. If you want to\nmerge lists, you'll need to "
64 "do this explicitly.");
65 err->AppendSubErr(Err(*existing_value, "value being clobbered."));
66 return;
67 }
68
57 // Keep the origin information from the original value. The normal 69 // Keep the origin information from the original value. The normal
58 // usage is for this to be used in a template, and if there's an error, 70 // usage is for this to be used in a template, and if there's an error,
59 // the user expects to see the line where they set the variable 71 // the user expects to see the line where they set the variable
60 // blamed, rather than a template call to forward_variables_from(). 72 // blamed, rather than a template call to forward_variables_from().
61 dest->SetValue(storage_key, *value, value->origin()); 73 dest->SetValue(storage_key, *value, value->origin());
62 } 74 }
63 } 75 }
64 } 76 }
65 77
66 } // namespace 78 } // namespace
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 230 }
219 } 231 }
220 232
221 // Not the right type of argument. 233 // Not the right type of argument.
222 *err = Err(what_value, "Not a valid list of variables to copy.", 234 *err = Err(what_value, "Not a valid list of variables to copy.",
223 "Expecting either the string \"*\" or a list of strings."); 235 "Expecting either the string \"*\" or a list of strings.");
224 return Value(); 236 return Value();
225 } 237 }
226 238
227 } // namespace functions 239 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698