ninja: Add support for 'ninja_use_console' in actions/rules

Setting this to 1 will make ninja use 'pool = console' for the action/rule.

BUG=
R=thakis@chromium.org

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

git-svn-id: http://gyp.googlecode.com/svn/trunk@1955 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 7cdb0e8..3d33d0a 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -599,8 +599,9 @@
       is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action)
                    if self.flavor == 'win' else False)
       args = action['action']
+      pool = 'console' if int(action.get('ninja_use_console', 0)) else None
       rule_name, _ = self.WriteNewNinjaRule(name, args, description,
-                                            is_cygwin, env=env)
+                                            is_cygwin, env, pool)
 
       inputs = [self.GypPathToNinja(i, env) for i in action['inputs']]
       if int(action.get('process_outputs_as_sources', False)):
@@ -638,8 +639,9 @@
           ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name)
       is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule)
                    if self.flavor == 'win' else False)
+      pool = 'console' if int(rule.get('ninja_use_console', 0)) else None
       rule_name, args = self.WriteNewNinjaRule(
-          name, args, description, is_cygwin, env=env)
+          name, args, description, is_cygwin, env, pool)
 
       # TODO: if the command references the outputs directly, we should
       # simplify it to just use $out.
@@ -1427,7 +1429,7 @@
       values = []
     ninja_file.variable(var, ' '.join(values))
 
-  def WriteNewNinjaRule(self, name, args, description, is_cygwin, env):
+  def WriteNewNinjaRule(self, name, args, description, is_cygwin, env, pool):
     """Write out a new ninja "rule" statement for a given command.
 
     Returns the name of the new rule, and a copy of |args| with variables
@@ -1485,7 +1487,7 @@
     # GYP rules/actions express being no-ops by not touching their outputs.
     # Avoid executing downstream dependencies in this case by specifying
     # restat=1 to ninja.
-    self.ninja.rule(rule_name, command, description, restat=True,
+    self.ninja.rule(rule_name, command, description, restat=True, pool=pool,
                     rspfile=rspfile, rspfile_content=rspfile_content)
     self.ninja.newline()
 
diff --git a/test/ninja/use-console/foo.bar b/test/ninja/use-console/foo.bar
new file mode 100644
index 0000000..07c476a
--- /dev/null
+++ b/test/ninja/use-console/foo.bar
@@ -0,0 +1,5 @@
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+This is a dummy file for rule/action input.
diff --git a/test/ninja/use-console/gyptest-use-console.py b/test/ninja/use-console/gyptest-use-console.py
new file mode 100644
index 0000000..f76fcd9
--- /dev/null
+++ b/test/ninja/use-console/gyptest-use-console.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Make sure 'ninja_use_console' is supported in actions and rules.
+"""
+
+import TestGyp
+
+test = TestGyp.TestGyp(formats=['ninja'])
+
+test.run_gyp('use-console.gyp')
+
+no_pool = open(test.built_file_path('obj/no_pool.ninja')).read()
+if 'pool =' in no_pool:
+  test.fail_test()
+
+action_pool = open(test.built_file_path('obj/action_pool.ninja')).read()
+if 'pool = console' not in action_pool:
+  test.fail_test()
+
+rule_pool = open(test.built_file_path('obj/rule_pool.ninja')).read()
+if 'pool = console' not in rule_pool:
+  test.fail_test()
+
+test.pass_test()
diff --git a/test/ninja/use-console/use-console.gyp b/test/ninja/use-console/use-console.gyp
new file mode 100644
index 0000000..84e6318
--- /dev/null
+++ b/test/ninja/use-console/use-console.gyp
@@ -0,0 +1,60 @@
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+  'targets': [
+    {
+      'target_name': 'no_pool',
+      'type': 'none',
+      'actions': [
+        {
+          'action_name': 'some_action',
+          'action': ['echo', 'hello'],
+          'inputs': ['foo.bar'],
+          'outputs': ['dummy'],
+        },
+      ],
+      'rules': [
+        {
+          'rule_name': 'some_rule',
+          'extension': 'bar',
+          'action': ['echo', 'hello'],
+          'outputs': ['dummy'],
+        },
+      ],
+      'sources': [
+        'foo.bar',
+      ],
+    },
+    {
+      'target_name': 'action_pool',
+      'type': 'none',
+      'actions': [
+        {
+          'action_name': 'some_action',
+          'action': ['echo', 'hello'],
+          'inputs': ['foo.bar'],
+          'outputs': ['dummy'],
+          'ninja_use_console': 1,
+        },
+      ],
+    },
+    {
+      'target_name': 'rule_pool',
+      'type': 'none',
+      'rules': [
+        {
+          'rule_name': 'some_rule',
+          'extension': 'bar',
+          'action': ['echo', 'hello'],
+          'outputs': ['dummy'],
+          'ninja_use_console': 1,
+        },
+      ],
+      'sources': [
+        'foo.bar',
+      ],
+    },
+  ],
+}