<s> import filecmp <EOL> import gyp . common <EOL> import gyp . xcodeproj_file <EOL> import gyp . xcode_ninja <EOL> import errno <EOL> import os <EOL> import sys <EOL> import posixpath <EOL> import re <EOL> import shutil <EOL> import subprocess <EOL> import tempfile <EOL> _intermediate_var = '<STR_LIT>' <EOL> _shared_intermediate_var = '<STR_LIT>' <EOL> _library_search_paths_var = '<STR_LIT>' <EOL> generator_default_variables = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % _intermediate_var , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % _shared_intermediate_var , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> generator_additional_path_sections = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> generator_additional_non_configuration_keys = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> generator_extra_sources_for_rules = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> generator_filelist_paths = None <EOL> xcode_standard_library_dirs = frozenset ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> def CreateXCConfigurationList ( configuration_names ) : <EOL> xccl = gyp . xcodeproj_file . XCConfigurationList ( { '<STR_LIT>' : [ ] } ) <EOL> if len ( configuration_names ) == <NUM_LIT:0> : <EOL> configuration_names = [ '<STR_LIT>' ] <EOL> for configuration_name in configuration_names : <EOL> xcbc = gyp . xcodeproj_file . XCBuildConfiguration ( { <EOL> '<STR_LIT:name>' : configuration_name } ) <EOL> xccl . AppendProperty ( '<STR_LIT>' , xcbc ) <EOL> xccl . SetProperty ( '<STR_LIT>' , configuration_names [ <NUM_LIT:0> ] ) <EOL> return xccl <EOL> class XcodeProject ( object ) : <EOL> def __init__ ( self , gyp_path , path , build_file_dict ) : <EOL> self . gyp_path = gyp_path <EOL> self . path = path <EOL> self . project = gyp . xcodeproj_file . PBXProject ( path = path ) <EOL> projectDirPath = gyp . common . RelativePath ( <EOL> os . path . dirname ( os . path . abspath ( self . gyp_path ) ) , <EOL> os . path . dirname ( path ) or '<STR_LIT:.>' ) <EOL> self . project . SetProperty ( '<STR_LIT>' , projectDirPath ) <EOL> self . project_file = gyp . xcodeproj_file . XCProjectFile ( { '<STR_LIT>' : self . project } ) <EOL> self . build_file_dict = build_file_dict <EOL> self . created_dir = False <EOL> try : <EOL> os . makedirs ( self . path ) <EOL> self . created_dir = True <EOL> except OSError , e : <EOL> if e . errno != errno . EEXIST : <EOL> raise <EOL> def Finalize1 ( self , xcode_targets , serialize_all_tests ) : <EOL> configurations = [ ] <EOL> for xct in self . project . GetProperty ( '<STR_LIT>' ) : <EOL> xccl = xct . GetProperty ( '<STR_LIT>' ) <EOL> xcbcs = xccl . GetProperty ( '<STR_LIT>' ) <EOL> for xcbc in xcbcs : <EOL> name = xcbc . GetProperty ( '<STR_LIT:name>' ) <EOL> if name not in configurations : <EOL> configurations . append ( name ) <EOL> try : <EOL> xccl = CreateXCConfigurationList ( configurations ) <EOL> self . project . SetProperty ( '<STR_LIT>' , xccl ) <EOL> except : <EOL> sys . stderr . write ( "<STR_LIT>" % self . gyp_path ) <EOL> raise <EOL> xccl . SetBuildSetting ( _intermediate_var , <EOL> '<STR_LIT>' ) <EOL> xccl . SetBuildSetting ( _shared_intermediate_var , <EOL> '<STR_LIT>' ) <EOL> for xck , xcv in self . build_file_dict . get ( '<STR_LIT>' , { } ) . iteritems ( ) : <EOL> xccl . SetBuildSetting ( xck , xcv ) <EOL> if '<STR_LIT>' in self . build_file_dict : <EOL> config_ref = self . project . AddOrGetFileInRootGroup ( <EOL> self . build_file_dict [ '<STR_LIT>' ] ) <EOL> xccl . SetBaseConfiguration ( config_ref ) <EOL> build_file_configurations = self . build_file_dict . get ( '<STR_LIT>' , { } ) <EOL> if build_file_configurations : <EOL> for config_name in configurations : <EOL> build_file_configuration_named = build_file_configurations . get ( config_name , { } ) <EOL> if build_file_configuration_named : <EOL> xcc = xccl . ConfigurationNamed ( config_name ) <EOL> for xck , xcv in build_file_configuration_named . get ( '<STR_LIT>' , <EOL> { } ) . iteritems ( ) : <EOL> xcc . SetBuildSetting ( xck , xcv ) <EOL> if '<STR_LIT>' in build_file_configuration_named : <EOL> config_ref = self . project . AddOrGetFileInRootGroup ( <EOL> build_file_configurations [ config_name ] [ '<STR_LIT>' ] ) <EOL> xcc . SetBaseConfiguration ( config_ref ) <EOL> ordinary_targets = [ ] <EOL> run_test_targets = [ ] <EOL> support_targets = [ ] <EOL> targets = [ ] <EOL> has_custom_all = False <EOL> targets_for_all = [ ] <EOL> for target in self . build_file_dict [ '<STR_LIT>' ] : <EOL> target_name = target [ '<STR_LIT>' ] <EOL> toolset = target [ '<STR_LIT>' ] <EOL> qualified_target = gyp . common . QualifiedTarget ( self . gyp_path , target_name , <EOL> toolset ) <EOL> xcode_target = xcode_targets [ qualified_target ] <EOL> assert xcode_target in self . project . _properties [ '<STR_LIT>' ] <EOL> targets . append ( xcode_target ) <EOL> ordinary_targets . append ( xcode_target ) <EOL> if xcode_target . support_target : <EOL> support_targets . append ( xcode_target . support_target ) <EOL> targets . append ( xcode_target . support_target ) <EOL> if not int ( target . get ( '<STR_LIT>' , False ) ) : <EOL> targets_for_all . append ( xcode_target ) <EOL> if target_name . lower ( ) == '<STR_LIT:all>' : <EOL> has_custom_all = True ; <EOL> if target . get ( '<STR_LIT>' ) : <EOL> xccl = CreateXCConfigurationList ( configurations ) <EOL> run_target = gyp . xcodeproj_file . PBXAggregateTarget ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' + target_name , <EOL> '<STR_LIT>' : xcode_target . GetProperty ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : xccl , <EOL> } , <EOL> parent = self . project ) <EOL> run_target . AddDependency ( xcode_target ) <EOL> command = target [ '<STR_LIT>' ] <EOL> script = '<STR_LIT>' <EOL> if command . get ( '<STR_LIT>' ) : <EOL> script = script + '<STR_LIT>' % gyp . xcodeproj_file . ConvertVariablesToShellSyntax ( <EOL> command . get ( '<STR_LIT>' ) ) <EOL> if command . get ( '<STR_LIT>' ) : <EOL> script = script + "<STR_LIT:\n>" . join ( <EOL> [ '<STR_LIT>' % <EOL> ( key , gyp . xcodeproj_file . ConvertVariablesToShellSyntax ( val ) ) <EOL> for ( key , val ) in command . get ( '<STR_LIT>' ) . iteritems ( ) ] ) + "<STR_LIT:\n>" <EOL> command_prefix = '<STR_LIT>' <EOL> if serialize_all_tests : <EOL> command_prefix = """<STR_LIT>""" <EOL> script = script + '<STR_LIT>' + command_prefix + '<STR_LIT>' % gyp . xcodeproj_file . ConvertVariablesToShellSyntax ( <EOL> gyp . common . EncodePOSIXShellList ( command . get ( '<STR_LIT:action>' ) ) ) <EOL> ssbp = gyp . xcodeproj_file . PBXShellScriptBuildPhase ( { <EOL> '<STR_LIT>' : script , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } ) <EOL> run_target . AppendProperty ( '<STR_LIT>' , ssbp ) <EOL> targets . append ( run_target ) <EOL> run_test_targets . append ( run_target ) <EOL> xcode_target . test_runner = run_target <EOL> assert len ( self . project . _properties [ '<STR_LIT>' ] ) == len ( ordinary_targets ) + len ( support_targets ) <EOL> self . project . _properties [ '<STR_LIT>' ] = targets <EOL> self . project . RootGroupsTakeOverOnlyChildren ( True ) <EOL> self . project . SortGroups ( ) <EOL> if len ( targets_for_all ) > <NUM_LIT:1> and not has_custom_all : <EOL> xccl = CreateXCConfigurationList ( configurations ) <EOL> all_target = gyp . xcodeproj_file . PBXAggregateTarget ( <EOL> { <EOL> '<STR_LIT>' : xccl , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> } , <EOL> parent = self . project ) <EOL> for target in targets_for_all : <EOL> all_target . AddDependency ( target ) <EOL> self . project . _properties [ '<STR_LIT>' ] . insert ( <NUM_LIT:0> , all_target ) <EOL> if len ( run_test_targets ) > <NUM_LIT:1> : <EOL> xccl = CreateXCConfigurationList ( configurations ) <EOL> run_all_tests_target = gyp . xcodeproj_file . PBXAggregateTarget ( <EOL> { <EOL> '<STR_LIT>' : xccl , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> } , <EOL> parent = self . project ) <EOL> for run_test_target in run_test_targets : <EOL> run_all_tests_target . AddDependency ( run_test_target ) <EOL> self . project . _properties [ '<STR_LIT>' ] . insert ( <NUM_LIT:1> , run_all_tests_target ) <EOL> def Finalize2 ( self , xcode_targets , xcode_target_to_target_dict ) : <EOL> for bf_tgt in self . build_file_dict [ '<STR_LIT>' ] : <EOL> if int ( bf_tgt . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) : <EOL> tgt_name = bf_tgt [ '<STR_LIT>' ] <EOL> toolset = bf_tgt [ '<STR_LIT>' ] <EOL> qualified_target = gyp . common . QualifiedTarget ( self . gyp_path , <EOL> tgt_name , toolset ) <EOL> xcode_target = xcode_targets [ qualified_target ] <EOL> if isinstance ( xcode_target , gyp . xcodeproj_file . PBXAggregateTarget ) : <EOL> all_run_tests = [ ] <EOL> pbxtds = xcode_target . GetProperty ( '<STR_LIT>' ) <EOL> for pbxtd in pbxtds : <EOL> pbxcip = pbxtd . GetProperty ( '<STR_LIT>' ) <EOL> dependency_xct = pbxcip . GetProperty ( '<STR_LIT>' ) <EOL> if hasattr ( dependency_xct , '<STR_LIT>' ) : <EOL> all_run_tests . append ( dependency_xct . test_runner ) <EOL> if len ( all_run_tests ) > <NUM_LIT:0> : <EOL> run_all_target = gyp . xcodeproj_file . PBXAggregateTarget ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' % tgt_name , <EOL> '<STR_LIT>' : tgt_name , <EOL> } , <EOL> parent = self . project ) <EOL> for run_test_target in all_run_tests : <EOL> run_all_target . AddDependency ( run_test_target ) <EOL> idx = self . project . _properties [ '<STR_LIT>' ] . index ( xcode_target ) <EOL> self . project . _properties [ '<STR_LIT>' ] . insert ( idx + <NUM_LIT:1> , run_all_target ) <EOL> for other_pbxproject in self . project . _other_pbxprojects . keys ( ) : <EOL> self . project . AddOrGetProjectReference ( other_pbxproject ) <EOL> self . project . SortRemoteProductReferences ( ) <EOL> self . project_file . ComputeIDs ( ) <EOL> self . project_file . EnsureNoIDCollisions ( ) <EOL> def Write ( self ) : <EOL> ( output_fd , new_pbxproj_path ) = tempfile . mkstemp ( suffix = '<STR_LIT>' , prefix = '<STR_LIT>' , <EOL> dir = self . path ) <EOL> try : <EOL> output_file = os . fdopen ( output_fd , '<STR_LIT:wb>' ) <EOL> self . project_file . Print ( output_file ) <EOL> output_file . close ( ) <EOL> pbxproj_path = os . path . join ( self . path , '<STR_LIT>' ) <EOL> same = False <EOL> try : <EOL> same = filecmp . cmp ( pbxproj_path , new_pbxproj_path , False ) <EOL> except OSError , e : <EOL> if e . errno != errno . ENOENT : <EOL> raise <EOL> if same : <EOL> os . unlink ( new_pbxproj_path ) <EOL> else : <EOL> umask = os . umask ( <NUM_LIT:0> <NUM_LIT> ) <EOL> os . umask ( umask ) <EOL> os . chmod ( new_pbxproj_path , <NUM_LIT:0> <NUM_LIT> & ~ umask ) <EOL> os . rename ( new_pbxproj_path , pbxproj_path ) <EOL> except Exception : <EOL> os . unlink ( new_pbxproj_path ) <EOL> if self . created_dir : <EOL> shutil . rmtree ( self . path , True ) <EOL> raise <EOL> def AddSourceToTarget ( source , type , pbxp , xct ) : <EOL> source_extensions = [ '<STR_LIT:c>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:m>' , '<STR_LIT>' , '<STR_LIT:s>' , '<STR_LIT>' ] <EOL> library_extensions = [ '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:o>' ] <EOL> basename = posixpath . basename ( source ) <EOL> ( root , ext ) = posixpath . splitext ( basename ) <EOL> if ext : <EOL> ext = ext [ <NUM_LIT:1> : ] . lower ( ) <EOL> if ext in source_extensions and type != '<STR_LIT:none>' : <EOL> xct . SourcesPhase ( ) . AddFile ( source ) <EOL> elif ext in library_extensions and type != '<STR_LIT:none>' : <EOL> xct . FrameworksPhase ( ) . AddFile ( source ) <EOL> else : <EOL> pbxp . AddOrGetFileInRootGroup ( source ) <EOL> def AddResourceToTarget ( resource , pbxp , xct ) : <EOL> xct . ResourcesPhase ( ) . AddFile ( resource ) <EOL> def AddHeaderToTarget ( header , pbxp , xct , is_public ) : <EOL> settings = '<STR_LIT>' % ( '<STR_LIT>' , '<STR_LIT>' ) [ is_public ] <EOL> xct . HeadersPhase ( ) . AddFile ( header , settings ) <EOL> _xcode_variable_re = re . compile ( r'<STR_LIT>' ) <EOL> def ExpandXcodeVariables ( string , expansions ) : <EOL> """<STR_LIT>""" <EOL> matches = _xcode_variable_re . findall ( string ) <EOL> if matches == None : <EOL> return string <EOL> matches . reverse ( ) <EOL> for match in matches : <EOL> ( to_replace , variable ) = match <EOL> if not variable in expansions : <EOL> continue <EOL> replacement = expansions [ variable ] <EOL> string = re . sub ( re . escape ( to_replace ) , replacement , string ) <EOL> return string <EOL> _xcode_define_re = re . compile ( r'<STR_LIT>' ) <EOL> def EscapeXcodeDefine ( s ) : <EOL> """<STR_LIT>""" <EOL> return re . sub ( _xcode_define_re , r'<STR_LIT>' , s ) <EOL> def PerformBuild ( data , configurations , params ) : <EOL> options = params [ '<STR_LIT>' ] <EOL> for build_file , build_file_dict in data . iteritems ( ) : <EOL> ( build_file_root , build_file_ext ) = os . path . splitext ( build_file ) <EOL> if build_file_ext != '<STR_LIT>' : <EOL> continue <EOL> xcodeproj_path = build_file_root + options . suffix + '<STR_LIT>' <EOL> if options . generator_output : <EOL> xcodeproj_path = os . path . join ( options . generator_output , xcodeproj_path ) <EOL> for config in configurations : <EOL> arguments = [ '<STR_LIT>' , '<STR_LIT>' , xcodeproj_path ] <EOL> arguments += [ '<STR_LIT>' , config ] <EOL> print "<STR_LIT>" % ( config , arguments ) <EOL> subprocess . check_call ( arguments ) <EOL> def CalculateGeneratorInputInfo ( params ) : <EOL> toplevel = params [ '<STR_LIT>' ] . toplevel_dir <EOL> if params . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> generator_dir = os . path . relpath ( params [ '<STR_LIT>' ] . generator_output or '<STR_LIT:.>' ) <EOL> output_dir = params . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> output_dir = os . path . normpath ( os . path . join ( generator_dir , output_dir ) ) <EOL> qualified_out_dir = os . path . normpath ( os . path . join ( <EOL> toplevel , output_dir , '<STR_LIT>' ) ) <EOL> else : <EOL> output_dir = os . path . normpath ( os . path . join ( toplevel , '<STR_LIT>' ) ) <EOL> qualified_out_dir = os . path . normpath ( os . path . join ( <EOL> toplevel , output_dir , '<STR_LIT>' ) ) <EOL> global generator_filelist_paths <EOL> generator_filelist_paths = { <EOL> '<STR_LIT>' : toplevel , <EOL> '<STR_LIT>' : qualified_out_dir , <EOL> } <EOL> def GenerateOutput ( target_list , target_dicts , data , params ) : <EOL> ninja_wrapper = params . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> if ninja_wrapper : <EOL> ( target_list , target_dicts , data ) = gyp . xcode_ninja . CreateWrapper ( target_list , target_dicts , data , params ) <EOL> options = params [ '<STR_LIT>' ] <EOL> generator_flags = params . get ( '<STR_LIT>' , { } ) <EOL> parallel_builds = generator_flags . get ( '<STR_LIT>' , True ) <EOL> serialize_all_tests = generator_flags . get ( '<STR_LIT>' , True ) <EOL> upgrade_check_project_version = generator_flags . get ( '<STR_LIT>' , None ) <EOL> if upgrade_check_project_version : <EOL> upgrade_check_project_version = str ( upgrade_check_project_version ) <EOL> while len ( upgrade_check_project_version ) < <NUM_LIT:4> : <EOL> upgrade_check_project_version = '<STR_LIT:0>' + upgrade_check_project_version <EOL> skip_excluded_files = not generator_flags . get ( '<STR_LIT>' , True ) <EOL> xcode_projects = { } <EOL> for build_file , build_file_dict in data . iteritems ( ) : <EOL> ( build_file_root , build_file_ext ) = os . path . splitext ( build_file ) <EOL> if build_file_ext != '<STR_LIT>' : <EOL> continue <EOL> xcodeproj_path = build_file_root + options . suffix + '<STR_LIT>' <EOL> if options . generator_output : <EOL> xcodeproj_path = os . path . join ( options . generator_output , xcodeproj_path ) <EOL> xcp = XcodeProject ( build_file , xcodeproj_path , build_file_dict ) <EOL> xcode_projects [ build_file ] = xcp <EOL> pbxp = xcp . project <EOL> project_attributes = { } ; <EOL> if parallel_builds : <EOL> project_attributes [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if upgrade_check_project_version : <EOL> project_attributes [ '<STR_LIT>' ] = upgrade_check_project_version <EOL> project_attributes [ '<STR_LIT>' ] = upgrade_check_project_version <EOL> project_attributes [ '<STR_LIT>' ] = upgrade_check_project_version <EOL> pbxp . SetProperty ( '<STR_LIT>' , project_attributes ) <EOL> if not generator_flags . get ( '<STR_LIT>' ) : <EOL> main_group = pbxp . GetProperty ( '<STR_LIT>' ) <EOL> build_group = gyp . xcodeproj_file . PBXGroup ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> main_group . AppendChild ( build_group ) <EOL> for included_file in build_file_dict [ '<STR_LIT>' ] : <EOL> build_group . AddOrGetFileByPath ( included_file , False ) <EOL> xcode_targets = { } <EOL> xcode_target_to_target_dict = { } <EOL> for qualified_target in target_list : <EOL> [ build_file , target_name , toolset ] = gyp . common . ParseQualifiedTarget ( qualified_target ) <EOL> spec = target_dicts [ qualified_target ] <EOL> if spec [ '<STR_LIT>' ] != '<STR_LIT:target>' : <EOL> raise Exception ( <EOL> '<STR_LIT>' % <EOL> qualified_target ) <EOL> configuration_names = [ spec [ '<STR_LIT>' ] ] <EOL> for configuration_name in sorted ( spec [ '<STR_LIT>' ] . keys ( ) ) : <EOL> if configuration_name not in configuration_names : <EOL> configuration_names . append ( configuration_name ) <EOL> xcp = xcode_projects [ build_file ] <EOL> pbxp = xcp . project <EOL> xccl = CreateXCConfigurationList ( configuration_names ) <EOL> _types = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> target_properties = { <EOL> '<STR_LIT>' : xccl , <EOL> '<STR_LIT:name>' : target_name , <EOL> } <EOL> type = spec [ '<STR_LIT:type>' ] <EOL> is_xctest = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> is_bundle = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) or is_xctest <EOL> is_app_extension = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> is_watchkit_extension = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> is_watch_app = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> if type != '<STR_LIT:none>' : <EOL> type_bundle_key = type <EOL> if is_xctest : <EOL> type_bundle_key += '<STR_LIT>' <EOL> assert type == '<STR_LIT>' , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % target_name ) <EOL> elif is_app_extension : <EOL> assert is_bundle , ( '<STR_LIT>' <EOL> '<STR_LIT>' % target_name ) <EOL> type_bundle_key += '<STR_LIT>' <EOL> elif is_watchkit_extension : <EOL> assert is_bundle , ( '<STR_LIT>' <EOL> '<STR_LIT>' % target_name ) <EOL> type_bundle_key += '<STR_LIT>' <EOL> elif is_watch_app : <EOL> assert is_bundle , ( '<STR_LIT>' <EOL> '<STR_LIT>' % target_name ) <EOL> type_bundle_key += '<STR_LIT>' <EOL> elif is_bundle : <EOL> type_bundle_key += '<STR_LIT>' <EOL> xctarget_type = gyp . xcodeproj_file . PBXNativeTarget <EOL> try : <EOL> target_properties [ '<STR_LIT>' ] = _types [ type_bundle_key ] <EOL> except KeyError , e : <EOL> gyp . common . ExceptionAppend ( e , "<STR_LIT>" <EOL> "<STR_LIT>" % target_name ) <EOL> raise <EOL> else : <EOL> xctarget_type = gyp . xcodeproj_file . PBXAggregateTarget <EOL> assert not is_bundle , ( <EOL> '<STR_LIT>' % <EOL> target_name ) <EOL> assert not is_xctest , ( <EOL> '<STR_LIT>' % <EOL> target_name ) <EOL> target_product_name = spec . get ( '<STR_LIT>' ) <EOL> if target_product_name is not None : <EOL> target_properties [ '<STR_LIT>' ] = target_product_name <EOL> xct = xctarget_type ( target_properties , parent = pbxp , <EOL> force_outdir = spec . get ( '<STR_LIT>' ) , <EOL> force_prefix = spec . get ( '<STR_LIT>' ) , <EOL> force_extension = spec . get ( '<STR_LIT>' ) ) <EOL> pbxp . AppendProperty ( '<STR_LIT>' , xct ) <EOL> xcode_targets [ qualified_target ] = xct <EOL> xcode_target_to_target_dict [ xct ] = spec <EOL> spec_actions = spec . get ( '<STR_LIT>' , [ ] ) <EOL> spec_rules = spec . get ( '<STR_LIT>' , [ ] ) <EOL> support_xct = None <EOL> if type != '<STR_LIT:none>' and ( spec_actions or spec_rules ) and not ninja_wrapper : <EOL> support_xccl = CreateXCConfigurationList ( configuration_names ) ; <EOL> support_target_suffix = generator_flags . get ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> support_target_properties = { <EOL> '<STR_LIT>' : support_xccl , <EOL> '<STR_LIT:name>' : target_name + support_target_suffix , <EOL> } <EOL> if target_product_name : <EOL> support_target_properties [ '<STR_LIT>' ] = target_product_name + '<STR_LIT>' <EOL> support_xct = gyp . xcodeproj_file . PBXAggregateTarget ( support_target_properties , <EOL> parent = pbxp ) <EOL> pbxp . AppendProperty ( '<STR_LIT>' , support_xct ) <EOL> xct . AddDependency ( support_xct ) <EOL> xct . support_target = support_xct <EOL> prebuild_index = <NUM_LIT:0> <EOL> for action in spec_actions : <EOL> message = action . get ( '<STR_LIT:message>' ) <EOL> if message : <EOL> message = '<STR_LIT>' + gyp . common . EncodePOSIXShellArgument ( message ) <EOL> else : <EOL> message = '<STR_LIT>' <EOL> action_string = gyp . common . EncodePOSIXShellList ( action [ '<STR_LIT:action>' ] ) <EOL> message_sh = gyp . xcodeproj_file . ConvertVariablesToShellSyntax ( message ) <EOL> action_string_sh = gyp . xcodeproj_file . ConvertVariablesToShellSyntax ( <EOL> action_string ) <EOL> script = '<STR_LIT>' <EOL> if message_sh : <EOL> script += message_sh + '<STR_LIT:\n>' <EOL> script += '<STR_LIT>' + action_string_sh + '<STR_LIT>' <EOL> ssbp = gyp . xcodeproj_file . PBXShellScriptBuildPhase ( { <EOL> '<STR_LIT>' : action [ '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' + action [ '<STR_LIT>' ] + '<STR_LIT:">' , <EOL> '<STR_LIT>' : action [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : script , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } ) <EOL> if support_xct : <EOL> support_xct . AppendProperty ( '<STR_LIT>' , ssbp ) <EOL> else : <EOL> xct . _properties [ '<STR_LIT>' ] . insert ( prebuild_index , ssbp ) <EOL> prebuild_index = prebuild_index + <NUM_LIT:1> <EOL> if int ( action . get ( '<STR_LIT>' , False ) ) : <EOL> for output in action [ '<STR_LIT>' ] : <EOL> AddSourceToTarget ( output , type , pbxp , xct ) <EOL> if int ( action . get ( '<STR_LIT>' , False ) ) : <EOL> for output in action [ '<STR_LIT>' ] : <EOL> AddResourceToTarget ( output , pbxp , xct ) <EOL> if is_bundle : <EOL> tgt_mac_bundle_resources = spec . get ( '<STR_LIT>' , [ ] ) <EOL> else : <EOL> tgt_mac_bundle_resources = [ ] <EOL> rules_by_ext = { } <EOL> for rule in spec_rules : <EOL> rules_by_ext [ rule [ '<STR_LIT>' ] ] = rule <EOL> concrete_outputs_by_rule_source = [ ] <EOL> concrete_outputs_all = [ ] <EOL> messages = [ ] <EOL> actions = [ ] <EOL> for rule_source in rule . get ( '<STR_LIT>' , [ ] ) : <EOL> rule_source_dirname , rule_source_basename = posixpath . split ( rule_source ) <EOL> ( rule_source_root , rule_source_ext ) = posixpath . splitext ( rule_source_basename ) <EOL> rule_input_dict = { <EOL> '<STR_LIT>' : rule_source_root , <EOL> '<STR_LIT>' : rule_source_ext , <EOL> '<STR_LIT>' : rule_source_basename , <EOL> '<STR_LIT>' : rule_source , <EOL> '<STR_LIT>' : rule_source_dirname , <EOL> } <EOL> concrete_outputs_for_this_rule_source = [ ] <EOL> for output in rule . get ( '<STR_LIT>' , [ ] ) : <EOL> concrete_output = ExpandXcodeVariables ( output , rule_input_dict ) <EOL> concrete_outputs_for_this_rule_source . append ( concrete_output ) <EOL> pbxp . AddOrGetFileInRootGroup ( concrete_output ) <EOL> concrete_outputs_by_rule_source . append ( concrete_outputs_for_this_rule_source ) <EOL> concrete_outputs_all . extend ( concrete_outputs_for_this_rule_source ) <EOL> if int ( rule . get ( '<STR_LIT>' , False ) ) : <EOL> for output in concrete_outputs_for_this_rule_source : <EOL> AddSourceToTarget ( output , type , pbxp , xct ) <EOL> was_mac_bundle_resource = rule_source in tgt_mac_bundle_resources <EOL> if was_mac_bundle_resource or int ( rule . get ( '<STR_LIT>' , False ) ) : <EOL> for output in concrete_outputs_for_this_rule_source : <EOL> AddResourceToTarget ( output , pbxp , xct ) <EOL> message = rule . get ( '<STR_LIT:message>' ) <EOL> if message : <EOL> message = gyp . common . EncodePOSIXShellArgument ( message ) <EOL> message = ExpandXcodeVariables ( message , rule_input_dict ) <EOL> messages . append ( message ) <EOL> action_string = gyp . common . EncodePOSIXShellList ( rule [ '<STR_LIT:action>' ] ) <EOL> action = ExpandXcodeVariables ( action_string , rule_input_dict ) <EOL> actions . append ( action ) <EOL> if len ( concrete_outputs_all ) > <NUM_LIT:0> : <EOL> makefile_name = '<STR_LIT>' % re . sub ( <EOL> '<STR_LIT>' , '<STR_LIT:_>' , '<STR_LIT>' % ( target_name , rule [ '<STR_LIT>' ] ) ) <EOL> makefile_path = os . path . join ( xcode_projects [ build_file ] . path , <EOL> makefile_name ) <EOL> makefile = open ( makefile_path , '<STR_LIT:wb>' ) <EOL> makefile . write ( '<STR_LIT>' ) <EOL> for concrete_output_index in xrange ( <NUM_LIT:0> , len ( concrete_outputs_by_rule_source ) ) : <EOL> concrete_output = concrete_outputs_by_rule_source [ concrete_output_index ] [ <NUM_LIT:0> ] <EOL> if concrete_output_index == len ( concrete_outputs_by_rule_source ) - <NUM_LIT:1> : <EOL> eol = '<STR_LIT>' <EOL> else : <EOL> eol = '<STR_LIT>' <EOL> makefile . write ( '<STR_LIT>' % ( concrete_output , eol ) ) <EOL> for ( rule_source , concrete_outputs , message , action ) in zip ( rule [ '<STR_LIT>' ] , concrete_outputs_by_rule_source , <EOL> messages , actions ) : <EOL> makefile . write ( '<STR_LIT:\n>' ) <EOL> concrete_output_dirs = [ ] <EOL> for concrete_output_index in xrange ( <NUM_LIT:0> , len ( concrete_outputs ) ) : <EOL> concrete_output = concrete_outputs [ concrete_output_index ] <EOL> if concrete_output_index == <NUM_LIT:0> : <EOL> bol = '<STR_LIT>' <EOL> else : <EOL> bol = '<STR_LIT:U+0020>' <EOL> makefile . write ( '<STR_LIT>' % ( bol , concrete_output ) ) <EOL> concrete_output_dir = posixpath . dirname ( concrete_output ) <EOL> if ( concrete_output_dir and <EOL> concrete_output_dir not in concrete_output_dirs ) : <EOL> concrete_output_dirs . append ( concrete_output_dir ) <EOL> makefile . write ( '<STR_LIT>' ) <EOL> prerequisites = [ rule_source ] <EOL> prerequisites . extend ( rule . get ( '<STR_LIT>' , [ ] ) ) <EOL> for prerequisite_index in xrange ( <NUM_LIT:0> , len ( prerequisites ) ) : <EOL> prerequisite = prerequisites [ prerequisite_index ] <EOL> if prerequisite_index == len ( prerequisites ) - <NUM_LIT:1> : <EOL> eol = '<STR_LIT>' <EOL> else : <EOL> eol = '<STR_LIT>' <EOL> makefile . write ( '<STR_LIT>' % ( prerequisite , eol ) ) <EOL> if len ( concrete_output_dirs ) > <NUM_LIT:0> : <EOL> makefile . write ( '<STR_LIT>' % <EOL> '<STR_LIT>' . join ( concrete_output_dirs ) ) <EOL> if message : <EOL> makefile . write ( '<STR_LIT>' % message ) <EOL> makefile . write ( '<STR_LIT>' % action ) <EOL> makefile . close ( ) <EOL> script = """<STR_LIT>""" % makefile_name <EOL> ssbp = gyp . xcodeproj_file . PBXShellScriptBuildPhase ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' + rule [ '<STR_LIT>' ] + '<STR_LIT:">' , <EOL> '<STR_LIT>' : script , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } ) <EOL> if support_xct : <EOL> support_xct . AppendProperty ( '<STR_LIT>' , ssbp ) <EOL> else : <EOL> xct . _properties [ '<STR_LIT>' ] . insert ( prebuild_index , ssbp ) <EOL> prebuild_index = prebuild_index + <NUM_LIT:1> <EOL> groups = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if skip_excluded_files : <EOL> groups = [ x for x in groups if not x . endswith ( '<STR_LIT>' ) ] <EOL> for group in groups : <EOL> for item in rule . get ( group , [ ] ) : <EOL> pbxp . AddOrGetFileInRootGroup ( item ) <EOL> for source in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> ( source_root , source_extension ) = posixpath . splitext ( source ) <EOL> if source_extension [ <NUM_LIT:1> : ] not in rules_by_ext : <EOL> AddSourceToTarget ( source , type , pbxp , xct ) <EOL> else : <EOL> pbxp . AddOrGetFileInRootGroup ( source ) <EOL> if is_bundle : <EOL> for resource in tgt_mac_bundle_resources : <EOL> ( resource_root , resource_extension ) = posixpath . splitext ( resource ) <EOL> if resource_extension [ <NUM_LIT:1> : ] not in rules_by_ext : <EOL> AddResourceToTarget ( resource , pbxp , xct ) <EOL> else : <EOL> pbxp . AddOrGetFileInRootGroup ( resource ) <EOL> for header in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> AddHeaderToTarget ( header , pbxp , xct , False ) <EOL> if is_bundle or type == '<STR_LIT>' : <EOL> for header in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> AddHeaderToTarget ( header , pbxp , xct , True ) <EOL> pbxcp_dict = { } <EOL> for copy_group in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> dest = copy_group [ '<STR_LIT>' ] <EOL> if dest [ <NUM_LIT:0> ] not in ( '<STR_LIT:/>' , '<STR_LIT:$>' ) : <EOL> dest = '<STR_LIT>' + dest <EOL> code_sign = int ( copy_group . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> settings = ( None , '<STR_LIT>' ) [ code_sign ] ; <EOL> pbxcp = pbxcp_dict . get ( dest , None ) <EOL> if pbxcp is None : <EOL> pbxcp = gyp . xcodeproj_file . PBXCopyFilesBuildPhase ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' + copy_group [ '<STR_LIT>' ] <EOL> } , <EOL> parent = xct ) <EOL> pbxcp . SetDestination ( dest ) <EOL> xct . _properties [ '<STR_LIT>' ] . insert ( prebuild_index , pbxcp ) <EOL> pbxcp_dict [ dest ] = pbxcp <EOL> for file in copy_group [ '<STR_LIT>' ] : <EOL> pbxcp . AddFile ( file , settings ) <EOL> if not skip_excluded_files : <EOL> for key in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> excluded_key = key + '<STR_LIT>' <EOL> for item in spec . get ( excluded_key , [ ] ) : <EOL> pbxp . AddOrGetFileInRootGroup ( item ) <EOL> groups = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if skip_excluded_files : <EOL> groups = [ x for x in groups if not x . endswith ( '<STR_LIT>' ) ] <EOL> for action in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> for group in groups : <EOL> for item in action . get ( group , [ ] ) : <EOL> if not item . startswith ( '<STR_LIT>' ) : <EOL> pbxp . AddOrGetFileInRootGroup ( item ) <EOL> for postbuild in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> action_string_sh = gyp . common . EncodePOSIXShellList ( postbuild [ '<STR_LIT:action>' ] ) <EOL> script = '<STR_LIT>' + action_string_sh + '<STR_LIT>' <EOL> ssbp = gyp . xcodeproj_file . PBXShellScriptBuildPhase ( { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : '<STR_LIT>' + postbuild [ '<STR_LIT>' ] + '<STR_LIT:">' , <EOL> '<STR_LIT>' : script , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } ) <EOL> xct . AppendProperty ( '<STR_LIT>' , ssbp ) <EOL> if '<STR_LIT>' in spec : <EOL> for dependency in spec [ '<STR_LIT>' ] : <EOL> xct . AddDependency ( xcode_targets [ dependency ] ) <EOL> if support_xct : <EOL> support_xct . AddDependency ( xcode_targets [ dependency ] ) <EOL> if '<STR_LIT>' in spec : <EOL> for library in spec [ '<STR_LIT>' ] : <EOL> xct . FrameworksPhase ( ) . AddFile ( library ) <EOL> library_dir = posixpath . dirname ( library ) <EOL> if library_dir not in xcode_standard_library_dirs and ( <EOL> not xct . HasBuildSetting ( _library_search_paths_var ) or <EOL> library_dir not in xct . GetBuildSetting ( _library_search_paths_var ) ) : <EOL> xct . AppendBuildSetting ( _library_search_paths_var , library_dir ) <EOL> for configuration_name in configuration_names : <EOL> configuration = spec [ '<STR_LIT>' ] [ configuration_name ] <EOL> xcbc = xct . ConfigurationNamed ( configuration_name ) <EOL> for include_dir in configuration . get ( '<STR_LIT>' , [ ] ) : <EOL> xcbc . AppendBuildSetting ( '<STR_LIT>' , include_dir ) <EOL> for include_dir in configuration . get ( '<STR_LIT>' , [ ] ) : <EOL> xcbc . AppendBuildSetting ( '<STR_LIT>' , include_dir ) <EOL> for library_dir in configuration . get ( '<STR_LIT>' , [ ] ) : <EOL> if library_dir not in xcode_standard_library_dirs and ( <EOL> not xcbc . HasBuildSetting ( _library_search_paths_var ) or <EOL> library_dir not in xcbc . GetBuildSetting ( _library_search_paths_var ) ) : <EOL> xcbc . AppendBuildSetting ( _library_search_paths_var , library_dir ) <EOL> if '<STR_LIT>' in configuration : <EOL> for define in configuration [ '<STR_LIT>' ] : <EOL> set_define = EscapeXcodeDefine ( define ) <EOL> xcbc . AppendBuildSetting ( '<STR_LIT>' , set_define ) <EOL> if '<STR_LIT>' in configuration : <EOL> for xck , xcv in configuration [ '<STR_LIT>' ] . iteritems ( ) : <EOL> xcbc . SetBuildSetting ( xck , xcv ) <EOL> if '<STR_LIT>' in configuration : <EOL> config_ref = pbxp . AddOrGetFileInRootGroup ( <EOL> configuration [ '<STR_LIT>' ] ) <EOL> xcbc . SetBaseConfiguration ( config_ref ) <EOL> build_files = [ ] <EOL> for build_file , build_file_dict in data . iteritems ( ) : <EOL> if build_file . endswith ( '<STR_LIT>' ) : <EOL> build_files . append ( build_file ) <EOL> for build_file in build_files : <EOL> xcode_projects [ build_file ] . Finalize1 ( xcode_targets , serialize_all_tests ) <EOL> for build_file in build_files : <EOL> xcode_projects [ build_file ] . Finalize2 ( xcode_targets , <EOL> xcode_target_to_target_dict ) <EOL> for build_file in build_files : <EOL> xcode_projects [ build_file ] . Write ( ) </s>
