Commit 6eb496ce authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

[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/563650Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485529}
parent a12d126b
......@@ -219,6 +219,46 @@ void FindXCTestFilesForApplicationTargets(
}
}
// 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 @@ void XcodeWriter::CreateProductsProject(
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);
}
SourceDir source_dir("//");
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment