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

Unified Diff: tools/gn/xcode_object.cc

Issue 2057873002: [GN] Export include directories, defines and dialects to Xcode projects Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/xcode_object.h ('k') | tools/gn/xcode_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/xcode_object.cc
diff --git a/tools/gn/xcode_object.cc b/tools/gn/xcode_object.cc
index ef24e7d07fe91bad72ad731e865263069d3caaae..39cb3d9c9c2234d67d030406763931e771f7bfe2 100644
--- a/tools/gn/xcode_object.cc
+++ b/tools/gn/xcode_object.cc
@@ -222,6 +222,36 @@ void PrintValue(std::ostream& out,
out << "}";
}
+struct BuildSettingsValue
+{
+ BuildSettingsValue(const std::string &s) : value(s) { }
+ std::string value;
+};
+
+// Build settings can contain multiple values represented by multiline string
+void PrintValue(std::ostream& out,
+ IndentRules rules,
+ const BuildSettingsValue & buildSettingValue) {
+ const auto & value = buildSettingValue.value;
+ if (value.find('\n') == std::string::npos) {
+ PrintValue(out, rules, value);
+ } else {
+ // split and print as vector
matt.k 2016/06/10 07:35:11 Splitting the string to get multiple values is a h
+ std::vector<std::string> values;
+ std::size_t start = 0, end = 0;
+ while ((end = value.find('\n', start)) != std::string::npos) {
+ std::string sub = value.substr(start, end - start);
+ if (!sub.empty()) values.push_back(sub);
+ start = end + 1;
+ }
+ std::string last = value.substr(start);
+ if (!last.empty()) {
+ values.push_back(last);
+ }
+ PrintValue(out, rules, values);
+ }
+}
+
template <typename ValueType>
void PrintProperty(std::ostream& out,
IndentRules rules,
@@ -365,8 +395,10 @@ void PBXAggregateTarget::Print(std::ostream& out, unsigned indent) const {
// PBXBuildFile ---------------------------------------------------------------
PBXBuildFile::PBXBuildFile(const PBXFileReference* file_reference,
- const PBXSourcesBuildPhase* build_phase)
- : file_reference_(file_reference), build_phase_(build_phase) {
+ const PBXSourcesBuildPhase* build_phase,
+ const std::string& cflags)
+ : file_reference_(file_reference), build_phase_(build_phase),
+ cflags_(cflags) {
DCHECK(file_reference_);
DCHECK(build_phase_);
}
@@ -387,6 +419,11 @@ void PBXBuildFile::Print(std::ostream& out, unsigned indent) const {
out << indent_str << Reference() << " = {";
PrintProperty(out, rules, "isa", ToString(Class()));
PrintProperty(out, rules, "fileRef", file_reference_);
+ if (!cflags_.empty()) {
+ std::map<std::string, std::string> settings;
+ settings["COMPILER_FLAGS"] = cflags_;
+ PrintProperty(out, rules, "settings", settings);
+ }
out << "};\n";
}
@@ -559,11 +596,12 @@ PBXNativeTarget::PBXNativeTarget(const std::string& name,
PBXNativeTarget::~PBXNativeTarget() {}
-void PBXNativeTarget::AddFileForIndexing(
- const PBXFileReference* file_reference) {
+void PBXNativeTarget::AddFileForIndexing(const PBXFileReference* file_reference,
+ const std::string& cflags) {
DCHECK(file_reference);
source_build_phase_->AddBuildFile(
- base::WrapUnique(new PBXBuildFile(file_reference, source_build_phase_)));
+ base::WrapUnique(new PBXBuildFile(file_reference, source_build_phase_,
+ cflags)));
}
PBXObjectClass PBXNativeTarget::Class() const {
@@ -607,16 +645,20 @@ PBXProject::PBXProject(const std::string& name,
PBXProject::~PBXProject() {}
-void PBXProject::AddSourceFile(const std::string& source_path) {
- PBXFileReference* file_reference = sources_->AddSourceFile(source_path);
+bool PBXProject::SourceFileShouldBeIndexed(const std::string& source_path) {
base::StringPiece ext = FindExtension(&source_path);
- if (!IsSourceFileForIndexing(ext))
+ return IsSourceFileForIndexing(ext);
+}
+
+void PBXProject::AddSourceFile(const std::string& source_path,
+ const std::string& cflags) {
+ PBXFileReference* file_reference = sources_->AddSourceFile(source_path);
+ if (!SourceFileShouldBeIndexed(source_path))
return;
if (!target_for_indexing_) {
PBXAttributes attributes;
attributes["EXECUTABLE_PREFIX"] = "";
- attributes["HEADER_SEARCH_PATHS"] = sources_->path();
attributes["PRODUCT_NAME"] = name_;
PBXFileReference* product_reference = static_cast<PBXFileReference*>(
@@ -631,7 +673,7 @@ void PBXProject::AddSourceFile(const std::string& source_path) {
}
DCHECK(target_for_indexing_);
- target_for_indexing_->AddFileForIndexing(file_reference);
+ target_for_indexing_->AddFileForIndexing(file_reference, cflags);
}
void PBXProject::AddAggregateTarget(const std::string& name,
@@ -818,7 +860,12 @@ void XCBuildConfiguration::Print(std::ostream& out, unsigned indent) const {
const IndentRules rules = {false, indent + 1};
out << indent_str << Reference() << " = {\n";
PrintProperty(out, rules, "isa", ToString(Class()));
- PrintProperty(out, rules, "buildSettings", attributes_);
+ std::map<std::string, BuildSettingsValue> build_settings;
sdefresne 2016/06/10 08:52:34 I would use a multimap instead of splitting using
+ for (const auto & pair : attributes_) {
+ build_settings.emplace(std::make_pair(pair.first,
+ BuildSettingsValue(pair.second)));
+ }
+ PrintProperty(out, rules, "buildSettings", build_settings);
PrintProperty(out, rules, "name", name_);
out << indent_str << "};\n";
}
« no previous file with comments | « tools/gn/xcode_object.h ('k') | tools/gn/xcode_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698