[Refactor Xcode Objects] Enable adding per file '--help' compiler flag.

This CL refactors xcode_object.h and xcode_object.cc to enable generating '--help'
as per file compiler flag for the files in the "Compiler Sources" in
"Build Phases".

BUG=614818

Review-Url: https://codereview.chromium.org/2574333002
Cr-Original-Commit-Position: refs/heads/master@{#439913}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8fb7d9d9c9ddf8bd3d1448241fafa27416e1f756
diff --git a/tools/gn/xcode_object.cc b/tools/gn/xcode_object.cc
index e97cbfd..4f1dcbe 100644
--- a/tools/gn/xcode_object.cc
+++ b/tools/gn/xcode_object.cc
@@ -365,8 +365,11 @@
 // PBXBuildFile ---------------------------------------------------------------
 
 PBXBuildFile::PBXBuildFile(const PBXFileReference* file_reference,
-                           const PBXSourcesBuildPhase* build_phase)
-    : file_reference_(file_reference), build_phase_(build_phase) {
+                           const PBXSourcesBuildPhase* build_phase,
+                           const CompilerFlags compiler_flag)
+    : file_reference_(file_reference),
+      build_phase_(build_phase),
+      compiler_flag_(compiler_flag) {
   DCHECK(file_reference_);
   DCHECK(build_phase_);
 }
@@ -387,6 +390,12 @@
   out << indent_str << Reference() << " = {";
   PrintProperty(out, rules, "isa", ToString(Class()));
   PrintProperty(out, rules, "fileRef", file_reference_);
+  if (compiler_flag_ == CompilerFlags::HELP) {
+    std::map<std::string, std::string> settings = {
+        {"COMPILER_FLAGS", "--help"},
+    };
+    PrintProperty(out, rules, "settings", settings);
+  }
   out << "};\n";
 }
 
@@ -563,11 +572,11 @@
 
 PBXNativeTarget::~PBXNativeTarget() {}
 
-void PBXNativeTarget::AddFileForIndexing(
-    const PBXFileReference* file_reference) {
+void PBXNativeTarget::AddFileForIndexing(const PBXFileReference* file_reference,
+                                         const CompilerFlags compiler_flag) {
   DCHECK(file_reference);
-  source_build_phase_->AddBuildFile(
-      base::MakeUnique<PBXBuildFile>(file_reference, source_build_phase_));
+  source_build_phase_->AddBuildFile(base::MakeUnique<PBXBuildFile>(
+      file_reference, source_build_phase_, compiler_flag));
 }
 
 PBXObjectClass PBXNativeTarget::Class() const {
@@ -614,15 +623,18 @@
 
 void PBXProject::AddSourceFileToIndexingTarget(
     const std::string& navigator_path,
-    const std::string& source_path) {
+    const std::string& source_path,
+    const CompilerFlags compiler_flag) {
   if (!target_for_indexing_) {
     AddIndexingTarget();
   }
-  AddSourceFile(navigator_path, source_path, target_for_indexing_);
+  AddSourceFile(navigator_path, source_path, compiler_flag,
+                target_for_indexing_);
 }
 
 void PBXProject::AddSourceFile(const std::string& navigator_path,
                                const std::string& source_path,
+                               const CompilerFlags compiler_flag,
                                PBXNativeTarget* target) {
   PBXFileReference* file_reference =
       sources_->AddSourceFile(navigator_path, source_path);
@@ -631,7 +643,7 @@
     return;
 
   DCHECK(target);
-  target->AddFileForIndexing(file_reference);
+  target->AddFileForIndexing(file_reference, compiler_flag);
 }
 
 void PBXProject::AddAggregateTarget(const std::string& name,
diff --git a/tools/gn/xcode_object.h b/tools/gn/xcode_object.h
index f56de09..22be61e 100644
--- a/tools/gn/xcode_object.h
+++ b/tools/gn/xcode_object.h
@@ -22,6 +22,11 @@
 // See https://chromium.googlesource.com/external/gyp/+/master/pylib/gyp/xcodeproj_file.py
 // for more information on Xcode project file format.
 
+enum class CompilerFlags {
+  NONE,
+  HELP,
+};
+
 // PBXObjectClass -------------------------------------------------------------
 
 enum PBXObjectClass {
@@ -154,7 +159,8 @@
 class PBXBuildFile : public PBXObject {
  public:
   PBXBuildFile(const PBXFileReference* file_reference,
-               const PBXSourcesBuildPhase* build_phase);
+               const PBXSourcesBuildPhase* build_phase,
+               const CompilerFlags compiler_flag);
   ~PBXBuildFile() override;
 
   // PXBObject implementation.
@@ -165,6 +171,7 @@
  private:
   const PBXFileReference* file_reference_;
   const PBXSourcesBuildPhase* build_phase_;
+  const CompilerFlags compiler_flag_;
 
   DISALLOW_COPY_AND_ASSIGN(PBXBuildFile);
 };
@@ -251,7 +258,8 @@
                   const PBXFileReference* product_reference);
   ~PBXNativeTarget() override;
 
-  void AddFileForIndexing(const PBXFileReference* file_reference);
+  void AddFileForIndexing(const PBXFileReference* file_reference,
+                          const CompilerFlags compiler_flag);
 
   // PBXObject implementation.
   PBXObjectClass Class() const override;
@@ -276,11 +284,12 @@
   ~PBXProject() override;
 
   void AddSourceFileToIndexingTarget(const std::string& navigator_path,
-                                     const std::string& source_path);
+                                     const std::string& source_path,
+                                     const CompilerFlags compiler_flag);
   void AddSourceFile(const std::string& navigator_path,
                      const std::string& source_path,
+                     const CompilerFlags compiler_flag,
                      PBXNativeTarget* target);
-
   void AddAggregateTarget(const std::string& name,
                           const std::string& shell_script);
   void AddIndexingTarget();
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc
index b052683..b35cb44 100644
--- a/tools/gn/xcode_writer.cc
+++ b/tools/gn/xcode_writer.cc
@@ -353,8 +353,8 @@
   for (const SourceFile& source : sources) {
     std::string source_file =
         RebasePath(source.value(), source_dir, absolute_source_path);
-    sources_for_indexing->AddSourceFileToIndexingTarget(source_file,
-                                                        source_file);
+    sources_for_indexing->AddSourceFileToIndexingTarget(
+        source_file, source_file, CompilerFlags::NONE);
   }
 
   projects_.push_back(std::move(sources_for_indexing));