Commit 898a56b7 authored by liaoyuke's avatar liaoyuke Committed by Commit bot

[Refactor Xcode Objects] Decouple file references and indexing target.

Previously, whenever a file reference needs to be added for indexing, a default
target with the same name as the project is always assumed to be the one to
bound to.

This CL decouples file references from the default indexing target, and allows
file references to be bound to any of the native targets.

BUG=614818

Review-Url: https://codereview.chromium.org/2577753002
Cr-Commit-Position: refs/heads/master@{#439894}
parent a5b1973c
...@@ -612,33 +612,26 @@ PBXProject::PBXProject(const std::string& name, ...@@ -612,33 +612,26 @@ PBXProject::PBXProject(const std::string& name,
PBXProject::~PBXProject() {} PBXProject::~PBXProject() {}
void PBXProject::AddSourceFileToIndexingTarget(
const std::string& navigator_path,
const std::string& source_path) {
if (!target_for_indexing_) {
AddIndexingTarget();
}
AddSourceFile(navigator_path, source_path, target_for_indexing_);
}
void PBXProject::AddSourceFile(const std::string& navigator_path, void PBXProject::AddSourceFile(const std::string& navigator_path,
const std::string& source_path) { const std::string& source_path,
PBXNativeTarget* target) {
PBXFileReference* file_reference = PBXFileReference* file_reference =
sources_->AddSourceFile(navigator_path, source_path); sources_->AddSourceFile(navigator_path, source_path);
base::StringPiece ext = FindExtension(&source_path); base::StringPiece ext = FindExtension(&source_path);
if (!IsSourceFileForIndexing(ext)) if (!IsSourceFileForIndexing(ext))
return; return;
if (!target_for_indexing_) { DCHECK(target);
PBXAttributes attributes; target->AddFileForIndexing(file_reference);
attributes["EXECUTABLE_PREFIX"] = "";
attributes["HEADER_SEARCH_PATHS"] = sources_->path();
attributes["PRODUCT_NAME"] = name_;
PBXFileReference* product_reference = static_cast<PBXFileReference*>(
products_->AddChild(base::MakeUnique<PBXFileReference>(
std::string(), name_, "compiled.mach-o.executable")));
const char product_type[] = "com.apple.product-type.tool";
targets_.push_back(base::MakeUnique<PBXNativeTarget>(
name_, std::string(), config_name_, attributes, product_type, name_,
product_reference));
target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get());
}
DCHECK(target_for_indexing_);
target_for_indexing_->AddFileForIndexing(file_reference);
} }
void PBXProject::AddAggregateTarget(const std::string& name, void PBXProject::AddAggregateTarget(const std::string& name,
...@@ -652,6 +645,24 @@ void PBXProject::AddAggregateTarget(const std::string& name, ...@@ -652,6 +645,24 @@ void PBXProject::AddAggregateTarget(const std::string& name,
name, shell_script, config_name_, attributes)); name, shell_script, config_name_, attributes));
} }
void PBXProject::AddIndexingTarget() {
DCHECK(!target_for_indexing_);
PBXAttributes attributes;
attributes["EXECUTABLE_PREFIX"] = "";
attributes["HEADER_SEARCH_PATHS"] = sources_->path();
attributes["PRODUCT_NAME"] = name_;
PBXFileReference* product_reference = static_cast<PBXFileReference*>(
products_->AddChild(base::MakeUnique<PBXFileReference>(
std::string(), name_, "compiled.mach-o.executable")));
const char product_type[] = "com.apple.product-type.tool";
targets_.push_back(base::MakeUnique<PBXNativeTarget>(
name_, std::string(), config_name_, attributes, product_type, name_,
product_reference));
target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get());
}
void PBXProject::AddNativeTarget(const std::string& name, void PBXProject::AddNativeTarget(const std::string& name,
const std::string& type, const std::string& type,
const std::string& output_name, const std::string& output_name,
......
...@@ -275,10 +275,15 @@ class PBXProject : public PBXObject { ...@@ -275,10 +275,15 @@ class PBXProject : public PBXObject {
const PBXAttributes& attributes); const PBXAttributes& attributes);
~PBXProject() override; ~PBXProject() override;
void AddSourceFileToIndexingTarget(const std::string& navigator_path,
const std::string& source_path);
void AddSourceFile(const std::string& navigator_path, void AddSourceFile(const std::string& navigator_path,
const std::string& source_path); const std::string& source_path,
PBXNativeTarget* target);
void AddAggregateTarget(const std::string& name, void AddAggregateTarget(const std::string& name,
const std::string& shell_script); const std::string& shell_script);
void AddIndexingTarget();
void AddNativeTarget(const std::string& name, void AddNativeTarget(const std::string& name,
const std::string& type, const std::string& type,
const std::string& output_name, const std::string& output_name,
......
...@@ -353,7 +353,8 @@ void XcodeWriter::CreateSourcesProject( ...@@ -353,7 +353,8 @@ void XcodeWriter::CreateSourcesProject(
for (const SourceFile& source : sources) { for (const SourceFile& source : sources) {
std::string source_file = std::string source_file =
RebasePath(source.value(), source_dir, absolute_source_path); RebasePath(source.value(), source_dir, absolute_source_path);
sources_for_indexing->AddSourceFile(source_file, source_file); sources_for_indexing->AddSourceFileToIndexingTarget(source_file,
source_file);
} }
projects_.push_back(std::move(sources_for_indexing)); projects_.push_back(std::move(sources_for_indexing));
......
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