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

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

Issue 2363193002: Use WithoutPathExpansion on DictionaryValue in GN. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | tools/gn/command_desc.cc » ('j') | tools/gn/json_project_writer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/analyzer.h" 5 #include "tools/gn/analyzer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 strings.push_back(std::move(s)); 96 strings.push_back(std::move(s));
97 } 97 }
98 *err = Err(); 98 *err = Err();
99 return strings; 99 return strings;
100 } 100 }
101 101
102 void WriteString(base::DictionaryValue& dict, 102 void WriteString(base::DictionaryValue& dict,
103 const std::string& key, 103 const std::string& key,
104 const std::string& value) { 104 const std::string& value) {
105 dict.SetString(key, value); 105 dict.SetStringWithoutPathExpansion(key, value);
106 }; 106 };
107 107
108 void WriteLabels(const Label& default_toolchain, 108 void WriteLabels(const Label& default_toolchain,
109 base::DictionaryValue& dict, 109 base::DictionaryValue& dict,
110 const std::string& key, 110 const std::string& key,
111 const LabelSet& labels) { 111 const LabelSet& labels) {
112 std::vector<std::string> strings; 112 std::vector<std::string> strings;
113 auto value = base::WrapUnique(new base::ListValue()); 113 auto value = base::WrapUnique(new base::ListValue());
114 for (const auto l : labels) 114 for (const auto l : labels)
115 strings.push_back(l.GetUserVisibleName(default_toolchain)); 115 strings.push_back(l.GetUserVisibleName(default_toolchain));
116 std::sort(strings.begin(), strings.end()); 116 std::sort(strings.begin(), strings.end());
117 value->AppendStrings(strings); 117 value->AppendStrings(strings);
118 dict.Set(key, std::move(value)); 118 dict.SetWithoutPathExpansion(key, std::move(value));
119 } 119 }
120 120
121 Label AbsoluteOrSourceAbsoluteStringToLabel(const Label& default_toolchain, 121 Label AbsoluteOrSourceAbsoluteStringToLabel(const Label& default_toolchain,
122 const std::string& s, Err* err) { 122 const std::string& s, Err* err) {
123 if (!IsPathSourceAbsolute(s) && !IsPathAbsolute(s)) { 123 if (!IsPathSourceAbsolute(s) && !IsPathAbsolute(s)) {
124 *err = Err(Location(), 124 *err = Err(Location(),
125 "\"" + s + "\" is not a source-absolute or absolute path."); 125 "\"" + s + "\" is not a source-absolute or absolute path.");
126 return Label(); 126 return Label();
127 } 127 }
128 return Label::Resolve(SourceDir("//"), default_toolchain, Value(nullptr, s), 128 return Label::Resolve(SourceDir("//"), default_toolchain, Value(nullptr, s),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 if (outputs.error.size()) { 201 if (outputs.error.size()) {
202 WriteString(*value, "error", outputs.error); 202 WriteString(*value, "error", outputs.error);
203 WriteLabels(default_toolchain, *value, "invalid_targets", 203 WriteLabels(default_toolchain, *value, "invalid_targets",
204 outputs.invalid_labels); 204 outputs.invalid_labels);
205 } else { 205 } else {
206 WriteString(*value, "status", outputs.status); 206 WriteString(*value, "status", outputs.status);
207 if (outputs.compile_includes_all) { 207 if (outputs.compile_includes_all) {
208 auto compile_targets = base::WrapUnique(new base::ListValue()); 208 auto compile_targets = base::WrapUnique(new base::ListValue());
209 compile_targets->AppendString("all"); 209 compile_targets->AppendString("all");
210 value->Set("compile_targets", std::move(compile_targets)); 210 value->SetWithoutPathExpansion("compile_targets",
211 std::move(compile_targets));
211 } else { 212 } else {
212 WriteLabels(default_toolchain, *value, "compile_targets", 213 WriteLabels(default_toolchain, *value, "compile_targets",
213 outputs.compile_labels); 214 outputs.compile_labels);
214 } 215 }
215 WriteLabels(default_toolchain, *value, "test_targets", outputs.test_labels); 216 WriteLabels(default_toolchain, *value, "test_targets", outputs.test_labels);
216 } 217 }
217 218
218 if (!base::JSONWriter::Write(*value.get(), &output)) 219 if (!base::JSONWriter::Write(*value.get(), &output))
219 *err = Err(Location(), "Failed to marshal JSON value for output"); 220 *err = Err(Location(), "Failed to marshal JSON value for output");
220 return output; 221 return output;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { 403 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const {
403 if (results->find(target) != results->end()) 404 if (results->find(target) != results->end())
404 return; // Already found this target. 405 return; // Already found this target.
405 results->insert(target); 406 results->insert(target);
406 407
407 auto dep_begin = dep_map_.lower_bound(target); 408 auto dep_begin = dep_map_.lower_bound(target);
408 auto dep_end = dep_map_.upper_bound(target); 409 auto dep_end = dep_map_.upper_bound(target);
409 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) 410 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++)
410 AddAllRefsTo(cur_dep->second, results); 411 AddAllRefsTo(cur_dep->second, results);
411 } 412 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/command_desc.cc » ('j') | tools/gn/json_project_writer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698