ios/build/tools/convert_gn_xcodeproj.py
def UpdateXcodeProject(project_dir, old_project_dir, configurations, root_dir):
  """Update inplace Xcode project to support multiple configurations.

  Args:
    project_dir: path to the input Xcode project
    configurations: list of string corresponding to the configurations that
      need to be supported by the tweaked Xcode projects, must contains at
      least one value.
    root_dir: path to the root directory used to find markdown files
  """
  json_data = json.loads(LoadXcodeProjectAsJSON(project_dir))
  project = XcodeProject(json_data['objects'])
  schemes_template = None

  objects_to_remove = []
  for value in list(project.objects.values()):
    isa = value['isa']

    # Teach build shell script to look for the configuration and platform.
    if isa == 'PBXShellScriptBuildPhase':
      shell_path = value['shellPath']
      if shell_path.endswith('/sh'):
        value['shellScript'] = value['shellScript'].replace(
            'ninja -C .',
            'ninja -C "../${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}"')
      elif re.search('[ /]python[23]?$', shell_path):
        value['shellScript'] = value['shellScript'].replace(
            'ninja_params = [ \'-C\', \'.\' ]',
            'ninja_params = [ \'-C\', \'../\' + os.environ[\'CONFIGURATION\']'
            ' + os.environ[\'EFFECTIVE_PLATFORM_NAME\'] ]')

    # Add new configuration, using the first one as default.
    if isa == 'XCConfigurationList':
      value['defaultConfigurationName'] = configurations[0]
      objects_to_remove.extend(value['buildConfigurations'])

      build_config_template = project.objects[value['buildConfigurations'][0]]
      build_config_template['buildSettings']['CONFIGURATION_BUILD_DIR'] = \
          '$(PROJECT_DIR)/../$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'

      value['buildConfigurations'] = []
      for configuration in configurations:
        new_build_config = copy.copy(build_config_template)
        new_build_config['name'] = configuration
        value['buildConfigurations'].append(
            project.AddObject('products', new_build_config))

    # Create scheme files for application, extensions and framework targets.
    if isa == 'PBXNativeTarget':
      product_type = value['productType']
      if product_type not in (
          'com.apple.product-type.app-extension',
          'com.apple.product-type.application',
          'com.apple.product-type.framework'):
        continue

      if schemes_template is None:
        schemes_template = LoadSchemeTemplate(root_dir)

      product = project.objects[value['productReference']]
      GenerateSchemeForTarget(
          project_dir, old_project_dir, value['name'],
          product['path'], schemes_template)

  for object_id in objects_to_remove:
    del project.objects[object_id]

  source = GetOrCreateRootGroup(project, json_data['rootObject'], 'Source')
  AddMarkdownToProject(project, root_dir, source)
  SortFileReferencesByName(project, source)

  objects = collections.OrderedDict(sorted(project.objects.items()))
  WriteXcodeProject(project_dir, json.dumps(json_data))
Update inplace Xcode project to support multiple configurations.

  Args:
    project_dir: path to the input Xcode project
    configurations: list of string corresponding to the configurations that
      need to be supported by the tweaked Xcode projects, must contains at
      least one value.
    root_dir: path to the root directory used to find markdown files
  
Update inplace Xcode project to support multiple configurations.
Update inplace Xcode project to support multiple configurations .
def UpdateXcodeProject(project_dir, old_project_dir, configurations, root_dir):
  json_data = json.loads(LoadXcodeProjectAsJSON(project_dir))
  project = XcodeProject(json_data['objects'])
  schemes_template = None
  objects_to_remove = []
  for value in list(project.objects.values()):
    isa = value['isa']
    if isa == 'PBXShellScriptBuildPhase':
      shell_path = value['shellPath']
      if shell_path.endswith('/sh'):
        value['shellScript'] = value['shellScript'].replace(
            'ninja -C .',
            'ninja -C "../${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}"')
      elif re.search('[ /]python[23]?$', shell_path):
        value['shellScript'] = value['shellScript'].replace(
            'ninja_params = [ \'-C\', \'.\' ]',
            'ninja_params = [ \'-C\', \'../\' + os.environ[\'CONFIGURATION\']'
            ' + os.environ[\'EFFECTIVE_PLATFORM_NAME\'] ]')
    if isa == 'XCConfigurationList':
      value['defaultConfigurationName'] = configurations[0]
      objects_to_remove.extend(value['buildConfigurations'])
      build_config_template = project.objects[value['buildConfigurations'][0]]
      build_config_template['buildSettings']['CONFIGURATION_BUILD_DIR'] = \
          '$(PROJECT_DIR)/../$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
      value['buildConfigurations'] = []
      for configuration in configurations:
        new_build_config = copy.copy(build_config_template)
        new_build_config['name'] = configuration
        value['buildConfigurations'].append(
            project.AddObject('products', new_build_config))
    if isa == 'PBXNativeTarget':
      product_type = value['productType']
      if product_type not in (
          'com.apple.product-type.app-extension',
          'com.apple.product-type.application',
          'com.apple.product-type.framework'):
        continue
      if schemes_template is None:
        schemes_template = LoadSchemeTemplate(root_dir)
      product = project.objects[value['productReference']]
      GenerateSchemeForTarget(
          project_dir, old_project_dir, value['name'],
          product['path'], schemes_template)
  for object_id in objects_to_remove:
    del project.objects[object_id]
  source = GetOrCreateRootGroup(project, json_data['rootObject'], 'Source')
  AddMarkdownToProject(project, root_dir, source)
  SortFileReferencesByName(project, source)
  objects = collections.OrderedDict(sorted(project.objects.items()))
  WriteXcodeProject(project_dir, json.dumps(json_data))
