ninja/mac: Create -iphoneos device builds for iOS ninja generator.

For builds that have iOS targets, clone each configuration with an "-iphoneos"
that builds for armv7 ios devices. Gyp authors no longer need to set
target_arch=armv7, although that is still supported.

R=thakis@chromium.org

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



git-svn-id: http://gyp.googlecode.com/svn/trunk@1748 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 6537a07..2d5b17c 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -2101,6 +2101,10 @@
 
 
 def GenerateOutput(target_list, target_dicts, data, params):
+  # Update target_dicts for iOS device builds.
+  target_dicts = gyp.xcode_emulation.CloneConfigurationForDeviceAndEmulator(
+      target_dicts)
+
   user_config = params.get('generator_flags', {}).get('config', None)
   if gyp.common.GetFlavor(params) == 'win':
     target_list, target_dicts = MSVSUtil.ShardTargets(target_list, target_dicts)
diff --git a/pylib/gyp/xcode_emulation.py b/pylib/gyp/xcode_emulation.py
index ef84df8..c18efd8 100644
--- a/pylib/gyp/xcode_emulation.py
+++ b/pylib/gyp/xcode_emulation.py
@@ -7,6 +7,7 @@
 other build systems, such as make and ninja.
 """
 
+import copy
 import gyp.common
 import os.path
 import re
@@ -1190,3 +1191,35 @@
             spec['target_name'], postbuild['postbuild_name']))
     postbuilds.append(gyp.common.EncodePOSIXShellList(postbuild['action']))
   return postbuilds
+
+
+def _HasIOSTarget(targets):
+  """Returns true if any target contains the iOS specific key
+  IPHONEOS_DEPLOYMENT_TARGET."""
+  for target_dict in targets.values():
+    for config in target_dict['configurations'].values():
+      if config.get('xcode_settings', {}).get('IPHONEOS_DEPLOYMENT_TARGET'):
+        return True
+  return False
+
+
+def _AddIOSDeviceConfigurations(targets):
+  """Clone all targets and append -iphoneos to the name. Configure these targets
+  to build for iOS devices."""
+  for target_dict in targets.values():
+    for config_name in target_dict['configurations'].keys():
+      config = target_dict['configurations'][config_name]
+      new_config_name = config_name + '-iphoneos'
+      new_config_dict = copy.deepcopy(config)
+      if target_dict['toolset'] == 'target':
+        new_config_dict['xcode_settings']['ARCHS'] = ['armv7']
+        new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos'
+      target_dict['configurations'][new_config_name] = new_config_dict
+  return targets
+
+def CloneConfigurationForDeviceAndEmulator(target_dicts):
+  """If |target_dicts| contains any iOS targets, automatically create -iphoneos
+  targets for iOS device builds."""
+  if _HasIOSTarget(target_dicts):
+    return _AddIOSDeviceConfigurations(target_dicts)
+  return target_dicts
diff --git a/test/ios/app-bundle/test-device.gyp b/test/ios/app-bundle/test-device.gyp
index 7ba0aa0..4810f4a 100644
--- a/test/ios/app-bundle/test-device.gyp
+++ b/test/ios/app-bundle/test-device.gyp
@@ -2,22 +2,6 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 {
-   'target_defaults': {
-    'configurations': {
-      'Debug-iphoneos': {
-        'xcode_settings': {
-          'ARCHS': [ 'armv7' ],
-          'SDKROOT': 'iphoneos',  # -isysroot
-        },
-      },
-      'Debug-iphonesimulator': {
-        'xcode_settings': {
-          'ARCHS': [ 'i386' ],
-          'SDKROOT': 'iphonesimulator',  # -isysroot
-        },
-      },
-    },
-  },
   'make_global_settings': [
     ['CC', '/usr/bin/clang'],
   ],
@@ -45,6 +29,7 @@
         'OTHER_CFLAGS': [
           '-fobjc-abi-version=2',
         ],
+        'SDKROOT': 'iphonesimulator',  # -isysroot
         'INFOPLIST_FILE': 'TestApp/TestApp-Info.plist',
         'IPHONEOS_DEPLOYMENT_TARGET': '4.2',
       },
diff --git a/test/ios/gyptest-per-config-settings.py b/test/ios/gyptest-per-config-settings.py
index 5b1e52e..96def8e 100644
--- a/test/ios/gyptest-per-config-settings.py
+++ b/test/ios/gyptest-per-config-settings.py
@@ -29,13 +29,13 @@
 
   test.run_gyp('test-device.gyp', chdir='app-bundle')
 
-  for configuration in ['Debug-iphoneos', 'Debug-iphonesimulator']:
+  for configuration in ['Default-iphoneos', 'Default']:
     test.set_configuration(configuration)
     test.build('test-device.gyp', test.ALL, chdir='app-bundle')
     result_file = test.built_file_path('Test App Gyp.bundle/Test App Gyp',
                                        chdir='app-bundle')
     test.must_exist(result_file)
-    if configuration == 'Debug-iphoneos':
+    if configuration == 'Default-iphoneos':
       CheckFileType(result_file, 'armv7')
     else:
       CheckFileType(result_file, 'i386')