<s> """<STR_LIT>""" <EOL> import errno <EOL> import gyp . generator . ninja <EOL> import os <EOL> import re <EOL> import xml . sax . saxutils <EOL> def _WriteWorkspace ( main_gyp , sources_gyp , params ) : <EOL> """<STR_LIT>""" <EOL> ( build_file_root , build_file_ext ) = os . path . splitext ( main_gyp ) <EOL> workspace_path = build_file_root + '<STR_LIT>' <EOL> options = params [ '<STR_LIT>' ] <EOL> if options . generator_output : <EOL> workspace_path = os . path . join ( options . generator_output , workspace_path ) <EOL> try : <EOL> os . makedirs ( workspace_path ) <EOL> except OSError , e : <EOL> if e . errno != errno . EEXIST : <EOL> raise <EOL> output_string = '<STR_LIT>' + '<STR_LIT>' <EOL> for gyp_name in [ main_gyp , sources_gyp ] : <EOL> name = os . path . splitext ( os . path . basename ( gyp_name ) ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> name = xml . sax . saxutils . quoteattr ( "<STR_LIT>" + name ) <EOL> output_string += '<STR_LIT>' % name <EOL> output_string += '<STR_LIT>' <EOL> workspace_file = os . path . join ( workspace_path , "<STR_LIT>" ) <EOL> try : <EOL> with open ( workspace_file , '<STR_LIT:r>' ) as input_file : <EOL> input_string = input_file . read ( ) <EOL> if input_string == output_string : <EOL> return <EOL> except IOError : <EOL> pass <EOL> with open ( workspace_file , '<STR_LIT:w>' ) as output_file : <EOL> output_file . write ( output_string ) <EOL> def _TargetFromSpec ( old_spec , params ) : <EOL> """<STR_LIT>""" <EOL> ninja_toplevel = None <EOL> jobs = <NUM_LIT:0> <EOL> if params : <EOL> options = params [ '<STR_LIT>' ] <EOL> ninja_toplevel = os . path . join ( options . toplevel_dir , <EOL> gyp . generator . ninja . ComputeOutputDir ( params ) ) <EOL> jobs = params . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> target_name = old_spec . get ( '<STR_LIT>' ) <EOL> product_name = old_spec . get ( '<STR_LIT>' , target_name ) <EOL> product_extension = old_spec . get ( '<STR_LIT>' ) <EOL> ninja_target = { } <EOL> ninja_target [ '<STR_LIT>' ] = target_name <EOL> ninja_target [ '<STR_LIT>' ] = product_name <EOL> if product_extension : <EOL> ninja_target [ '<STR_LIT>' ] = product_extension <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' ) <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' ) <EOL> ninja_target [ '<STR_LIT>' ] = { } <EOL> new_xcode_settings = { } <EOL> if ninja_toplevel : <EOL> new_xcode_settings [ '<STR_LIT>' ] = "<STR_LIT>" % ninja_toplevel <EOL> if '<STR_LIT>' in old_spec : <EOL> for config in old_spec [ '<STR_LIT>' ] . keys ( ) : <EOL> old_xcode_settings = old_spec [ '<STR_LIT>' ] [ config ] . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' in old_xcode_settings : <EOL> new_xcode_settings [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> new_xcode_settings [ '<STR_LIT>' ] = old_xcode_settings [ '<STR_LIT>' ] <EOL> ninja_target [ '<STR_LIT>' ] [ config ] = { } <EOL> ninja_target [ '<STR_LIT>' ] [ config ] [ '<STR_LIT>' ] = new_xcode_settings <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> ninja_target [ '<STR_LIT>' ] = old_spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> ninja_target [ '<STR_LIT:type>' ] = old_spec [ '<STR_LIT:type>' ] <EOL> if ninja_toplevel : <EOL> ninja_target [ '<STR_LIT>' ] = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' % target_name , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT:action>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % os . environ [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> new_xcode_settings [ '<STR_LIT>' ] , <EOL> target_name , <EOL> ] , <EOL> '<STR_LIT:message>' : '<STR_LIT>' % target_name , <EOL> } , <EOL> ] <EOL> if jobs > <NUM_LIT:0> : <EOL> ninja_target [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:action>' ] . extend ( ( '<STR_LIT>' , jobs ) ) <EOL> return ninja_target <EOL> def IsValidTargetForWrapper ( target_extras , executable_target_pattern , spec ) : <EOL> """<STR_LIT>""" <EOL> target_name = spec . get ( '<STR_LIT>' ) <EOL> if target_extras is not None and re . search ( target_extras , target_name ) : <EOL> return True <EOL> if spec . get ( '<STR_LIT:type>' , '<STR_LIT>' ) == '<STR_LIT>' and spec . get ( '<STR_LIT>' , '<STR_LIT>' ) != '<STR_LIT>' : <EOL> if executable_target_pattern is not None : <EOL> if not re . search ( executable_target_pattern , target_name ) : <EOL> return False <EOL> return True <EOL> return False <EOL> def CreateWrapper ( target_list , target_dicts , data , params ) : <EOL> """<STR_LIT>""" <EOL> orig_gyp = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> for gyp_name , gyp_dict in data . items ( ) : <EOL> if gyp_name == orig_gyp : <EOL> depth = gyp_dict [ '<STR_LIT>' ] <EOL> generator_flags = params . get ( '<STR_LIT>' , { } ) <EOL> main_gyp = generator_flags . get ( '<STR_LIT>' , None ) <EOL> if main_gyp is None : <EOL> ( build_file_root , build_file_ext ) = os . path . splitext ( orig_gyp ) <EOL> main_gyp = build_file_root + "<STR_LIT>" + build_file_ext <EOL> new_target_list = [ ] <EOL> new_target_dicts = { } <EOL> new_data = { } <EOL> new_data [ main_gyp ] = { } <EOL> new_data [ main_gyp ] [ '<STR_LIT>' ] = [ ] <EOL> new_data [ main_gyp ] [ '<STR_LIT>' ] = [ ] <EOL> new_data [ main_gyp ] [ '<STR_LIT>' ] = data [ orig_gyp ] . get ( '<STR_LIT>' , { } ) <EOL> executable_target_pattern = generator_flags . get ( '<STR_LIT>' , None ) <EOL> target_extras = generator_flags . get ( '<STR_LIT>' , None ) <EOL> for old_qualified_target in target_list : <EOL> spec = target_dicts [ old_qualified_target ] <EOL> if IsValidTargetForWrapper ( target_extras , executable_target_pattern , spec ) : <EOL> target_name = spec . get ( '<STR_LIT>' ) <EOL> new_target_name = '<STR_LIT>' % ( main_gyp , target_name ) <EOL> new_target_list . append ( new_target_name ) <EOL> new_target_dicts [ new_target_name ] = _TargetFromSpec ( spec , params ) <EOL> for old_target in data [ old_qualified_target . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] ] [ '<STR_LIT>' ] : <EOL> if old_target [ '<STR_LIT>' ] == target_name : <EOL> new_data_target = { } <EOL> new_data_target [ '<STR_LIT>' ] = old_target [ '<STR_LIT>' ] <EOL> new_data_target [ '<STR_LIT>' ] = old_target [ '<STR_LIT>' ] <EOL> new_data [ main_gyp ] [ '<STR_LIT>' ] . append ( new_data_target ) <EOL> sources_target_name = '<STR_LIT>' <EOL> sources_target = _TargetFromSpec ( <EOL> { '<STR_LIT>' : sources_target_name , <EOL> '<STR_LIT>' : '<STR_LIT:target>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , None ) <EOL> sources_target [ '<STR_LIT>' ] = { '<STR_LIT>' : { '<STR_LIT>' : [ depth ] } } <EOL> sources = [ ] <EOL> for target , target_dict in target_dicts . items ( ) : <EOL> base = os . path . dirname ( target ) <EOL> files = target_dict . get ( '<STR_LIT>' , [ ] ) + target_dict . get ( '<STR_LIT>' , [ ] ) <EOL> files = [ file for file in files if not file . startswith ( '<STR_LIT:$>' ) ] <EOL> relative_path = os . path . dirname ( main_gyp ) <EOL> sources += [ os . path . relpath ( os . path . join ( base , file ) , relative_path ) <EOL> for file in files ] <EOL> sources_target [ '<STR_LIT>' ] = sorted ( set ( sources ) ) <EOL> sources_gyp = os . path . join ( os . path . dirname ( main_gyp ) , sources_target_name + "<STR_LIT>" ) <EOL> fully_qualified_target_name = '<STR_LIT>' % ( sources_gyp , sources_target_name ) <EOL> new_target_list . append ( fully_qualified_target_name ) <EOL> new_target_dicts [ fully_qualified_target_name ] = sources_target <EOL> new_data_target = { } <EOL> new_data_target [ '<STR_LIT>' ] = sources_target [ '<STR_LIT>' ] <EOL> new_data_target [ '<STR_LIT>' ] = depth <EOL> new_data_target [ '<STR_LIT>' ] = "<STR_LIT:target>" <EOL> new_data [ sources_gyp ] = { } <EOL> new_data [ sources_gyp ] [ '<STR_LIT>' ] = [ ] <EOL> new_data [ sources_gyp ] [ '<STR_LIT>' ] = [ ] <EOL> new_data [ sources_gyp ] [ '<STR_LIT>' ] = data [ orig_gyp ] . get ( '<STR_LIT>' , { } ) <EOL> new_data [ sources_gyp ] [ '<STR_LIT>' ] . append ( new_data_target ) <EOL> _WriteWorkspace ( main_gyp , sources_gyp , params ) <EOL> return ( new_target_list , new_target_dicts , new_data ) </s>