def UpdateXcodeProject ( project_dir , old_project_dir , configurations , root_dir ) : json_data = json . loads ( LoadXcodeProjectAsJSON ( project_dir ) ) project = XcodeProject ( json_data [ 'objects' ] ) schemes_template = None objects_to_remove = [ ] for value in list ( project . objects . values ( ) ) : isa = value [ 'isa' ] if isa == 'PBXShellScriptBuildPhase' : shell_path = value [ 'shellPath' ] if shell_path . endswith ( '/sh' ) : value [ 'shellScript' ] = value [ 'shellScript' ] . replace ( 'ninja -C .' , 'ninja -C "../${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}"' ) elif re . search ( '[ /]python[23]?$' , shell_path ) : value [ 'shellScript' ] = value [ 'shellScript' ] . replace ( 'ninja_params = [ \'-C\', \'.\' ]' , 'ninja_params = [ \'-C\', \'../\' + os.environ[\'CONFIGURATION\']' ' + os.environ[\'EFFECTIVE_PLATFORM_NAME\'] ]' ) if isa == 'XCConfigurationList' : value [ 'defaultConfigurationName' ] = configurations [ 0 ] objects_to_remove . extend ( value [ 'buildConfigurations' ] ) build_config_template = project . objects [ value [ 'buildConfigurations' ] [ 0 ] ] build_config_template [ 'buildSettings' ] [ 'CONFIGURATION_BUILD_DIR' ] = '$(PROJECT_DIR)/../$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)' value [ 'buildConfigurations' ] = [ ] for configuration in configurations : new_build_config = copy . copy ( build_config_template ) new_build_config [ 'name' ] = configuration value [ 'buildConfigurations' ] . append ( project . AddObject ( 'products' , new_build_config ) ) if isa == 'PBXNativeTarget' : product_type = value [ 'productType' ] if product_type not in ( 'com.apple.product-type.app-extension' , 'com.apple.product-type.application' , 'com.apple.product-type.framework' ) : continue if schemes_template is None : schemes_template = LoadSchemeTemplate ( root_dir ) product = project . objects [ value [ 'productReference' ] ] GenerateSchemeForTarget ( project_dir , old_project_dir , value [ 'name' ] , product [ 'path' ] , schemes_template ) for object_id in objects_to_remove : del project . objects [ object_id ] source = GetOrCreateRootGroup ( project , json_data [ 'rootObject' ] , 'Source' ) AddMarkdownToProject ( project , root_dir , source ) SortFileReferencesByName ( project , source ) objects = collections . OrderedDict ( sorted ( project . objects . items ( ) ) ) WriteXcodeProject ( project_dir , json . dumps ( json_data ) )
Update inplace Xcode project to support multiple configurations.
Update inplace Xcode project to support multiple configurations .
"""Update inplace Xcode project to support multiple configurations.

  Args:
    project_dir: path to the input Xcode project
    configurations: list of string corresponding to the configurations that
      need to be supported by the tweaked Xcode projects, must contains at
      least one value.
    root_dir: path to the root directory used to find markdown files
  """ # Teach build shell script to look for the configuration and platform. # Add new configuration, using the first one as default. # Create scheme files for application, extensions and framework targets.
project_dir
path to the input Xcode project
path to the input Xcode project
old_project_dir
configurations
list of string corresponding to the configurations that
need to be supported by the tweaked Xcode projects, must contains at
least one value.
list of string corresponding to the configurations that need to be supported by the tweaked Xcode projects must contains at least one value .
root_dir
path to the root directory used to find markdown files
path to the root directory used to find markdown files