Chromium Code Reviews| Index: tools/gn/visual_studio_writer.cc |
| diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc |
| index 7748fbe19df46326e53f19630d2b23ee04b7f568..11dd51e36c248e715a98fa63bedd98399e458565 100644 |
| --- a/tools/gn/visual_studio_writer.cc |
| +++ b/tools/gn/visual_studio_writer.cc |
| @@ -11,12 +11,15 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "tools/gn/builder.h" |
| +#include "tools/gn/commands.h" |
| #include "tools/gn/config.h" |
| #include "tools/gn/config_values_extractors.h" |
| #include "tools/gn/filesystem_utils.h" |
| +#include "tools/gn/label_pattern.h" |
| #include "tools/gn/parse_tree.h" |
| #include "tools/gn/path_output.h" |
| #include "tools/gn/source_file_type.h" |
| @@ -214,8 +217,30 @@ VisualStudioWriter::~VisualStudioWriter() { |
| bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, |
| Builder* builder, |
| Version version, |
| + const std::string& sln_name, |
| + const std::string& dir_filters, |
| Err* err) { |
| - std::vector<const Target*> targets = builder->GetAllResolvedTargets(); |
| + std::vector<const Target*> targets; |
| + if (dir_filters.empty()) { |
| + targets = builder->GetAllResolvedTargets(); |
| + } else { |
| + std::vector<std::string> tokens = base::SplitString( |
| + dir_filters, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| + SourceDir root_dir = |
| + SourceDirForCurrentDirectory(build_settings->root_path()); |
| + |
| + std::vector<LabelPattern> filters; |
| + 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.
|
| + LabelPattern pattern = |
| + LabelPattern::GetPattern(root_dir, Value(nullptr, token), err); |
| + if (err->has_error()) |
| + return false; |
| + filters.push_back(pattern); |
| + } |
| + |
| + commands::FilterTargetsByPatterns(builder->GetAllResolvedTargets(), filters, |
| + &targets); |
| + } |
| VisualStudioWriter writer(build_settings, version); |
| writer.projects_.reserve(targets.size()); |
| @@ -247,7 +272,7 @@ bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, |
| }); |
| writer.ResolveSolutionFolders(); |
| - return writer.WriteSolutionFile(err); |
| + return writer.WriteSolutionFile(sln_name, err); |
| } |
| bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) { |
| @@ -579,9 +604,11 @@ void VisualStudioWriter::WriteFiltersFileContents(std::ostream& out, |
| project.Text(files_out.str()); |
| } |
| -bool VisualStudioWriter::WriteSolutionFile(Err* err) { |
| +bool VisualStudioWriter::WriteSolutionFile(const std::string& sln_name, |
| + Err* err) { |
| + std::string name = sln_name.empty() ? "all" : sln_name; |
| SourceFile sln_file = build_settings_->build_dir().ResolveRelativeFile( |
| - Value(nullptr, "all.sln"), err); |
| + Value(nullptr, name + ".sln"), err); |
| if (sln_file.is_null()) |
| return false; |
| @@ -694,7 +721,8 @@ void VisualStudioWriter::ResolveSolutionFolders() { |
| else if (root_folder_path_[i] != folder_path[i]) |
| break; |
| } |
| - if (i == max_common_length) |
| + if (i == max_common_length && |
| + (i == folder_path.size() || IsSlash(folder_path[i]))) |
| common_prefix_len = max_common_length; |
| if (common_prefix_len < root_folder_path_.size()) { |
| if (IsSlash(root_folder_path_[common_prefix_len - 1])) |