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

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

Issue 161783002: Remove default value checking in GN, adds getenv function, reorders parameters to rebase_path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/gn/command_args.cc » ('j') | tools/gn/command_args.cc » ('J')
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/args.h" 5 #include "tools/gn/args.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "tools/gn/variables.h" 8 #include "tools/gn/variables.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 Err* err) const { 108 Err* err) const {
109 base::AutoLock lock(lock_); 109 base::AutoLock lock(lock_);
110 110
111 for (Scope::KeyValueMap::const_iterator i = args.begin(); 111 for (Scope::KeyValueMap::const_iterator i = args.begin();
112 i != args.end(); ++i) { 112 i != args.end(); ++i) {
113 // Verify that the value hasn't already been declared. We want each value 113 // Verify that the value hasn't already been declared. We want each value
114 // to be declared only once. 114 // to be declared only once.
115 // 115 //
116 // The tricky part is that a buildfile can be interpreted multiple times 116 // The tricky part is that a buildfile can be interpreted multiple times
117 // when used from different toolchains, so we can't just check that we've 117 // when used from different toolchains, so we can't just check that we've
118 // seen it before. Instead, we check that the location matches. We 118 // seen it before. Instead, we check that the location matches.
119 // additionally check that the value matches to prevent people from
120 // declaring defaults based on other parameters that may change. The
121 // rationale is that you should have exactly one default value for each
122 // argument that we can display in the help.
123 Scope::KeyValueMap::iterator previously_declared = 119 Scope::KeyValueMap::iterator previously_declared =
124 declared_arguments_.find(i->first); 120 declared_arguments_.find(i->first);
125 if (previously_declared != declared_arguments_.end()) { 121 if (previously_declared != declared_arguments_.end()) {
126 if (previously_declared->second.origin() != i->second.origin()) { 122 if (previously_declared->second.origin() != i->second.origin()) {
127 // Declaration location mismatch. 123 // Declaration location mismatch.
128 *err = Err(i->second.origin(), "Duplicate build argument declaration.", 124 *err = Err(i->second.origin(), "Duplicate build argument declaration.",
129 "Here you're declaring an argument that was already declared " 125 "Here you're declaring an argument that was already declared "
130 "elsewhere.\nYou can only declare each argument once in the entire " 126 "elsewhere.\nYou can only declare each argument once in the entire "
131 "build so there is one\ncanonical place for documentation and the " 127 "build so there is one\ncanonical place for documentation and the "
132 "default value. Either move this\nargument to the build config " 128 "default value. Either move this\nargument to the build config "
133 "file (for visibility everywhere) or to a .gni file\nthat you " 129 "file (for visibility everywhere) or to a .gni file\nthat you "
134 "\"import\" from the files where you need it (preferred)."); 130 "\"import\" from the files where you need it (preferred).");
135 err->AppendSubErr(Err(previously_declared->second.origin(), 131 err->AppendSubErr(Err(previously_declared->second.origin(),
136 "Previous declaration.", 132 "Previous declaration.",
137 "See also \"gn help buildargs\" for more on how " 133 "See also \"gn help buildargs\" for more on how "
138 "build arguments work.")); 134 "build arguments work."));
139 return false; 135 return false;
140 } else if (previously_declared->second != i->second) {
141 // Default value mismatch.
142 *err = Err(i->second.origin(),
143 "Non-constant default value for build argument.",
144 "Each build argument should have one default value so we report "
145 "it nicely in the\n\"gn args\" command. Please make this value "
146 "constant.");
147 return false;
148 } 136 }
149 } else { 137 } else {
150 declared_arguments_.insert(*i); 138 declared_arguments_.insert(*i);
151 } 139 }
152 140
153 // Only set on the current scope to the new value if it hasn't been already 141 // Only set on the current scope to the new value if it hasn't been already
154 // set. Mark the variable used so the build script can override it in 142 // set. Mark the variable used so the build script can override it in
155 // certain cases without getting unused value errors. 143 // certain cases without getting unused value errors.
156 if (!scope_to_set->GetValue(i->first)) { 144 if (!scope_to_set->GetValue(i->first)) {
157 scope_to_set->SetValue(i->first, i->second, i->second.origin()); 145 scope_to_set->SetValue(i->first, i->second, i->second.origin());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 for (Scope::KeyValueMap::const_iterator i = values.begin(); 255 for (Scope::KeyValueMap::const_iterator i = values.begin();
268 i != values.end(); ++i) 256 i != values.end(); ++i)
269 scope->SetValue(i->first, i->second, i->second.origin()); 257 scope->SetValue(i->first, i->second, i->second.origin());
270 } 258 }
271 259
272 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const { 260 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const {
273 for (Scope::KeyValueMap::const_iterator i = values.begin(); 261 for (Scope::KeyValueMap::const_iterator i = values.begin();
274 i != values.end(); ++i) 262 i != values.end(); ++i)
275 all_overrides_[i->first] = i->second; 263 all_overrides_[i->first] = i->second;
276 } 264 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/command_args.cc » ('j') | tools/gn/command_args.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698