[iOS] Refactoring XcodeWriter::CreateProductsProject.
|XcodeWriter::CreateProductsProject| in xcode_writer.cc has evolved
into a giant function, so this CL makes it smaller by refactoring the
logic that adds source files to the project for indexing into a
separate function.
Bug: 709289
Change-Id: I19fab218e1af87a87cacf8f65f19c2acf8091713
Reviewed-on: https://chromium-review.googlesource.com/563650
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#485529}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 6eb496ce333c630963d608e9f3a6fd177ecb29c4
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc
index d029291..3aff656 100644
--- a/tools/gn/xcode_writer.cc
+++ b/tools/gn/xcode_writer.cc
@@ -219,6 +219,46 @@
}
}
+// Add all source files for indexing, both private and public.
+void AddSourceFilesToProjectForIndexing(
+ const std::vector<const Target*>& targets,
+ PBXProject* project,
+ SourceDir source_dir,
+ const BuildSettings* build_settings) {
+ std::vector<SourceFile> sources;
+ for (const Target* target : targets) {
+ for (const SourceFile& source : target->sources()) {
+ if (IsStringInOutputDir(build_settings->build_dir(), source.value()))
+ continue;
+
+ sources.push_back(source);
+ }
+
+ if (target->all_headers_public())
+ continue;
+
+ for (const SourceFile& source : target->public_headers()) {
+ if (IsStringInOutputDir(build_settings->build_dir(), source.value()))
+ continue;
+
+ sources.push_back(source);
+ }
+ }
+
+ // Sort sources to ensure determinism of the project file generation and
+ // remove duplicate reference to the source files (can happen due to the
+ // bundle_data targets).
+ std::sort(sources.begin(), sources.end());
+ sources.erase(std::unique(sources.begin(), sources.end()), sources.end());
+
+ for (const SourceFile& source : sources) {
+ std::string source_file = RebasePath(source.value(), source_dir,
+ build_settings->root_path_utf8());
+ project->AddSourceFileToIndexingTarget(source_file, source_file,
+ CompilerFlags::NONE);
+ }
+}
+
class CollectPBXObjectsPerClassHelper : public PBXObjectVisitor {
public:
CollectPBXObjectsPerClassHelper() {}
@@ -419,41 +459,10 @@
TargetOsType target_os) {
std::unique_ptr<PBXProject> main_project(
new PBXProject("products", config_name, source_path, attributes));
+
SourceDir source_dir("//");
-
- // Add all source files for indexing, both private and public.
- std::vector<SourceFile> sources;
- for (const Target* target : all_targets) {
- for (const SourceFile& source : target->sources()) {
- if (IsStringInOutputDir(build_settings->build_dir(), source.value()))
- continue;
-
- sources.push_back(source);
- }
-
- if (target->all_headers_public())
- continue;
-
- for (const SourceFile& source : target->public_headers()) {
- if (IsStringInOutputDir(build_settings->build_dir(), source.value()))
- continue;
-
- sources.push_back(source);
- }
- }
-
- // Sort sources to ensure determinisn of the project file generation and
- // remove duplicate reference to the source files (can happen due to the
- // bundle_data targets).
- std::sort(sources.begin(), sources.end());
- sources.erase(std::unique(sources.begin(), sources.end()), sources.end());
-
- for (const SourceFile& source : sources) {
- std::string source_file = RebasePath(source.value(), source_dir,
- build_settings->root_path_utf8());
- main_project->AddSourceFileToIndexingTarget(source_file, source_file,
- CompilerFlags::NONE);
- }
+ AddSourceFilesToProjectForIndexing(all_targets, main_project.get(),
+ source_dir, build_settings);
// Filter xctest module and application targets and find list of xctest files
// recursively under them.