ninja/mac: Fix a regression from r1709.

r1709 set the output of a target to the stamp file if the target has no
linkable object files.  That's ok, but Target.Linkable() still considered
the target to be linkable, so the linker then tried to link in the stamp
file, which made ld complain (see e.g.
http://build.chromium.org/p/tryserver.chromium/builders/mac/builds/82504/steps/compile/logs/stdio
).  As a fix, set the target type to None if it doesn't have a binary, the
Linkable() will return False.

R=mark@chromium.org

Review URL: https://codereview.chromium.org/23877003

git-svn-id: http://gyp.googlecode.com/svn/trunk@1711 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 8074136..ac449a3 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -1073,10 +1073,14 @@
     return linked_binary
 
   def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
-    if spec['type'] == 'none' or not link_deps:
+    extra_link_deps = any(self.target_outputs.get(dep).Linkable()
+                          for dep in spec.get('dependencies', [])
+                          if dep in self.target_outputs)
+    if spec['type'] == 'none' or (not link_deps and not extra_link_deps):
       # TODO(evan): don't call this function for 'none' target types, as
       # it doesn't do anything, and we fake out a 'binary' with a stamp file.
       self.target.binary = compile_deps
+      self.target.type = 'none'
     elif spec['type'] == 'static_library':
       self.target.binary = self.ComputeOutput(spec)
       if (self.flavor not in ('mac', 'openbsd', 'win') and not
diff --git a/test/mac/gyptest-sourceless-module.py b/test/mac/gyptest-sourceless-module.py
index c3ea73a..10dea50 100644
--- a/test/mac/gyptest-sourceless-module.py
+++ b/test/mac/gyptest-sourceless-module.py
@@ -43,4 +43,19 @@
       'resource_bundle.bundle/Contents/MacOS/resource_bundle',
       chdir='sourceless-module')
 
+  # TODO(thakis): shared_libraries that have no sources but depend on static
+  # libraries currently only work with the ninja generator.  This is used by
+  # chrome/mac's components build.
+  if test.format == 'ninja':
+    # Check that an executable depending on a resource framework links fine too.
+    test.build(
+       'test.gyp', 'dependent_on_resource_framework', chdir='sourceless-module')
+
+    test.built_file_must_exist(
+        'resource_framework.framework/Resources/foo.manifest',
+        chdir='sourceless-module')
+    test.built_file_must_exist(
+        'resource_framework.framework/resource_framework',
+        chdir='sourceless-module')
+
   test.pass_test()
diff --git a/test/mac/sourceless-module/fun.c b/test/mac/sourceless-module/fun.c
new file mode 100644
index 0000000..d64ff8c
--- /dev/null
+++ b/test/mac/sourceless-module/fun.c
@@ -0,0 +1 @@
+int f() { return 42; }
diff --git a/test/mac/sourceless-module/test.gyp b/test/mac/sourceless-module/test.gyp
index 49dc2af..3bda70f 100644
--- a/test/mac/sourceless-module/test.gyp
+++ b/test/mac/sourceless-module/test.gyp
@@ -34,6 +34,41 @@
         'resource_bundle',
       ],
     },
+
+    {
+      'target_name': 'alib',
+      'type': 'static_library',
+      'sources': [ 'fun.c' ]
+    },
+    { # No sources, but depends on a static_library so must be linked.
+      'target_name': 'resource_framework',
+      'type': 'shared_library',
+      'mac_bundle': 1,
+      'dependencies': [
+        'alib',
+      ],
+      'actions': [
+        {
+          'action_name': 'Add Resource',
+          'inputs': [],
+          'outputs': [
+            '<(INTERMEDIATE_DIR)/app_manifest/foo.manifest',
+          ],
+          'action': [
+            'touch', '<(INTERMEDIATE_DIR)/app_manifest/foo.manifest',
+          ],
+          'process_outputs_as_mac_bundle_resources': 1,
+        },
+      ],
+    },
+    {
+      'target_name': 'dependent_on_resource_framework',
+      'type': 'executable',
+      'sources': [ 'empty.c' ],
+      'dependencies': [
+        'resource_framework',
+      ],
+    },
   ],
 }