Configure xctest build settings to prevent Xcode from linking objects.

Test files need to be known to Xcode for proper indexing and for discovery of
tests function for XCTest, but the compilation is done via ninja, which causes
Xcode fail find object files when trying to link.

This CL configures the build settings of XCTest targets to trick Xcode to
blindly return success when trying to link object files.

BUG=614818

Review-Url: https://codereview.chromium.org/2594033002
Cr-Original-Commit-Position: refs/heads/master@{#441500}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 7e5894a9a070055aec683a83d50523df7f585f38
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc
index ffdbf57..5030b5a 100644
--- a/tools/gn/xcode_writer.cc
+++ b/tools/gn/xcode_writer.cc
@@ -432,10 +432,21 @@
                            env.get()));
         break;
 
-      case Target::CREATE_BUNDLE:
+      case Target::CREATE_BUNDLE: {
         if (target->bundle_data().product_type().empty())
           continue;
 
+        // Test files need to be known to Xcode for proper indexing and for
+        // discovery of tests function for XCTest, but the compilation is done
+        // via ninja and thus must prevent Xcode from linking object files via
+        // this hack.
+        PBXAttributes extra_attributes;
+        if (IsXCTestModuleTarget(target)) {
+          extra_attributes["OTHER_LDFLAGS"] = "-help";
+          extra_attributes["ONLY_ACTIVE_ARCH"] = "YES";
+          extra_attributes["DEBUG_INFORMATION_FORMAT"] = "dwarf";
+        }
+
         main_project->AddNativeTarget(
             target->label().name(), std::string(),
             RebasePath(target->bundle_data()
@@ -443,9 +454,10 @@
                            .value(),
                        build_settings->build_dir()),
             target->bundle_data().product_type(),
-            GetBuildScript(target->label().name(), ninja_extra_args,
-                           env.get()));
+            GetBuildScript(target->label().name(), ninja_extra_args, env.get()),
+            extra_attributes);
         break;
+      }
 
       default:
         break;