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

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

Issue 1718093006: Limit the set of Visual Studio projects generated by GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use label patterns + gen command help fixes Created 4 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
« no previous file with comments | « tools/gn/visual_studio_writer.h ('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 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/visual_studio_writer.h" 5 #include "tools/gn/visual_studio_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "tools/gn/builder.h" 17 #include "tools/gn/builder.h"
18 #include "tools/gn/commands.h"
17 #include "tools/gn/config.h" 19 #include "tools/gn/config.h"
18 #include "tools/gn/config_values_extractors.h" 20 #include "tools/gn/config_values_extractors.h"
19 #include "tools/gn/filesystem_utils.h" 21 #include "tools/gn/filesystem_utils.h"
22 #include "tools/gn/label_pattern.h"
20 #include "tools/gn/parse_tree.h" 23 #include "tools/gn/parse_tree.h"
21 #include "tools/gn/path_output.h" 24 #include "tools/gn/path_output.h"
22 #include "tools/gn/source_file_type.h" 25 #include "tools/gn/source_file_type.h"
23 #include "tools/gn/standard_out.h" 26 #include "tools/gn/standard_out.h"
24 #include "tools/gn/target.h" 27 #include "tools/gn/target.h"
25 #include "tools/gn/variables.h" 28 #include "tools/gn/variables.h"
26 #include "tools/gn/visual_studio_utils.h" 29 #include "tools/gn/visual_studio_utils.h"
27 #include "tools/gn/xml_element_writer.h" 30 #include "tools/gn/xml_element_writer.h"
28 31
29 #if defined(OS_WIN) 32 #if defined(OS_WIN)
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 210
208 VisualStudioWriter::~VisualStudioWriter() { 211 VisualStudioWriter::~VisualStudioWriter() {
209 STLDeleteContainerPointers(projects_.begin(), projects_.end()); 212 STLDeleteContainerPointers(projects_.begin(), projects_.end());
210 STLDeleteContainerPointers(folders_.begin(), folders_.end()); 213 STLDeleteContainerPointers(folders_.begin(), folders_.end());
211 } 214 }
212 215
213 // static 216 // static
214 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, 217 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings,
215 Builder* builder, 218 Builder* builder,
216 Version version, 219 Version version,
220 const std::string& sln_name,
221 const std::string& dir_filters,
217 Err* err) { 222 Err* err) {
218 std::vector<const Target*> targets = builder->GetAllResolvedTargets(); 223 std::vector<const Target*> targets;
224 if (dir_filters.empty()) {
225 targets = builder->GetAllResolvedTargets();
226 } else {
227 std::vector<std::string> tokens = base::SplitString(
228 dir_filters, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
229 SourceDir root_dir =
230 SourceDirForCurrentDirectory(build_settings->root_path());
231
232 std::vector<LabelPattern> filters;
233 for (std::string& token : tokens) {
brettw 2016/02/25 22:38:33 Can you make this a "const std::string& token"?
Tomasz Moniuszko 2016/02/26 11:47:14 Done.
234 LabelPattern pattern =
235 LabelPattern::GetPattern(root_dir, Value(nullptr, token), err);
236 if (err->has_error())
237 return false;
238 filters.push_back(pattern);
239 }
240
241 commands::FilterTargetsByPatterns(builder->GetAllResolvedTargets(), filters,
242 &targets);
243 }
219 244
220 VisualStudioWriter writer(build_settings, version); 245 VisualStudioWriter writer(build_settings, version);
221 writer.projects_.reserve(targets.size()); 246 writer.projects_.reserve(targets.size());
222 writer.folders_.reserve(targets.size()); 247 writer.folders_.reserve(targets.size());
223 248
224 for (const Target* target : targets) { 249 for (const Target* target : targets) {
225 // Skip actions and groups. 250 // Skip actions and groups.
226 if (target->output_type() == Target::GROUP || 251 if (target->output_type() == Target::GROUP ||
227 target->output_type() == Target::COPY_FILES || 252 target->output_type() == Target::COPY_FILES ||
228 target->output_type() == Target::ACTION || 253 target->output_type() == Target::ACTION ||
(...skipping 11 matching lines...) Expand all
240 } 265 }
241 266
242 // Sort projects so they appear always in the same order in solution file. 267 // Sort projects so they appear always in the same order in solution file.
243 // Otherwise solution file is rewritten and reloaded by Visual Studio. 268 // Otherwise solution file is rewritten and reloaded by Visual Studio.
244 std::sort(writer.projects_.begin(), writer.projects_.end(), 269 std::sort(writer.projects_.begin(), writer.projects_.end(),
245 [](const SolutionEntry* a, const SolutionEntry* b) { 270 [](const SolutionEntry* a, const SolutionEntry* b) {
246 return a->path < b->path; 271 return a->path < b->path;
247 }); 272 });
248 273
249 writer.ResolveSolutionFolders(); 274 writer.ResolveSolutionFolders();
250 return writer.WriteSolutionFile(err); 275 return writer.WriteSolutionFile(sln_name, err);
251 } 276 }
252 277
253 bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) { 278 bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) {
254 std::string project_name = target->label().name(); 279 std::string project_name = target->label().name();
255 std::string project_config_platform = config_platform_; 280 std::string project_config_platform = config_platform_;
256 if (!target->settings()->is_default()) { 281 if (!target->settings()->is_default()) {
257 project_name += "_" + target->toolchain()->label().name(); 282 project_name += "_" + target->toolchain()->label().name();
258 project_config_platform = target->toolchain() 283 project_config_platform = target->toolchain()
259 ->settings() 284 ->settings()
260 ->build_settings() 285 ->build_settings()
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 597 }
573 cl_item->SubElement("Filter")->Text(filter_path); 598 cl_item->SubElement("Filter")->Text(filter_path);
574 } 599 }
575 } 600 }
576 } 601 }
577 } 602 }
578 603
579 project.Text(files_out.str()); 604 project.Text(files_out.str());
580 } 605 }
581 606
582 bool VisualStudioWriter::WriteSolutionFile(Err* err) { 607 bool VisualStudioWriter::WriteSolutionFile(const std::string& sln_name,
608 Err* err) {
609 std::string name = sln_name.empty() ? "all" : sln_name;
583 SourceFile sln_file = build_settings_->build_dir().ResolveRelativeFile( 610 SourceFile sln_file = build_settings_->build_dir().ResolveRelativeFile(
584 Value(nullptr, "all.sln"), err); 611 Value(nullptr, name + ".sln"), err);
585 if (sln_file.is_null()) 612 if (sln_file.is_null())
586 return false; 613 return false;
587 614
588 base::FilePath sln_path = build_settings_->GetFullPath(sln_file); 615 base::FilePath sln_path = build_settings_->GetFullPath(sln_file);
589 616
590 std::stringstream string_out; 617 std::stringstream string_out;
591 WriteSolutionFileContents(string_out, sln_path.DirName()); 618 WriteSolutionFileContents(string_out, sln_path.DirName());
592 619
593 // Only write the content to the file if it's different. That is 620 // Only write the content to the file if it's different. That is
594 // both a performance optimization and more importantly, prevents 621 // both a performance optimization and more importantly, prevents
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 size_t common_prefix_len = 0; 714 size_t common_prefix_len = 0;
688 size_t max_common_length = 715 size_t max_common_length =
689 std::min(root_folder_path_.size(), folder_path.size()); 716 std::min(root_folder_path_.size(), folder_path.size());
690 size_t i; 717 size_t i;
691 for (i = common_prefix_len; i < max_common_length; ++i) { 718 for (i = common_prefix_len; i < max_common_length; ++i) {
692 if (IsSlash(root_folder_path_[i]) && IsSlash(folder_path[i])) 719 if (IsSlash(root_folder_path_[i]) && IsSlash(folder_path[i]))
693 common_prefix_len = i + 1; 720 common_prefix_len = i + 1;
694 else if (root_folder_path_[i] != folder_path[i]) 721 else if (root_folder_path_[i] != folder_path[i])
695 break; 722 break;
696 } 723 }
697 if (i == max_common_length) 724 if (i == max_common_length &&
725 (i == folder_path.size() || IsSlash(folder_path[i])))
698 common_prefix_len = max_common_length; 726 common_prefix_len = max_common_length;
699 if (common_prefix_len < root_folder_path_.size()) { 727 if (common_prefix_len < root_folder_path_.size()) {
700 if (IsSlash(root_folder_path_[common_prefix_len - 1])) 728 if (IsSlash(root_folder_path_[common_prefix_len - 1]))
701 --common_prefix_len; 729 --common_prefix_len;
702 root_folder_path_ = root_folder_path_.substr(0, common_prefix_len); 730 root_folder_path_ = root_folder_path_.substr(0, common_prefix_len);
703 } 731 }
704 } 732 }
705 } 733 }
706 } 734 }
707 735
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 base::CompareCase::SENSITIVE)) { 772 base::CompareCase::SENSITIVE)) {
745 folder->parent_folder = parents.back(); 773 folder->parent_folder = parents.back();
746 break; 774 break;
747 } else { 775 } else {
748 parents.pop_back(); 776 parents.pop_back();
749 } 777 }
750 } 778 }
751 parents.push_back(folder); 779 parents.push_back(folder);
752 } 780 }
753 } 781 }
OLDNEW
« no previous file with comments | « tools/gn/visual_studio_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698