| OLD | NEW | 
|    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 16 matching lines...) Expand all  Loading... | 
|   27 using LabelSet = Analyzer::LabelSet; |   27 using LabelSet = Analyzer::LabelSet; | 
|   28 using SourceFileSet = Analyzer::SourceFileSet; |   28 using SourceFileSet = Analyzer::SourceFileSet; | 
|   29 using TargetSet = Analyzer::TargetSet; |   29 using TargetSet = Analyzer::TargetSet; | 
|   30  |   30  | 
|   31 namespace { |   31 namespace { | 
|   32  |   32  | 
|   33 struct Inputs { |   33 struct Inputs { | 
|   34   std::vector<SourceFile> source_vec; |   34   std::vector<SourceFile> source_vec; | 
|   35   std::vector<Label> compile_vec; |   35   std::vector<Label> compile_vec; | 
|   36   std::vector<Label> test_vec; |   36   std::vector<Label> test_vec; | 
|   37   bool compile_included_all; |   37   bool compile_included_all = false; | 
|   38   SourceFileSet source_files; |   38   SourceFileSet source_files; | 
|   39   LabelSet compile_labels; |   39   LabelSet compile_labels; | 
|   40   LabelSet test_labels; |   40   LabelSet test_labels; | 
|   41 }; |   41 }; | 
|   42  |   42  | 
|   43 struct Outputs { |   43 struct Outputs { | 
|   44   std::string status; |   44   std::string status; | 
|   45   std::string error; |   45   std::string error; | 
 |   46   bool compile_includes_all = false; | 
|   46   LabelSet compile_labels; |   47   LabelSet compile_labels; | 
|   47   LabelSet test_labels; |   48   LabelSet test_labels; | 
|   48   LabelSet invalid_labels; |   49   LabelSet invalid_labels; | 
|   49 }; |   50 }; | 
|   50  |   51  | 
|   51 LabelSet LabelsFor(const TargetSet& targets) { |   52 LabelSet LabelsFor(const TargetSet& targets) { | 
|   52   LabelSet labels; |   53   LabelSet labels; | 
|   53   for (const auto& target : targets) |   54   for (const auto& target : targets) | 
|   54     labels.insert(target->label()); |   55     labels.insert(target->label()); | 
|   55   return labels; |   56   return labels; | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  196                           const Label& default_toolchain, Err *err) { |  197                           const Label& default_toolchain, Err *err) { | 
|  197   std::string output; |  198   std::string output; | 
|  198   auto value = base::MakeUnique<base::DictionaryValue>(); |  199   auto value = base::MakeUnique<base::DictionaryValue>(); | 
|  199  |  200  | 
|  200   if (outputs.error.size()) { |  201   if (outputs.error.size()) { | 
|  201     WriteString(*value, "error", outputs.error); |  202     WriteString(*value, "error", outputs.error); | 
|  202     WriteLabels(default_toolchain, *value, "invalid_targets", |  203     WriteLabels(default_toolchain, *value, "invalid_targets", | 
|  203                 outputs.invalid_labels); |  204                 outputs.invalid_labels); | 
|  204   } else { |  205   } else { | 
|  205     WriteString(*value, "status", outputs.status); |  206     WriteString(*value, "status", outputs.status); | 
|  206     WriteLabels(default_toolchain, *value, "compile_targets", |  207     if (outputs.compile_includes_all) { | 
|  207                 outputs.compile_labels); |  208       auto compile_targets = base::WrapUnique(new base::ListValue()); | 
 |  209       compile_targets->AppendString("all"); | 
 |  210       value->Set("compile_targets", std::move(compile_targets)); | 
 |  211     } else { | 
 |  212       WriteLabels(default_toolchain, *value, "compile_targets", | 
 |  213                   outputs.compile_labels); | 
 |  214     } | 
|  208     WriteLabels(default_toolchain, *value, "test_targets", outputs.test_labels); |  215     WriteLabels(default_toolchain, *value, "test_targets", outputs.test_labels); | 
|  209   } |  216   } | 
|  210  |  217  | 
|  211   if (!base::JSONWriter::Write(*value.get(), &output)) |  218   if (!base::JSONWriter::Write(*value.get(), &output)) | 
|  212     *err = Err(Location(), "Failed to marshal JSON value for output"); |  219     *err = Err(Location(), "Failed to marshal JSON value for output"); | 
|  213   return output; |  220   return output; | 
|  214 } |  221 } | 
|  215  |  222  | 
|  216 }  // namespace |  223 }  // namespace | 
|  217  |  224  | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  252     return OutputsToJSON(outputs, default_toolchain_, err); |  259     return OutputsToJSON(outputs, default_toolchain_, err); | 
|  253   } |  260   } | 
|  254  |  261  | 
|  255   // TODO(crbug.com/555273): We can do smarter things when we detect changes |  262   // TODO(crbug.com/555273): We can do smarter things when we detect changes | 
|  256   // to build files. For example, if all of the ninja files are unchanged, |  263   // to build files. For example, if all of the ninja files are unchanged, | 
|  257   // we know that we can ignore changes to these files. Also, for most .gn |  264   // we know that we can ignore changes to these files. Also, for most .gn | 
|  258   // files, we can treat a change as simply affecting every target, config, |  265   // files, we can treat a change as simply affecting every target, config, | 
|  259   // or toolchain defined in that file. |  266   // or toolchain defined in that file. | 
|  260   if (AnyBuildFilesWereModified(inputs.source_files)) { |  267   if (AnyBuildFilesWereModified(inputs.source_files)) { | 
|  261     outputs.status = "Found dependency (all)"; |  268     outputs.status = "Found dependency (all)"; | 
|  262     outputs.compile_labels = inputs.compile_labels; |  269     if (inputs.compile_included_all) { | 
 |  270       outputs.compile_includes_all = true; | 
 |  271     } else { | 
 |  272       outputs.compile_labels.insert(inputs.compile_labels.begin(), | 
 |  273                                     inputs.compile_labels.end()); | 
 |  274       outputs.compile_labels.insert(inputs.test_labels.begin(), | 
 |  275                                     inputs.test_labels.end()); | 
 |  276     } | 
|  263     outputs.test_labels = inputs.test_labels; |  277     outputs.test_labels = inputs.test_labels; | 
|  264     return OutputsToJSON(outputs, default_toolchain_, err); |  278     return OutputsToJSON(outputs, default_toolchain_, err); | 
|  265   } |  279   } | 
|  266  |  280  | 
|  267   TargetSet affected_targets = AllAffectedTargets(inputs.source_files); |  281   TargetSet affected_targets = AllAffectedTargets(inputs.source_files); | 
|  268   if (affected_targets.empty()) { |  282   if (affected_targets.empty()) { | 
|  269     outputs.status = "No dependency"; |  283     outputs.status = "No dependency"; | 
|  270     return OutputsToJSON(outputs, default_toolchain_, err); |  284     return OutputsToJSON(outputs, default_toolchain_, err); | 
|  271   } |  285   } | 
|  272  |  286  | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  388 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { |  402 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { | 
|  389   if (results->find(target) != results->end()) |  403   if (results->find(target) != results->end()) | 
|  390     return;  // Already found this target. |  404     return;  // Already found this target. | 
|  391   results->insert(target); |  405   results->insert(target); | 
|  392  |  406  | 
|  393   auto dep_begin = dep_map_.lower_bound(target); |  407   auto dep_begin = dep_map_.lower_bound(target); | 
|  394   auto dep_end = dep_map_.upper_bound(target); |  408   auto dep_end = dep_map_.upper_bound(target); | 
|  395   for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) |  409   for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) | 
|  396     AddAllRefsTo(cur_dep->second, results); |  410     AddAllRefsTo(cur_dep->second, results); | 
|  397 } |  411 } | 
| OLD | NEW |