<s> import copy <EOL> import ntpath <EOL> import os <EOL> import posixpath <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> import gyp . common <EOL> import gyp . easy_xml as easy_xml <EOL> import gyp . generator . ninja as ninja_generator <EOL> import gyp . MSVSNew as MSVSNew <EOL> import gyp . MSVSProject as MSVSProject <EOL> import gyp . MSVSSettings as MSVSSettings <EOL> import gyp . MSVSToolFile as MSVSToolFile <EOL> import gyp . MSVSUserFile as MSVSUserFile <EOL> import gyp . MSVSUtil as MSVSUtil <EOL> import gyp . MSVSVersion as MSVSVersion <EOL> from gyp . common import GypError <EOL> from gyp . common import OrderedSet <EOL> def _import_OrderedDict ( ) : <EOL> import collections <EOL> try : <EOL> return collections . OrderedDict <EOL> except AttributeError : <EOL> import gyp . ordered_dict <EOL> return gyp . ordered_dict . OrderedDict <EOL> OrderedDict = _import_OrderedDict ( ) <EOL> VALID_MSVS_GUID_CHARS = re . compile ( r'<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>' , <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> } <EOL> generator_additional_path_sections = [ <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> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> precomp_keys = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> cached_username = None <EOL> cached_domain = None <EOL> def _GetDomainAndUserName ( ) : <EOL> if sys . platform not in ( '<STR_LIT:win32>' , '<STR_LIT>' ) : <EOL> return ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> global cached_username <EOL> global cached_domain <EOL> if not cached_domain or not cached_username : <EOL> domain = os . environ . get ( '<STR_LIT>' ) <EOL> username = os . environ . get ( '<STR_LIT>' ) <EOL> if not domain or not username : <EOL> call = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE ) <EOL> config = call . communicate ( ) [ <NUM_LIT:0> ] <EOL> username_re = re . compile ( r'<STR_LIT>' , re . MULTILINE ) <EOL> username_match = username_re . search ( config ) <EOL> if username_match : <EOL> username = username_match . group ( <NUM_LIT:1> ) <EOL> domain_re = re . compile ( r'<STR_LIT>' , re . MULTILINE ) <EOL> domain_match = domain_re . search ( config ) <EOL> if domain_match : <EOL> domain = domain_match . group ( <NUM_LIT:1> ) <EOL> cached_domain = domain <EOL> cached_username = username <EOL> return ( cached_domain , cached_username ) <EOL> fixpath_prefix = None <EOL> def _NormalizedSource ( source ) : <EOL> """<STR_LIT>""" <EOL> normalized = os . path . normpath ( source ) <EOL> if source . count ( '<STR_LIT:$>' ) == normalized . count ( '<STR_LIT:$>' ) : <EOL> source = normalized <EOL> return source <EOL> def _FixPath ( path ) : <EOL> """<STR_LIT>""" <EOL> if fixpath_prefix and path and not os . path . isabs ( path ) and not path [ <NUM_LIT:0> ] == '<STR_LIT:$>' : <EOL> path = os . path . join ( fixpath_prefix , path ) <EOL> path = path . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) <EOL> path = _NormalizedSource ( path ) <EOL> if path and path [ - <NUM_LIT:1> ] == '<STR_LIT:\\>' : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> return path <EOL> def _FixPaths ( paths ) : <EOL> """<STR_LIT>""" <EOL> return [ _FixPath ( i ) for i in paths ] <EOL> def _ConvertSourcesToFilterHierarchy ( sources , prefix = None , excluded = None , <EOL> list_excluded = True , msvs_version = None ) : <EOL> """<STR_LIT>""" <EOL> if not prefix : prefix = [ ] <EOL> result = [ ] <EOL> excluded_result = [ ] <EOL> folders = OrderedDict ( ) <EOL> for s in sources : <EOL> if len ( s ) == <NUM_LIT:1> : <EOL> filename = _NormalizedSource ( '<STR_LIT:\\>' . join ( prefix + s ) ) <EOL> if filename in excluded : <EOL> excluded_result . append ( filename ) <EOL> else : <EOL> result . append ( filename ) <EOL> elif msvs_version and not msvs_version . UsesVcxproj ( ) : <EOL> if not folders . get ( s [ <NUM_LIT:0> ] ) : <EOL> folders [ s [ <NUM_LIT:0> ] ] = [ ] <EOL> folders [ s [ <NUM_LIT:0> ] ] . append ( s [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> contents = _ConvertSourcesToFilterHierarchy ( [ s [ <NUM_LIT:1> : ] ] , prefix + [ s [ <NUM_LIT:0> ] ] , <EOL> excluded = excluded , <EOL> list_excluded = list_excluded , <EOL> msvs_version = msvs_version ) <EOL> contents = MSVSProject . Filter ( s [ <NUM_LIT:0> ] , contents = contents ) <EOL> result . append ( contents ) <EOL> if excluded_result and list_excluded : <EOL> excluded_folder = MSVSProject . Filter ( '<STR_LIT>' , <EOL> contents = excluded_result ) <EOL> result . append ( excluded_folder ) <EOL> if msvs_version and msvs_version . UsesVcxproj ( ) : <EOL> return result <EOL> for f in folders : <EOL> contents = _ConvertSourcesToFilterHierarchy ( folders [ f ] , prefix = prefix + [ f ] , <EOL> excluded = excluded , <EOL> list_excluded = list_excluded , <EOL> msvs_version = msvs_version ) <EOL> contents = MSVSProject . Filter ( f , contents = contents ) <EOL> result . append ( contents ) <EOL> return result <EOL> def _ToolAppend ( tools , tool_name , setting , value , only_if_unset = False ) : <EOL> if not value : return <EOL> _ToolSetOrAppend ( tools , tool_name , setting , value , only_if_unset ) <EOL> def _ToolSetOrAppend ( tools , tool_name , setting , value , only_if_unset = False ) : <EOL> if '<STR_LIT>' in setting or '<STR_LIT>' in setting : <EOL> if type ( value ) == str : <EOL> value = value . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) <EOL> else : <EOL> value = [ i . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) for i in value ] <EOL> if not tools . get ( tool_name ) : <EOL> tools [ tool_name ] = dict ( ) <EOL> tool = tools [ tool_name ] <EOL> if tool . get ( setting ) : <EOL> if only_if_unset : return <EOL> if type ( tool [ setting ] ) == list and type ( value ) == list : <EOL> tool [ setting ] += value <EOL> else : <EOL> raise TypeError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> value , setting , tool_name , str ( tool [ setting ] ) ) ) <EOL> else : <EOL> tool [ setting ] = value <EOL> def _ConfigPlatform ( config_data ) : <EOL> return config_data . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _ConfigBaseName ( config_name , platform_name ) : <EOL> if config_name . endswith ( '<STR_LIT:_>' + platform_name ) : <EOL> return config_name [ <NUM_LIT:0> : - len ( platform_name ) - <NUM_LIT:1> ] <EOL> else : <EOL> return config_name <EOL> def _ConfigFullName ( config_name , config_data ) : <EOL> platform_name = _ConfigPlatform ( config_data ) <EOL> return '<STR_LIT>' % ( _ConfigBaseName ( config_name , platform_name ) , platform_name ) <EOL> def _BuildCommandLineForRuleRaw ( spec , cmd , cygwin_shell , has_input_path , <EOL> quote_cmd , do_setup_env ) : <EOL> if [ x for x in cmd if '<STR_LIT>' in x ] : <EOL> input_dir_preamble = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> input_dir_preamble = '<STR_LIT>' <EOL> if cygwin_shell : <EOL> cygwin_dir = _FixPath ( spec . get ( '<STR_LIT>' , [ '<STR_LIT:.>' ] ) [ <NUM_LIT:0> ] ) <EOL> direct_cmd = cmd <EOL> direct_cmd = [ i . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) for i in direct_cmd ] <EOL> direct_cmd = [ i . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) for i in direct_cmd ] <EOL> direct_cmd = [ i . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) for i in direct_cmd ] <EOL> if has_input_path : <EOL> direct_cmd = [ i . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> for i in direct_cmd ] <EOL> direct_cmd = [ '<STR_LIT>' % i . replace ( '<STR_LIT:">' , '<STR_LIT>' ) for i in direct_cmd ] <EOL> direct_cmd = '<STR_LIT:U+0020>' . join ( direct_cmd ) <EOL> cmd = '<STR_LIT>' <EOL> if do_setup_env : <EOL> cmd += '<STR_LIT>' <EOL> cmd += '<STR_LIT>' <EOL> if direct_cmd . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' <EOL> if direct_cmd . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' <EOL> if direct_cmd . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' <EOL> if has_input_path and direct_cmd . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> cmd += '<STR_LIT>' <EOL> cmd += '<STR_LIT>' <EOL> cmd = cmd % { '<STR_LIT>' : cygwin_dir , <EOL> '<STR_LIT>' : direct_cmd } <EOL> return input_dir_preamble + cmd <EOL> else : <EOL> if cmd [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> command = [ '<STR_LIT:type>' ] <EOL> else : <EOL> command = [ cmd [ <NUM_LIT:0> ] . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) ] <EOL> command . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> arguments = [ i if ( i [ : <NUM_LIT:1> ] in "<STR_LIT>" ) else _FixPath ( i ) for i in cmd [ <NUM_LIT:1> : ] ] <EOL> arguments = [ i . replace ( '<STR_LIT>' , '<STR_LIT>' ) for i in arguments ] <EOL> arguments = [ MSVSSettings . FixVCMacroSlashes ( i ) for i in arguments ] <EOL> if quote_cmd : <EOL> arguments = [ '<STR_LIT>' % i for i in arguments ] <EOL> return input_dir_preamble + '<STR_LIT:U+0020>' . join ( command + arguments ) <EOL> def _BuildCommandLineForRule ( spec , rule , has_input_path , do_setup_env ) : <EOL> mcs = rule . get ( '<STR_LIT>' ) <EOL> if mcs is None : <EOL> mcs = int ( spec . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> elif isinstance ( mcs , str ) : <EOL> mcs = int ( mcs ) <EOL> quote_cmd = int ( rule . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> return _BuildCommandLineForRuleRaw ( spec , rule [ '<STR_LIT:action>' ] , mcs , has_input_path , <EOL> quote_cmd , do_setup_env = do_setup_env ) <EOL> def _AddActionStep ( actions_dict , inputs , outputs , description , command ) : <EOL> """<STR_LIT>""" <EOL> assert inputs <EOL> action = { <EOL> '<STR_LIT>' : inputs , <EOL> '<STR_LIT>' : outputs , <EOL> '<STR_LIT:description>' : description , <EOL> '<STR_LIT>' : command , <EOL> } <EOL> chosen_input = inputs [ <NUM_LIT:0> ] <EOL> if chosen_input not in actions_dict : <EOL> actions_dict [ chosen_input ] = [ ] <EOL> actions_dict [ chosen_input ] . append ( action ) <EOL> def _AddCustomBuildToolForMSVS ( p , spec , primary_input , <EOL> inputs , outputs , description , cmd ) : <EOL> """<STR_LIT>""" <EOL> inputs = _FixPaths ( inputs ) <EOL> outputs = _FixPaths ( outputs ) <EOL> tool = MSVSProject . Tool ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : description , <EOL> '<STR_LIT>' : '<STR_LIT:;>' . join ( inputs ) , <EOL> '<STR_LIT>' : '<STR_LIT:;>' . join ( outputs ) , <EOL> '<STR_LIT>' : cmd , <EOL> } ) <EOL> for config_name , c_data in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> p . AddFileConfig ( _FixPath ( primary_input ) , <EOL> _ConfigFullName ( config_name , c_data ) , tools = [ tool ] ) <EOL> def _AddAccumulatedActionsToMSVS ( p , spec , actions_dict ) : <EOL> """<STR_LIT>""" <EOL> for primary_input in actions_dict : <EOL> inputs = OrderedSet ( ) <EOL> outputs = OrderedSet ( ) <EOL> descriptions = [ ] <EOL> commands = [ ] <EOL> for action in actions_dict [ primary_input ] : <EOL> inputs . update ( OrderedSet ( action [ '<STR_LIT>' ] ) ) <EOL> outputs . update ( OrderedSet ( action [ '<STR_LIT>' ] ) ) <EOL> descriptions . append ( action [ '<STR_LIT:description>' ] ) <EOL> commands . append ( action [ '<STR_LIT>' ] ) <EOL> description = '<STR_LIT>' . join ( descriptions ) <EOL> command = '<STR_LIT:\r\n>' . join ( commands ) <EOL> _AddCustomBuildToolForMSVS ( p , spec , <EOL> primary_input = primary_input , <EOL> inputs = inputs , <EOL> outputs = outputs , <EOL> description = description , <EOL> cmd = command ) <EOL> def _RuleExpandPath ( path , input_file ) : <EOL> """<STR_LIT>""" <EOL> path = path . replace ( '<STR_LIT>' , <EOL> os . path . splitext ( os . path . split ( input_file ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] ) <EOL> path = path . replace ( '<STR_LIT>' , os . path . dirname ( input_file ) ) <EOL> path = path . replace ( '<STR_LIT>' , <EOL> os . path . splitext ( os . path . split ( input_file ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:1> ] ) <EOL> path = path . replace ( '<STR_LIT>' , os . path . split ( input_file ) [ <NUM_LIT:1> ] ) <EOL> path = path . replace ( '<STR_LIT>' , input_file ) <EOL> return path <EOL> def _FindRuleTriggerFiles ( rule , sources ) : <EOL> """<STR_LIT>""" <EOL> return rule . get ( '<STR_LIT>' , [ ] ) <EOL> def _RuleInputsAndOutputs ( rule , trigger_file ) : <EOL> """<STR_LIT>""" <EOL> raw_inputs = _FixPaths ( rule . get ( '<STR_LIT>' , [ ] ) ) <EOL> raw_outputs = _FixPaths ( rule . get ( '<STR_LIT>' , [ ] ) ) <EOL> inputs = OrderedSet ( ) <EOL> outputs = OrderedSet ( ) <EOL> inputs . add ( trigger_file ) <EOL> for i in raw_inputs : <EOL> inputs . add ( _RuleExpandPath ( i , trigger_file ) ) <EOL> for o in raw_outputs : <EOL> outputs . add ( _RuleExpandPath ( o , trigger_file ) ) <EOL> return ( inputs , outputs ) <EOL> def _GenerateNativeRulesForMSVS ( p , rules , output_dir , spec , options ) : <EOL> """<STR_LIT>""" <EOL> rules_filename = '<STR_LIT>' % ( spec [ '<STR_LIT>' ] , <EOL> options . suffix ) <EOL> rules_file = MSVSToolFile . Writer ( os . path . join ( output_dir , rules_filename ) , <EOL> spec [ '<STR_LIT>' ] ) <EOL> for r in rules : <EOL> rule_name = r [ '<STR_LIT>' ] <EOL> rule_ext = r [ '<STR_LIT>' ] <EOL> inputs = _FixPaths ( r . get ( '<STR_LIT>' , [ ] ) ) <EOL> outputs = _FixPaths ( r . get ( '<STR_LIT>' , [ ] ) ) <EOL> if '<STR_LIT:action>' not in r and not r . get ( '<STR_LIT>' , [ ] ) : <EOL> continue <EOL> cmd = _BuildCommandLineForRule ( spec , r , has_input_path = True , <EOL> do_setup_env = True ) <EOL> rules_file . AddCustomBuildRule ( name = rule_name , <EOL> description = r . get ( '<STR_LIT:message>' , rule_name ) , <EOL> extensions = [ rule_ext ] , <EOL> additional_dependencies = inputs , <EOL> outputs = outputs , <EOL> cmd = cmd ) <EOL> rules_file . WriteIfChanged ( ) <EOL> p . AddToolFile ( rules_filename ) <EOL> def _Cygwinify ( path ) : <EOL> path = path . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> path = path . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return path <EOL> def _GenerateExternalRules ( rules , output_dir , spec , <EOL> sources , options , actions_to_add ) : <EOL> """<STR_LIT>""" <EOL> filename = '<STR_LIT>' % ( spec [ '<STR_LIT>' ] , options . suffix ) <EOL> mk_file = gyp . common . WriteOnDiff ( os . path . join ( output_dir , filename ) ) <EOL> mk_file . write ( '<STR_LIT>' ) <EOL> mk_file . write ( '<STR_LIT>' ) <EOL> all_inputs = OrderedSet ( ) <EOL> all_outputs = OrderedSet ( ) <EOL> all_output_dirs = OrderedSet ( ) <EOL> first_outputs = [ ] <EOL> for rule in rules : <EOL> trigger_files = _FindRuleTriggerFiles ( rule , sources ) <EOL> for tf in trigger_files : <EOL> inputs , outputs = _RuleInputsAndOutputs ( rule , tf ) <EOL> all_inputs . update ( OrderedSet ( inputs ) ) <EOL> all_outputs . update ( OrderedSet ( outputs ) ) <EOL> first_outputs . append ( list ( outputs ) [ <NUM_LIT:0> ] ) <EOL> output_dirs = [ os . path . split ( i ) [ <NUM_LIT:0> ] for i in outputs ] <EOL> for od in output_dirs : <EOL> all_output_dirs . add ( od ) <EOL> first_outputs_cyg = [ _Cygwinify ( i ) for i in first_outputs ] <EOL> mk_file . write ( '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( first_outputs_cyg ) ) <EOL> for od in all_output_dirs : <EOL> if od : <EOL> mk_file . write ( '<STR_LIT>' % od ) <EOL> mk_file . write ( '<STR_LIT:\n>' ) <EOL> for rule in rules : <EOL> trigger_files = _FindRuleTriggerFiles ( rule , sources ) <EOL> for tf in trigger_files : <EOL> inputs , outputs = _RuleInputsAndOutputs ( rule , tf ) <EOL> inputs = [ _Cygwinify ( i ) for i in inputs ] <EOL> outputs = [ _Cygwinify ( i ) for i in outputs ] <EOL> cmd = [ _RuleExpandPath ( c , tf ) for c in rule [ '<STR_LIT:action>' ] ] <EOL> cmd = [ '<STR_LIT>' % i for i in cmd ] <EOL> cmd = '<STR_LIT:U+0020>' . join ( cmd ) <EOL> mk_file . write ( '<STR_LIT>' % ( '<STR_LIT:U+0020>' . join ( outputs ) , '<STR_LIT:U+0020>' . join ( inputs ) ) ) <EOL> mk_file . write ( '<STR_LIT>' % cmd ) <EOL> mk_file . close ( ) <EOL> sources . add ( filename ) <EOL> cmd = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , filename ] <EOL> cmd = _BuildCommandLineForRuleRaw ( spec , cmd , True , False , True , True ) <EOL> all_inputs = list ( all_inputs ) <EOL> all_inputs . insert ( <NUM_LIT:0> , filename ) <EOL> _AddActionStep ( actions_to_add , <EOL> inputs = _FixPaths ( all_inputs ) , <EOL> outputs = _FixPaths ( all_outputs ) , <EOL> description = '<STR_LIT>' % <EOL> spec [ '<STR_LIT>' ] , <EOL> command = cmd ) <EOL> def _EscapeEnvironmentVariableExpansion ( s ) : <EOL> """<STR_LIT>""" <EOL> s = s . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) <EOL> return s <EOL> quote_replacer_regex = re . compile ( r'<STR_LIT>' ) <EOL> def _EscapeCommandLineArgumentForMSVS ( s ) : <EOL> """<STR_LIT>""" <EOL> def _Replace ( match ) : <EOL> return <NUM_LIT:2> * match . group ( <NUM_LIT:1> ) + '<STR_LIT>' <EOL> s = quote_replacer_regex . sub ( _Replace , s ) <EOL> s = '<STR_LIT:">' + s + '<STR_LIT:">' <EOL> return s <EOL> delimiters_replacer_regex = re . compile ( r'<STR_LIT>' ) <EOL> def _EscapeVCProjCommandLineArgListItem ( s ) : <EOL> """<STR_LIT>""" <EOL> def _Replace ( match ) : <EOL> return <NUM_LIT:2> * match . group ( <NUM_LIT:1> ) + '<STR_LIT:">' + match . group ( <NUM_LIT:2> ) + '<STR_LIT:">' <EOL> segments = s . split ( '<STR_LIT:">' ) <EOL> for i in range ( <NUM_LIT:0> , len ( segments ) , <NUM_LIT:2> ) : <EOL> segments [ i ] = delimiters_replacer_regex . sub ( _Replace , segments [ i ] ) <EOL> s = '<STR_LIT:">' . join ( segments ) <EOL> if len ( segments ) % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> print >> sys . stderr , ( '<STR_LIT>' + <EOL> '<STR_LIT>' + s ) <EOL> return s <EOL> def _EscapeCppDefineForMSVS ( s ) : <EOL> """<STR_LIT>""" <EOL> s = _EscapeEnvironmentVariableExpansion ( s ) <EOL> s = _EscapeCommandLineArgumentForMSVS ( s ) <EOL> s = _EscapeVCProjCommandLineArgListItem ( s ) <EOL> s = s . replace ( '<STR_LIT:#>' , '<STR_LIT>' % ord ( '<STR_LIT:#>' ) ) <EOL> return s <EOL> quote_replacer_regex2 = re . compile ( r'<STR_LIT>' ) <EOL> def _EscapeCommandLineArgumentForMSBuild ( s ) : <EOL> """<STR_LIT>""" <EOL> def _Replace ( match ) : <EOL> return ( len ( match . group ( <NUM_LIT:1> ) ) / <NUM_LIT:2> * <NUM_LIT:4> ) * '<STR_LIT:\\>' + '<STR_LIT>' <EOL> s = quote_replacer_regex2 . sub ( _Replace , s ) <EOL> return s <EOL> def _EscapeMSBuildSpecialCharacters ( s ) : <EOL> escape_dictionary = { <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> } <EOL> result = '<STR_LIT>' . join ( [ escape_dictionary . get ( c , c ) for c in s ] ) <EOL> return result <EOL> def _EscapeCppDefineForMSBuild ( s ) : <EOL> """<STR_LIT>""" <EOL> s = _EscapeEnvironmentVariableExpansion ( s ) <EOL> s = _EscapeCommandLineArgumentForMSBuild ( s ) <EOL> s = _EscapeMSBuildSpecialCharacters ( s ) <EOL> s = s . replace ( '<STR_LIT:#>' , '<STR_LIT>' % ord ( '<STR_LIT:#>' ) ) <EOL> return s <EOL> def _GenerateRulesForMSVS ( p , output_dir , options , spec , <EOL> sources , excluded_sources , <EOL> actions_to_add ) : <EOL> """<STR_LIT>""" <EOL> rules = spec . get ( '<STR_LIT>' , [ ] ) <EOL> rules_native = [ r for r in rules if not int ( r . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) ] <EOL> rules_external = [ r for r in rules if int ( r . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) ] <EOL> if rules_native : <EOL> _GenerateNativeRulesForMSVS ( p , rules_native , output_dir , spec , options ) <EOL> if rules_external : <EOL> _GenerateExternalRules ( rules_external , output_dir , spec , <EOL> sources , options , actions_to_add ) <EOL> _AdjustSourcesForRules ( rules , sources , excluded_sources , False ) <EOL> def _AdjustSourcesForRules ( rules , sources , excluded_sources , is_msbuild ) : <EOL> for rule in rules : <EOL> trigger_files = _FindRuleTriggerFiles ( rule , sources ) <EOL> for trigger_file in trigger_files : <EOL> excluded_sources . discard ( _FixPath ( trigger_file ) ) <EOL> if int ( rule . get ( '<STR_LIT>' , False ) ) : <EOL> inputs , outputs = _RuleInputsAndOutputs ( rule , trigger_file ) <EOL> inputs = OrderedSet ( _FixPaths ( inputs ) ) <EOL> outputs = OrderedSet ( _FixPaths ( outputs ) ) <EOL> inputs . remove ( _FixPath ( trigger_file ) ) <EOL> sources . update ( inputs ) <EOL> if not is_msbuild : <EOL> excluded_sources . update ( inputs ) <EOL> sources . update ( outputs ) <EOL> def _FilterActionsFromExcluded ( excluded_sources , actions_to_add ) : <EOL> """<STR_LIT>""" <EOL> must_keep = OrderedSet ( _FixPaths ( actions_to_add . keys ( ) ) ) <EOL> return [ s for s in excluded_sources if s not in must_keep ] <EOL> def _GetDefaultConfiguration ( spec ) : <EOL> return spec [ '<STR_LIT>' ] [ spec [ '<STR_LIT>' ] ] <EOL> def _GetGuidOfProject ( proj_path , spec ) : <EOL> """<STR_LIT>""" <EOL> default_config = _GetDefaultConfiguration ( spec ) <EOL> guid = default_config . get ( '<STR_LIT>' ) <EOL> if guid : <EOL> if VALID_MSVS_GUID_CHARS . match ( guid ) is None : <EOL> raise ValueError ( '<STR_LIT>' % <EOL> ( guid , VALID_MSVS_GUID_CHARS . pattern ) ) <EOL> guid = '<STR_LIT>' % guid <EOL> guid = guid or MSVSNew . MakeGuid ( proj_path ) <EOL> return guid <EOL> def _GetMsbuildToolsetOfProject ( proj_path , spec , version ) : <EOL> """<STR_LIT>""" <EOL> default_config = _GetDefaultConfiguration ( spec ) <EOL> toolset = default_config . get ( '<STR_LIT>' ) <EOL> if not toolset and version . DefaultToolset ( ) : <EOL> toolset = version . DefaultToolset ( ) <EOL> return toolset <EOL> def _GenerateProject ( project , options , version , generator_flags ) : <EOL> """<STR_LIT>""" <EOL> default_config = _GetDefaultConfiguration ( project . spec ) <EOL> if default_config . get ( '<STR_LIT>' ) : <EOL> return [ ] <EOL> if version . UsesVcxproj ( ) : <EOL> return _GenerateMSBuildProject ( project , options , version , generator_flags ) <EOL> else : <EOL> return _GenerateMSVSProject ( project , options , version , generator_flags ) <EOL> def _ValidateSourcesForMSVSProject ( spec , version ) : <EOL> """<STR_LIT>""" <EOL> assert not version . UsesVcxproj ( ) <EOL> if spec . get ( '<STR_LIT:type>' , None ) not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> sources = spec . get ( '<STR_LIT>' , [ ] ) <EOL> basenames = { } <EOL> for source in sources : <EOL> name , ext = os . path . splitext ( source ) <EOL> is_compiled_file = ext in [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if not is_compiled_file : <EOL> continue <EOL> basename = os . path . basename ( name ) <EOL> basenames . setdefault ( basename , [ ] ) . append ( source ) <EOL> error = '<STR_LIT>' <EOL> for basename , files in basenames . iteritems ( ) : <EOL> if len ( files ) > <NUM_LIT:1> : <EOL> error += '<STR_LIT>' % ( basename , '<STR_LIT:U+0020>' . join ( files ) ) <EOL> if error : <EOL> print ( '<STR_LIT>' % <EOL> spec [ '<STR_LIT>' ] + error + '<STR_LIT>' ) <EOL> raise GypError ( '<STR_LIT>' ) <EOL> def _GenerateMSVSProject ( project , options , version , generator_flags ) : <EOL> """<STR_LIT>""" <EOL> spec = project . spec <EOL> gyp . common . EnsureDirExists ( project . path ) <EOL> platforms = _GetUniquePlatforms ( spec ) <EOL> p = MSVSProject . Writer ( project . path , version , spec [ '<STR_LIT>' ] , <EOL> project . guid , platforms ) <EOL> project_dir = os . path . split ( project . path ) [ <NUM_LIT:0> ] <EOL> gyp_path = _NormalizedSource ( project . build_file ) <EOL> relative_path_of_gyp_file = gyp . common . RelativePath ( gyp_path , project_dir ) <EOL> config_type = _GetMSVSConfigurationType ( spec , project . build_file ) <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> _AddConfigurationToMSVSProject ( p , spec , config_type , config_name , config ) <EOL> _ValidateSourcesForMSVSProject ( spec , version ) <EOL> gyp_file = os . path . split ( project . build_file ) [ <NUM_LIT:1> ] <EOL> sources , excluded_sources = _PrepareListOfSources ( spec , generator_flags , <EOL> gyp_file ) <EOL> actions_to_add = { } <EOL> _GenerateRulesForMSVS ( p , project_dir , options , spec , <EOL> sources , excluded_sources , <EOL> actions_to_add ) <EOL> list_excluded = generator_flags . get ( '<STR_LIT>' , True ) <EOL> sources , excluded_sources , excluded_idl = ( <EOL> _AdjustSourcesAndConvertToFilterHierarchy ( spec , options , project_dir , <EOL> sources , excluded_sources , <EOL> list_excluded , version ) ) <EOL> missing_sources = _VerifySourcesExist ( sources , project_dir ) <EOL> p . AddFiles ( sources ) <EOL> _AddToolFilesToMSVS ( p , spec ) <EOL> _HandlePreCompiledHeaders ( p , sources , spec ) <EOL> _AddActions ( actions_to_add , spec , relative_path_of_gyp_file ) <EOL> _AddCopies ( actions_to_add , spec ) <EOL> _WriteMSVSUserFile ( project . path , version , spec ) <EOL> excluded_sources = _FilterActionsFromExcluded ( <EOL> excluded_sources , actions_to_add ) <EOL> _ExcludeFilesFromBeingBuilt ( p , spec , excluded_sources , excluded_idl , <EOL> list_excluded ) <EOL> _AddAccumulatedActionsToMSVS ( p , spec , actions_to_add ) <EOL> p . WriteIfChanged ( ) <EOL> return missing_sources <EOL> def _GetUniquePlatforms ( spec ) : <EOL> """<STR_LIT>""" <EOL> platforms = OrderedSet ( ) <EOL> for configuration in spec [ '<STR_LIT>' ] : <EOL> platforms . add ( _ConfigPlatform ( spec [ '<STR_LIT>' ] [ configuration ] ) ) <EOL> platforms = list ( platforms ) <EOL> return platforms <EOL> def _CreateMSVSUserFile ( proj_path , version , spec ) : <EOL> """<STR_LIT>""" <EOL> ( domain , username ) = _GetDomainAndUserName ( ) <EOL> vcuser_filename = '<STR_LIT:.>' . join ( [ proj_path , domain , username , '<STR_LIT:user>' ] ) <EOL> user_file = MSVSUserFile . Writer ( vcuser_filename , version , <EOL> spec [ '<STR_LIT>' ] ) <EOL> return user_file <EOL> def _GetMSVSConfigurationType ( spec , build_file ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> config_type = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT:none>' : '<STR_LIT>' , <EOL> } [ spec [ '<STR_LIT:type>' ] ] <EOL> except KeyError : <EOL> if spec . get ( '<STR_LIT:type>' ) : <EOL> raise GypError ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( spec [ '<STR_LIT:type>' ] , spec [ '<STR_LIT>' ] , build_file ) ) <EOL> else : <EOL> raise GypError ( '<STR_LIT>' % <EOL> ( spec [ '<STR_LIT>' ] , build_file ) ) <EOL> return config_type <EOL> def _AddConfigurationToMSVSProject ( p , spec , config_type , config_name , config ) : <EOL> """<STR_LIT>""" <EOL> include_dirs , midl_include_dirs , resource_include_dirs = _GetIncludeDirs ( config ) <EOL> libraries = _GetLibraries ( spec ) <EOL> library_dirs = _GetLibraryDirs ( config ) <EOL> out_file , vc_tool , _ = _GetOutputFilePathAndTool ( spec , msbuild = False ) <EOL> defines = _GetDefines ( config ) <EOL> defines = [ _EscapeCppDefineForMSVS ( d ) for d in defines ] <EOL> disabled_warnings = _GetDisabledWarnings ( config ) <EOL> prebuild = config . get ( '<STR_LIT>' ) <EOL> postbuild = config . get ( '<STR_LIT>' ) <EOL> def_file = _GetModuleDefinition ( spec ) <EOL> precompiled_header = config . get ( '<STR_LIT>' ) <EOL> tools = dict ( ) <EOL> msvs_settings = config . get ( '<STR_LIT>' , { } ) <EOL> MSVSSettings . ValidateMSVSSettings ( msvs_settings ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> for tool in msvs_settings : <EOL> settings = config [ '<STR_LIT>' ] [ tool ] <EOL> for setting in settings : <EOL> _ToolAppend ( tools , tool , setting , settings [ setting ] ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , include_dirs ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , midl_include_dirs ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , resource_include_dirs ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , libraries ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , <EOL> library_dirs ) <EOL> if out_file : <EOL> _ToolAppend ( tools , vc_tool , '<STR_LIT>' , out_file , only_if_unset = True ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , defines ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , <EOL> defines ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , only_if_unset = True ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , disabled_warnings ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , prebuild ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , postbuild ) <EOL> if precompiled_header : <EOL> precompiled_header = os . path . split ( precompiled_header ) [ <NUM_LIT:1> ] <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:2>' ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , precompiled_header ) <EOL> _ToolAppend ( tools , '<STR_LIT>' , <EOL> '<STR_LIT>' , precompiled_header ) <EOL> if spec [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> if def_file : <EOL> _ToolAppend ( tools , '<STR_LIT>' , '<STR_LIT>' , def_file ) <EOL> _AddConfigurationToMSVS ( p , spec , tools , config , config_type , config_name ) <EOL> def _GetIncludeDirs ( config ) : <EOL> """<STR_LIT>""" <EOL> include_dirs = ( <EOL> config . get ( '<STR_LIT>' , [ ] ) + <EOL> config . get ( '<STR_LIT>' , [ ] ) ) <EOL> midl_include_dirs = ( <EOL> config . get ( '<STR_LIT>' , [ ] ) + <EOL> config . get ( '<STR_LIT>' , [ ] ) ) <EOL> resource_include_dirs = config . get ( '<STR_LIT>' , include_dirs ) <EOL> include_dirs = _FixPaths ( include_dirs ) <EOL> midl_include_dirs = _FixPaths ( midl_include_dirs ) <EOL> resource_include_dirs = _FixPaths ( resource_include_dirs ) <EOL> return include_dirs , midl_include_dirs , resource_include_dirs <EOL> def _GetLibraryDirs ( config ) : <EOL> """<STR_LIT>""" <EOL> library_dirs = config . get ( '<STR_LIT>' , [ ] ) <EOL> library_dirs = _FixPaths ( library_dirs ) <EOL> return library_dirs <EOL> def _GetLibraries ( spec ) : <EOL> """<STR_LIT>""" <EOL> libraries = spec . get ( '<STR_LIT>' , [ ] ) <EOL> found = OrderedSet ( ) <EOL> unique_libraries_list = [ ] <EOL> for entry in reversed ( libraries ) : <EOL> library = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , entry ) <EOL> if not os . path . splitext ( library ) [ <NUM_LIT:1> ] : <EOL> library += '<STR_LIT>' <EOL> if library not in found : <EOL> found . add ( library ) <EOL> unique_libraries_list . append ( library ) <EOL> unique_libraries_list . reverse ( ) <EOL> return unique_libraries_list <EOL> def _GetOutputFilePathAndTool ( spec , msbuild ) : <EOL> """<STR_LIT>""" <EOL> out_file = '<STR_LIT>' <EOL> vc_tool = '<STR_LIT>' <EOL> msbuild_tool = '<STR_LIT>' <EOL> output_file_map = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> output_file_props = output_file_map . get ( spec [ '<STR_LIT:type>' ] ) <EOL> if output_file_props and int ( spec . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) : <EOL> vc_tool , msbuild_tool , out_dir , suffix = output_file_props <EOL> if spec . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> out_dir = '<STR_LIT>' <EOL> out_dir = spec . get ( '<STR_LIT>' , out_dir ) <EOL> product_extension = spec . get ( '<STR_LIT>' ) <EOL> if product_extension : <EOL> suffix = '<STR_LIT:.>' + product_extension <EOL> elif msbuild : <EOL> suffix = '<STR_LIT>' <EOL> prefix = spec . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> product_name = spec . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> out_file = ntpath . join ( out_dir , prefix + product_name + suffix ) <EOL> return out_file , vc_tool , msbuild_tool <EOL> def _GetOutputTargetExt ( spec ) : <EOL> """<STR_LIT>""" <EOL> target_extension = spec . get ( '<STR_LIT>' ) <EOL> if target_extension : <EOL> return '<STR_LIT:.>' + target_extension <EOL> return None <EOL> def _GetDefines ( config ) : <EOL> """<STR_LIT>""" <EOL> defines = [ ] <EOL> for d in config . get ( '<STR_LIT>' , [ ] ) : <EOL> if type ( d ) == list : <EOL> fd = '<STR_LIT:=>' . join ( [ str ( dpart ) for dpart in d ] ) <EOL> else : <EOL> fd = str ( d ) <EOL> defines . append ( fd ) <EOL> return defines <EOL> def _GetDisabledWarnings ( config ) : <EOL> return [ str ( i ) for i in config . get ( '<STR_LIT>' , [ ] ) ] <EOL> def _GetModuleDefinition ( spec ) : <EOL> def_file = '<STR_LIT>' <EOL> if spec [ '<STR_LIT:type>' ] in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> def_files = [ s for s in spec . get ( '<STR_LIT>' , [ ] ) if s . endswith ( '<STR_LIT>' ) ] <EOL> if len ( def_files ) == <NUM_LIT:1> : <EOL> def_file = _FixPath ( def_files [ <NUM_LIT:0> ] ) <EOL> elif def_files : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> spec [ '<STR_LIT>' ] , '<STR_LIT:U+0020>' . join ( def_files ) ) ) <EOL> return def_file <EOL> def _ConvertToolsToExpectedForm ( tools ) : <EOL> """<STR_LIT>""" <EOL> tool_list = [ ] <EOL> for tool , settings in tools . iteritems ( ) : <EOL> settings_fixed = { } <EOL> for setting , value in settings . iteritems ( ) : <EOL> if type ( value ) == list : <EOL> if ( ( tool == '<STR_LIT>' and <EOL> setting == '<STR_LIT>' ) or <EOL> setting == '<STR_LIT>' ) : <EOL> settings_fixed [ setting ] = '<STR_LIT:U+0020>' . join ( value ) <EOL> else : <EOL> settings_fixed [ setting ] = '<STR_LIT:;>' . join ( value ) <EOL> else : <EOL> settings_fixed [ setting ] = value <EOL> tool_list . append ( MSVSProject . Tool ( tool , settings_fixed ) ) <EOL> return tool_list <EOL> def _AddConfigurationToMSVS ( p , spec , tools , config , config_type , config_name ) : <EOL> """<STR_LIT>""" <EOL> attributes = _GetMSVSAttributes ( spec , config , config_type ) <EOL> tool_list = _ConvertToolsToExpectedForm ( tools ) <EOL> p . AddConfig ( _ConfigFullName ( config_name , config ) , <EOL> attrs = attributes , tools = tool_list ) <EOL> def _GetMSVSAttributes ( spec , config , config_type ) : <EOL> prepared_attrs = { } <EOL> source_attrs = config . get ( '<STR_LIT>' , { } ) <EOL> for a in source_attrs : <EOL> prepared_attrs [ a ] = source_attrs [ a ] <EOL> vsprops_dirs = config . get ( '<STR_LIT>' , [ ] ) <EOL> vsprops_dirs = _FixPaths ( vsprops_dirs ) <EOL> if vsprops_dirs : <EOL> prepared_attrs [ '<STR_LIT>' ] = '<STR_LIT:;>' . join ( vsprops_dirs ) <EOL> prepared_attrs [ '<STR_LIT>' ] = config_type <EOL> output_dir = prepared_attrs . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> prepared_attrs [ '<STR_LIT>' ] = _FixPath ( output_dir ) + '<STR_LIT:\\>' <EOL> if '<STR_LIT>' not in prepared_attrs : <EOL> intermediate = '<STR_LIT>' <EOL> prepared_attrs [ '<STR_LIT>' ] = _FixPath ( intermediate ) + '<STR_LIT:\\>' <EOL> else : <EOL> intermediate = _FixPath ( prepared_attrs [ '<STR_LIT>' ] ) + '<STR_LIT:\\>' <EOL> intermediate = MSVSSettings . FixVCMacroSlashes ( intermediate ) <EOL> prepared_attrs [ '<STR_LIT>' ] = intermediate <EOL> return prepared_attrs <EOL> def _AddNormalizedSources ( sources_set , sources_array ) : <EOL> sources_set . update ( _NormalizedSource ( s ) for s in sources_array ) <EOL> def _PrepareListOfSources ( spec , generator_flags , gyp_file ) : <EOL> """<STR_LIT>""" <EOL> sources = OrderedSet ( ) <EOL> _AddNormalizedSources ( sources , spec . get ( '<STR_LIT>' , [ ] ) ) <EOL> excluded_sources = OrderedSet ( ) <EOL> if not generator_flags . get ( '<STR_LIT>' ) : <EOL> sources . add ( gyp_file ) <EOL> for a in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> inputs = a [ '<STR_LIT>' ] <EOL> inputs = [ _NormalizedSource ( i ) for i in inputs ] <EOL> inputs = OrderedSet ( inputs ) <EOL> sources . update ( inputs ) <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> excluded_sources . update ( inputs ) <EOL> if int ( a . get ( '<STR_LIT>' , False ) ) : <EOL> _AddNormalizedSources ( sources , a . get ( '<STR_LIT>' , [ ] ) ) <EOL> for cpy in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> _AddNormalizedSources ( sources , cpy . get ( '<STR_LIT>' , [ ] ) ) <EOL> return ( sources , excluded_sources ) <EOL> def _AdjustSourcesAndConvertToFilterHierarchy ( <EOL> spec , options , gyp_dir , sources , excluded_sources , list_excluded , version ) : <EOL> """<STR_LIT>""" <EOL> excluded_sources . update ( OrderedSet ( spec . get ( '<STR_LIT>' , [ ] ) ) ) <EOL> sources . update ( excluded_sources ) <EOL> sources = _FixPaths ( sources ) <EOL> excluded_sources = _FixPaths ( excluded_sources ) <EOL> excluded_idl = _IdlFilesHandledNonNatively ( spec , sources ) <EOL> precompiled_related = _GetPrecompileRelatedFiles ( spec ) <EOL> fully_excluded = [ i for i in excluded_sources if i not in precompiled_related ] <EOL> sources = [ i . split ( '<STR_LIT:\\>' ) for i in sources ] <EOL> sources = _ConvertSourcesToFilterHierarchy ( sources , excluded = fully_excluded , <EOL> list_excluded = list_excluded , <EOL> msvs_version = version ) <EOL> if version . UsesVcxproj ( ) : <EOL> while all ( [ isinstance ( s , MSVSProject . Filter ) for s in sources ] ) and len ( set ( [ s . name for s in sources ] ) ) == <NUM_LIT:1> : <EOL> assert all ( [ len ( s . contents ) == <NUM_LIT:1> for s in sources ] ) <EOL> sources = [ s . contents [ <NUM_LIT:0> ] for s in sources ] <EOL> else : <EOL> while len ( sources ) == <NUM_LIT:1> and isinstance ( sources [ <NUM_LIT:0> ] , MSVSProject . Filter ) : <EOL> sources = sources [ <NUM_LIT:0> ] . contents <EOL> return sources , excluded_sources , excluded_idl <EOL> def _IdlFilesHandledNonNatively ( spec , sources ) : <EOL> using_idl = False <EOL> for rule in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> if rule [ '<STR_LIT>' ] == '<STR_LIT>' and int ( rule . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) : <EOL> using_idl = True <EOL> break <EOL> if using_idl : <EOL> excluded_idl = [ i for i in sources if i . endswith ( '<STR_LIT>' ) ] <EOL> else : <EOL> excluded_idl = [ ] <EOL> return excluded_idl <EOL> def _GetPrecompileRelatedFiles ( spec ) : <EOL> precompiled_related = [ ] <EOL> for _ , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> for k in precomp_keys : <EOL> f = config . get ( k ) <EOL> if f : <EOL> precompiled_related . append ( _FixPath ( f ) ) <EOL> return precompiled_related <EOL> def _ExcludeFilesFromBeingBuilt ( p , spec , excluded_sources , excluded_idl , <EOL> list_excluded ) : <EOL> exclusions = _GetExcludedFilesFromBuild ( spec , excluded_sources , excluded_idl ) <EOL> for file_name , excluded_configs in exclusions . iteritems ( ) : <EOL> if ( not list_excluded and <EOL> len ( excluded_configs ) == len ( spec [ '<STR_LIT>' ] ) ) : <EOL> pass <EOL> else : <EOL> for config_name , config in excluded_configs : <EOL> p . AddFileConfig ( file_name , _ConfigFullName ( config_name , config ) , <EOL> { '<STR_LIT>' : '<STR_LIT:true>' } ) <EOL> def _GetExcludedFilesFromBuild ( spec , excluded_sources , excluded_idl ) : <EOL> exclusions = { } <EOL> for f in excluded_sources : <EOL> excluded_configs = [ ] <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> precomped = [ _FixPath ( config . get ( i , '<STR_LIT>' ) ) for i in precomp_keys ] <EOL> if f not in precomped : <EOL> excluded_configs . append ( ( config_name , config ) ) <EOL> exclusions [ f ] = excluded_configs <EOL> for f in excluded_idl : <EOL> excluded_configs = [ ] <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> excluded_configs . append ( ( config_name , config ) ) <EOL> exclusions [ f ] = excluded_configs <EOL> return exclusions <EOL> def _AddToolFilesToMSVS ( p , spec ) : <EOL> tool_files = OrderedSet ( ) <EOL> for _ , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> for f in config . get ( '<STR_LIT>' , [ ] ) : <EOL> tool_files . add ( f ) <EOL> for f in tool_files : <EOL> p . AddToolFile ( f ) <EOL> def _HandlePreCompiledHeaders ( p , sources , spec ) : <EOL> extensions_excluded_from_precompile = [ ] <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> source = config . get ( '<STR_LIT>' ) <EOL> if source : <EOL> source = _FixPath ( source ) <EOL> tool = MSVSProject . Tool ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> p . AddFileConfig ( source , _ConfigFullName ( config_name , config ) , <EOL> { } , tools = [ tool ] ) <EOL> basename , extension = os . path . splitext ( source ) <EOL> if extension == '<STR_LIT>' : <EOL> extensions_excluded_from_precompile = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> extensions_excluded_from_precompile = [ '<STR_LIT>' ] <EOL> def DisableForSourceTree ( source_tree ) : <EOL> for source in source_tree : <EOL> if isinstance ( source , MSVSProject . Filter ) : <EOL> DisableForSourceTree ( source . contents ) <EOL> else : <EOL> basename , extension = os . path . splitext ( source ) <EOL> if extension in extensions_excluded_from_precompile : <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> tool = MSVSProject . Tool ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> p . AddFileConfig ( _FixPath ( source ) , <EOL> _ConfigFullName ( config_name , config ) , <EOL> { } , tools = [ tool ] ) <EOL> if extensions_excluded_from_precompile : <EOL> DisableForSourceTree ( sources ) <EOL> def _AddActions ( actions_to_add , spec , relative_path_of_gyp_file ) : <EOL> actions = spec . get ( '<STR_LIT>' , [ ] ) <EOL> have_setup_env = set ( ) <EOL> for a in actions : <EOL> inputs = a . get ( '<STR_LIT>' ) or [ relative_path_of_gyp_file ] <EOL> attached_to = inputs [ <NUM_LIT:0> ] <EOL> need_setup_env = attached_to not in have_setup_env <EOL> cmd = _BuildCommandLineForRule ( spec , a , has_input_path = False , <EOL> do_setup_env = need_setup_env ) <EOL> have_setup_env . add ( attached_to ) <EOL> _AddActionStep ( actions_to_add , <EOL> inputs = inputs , <EOL> outputs = a . get ( '<STR_LIT>' , [ ] ) , <EOL> description = a . get ( '<STR_LIT:message>' , a [ '<STR_LIT>' ] ) , <EOL> command = cmd ) <EOL> def _WriteMSVSUserFile ( project_path , version , spec ) : <EOL> if '<STR_LIT>' in spec : <EOL> run_as = spec [ '<STR_LIT>' ] <EOL> action = run_as . get ( '<STR_LIT:action>' , [ ] ) <EOL> environment = run_as . get ( '<STR_LIT>' , [ ] ) <EOL> working_directory = run_as . get ( '<STR_LIT>' , '<STR_LIT:.>' ) <EOL> elif int ( spec . get ( '<STR_LIT:test>' , <NUM_LIT:0> ) ) : <EOL> action = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> environment = [ ] <EOL> working_directory = '<STR_LIT:.>' <EOL> else : <EOL> return <EOL> user_file = _CreateMSVSUserFile ( project_path , version , spec ) <EOL> for config_name , c_data in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> user_file . AddDebugSettings ( _ConfigFullName ( config_name , c_data ) , <EOL> action , environment , working_directory ) <EOL> user_file . WriteIfChanged ( ) <EOL> def _AddCopies ( actions_to_add , spec ) : <EOL> copies = _GetCopies ( spec ) <EOL> for inputs , outputs , cmd , description in copies : <EOL> _AddActionStep ( actions_to_add , inputs = inputs , outputs = outputs , <EOL> description = description , command = cmd ) <EOL> def _GetCopies ( spec ) : <EOL> copies = [ ] <EOL> for cpy in spec . get ( '<STR_LIT>' , [ ] ) : <EOL> for src in cpy . get ( '<STR_LIT>' , [ ] ) : <EOL> dst = os . path . join ( cpy [ '<STR_LIT>' ] , os . path . basename ( src ) ) <EOL> if src . endswith ( '<STR_LIT:/>' ) : <EOL> src_bare = src [ : - <NUM_LIT:1> ] <EOL> base_dir = posixpath . split ( src_bare ) [ <NUM_LIT:0> ] <EOL> outer_dir = posixpath . split ( src_bare ) [ <NUM_LIT:1> ] <EOL> cmd = '<STR_LIT>' % ( <EOL> _FixPath ( base_dir ) , outer_dir , _FixPath ( dst ) , outer_dir ) <EOL> copies . append ( ( [ src ] , [ '<STR_LIT>' , dst ] , cmd , <EOL> '<STR_LIT>' % ( src , dst ) ) ) <EOL> else : <EOL> cmd = '<STR_LIT>' % ( <EOL> _FixPath ( cpy [ '<STR_LIT>' ] ) , _FixPath ( src ) , _FixPath ( dst ) ) <EOL> copies . append ( ( [ src ] , [ dst ] , cmd , '<STR_LIT>' % ( src , dst ) ) ) <EOL> return copies <EOL> def _GetPathDict ( root , path ) : <EOL> if not path or path . endswith ( os . sep ) : <EOL> return root <EOL> parent , folder = os . path . split ( path ) <EOL> parent_dict = _GetPathDict ( root , parent ) <EOL> if folder not in parent_dict : <EOL> parent_dict [ folder ] = dict ( ) <EOL> return parent_dict [ folder ] <EOL> def _DictsToFolders ( base_path , bucket , flat ) : <EOL> children = [ ] <EOL> for folder , contents in bucket . iteritems ( ) : <EOL> if type ( contents ) == dict : <EOL> folder_children = _DictsToFolders ( os . path . join ( base_path , folder ) , <EOL> contents , flat ) <EOL> if flat : <EOL> children += folder_children <EOL> else : <EOL> folder_children = MSVSNew . MSVSFolder ( os . path . join ( base_path , folder ) , <EOL> name = '<STR_LIT:(>' + folder + '<STR_LIT:)>' , <EOL> entries = folder_children ) <EOL> children . append ( folder_children ) <EOL> else : <EOL> children . append ( contents ) <EOL> return children <EOL> def _CollapseSingles ( parent , node ) : <EOL> if ( type ( node ) == dict and <EOL> len ( node ) == <NUM_LIT:1> and <EOL> node . keys ( ) [ <NUM_LIT:0> ] == parent + '<STR_LIT>' ) : <EOL> return node [ node . keys ( ) [ <NUM_LIT:0> ] ] <EOL> if type ( node ) != dict : <EOL> return node <EOL> for child in node : <EOL> node [ child ] = _CollapseSingles ( child , node [ child ] ) <EOL> return node <EOL> def _GatherSolutionFolders ( sln_projects , project_objects , flat ) : <EOL> root = { } <EOL> for p in sln_projects : <EOL> gyp_file , target = gyp . common . ParseQualifiedTarget ( p ) [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> gyp_dir = os . path . dirname ( gyp_file ) <EOL> path_dict = _GetPathDict ( root , gyp_dir ) <EOL> path_dict [ target + '<STR_LIT>' ] = project_objects [ p ] <EOL> while len ( root ) == <NUM_LIT:1> and type ( root [ root . keys ( ) [ <NUM_LIT:0> ] ] ) == dict : <EOL> root = root [ root . keys ( ) [ <NUM_LIT:0> ] ] <EOL> root = _CollapseSingles ( '<STR_LIT>' , root ) <EOL> return _DictsToFolders ( '<STR_LIT>' , root , flat ) <EOL> def _GetPathOfProject ( qualified_target , spec , options , msvs_version ) : <EOL> default_config = _GetDefaultConfiguration ( spec ) <EOL> proj_filename = default_config . get ( '<STR_LIT>' ) <EOL> if not proj_filename : <EOL> proj_filename = ( spec [ '<STR_LIT>' ] + options . suffix + <EOL> msvs_version . ProjectExtension ( ) ) <EOL> build_file = gyp . common . BuildFile ( qualified_target ) <EOL> proj_path = os . path . join ( os . path . dirname ( build_file ) , proj_filename ) <EOL> fix_prefix = None <EOL> if options . generator_output : <EOL> project_dir_path = os . path . dirname ( os . path . abspath ( proj_path ) ) <EOL> proj_path = os . path . join ( options . generator_output , proj_path ) <EOL> fix_prefix = gyp . common . RelativePath ( project_dir_path , <EOL> os . path . dirname ( proj_path ) ) <EOL> return proj_path , fix_prefix <EOL> def _GetPlatformOverridesOfProject ( spec ) : <EOL> config_platform_overrides = { } <EOL> for config_name , c in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> config_fullname = _ConfigFullName ( config_name , c ) <EOL> platform = c . get ( '<STR_LIT>' , _ConfigPlatform ( c ) ) <EOL> fixed_config_fullname = '<STR_LIT>' % ( <EOL> _ConfigBaseName ( config_name , _ConfigPlatform ( c ) ) , platform ) <EOL> config_platform_overrides [ config_fullname ] = fixed_config_fullname <EOL> return config_platform_overrides <EOL> def _CreateProjectObjects ( target_list , target_dicts , options , msvs_version ) : <EOL> """<STR_LIT>""" <EOL> global fixpath_prefix <EOL> projects = { } <EOL> for qualified_target in target_list : <EOL> spec = target_dicts [ qualified_target ] <EOL> if spec [ '<STR_LIT>' ] != '<STR_LIT:target>' : <EOL> raise GypError ( <EOL> '<STR_LIT>' % <EOL> qualified_target ) <EOL> proj_path , fixpath_prefix = _GetPathOfProject ( qualified_target , spec , <EOL> options , msvs_version ) <EOL> guid = _GetGuidOfProject ( proj_path , spec ) <EOL> overrides = _GetPlatformOverridesOfProject ( spec ) <EOL> build_file = gyp . common . BuildFile ( qualified_target ) <EOL> obj = MSVSNew . MSVSProject ( <EOL> proj_path , <EOL> name = spec [ '<STR_LIT>' ] , <EOL> guid = guid , <EOL> spec = spec , <EOL> build_file = build_file , <EOL> config_platform_overrides = overrides , <EOL> fixpath_prefix = fixpath_prefix ) <EOL> if msvs_version . UsesVcxproj ( ) : <EOL> obj . set_msbuild_toolset ( <EOL> _GetMsbuildToolsetOfProject ( proj_path , spec , msvs_version ) ) <EOL> projects [ qualified_target ] = obj <EOL> for project in projects . values ( ) : <EOL> if not project . spec . get ( '<STR_LIT>' ) : <EOL> deps = project . spec . get ( '<STR_LIT>' , [ ] ) <EOL> deps = [ projects [ d ] for d in deps ] <EOL> project . set_dependencies ( deps ) <EOL> return projects <EOL> def _InitNinjaFlavor ( params , target_list , target_dicts ) : <EOL> """<STR_LIT>""" <EOL> for qualified_target in target_list : <EOL> spec = target_dicts [ qualified_target ] <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> continue <EOL> path_to_ninja = spec . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> spec [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> gyp_file , _ , _ = gyp . common . ParseQualifiedTarget ( qualified_target ) <EOL> gyp_dir = os . path . dirname ( gyp_file ) <EOL> configuration = '<STR_LIT>' <EOL> if params . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> configuration += '<STR_LIT>' <EOL> spec [ '<STR_LIT>' ] = os . path . join ( <EOL> gyp . common . RelativePath ( params [ '<STR_LIT>' ] . toplevel_dir , gyp_dir ) , <EOL> ninja_generator . ComputeOutputDir ( params ) , <EOL> configuration ) <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> spec [ '<STR_LIT>' ] = [ <EOL> path_to_ninja , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> spec [ '<STR_LIT>' ] = [ <EOL> path_to_ninja , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def CalculateVariables ( default_variables , params ) : <EOL> """<STR_LIT>""" <EOL> generator_flags = params . get ( '<STR_LIT>' , { } ) <EOL> msvs_version = MSVSVersion . SelectVisualStudioVersion ( <EOL> generator_flags . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> params [ '<STR_LIT>' ] = msvs_version <EOL> default_variables [ '<STR_LIT>' ] = msvs_version . ShortName ( ) <EOL> if ( os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> or <EOL> os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> default_variables [ '<STR_LIT>' ] = <NUM_LIT:64> <EOL> else : <EOL> default_variables [ '<STR_LIT>' ] = <NUM_LIT:32> <EOL> if gyp . common . GetFlavor ( params ) == '<STR_LIT>' : <EOL> default_variables [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def PerformBuild ( data , configurations , params ) : <EOL> options = params [ '<STR_LIT>' ] <EOL> msvs_version = params [ '<STR_LIT>' ] <EOL> devenv = os . path . join ( msvs_version . path , '<STR_LIT>' , '<STR_LIT>' , '<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> sln_path = build_file_root + options . suffix + '<STR_LIT>' <EOL> if options . generator_output : <EOL> sln_path = os . path . join ( options . generator_output , sln_path ) <EOL> for config in configurations : <EOL> arguments = [ devenv , sln_path , '<STR_LIT>' , config ] <EOL> print '<STR_LIT>' % ( config , arguments ) <EOL> rtn = subprocess . check_call ( arguments ) <EOL> def GenerateOutput ( target_list , target_dicts , data , params ) : <EOL> """<STR_LIT>""" <EOL> global fixpath_prefix <EOL> options = params [ '<STR_LIT>' ] <EOL> msvs_version = params [ '<STR_LIT>' ] <EOL> generator_flags = params . get ( '<STR_LIT>' , { } ) <EOL> ( target_list , target_dicts ) = MSVSUtil . ShardTargets ( target_list , target_dicts ) <EOL> ( target_list , target_dicts ) = MSVSUtil . InsertLargePdbShims ( <EOL> target_list , target_dicts , generator_default_variables ) <EOL> if params . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> _InitNinjaFlavor ( params , target_list , target_dicts ) <EOL> configs = set ( ) <EOL> for qualified_target in target_list : <EOL> spec = target_dicts [ qualified_target ] <EOL> for config_name , config in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> configs . add ( _ConfigFullName ( config_name , config ) ) <EOL> configs = list ( configs ) <EOL> project_objects = _CreateProjectObjects ( target_list , target_dicts , options , <EOL> msvs_version ) <EOL> missing_sources = [ ] <EOL> for project in project_objects . values ( ) : <EOL> fixpath_prefix = project . fixpath_prefix <EOL> missing_sources . extend ( _GenerateProject ( project , options , msvs_version , <EOL> generator_flags ) ) <EOL> fixpath_prefix = None <EOL> for build_file in data : <EOL> if not build_file . endswith ( '<STR_LIT>' ) : <EOL> continue <EOL> sln_path = os . path . splitext ( build_file ) [ <NUM_LIT:0> ] + options . suffix + '<STR_LIT>' <EOL> if options . generator_output : <EOL> sln_path = os . path . join ( options . generator_output , sln_path ) <EOL> sln_projects = gyp . common . BuildFileTargets ( target_list , build_file ) <EOL> sln_projects += gyp . common . DeepDependencyTargets ( target_dicts , sln_projects ) <EOL> root_entries = _GatherSolutionFolders ( <EOL> sln_projects , project_objects , flat = msvs_version . FlatSolution ( ) ) <EOL> sln = MSVSNew . MSVSSolution ( sln_path , <EOL> entries = root_entries , <EOL> variants = configs , <EOL> websiteProperties = False , <EOL> version = msvs_version ) <EOL> sln . Write ( ) <EOL> if missing_sources : <EOL> error_message = "<STR_LIT>" + '<STR_LIT:\n>' . join ( set ( missing_sources ) ) <EOL> if generator_flags . get ( '<STR_LIT>' , False ) : <EOL> raise GypError ( error_message ) <EOL> else : <EOL> print >> sys . stdout , "<STR_LIT>" + error_message <EOL> def _GenerateMSBuildFiltersFile ( filters_path , source_files , <EOL> rule_dependencies , extension_to_rule_name ) : <EOL> """<STR_LIT>""" <EOL> filter_group = [ ] <EOL> source_group = [ ] <EOL> _AppendFiltersForMSBuild ( '<STR_LIT>' , source_files , rule_dependencies , <EOL> extension_to_rule_name , filter_group , source_group ) <EOL> if filter_group : <EOL> content = [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> [ '<STR_LIT>' ] + filter_group , <EOL> [ '<STR_LIT>' ] + source_group <EOL> ] <EOL> easy_xml . WriteXmlIfChanged ( content , filters_path , pretty = True , win32 = True ) <EOL> elif os . path . exists ( filters_path ) : <EOL> os . unlink ( filters_path ) <EOL> def _AppendFiltersForMSBuild ( parent_filter_name , sources , rule_dependencies , <EOL> extension_to_rule_name , <EOL> filter_group , source_group ) : <EOL> """<STR_LIT>""" <EOL> for source in sources : <EOL> if isinstance ( source , MSVSProject . Filter ) : <EOL> if not parent_filter_name : <EOL> filter_name = source . name <EOL> else : <EOL> filter_name = '<STR_LIT>' % ( parent_filter_name , source . name ) <EOL> filter_group . append ( <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : filter_name } , <EOL> [ '<STR_LIT>' , MSVSNew . MakeGuid ( source . name ) ] ] ) <EOL> _AppendFiltersForMSBuild ( filter_name , source . contents , <EOL> rule_dependencies , extension_to_rule_name , <EOL> filter_group , source_group ) <EOL> else : <EOL> _ , element = _MapFileToMsBuildSourceType ( source , rule_dependencies , <EOL> extension_to_rule_name ) <EOL> source_entry = [ element , { '<STR_LIT>' : source } ] <EOL> if parent_filter_name : <EOL> source_entry . append ( [ '<STR_LIT>' , parent_filter_name ] ) <EOL> source_group . append ( source_entry ) <EOL> def _MapFileToMsBuildSourceType ( source , rule_dependencies , <EOL> extension_to_rule_name ) : <EOL> """<STR_LIT>""" <EOL> _ , ext = os . path . splitext ( source ) <EOL> if ext in extension_to_rule_name : <EOL> group = '<STR_LIT>' <EOL> element = extension_to_rule_name [ ext ] <EOL> elif ext in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> elif ext in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> elif ext == '<STR_LIT>' : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> elif ext == '<STR_LIT>' : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> elif ext == '<STR_LIT>' : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> elif source in rule_dependencies : <EOL> group = '<STR_LIT>' <EOL> element = '<STR_LIT>' <EOL> else : <EOL> group = '<STR_LIT:none>' <EOL> element = '<STR_LIT:None>' <EOL> return ( group , element ) <EOL> def _GenerateRulesForMSBuild ( output_dir , options , spec , <EOL> sources , excluded_sources , <EOL> props_files_of_rules , targets_files_of_rules , <EOL> actions_to_add , rule_dependencies , <EOL> extension_to_rule_name ) : <EOL> rules = spec . get ( '<STR_LIT>' , [ ] ) <EOL> rules_native = [ r for r in rules if not int ( r . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) ] <EOL> rules_external = [ r for r in rules if int ( r . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) ] <EOL> msbuild_rules = [ ] <EOL> for rule in rules_native : <EOL> if '<STR_LIT:action>' not in rule and not rule . get ( '<STR_LIT>' , [ ] ) : <EOL> continue <EOL> msbuild_rule = MSBuildRule ( rule , spec ) <EOL> msbuild_rules . append ( msbuild_rule ) <EOL> rule_dependencies . update ( msbuild_rule . additional_dependencies . split ( '<STR_LIT:;>' ) ) <EOL> extension_to_rule_name [ msbuild_rule . extension ] = msbuild_rule . rule_name <EOL> if msbuild_rules : <EOL> base = spec [ '<STR_LIT>' ] + options . suffix <EOL> props_name = base + '<STR_LIT>' <EOL> targets_name = base + '<STR_LIT>' <EOL> xml_name = base + '<STR_LIT>' <EOL> props_files_of_rules . add ( props_name ) <EOL> targets_files_of_rules . add ( targets_name ) <EOL> props_path = os . path . join ( output_dir , props_name ) <EOL> targets_path = os . path . join ( output_dir , targets_name ) <EOL> xml_path = os . path . join ( output_dir , xml_name ) <EOL> _GenerateMSBuildRulePropsFile ( props_path , msbuild_rules ) <EOL> _GenerateMSBuildRuleTargetsFile ( targets_path , msbuild_rules ) <EOL> _GenerateMSBuildRuleXmlFile ( xml_path , msbuild_rules ) <EOL> if rules_external : <EOL> _GenerateExternalRules ( rules_external , output_dir , spec , <EOL> sources , options , actions_to_add ) <EOL> _AdjustSourcesForRules ( rules , sources , excluded_sources , True ) <EOL> class MSBuildRule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rule , spec ) : <EOL> self . display_name = rule [ '<STR_LIT>' ] <EOL> self . rule_name = re . sub ( r'<STR_LIT>' , '<STR_LIT:_>' , self . display_name ) <EOL> self . target_name = '<STR_LIT:_>' + self . rule_name <EOL> self . after_targets = self . rule_name + '<STR_LIT>' <EOL> self . before_targets = self . rule_name + '<STR_LIT>' <EOL> self . depends_on = self . rule_name + '<STR_LIT>' <EOL> self . compute_output = '<STR_LIT>' % self . rule_name <EOL> self . dirs_to_make = self . rule_name + '<STR_LIT>' <EOL> self . inputs = self . rule_name + '<STR_LIT>' <EOL> self . tlog = self . rule_name + '<STR_LIT>' <EOL> self . extension = rule [ '<STR_LIT>' ] <EOL> if not self . extension . startswith ( '<STR_LIT:.>' ) : <EOL> self . extension = '<STR_LIT:.>' + self . extension <EOL> self . description = MSVSSettings . ConvertVCMacrosToMSBuild ( <EOL> rule . get ( '<STR_LIT:message>' , self . rule_name ) ) <EOL> old_additional_dependencies = _FixPaths ( rule . get ( '<STR_LIT>' , [ ] ) ) <EOL> self . additional_dependencies = ( <EOL> '<STR_LIT:;>' . join ( [ MSVSSettings . ConvertVCMacrosToMSBuild ( i ) <EOL> for i in old_additional_dependencies ] ) ) <EOL> old_outputs = _FixPaths ( rule . get ( '<STR_LIT>' , [ ] ) ) <EOL> self . outputs = '<STR_LIT:;>' . join ( [ MSVSSettings . ConvertVCMacrosToMSBuild ( i ) <EOL> for i in old_outputs ] ) <EOL> old_command = _BuildCommandLineForRule ( spec , rule , has_input_path = True , <EOL> do_setup_env = True ) <EOL> self . command = MSVSSettings . ConvertVCMacrosToMSBuild ( old_command ) <EOL> def _GenerateMSBuildRulePropsFile ( props_path , msbuild_rules ) : <EOL> """<STR_LIT>""" <EOL> content = [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> for rule in msbuild_rules : <EOL> content . extend ( [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" % ( rule . before_targets , <EOL> rule . after_targets ) <EOL> } , <EOL> [ rule . before_targets , '<STR_LIT>' ] , <EOL> [ rule . after_targets , '<STR_LIT>' ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ rule . depends_on , <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> '<STR_LIT>' % rule . depends_on <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ rule . rule_name , <EOL> [ '<STR_LIT>' , rule . command ] , <EOL> [ '<STR_LIT>' , rule . outputs ] , <EOL> [ '<STR_LIT>' , rule . description ] , <EOL> [ '<STR_LIT>' , rule . additional_dependencies ] , <EOL> ] , <EOL> ] <EOL> ] ) <EOL> easy_xml . WriteXmlIfChanged ( content , props_path , pretty = True , win32 = True ) <EOL> def _GenerateMSBuildRuleTargetsFile ( targets_path , msbuild_rules ) : <EOL> """<STR_LIT>""" <EOL> content = [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> item_group = [ <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } <EOL> ] <EOL> ] <EOL> for rule in msbuild_rules : <EOL> item_group . append ( <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : rule . rule_name } , <EOL> [ '<STR_LIT>' , rule . target_name ] , <EOL> ] ) <EOL> content . append ( item_group ) <EOL> for rule in msbuild_rules : <EOL> content . append ( <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : rule . rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] ) <EOL> for rule in msbuild_rules : <EOL> rule_name = rule . rule_name <EOL> target_outputs = '<STR_LIT>' % rule_name <EOL> target_inputs = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( rule_name , rule_name ) <EOL> rule_inputs = '<STR_LIT>' % rule_name <EOL> extension_condition = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> remove_section = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> [ rule_name , <EOL> { '<STR_LIT>' : '<STR_LIT>' % rule_name , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> ] <EOL> ] <EOL> inputs_section = [ <EOL> '<STR_LIT>' , <EOL> [ rule . inputs , { '<STR_LIT>' : '<STR_LIT>' % rule_name } ] <EOL> ] <EOL> logging_section = [ <EOL> '<STR_LIT>' , <EOL> [ rule . tlog , <EOL> { '<STR_LIT>' : '<STR_LIT>' % rule_name , <EOL> '<STR_LIT>' : ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( rule_name , rule_name ) ) <EOL> } , <EOL> [ '<STR_LIT>' , "<STR_LIT>" % rule_name ] , <EOL> [ '<STR_LIT>' , "<STR_LIT>" % rule . inputs ] , <EOL> ] , <EOL> ] <EOL> message_section = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule_name <EOL> } <EOL> ] <EOL> write_tlog_section = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" % ( rule . tlog , rule . tlog ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" % ( rule . tlog , <EOL> rule . tlog ) <EOL> } <EOL> ] <EOL> read_tlog_section = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" % ( rule . tlog , rule . tlog ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" % ( rule . tlog , rule . tlog ) <EOL> } <EOL> ] <EOL> command_and_input_section = [ <EOL> rule_name , <EOL> { '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" % ( rule_name , rule_name ) , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule_name , <EOL> '<STR_LIT>' : rule_inputs <EOL> } <EOL> ] <EOL> content . extend ( [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . target_name , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule . before_targets , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule . after_targets , <EOL> '<STR_LIT>' : "<STR_LIT>" % rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( rule . depends_on , <EOL> rule . compute_output ) , <EOL> '<STR_LIT>' : target_outputs , <EOL> '<STR_LIT>' : target_inputs <EOL> } , <EOL> remove_section , <EOL> inputs_section , <EOL> logging_section , <EOL> message_section , <EOL> write_tlog_section , <EOL> read_tlog_section , <EOL> command_and_input_section , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % rule . compute_output <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % rule . compute_output <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . compute_output , <EOL> '<STR_LIT>' : "<STR_LIT>" % rule_name <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ rule . dirs_to_make , <EOL> { '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" % ( rule_name , rule_name ) , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule_name <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' % rule . dirs_to_make , <EOL> '<STR_LIT>' : extension_condition <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' % rule . dirs_to_make , <EOL> '<STR_LIT>' : extension_condition <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' % rule . dirs_to_make , <EOL> '<STR_LIT>' : extension_condition <EOL> } <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : ( "<STR_LIT>" % <EOL> rule . dirs_to_make ) <EOL> } <EOL> ] <EOL> ] , <EOL> ] ) <EOL> easy_xml . WriteXmlIfChanged ( content , targets_path , pretty = True , win32 = True ) <EOL> def _GenerateMSBuildRuleXmlFile ( xml_path , msbuild_rules ) : <EOL> content = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> } <EOL> ] <EOL> for rule in msbuild_rules : <EOL> content . extend ( [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . display_name , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . rule_name <EOL> } <EOL> ] <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . before_targets , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule . before_targets <EOL> } <EOL> ] <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' <EOL> } <EOL> ] <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . after_targets , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % rule . after_targets <EOL> } <EOL> ] <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' <EOL> } <EOL> ] <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' , <EOL> '<STR_LIT>' : '<STR_LIT:false>' <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:Name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ] , <EOL> ] , <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . rule_name , <EOL> '<STR_LIT>' : rule . display_name <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : '<STR_LIT:*>' + rule . extension , <EOL> '<STR_LIT>' : rule . rule_name <EOL> } <EOL> ] , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT:Name>' : rule . rule_name , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rule . rule_name <EOL> } <EOL> ] <EOL> ] ) <EOL> easy_xml . WriteXmlIfChanged ( content , xml_path , pretty = True , win32 = True ) <EOL> def _GetConfigurationAndPlatform ( name , settings ) : <EOL> configuration = name . rsplit ( '<STR_LIT:_>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> platform = settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return ( configuration , platform ) <EOL> def _GetConfigurationCondition ( name , settings ) : <EOL> return ( r"<STR_LIT>" % <EOL> _GetConfigurationAndPlatform ( name , settings ) ) <EOL> def _GetMSBuildProjectConfigurations ( configurations ) : <EOL> group = [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> for ( name , settings ) in sorted ( configurations . iteritems ( ) ) : <EOL> configuration , platform = _GetConfigurationAndPlatform ( name , settings ) <EOL> designation = '<STR_LIT>' % ( configuration , platform ) <EOL> group . append ( <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : designation } , <EOL> [ '<STR_LIT>' , configuration ] , <EOL> [ '<STR_LIT>' , platform ] ] ) <EOL> return [ group ] <EOL> def _GetMSBuildGlobalProperties ( spec , guid , gyp_file_name ) : <EOL> namespace = os . path . splitext ( gyp_file_name ) [ <NUM_LIT:0> ] <EOL> properties = [ <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' , guid ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , namespace ] , <EOL> [ '<STR_LIT>' , '<STR_LIT:true>' ] , <EOL> ] <EOL> ] <EOL> if os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' or os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT:true>' ] ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> app_type_revision = spec . get ( '<STR_LIT>' ) <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , app_type_revision ] ) <EOL> else : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> target_platform_version = spec . get ( '<STR_LIT>' ) <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , <EOL> target_platform_version ] ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> target_platform_minversion = spec . get ( '<STR_LIT>' ) <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , <EOL> target_platform_minversion ] ) <EOL> else : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , <EOL> target_platform_version ] ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> else : <EOL> properties [ <NUM_LIT:0> ] . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return properties <EOL> def _GetMSBuildConfigurationDetails ( spec , build_file ) : <EOL> properties = { } <EOL> for name , settings in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> msbuild_attributes = _GetMSBuildAttributes ( spec , settings , build_file ) <EOL> condition = _GetConfigurationCondition ( name , settings ) <EOL> character_set = msbuild_attributes . get ( '<STR_LIT>' ) <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> msbuild_attributes [ '<STR_LIT>' ] ) <EOL> if character_set : <EOL> if '<STR_LIT>' not in spec : <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> character_set ) <EOL> return _GetMSBuildPropertyGroup ( spec , '<STR_LIT>' , properties ) <EOL> def _GetMSBuildLocalProperties ( msbuild_toolset ) : <EOL> properties = { } <EOL> if msbuild_toolset : <EOL> properties = [ <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' , msbuild_toolset ] , <EOL> ] <EOL> ] <EOL> return properties <EOL> def _GetMSBuildPropertySheets ( configurations ) : <EOL> user_props = r'<STR_LIT>' <EOL> additional_props = { } <EOL> props_specified = False <EOL> for name , settings in sorted ( configurations . iteritems ( ) ) : <EOL> configuration = _GetConfigurationCondition ( name , settings ) <EOL> if settings . has_key ( '<STR_LIT>' ) : <EOL> additional_props [ configuration ] = _FixPaths ( settings [ '<STR_LIT>' ] ) <EOL> props_specified = True <EOL> else : <EOL> additional_props [ configuration ] = '<STR_LIT>' <EOL> if not props_specified : <EOL> return [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : user_props , <EOL> '<STR_LIT>' : "<STR_LIT>" % user_props , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> ] <EOL> ] <EOL> else : <EOL> sheets = [ ] <EOL> for condition , props in additional_props . iteritems ( ) : <EOL> import_group = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : condition <EOL> } , <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : user_props , <EOL> '<STR_LIT>' : "<STR_LIT>" % user_props , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> ] <EOL> for props_file in props : <EOL> import_group . append ( [ '<STR_LIT>' , { '<STR_LIT>' : props_file } ] ) <EOL> sheets . append ( import_group ) <EOL> return sheets <EOL> def _ConvertMSVSBuildAttributes ( spec , config , build_file ) : <EOL> config_type = _GetMSVSConfigurationType ( spec , build_file ) <EOL> msvs_attributes = _GetMSVSAttributes ( spec , config , config_type ) <EOL> msbuild_attributes = { } <EOL> for a in msvs_attributes : <EOL> if a in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> directory = MSVSSettings . ConvertVCMacrosToMSBuild ( msvs_attributes [ a ] ) <EOL> if not directory . endswith ( '<STR_LIT:\\>' ) : <EOL> directory += '<STR_LIT:\\>' <EOL> msbuild_attributes [ a ] = directory <EOL> elif a == '<STR_LIT>' : <EOL> msbuild_attributes [ a ] = _ConvertMSVSCharacterSet ( msvs_attributes [ a ] ) <EOL> elif a == '<STR_LIT>' : <EOL> msbuild_attributes [ a ] = _ConvertMSVSConfigurationType ( msvs_attributes [ a ] ) <EOL> else : <EOL> print '<STR_LIT>' + a <EOL> return msbuild_attributes <EOL> def _ConvertMSVSCharacterSet ( char_set ) : <EOL> if char_set . isdigit ( ) : <EOL> char_set = { <EOL> '<STR_LIT:0>' : '<STR_LIT>' , <EOL> '<STR_LIT:1>' : '<STR_LIT>' , <EOL> '<STR_LIT:2>' : '<STR_LIT>' , <EOL> } [ char_set ] <EOL> return char_set <EOL> def _ConvertMSVSConfigurationType ( config_type ) : <EOL> if config_type . isdigit ( ) : <EOL> config_type = { <EOL> '<STR_LIT:1>' : '<STR_LIT>' , <EOL> '<STR_LIT:2>' : '<STR_LIT>' , <EOL> '<STR_LIT:4>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } [ config_type ] <EOL> return config_type <EOL> def _GetMSBuildAttributes ( spec , config , build_file ) : <EOL> if '<STR_LIT>' not in config : <EOL> msbuild_attributes = _ConvertMSVSBuildAttributes ( spec , config , build_file ) <EOL> else : <EOL> config_type = _GetMSVSConfigurationType ( spec , build_file ) <EOL> config_type = _ConvertMSVSConfigurationType ( config_type ) <EOL> msbuild_attributes = config . get ( '<STR_LIT>' , { } ) <EOL> msbuild_attributes . setdefault ( '<STR_LIT>' , config_type ) <EOL> output_dir = msbuild_attributes . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> msbuild_attributes [ '<STR_LIT>' ] = _FixPath ( output_dir ) + '<STR_LIT:\\>' <EOL> if '<STR_LIT>' not in msbuild_attributes : <EOL> intermediate = _FixPath ( '<STR_LIT>' ) + '<STR_LIT:\\>' <EOL> msbuild_attributes [ '<STR_LIT>' ] = intermediate <EOL> if '<STR_LIT>' in msbuild_attributes : <EOL> msbuild_attributes [ '<STR_LIT>' ] = _ConvertMSVSCharacterSet ( <EOL> msbuild_attributes [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' not in msbuild_attributes : <EOL> prefix = spec . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> product_name = spec . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> target_name = prefix + product_name <EOL> msbuild_attributes [ '<STR_LIT>' ] = target_name <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> external_out_dir = spec . get ( '<STR_LIT>' , '<STR_LIT:.>' ) <EOL> msbuild_attributes [ '<STR_LIT>' ] = _FixPath ( external_out_dir ) + '<STR_LIT:\\>' <EOL> msbuild_tool_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> msbuild_tool = msbuild_tool_map . get ( spec [ '<STR_LIT:type>' ] ) <EOL> if msbuild_tool : <EOL> msbuild_settings = config [ '<STR_LIT>' ] <EOL> out_file = msbuild_settings [ msbuild_tool ] . get ( '<STR_LIT>' ) <EOL> if out_file : <EOL> msbuild_attributes [ '<STR_LIT>' ] = _FixPath ( out_file ) <EOL> target_ext = msbuild_settings [ msbuild_tool ] . get ( '<STR_LIT>' ) <EOL> if target_ext : <EOL> msbuild_attributes [ '<STR_LIT>' ] = target_ext <EOL> return msbuild_attributes <EOL> def _GetMSBuildConfigurationGlobalProperties ( spec , configurations , build_file ) : <EOL> new_paths = [ ] <EOL> cygwin_dirs = spec . get ( '<STR_LIT>' , [ '<STR_LIT:.>' ] ) [ <NUM_LIT:0> ] <EOL> if cygwin_dirs : <EOL> cyg_path = '<STR_LIT>' % _FixPath ( cygwin_dirs ) <EOL> new_paths . append ( cyg_path ) <EOL> python_path = cyg_path . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> new_paths . append ( python_path ) <EOL> if new_paths : <EOL> new_paths = '<STR_LIT>' + '<STR_LIT:;>' . join ( new_paths ) <EOL> properties = { } <EOL> for ( name , configuration ) in sorted ( configurations . iteritems ( ) ) : <EOL> condition = _GetConfigurationCondition ( name , configuration ) <EOL> attributes = _GetMSBuildAttributes ( spec , configuration , build_file ) <EOL> msbuild_settings = configuration [ '<STR_LIT>' ] <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> attributes [ '<STR_LIT>' ] ) <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> attributes [ '<STR_LIT>' ] ) <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> attributes [ '<STR_LIT>' ] ) <EOL> if attributes . get ( '<STR_LIT>' ) : <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> attributes [ '<STR_LIT>' ] ) <EOL> if attributes . get ( '<STR_LIT>' ) : <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> attributes [ '<STR_LIT>' ] ) <EOL> if new_paths : <EOL> _AddConditionalProperty ( properties , condition , '<STR_LIT>' , <EOL> new_paths ) <EOL> tool_settings = msbuild_settings . get ( '<STR_LIT>' , { } ) <EOL> for name , value in sorted ( tool_settings . iteritems ( ) ) : <EOL> formatted_value = _GetValueFormattedForMSBuild ( '<STR_LIT>' , name , value ) <EOL> _AddConditionalProperty ( properties , condition , name , formatted_value ) <EOL> return _GetMSBuildPropertyGroup ( spec , None , properties ) <EOL> def _AddConditionalProperty ( properties , condition , name , value ) : <EOL> """<STR_LIT>""" <EOL> if name not in properties : <EOL> properties [ name ] = { } <EOL> values = properties [ name ] <EOL> if value not in values : <EOL> values [ value ] = [ ] <EOL> conditions = values [ value ] <EOL> conditions . append ( condition ) <EOL> MSVS_VARIABLE_REFERENCE = re . compile ( r'<STR_LIT>' ) <EOL> def _GetMSBuildPropertyGroup ( spec , label , properties ) : <EOL> """<STR_LIT>""" <EOL> group = [ '<STR_LIT>' ] <EOL> if label : <EOL> group . append ( { '<STR_LIT>' : label } ) <EOL> num_configurations = len ( spec [ '<STR_LIT>' ] ) <EOL> def GetEdges ( node ) : <EOL> edges = set ( ) <EOL> for value in sorted ( properties [ node ] . keys ( ) ) : <EOL> edges . update ( set ( [ v for v in MSVS_VARIABLE_REFERENCE . findall ( value ) <EOL> if v in properties and v != node ] ) ) <EOL> return edges <EOL> properties_ordered = gyp . common . TopologicallySorted ( <EOL> properties . keys ( ) , GetEdges ) <EOL> for name in reversed ( properties_ordered ) : <EOL> values = properties [ name ] <EOL> for value , conditions in sorted ( values . iteritems ( ) ) : <EOL> if len ( conditions ) == num_configurations : <EOL> group . append ( [ name , value ] ) <EOL> else : <EOL> for condition in conditions : <EOL> group . append ( [ name , { '<STR_LIT>' : condition } , value ] ) <EOL> return [ group ] <EOL> def _GetMSBuildToolSettingsSections ( spec , configurations ) : <EOL> groups = [ ] <EOL> for ( name , configuration ) in sorted ( configurations . iteritems ( ) ) : <EOL> msbuild_settings = configuration [ '<STR_LIT>' ] <EOL> group = [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : _GetConfigurationCondition ( name , configuration ) } <EOL> ] <EOL> for tool_name , tool_settings in sorted ( msbuild_settings . iteritems ( ) ) : <EOL> if tool_name : <EOL> if tool_settings : <EOL> tool = [ tool_name ] <EOL> for name , value in sorted ( tool_settings . iteritems ( ) ) : <EOL> formatted_value = _GetValueFormattedForMSBuild ( tool_name , name , <EOL> value ) <EOL> tool . append ( [ name , formatted_value ] ) <EOL> group . append ( tool ) <EOL> groups . append ( group ) <EOL> return groups <EOL> def _FinalizeMSBuildSettings ( spec , configuration ) : <EOL> if '<STR_LIT>' in configuration : <EOL> converted = False <EOL> msbuild_settings = configuration [ '<STR_LIT>' ] <EOL> MSVSSettings . ValidateMSBuildSettings ( msbuild_settings ) <EOL> else : <EOL> converted = True <EOL> msvs_settings = configuration . get ( '<STR_LIT>' , { } ) <EOL> msbuild_settings = MSVSSettings . ConvertToMSBuildSettings ( msvs_settings ) <EOL> include_dirs , midl_include_dirs , resource_include_dirs = _GetIncludeDirs ( configuration ) <EOL> libraries = _GetLibraries ( spec ) <EOL> library_dirs = _GetLibraryDirs ( configuration ) <EOL> out_file , _ , msbuild_tool = _GetOutputFilePathAndTool ( spec , msbuild = True ) <EOL> target_ext = _GetOutputTargetExt ( spec ) <EOL> defines = _GetDefines ( configuration ) <EOL> if converted : <EOL> defines = [ d for d in defines if d != '<STR_LIT>' ] <EOL> ignored_settings = [ '<STR_LIT>' ] <EOL> for ignored_setting in ignored_settings : <EOL> value = configuration . get ( ignored_setting ) <EOL> if value : <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( ignored_setting , str ( value ) ) ) <EOL> defines = [ _EscapeCppDefineForMSBuild ( d ) for d in defines ] <EOL> disabled_warnings = _GetDisabledWarnings ( configuration ) <EOL> prebuild = configuration . get ( '<STR_LIT>' ) <EOL> postbuild = configuration . get ( '<STR_LIT>' ) <EOL> def_file = _GetModuleDefinition ( spec ) <EOL> precompiled_header = configuration . get ( '<STR_LIT>' ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , include_dirs ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , midl_include_dirs ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , resource_include_dirs ) <EOL> _ToolSetOrAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , <EOL> libraries ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , <EOL> library_dirs ) <EOL> if out_file : <EOL> _ToolAppend ( msbuild_settings , msbuild_tool , '<STR_LIT>' , out_file , <EOL> only_if_unset = True ) <EOL> if target_ext : <EOL> _ToolAppend ( msbuild_settings , msbuild_tool , '<STR_LIT>' , target_ext , <EOL> only_if_unset = True ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , defines ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , defines ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , disabled_warnings ) <EOL> if precompiled_header : <EOL> precompiled_header = os . path . split ( precompiled_header ) [ <NUM_LIT:1> ] <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , precompiled_header ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , <EOL> '<STR_LIT>' , [ precompiled_header ] ) <EOL> else : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:false>' ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:false>' ) <EOL> if spec [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> if def_file : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , def_file ) <EOL> configuration [ '<STR_LIT>' ] = msbuild_settings <EOL> if prebuild : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , prebuild ) <EOL> if postbuild : <EOL> _ToolAppend ( msbuild_settings , '<STR_LIT>' , '<STR_LIT>' , postbuild ) <EOL> def _GetValueFormattedForMSBuild ( tool_name , name , value ) : <EOL> if type ( value ) == list : <EOL> if name in [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> value . append ( '<STR_LIT>' % name ) <EOL> exceptions = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> if tool_name in exceptions and name in exceptions [ tool_name ] : <EOL> char = '<STR_LIT:U+0020>' <EOL> else : <EOL> char = '<STR_LIT:;>' <EOL> formatted_value = char . join ( <EOL> [ MSVSSettings . ConvertVCMacrosToMSBuild ( i ) for i in value ] ) <EOL> else : <EOL> formatted_value = MSVSSettings . ConvertVCMacrosToMSBuild ( value ) <EOL> return formatted_value <EOL> def _VerifySourcesExist ( sources , root_dir ) : <EOL> """<STR_LIT>""" <EOL> missing_sources = [ ] <EOL> for source in sources : <EOL> if isinstance ( source , MSVSProject . Filter ) : <EOL> missing_sources . extend ( _VerifySourcesExist ( source . contents , root_dir ) ) <EOL> else : <EOL> if '<STR_LIT:$>' not in source : <EOL> full_path = os . path . join ( root_dir , source ) <EOL> if not os . path . exists ( full_path ) : <EOL> missing_sources . append ( full_path ) <EOL> return missing_sources <EOL> def _GetMSBuildSources ( spec , sources , exclusions , rule_dependencies , <EOL> extension_to_rule_name , actions_spec , <EOL> sources_handled_by_action , list_excluded ) : <EOL> groups = [ '<STR_LIT:none>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> grouped_sources = { } <EOL> for g in groups : <EOL> grouped_sources [ g ] = [ ] <EOL> _AddSources2 ( spec , sources , exclusions , grouped_sources , <EOL> rule_dependencies , extension_to_rule_name , <EOL> sources_handled_by_action , list_excluded ) <EOL> sources = [ ] <EOL> for g in groups : <EOL> if grouped_sources [ g ] : <EOL> sources . append ( [ '<STR_LIT>' ] + grouped_sources [ g ] ) <EOL> if actions_spec : <EOL> sources . append ( [ '<STR_LIT>' ] + actions_spec ) <EOL> return sources <EOL> def _AddSources2 ( spec , sources , exclusions , grouped_sources , <EOL> rule_dependencies , extension_to_rule_name , <EOL> sources_handled_by_action , <EOL> list_excluded ) : <EOL> extensions_excluded_from_precompile = [ ] <EOL> for source in sources : <EOL> if isinstance ( source , MSVSProject . Filter ) : <EOL> _AddSources2 ( spec , source . contents , exclusions , grouped_sources , <EOL> rule_dependencies , extension_to_rule_name , <EOL> sources_handled_by_action , <EOL> list_excluded ) <EOL> else : <EOL> if not source in sources_handled_by_action : <EOL> detail = [ ] <EOL> excluded_configurations = exclusions . get ( source , [ ] ) <EOL> if len ( excluded_configurations ) == len ( spec [ '<STR_LIT>' ] ) : <EOL> detail . append ( [ '<STR_LIT>' , '<STR_LIT:true>' ] ) <EOL> else : <EOL> for config_name , configuration in sorted ( excluded_configurations ) : <EOL> condition = _GetConfigurationCondition ( config_name , configuration ) <EOL> detail . append ( [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : condition } , <EOL> '<STR_LIT:true>' ] ) <EOL> for config_name , configuration in spec [ '<STR_LIT>' ] . iteritems ( ) : <EOL> precompiled_source = configuration . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if precompiled_source != '<STR_LIT>' : <EOL> precompiled_source = _FixPath ( precompiled_source ) <EOL> if not extensions_excluded_from_precompile : <EOL> basename , extension = os . path . splitext ( precompiled_source ) <EOL> if extension == '<STR_LIT>' : <EOL> extensions_excluded_from_precompile = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> extensions_excluded_from_precompile = [ '<STR_LIT>' ] <EOL> if precompiled_source == source : <EOL> condition = _GetConfigurationCondition ( config_name , configuration ) <EOL> detail . append ( [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : condition } , <EOL> '<STR_LIT>' <EOL> ] ) <EOL> else : <EOL> for extension in extensions_excluded_from_precompile : <EOL> if source . endswith ( extension ) : <EOL> detail . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> detail . append ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> group , element = _MapFileToMsBuildSourceType ( source , rule_dependencies , <EOL> extension_to_rule_name ) <EOL> grouped_sources [ group ] . append ( [ element , { '<STR_LIT>' : source } ] + detail ) <EOL> def _GetMSBuildProjectReferences ( project ) : <EOL> references = [ ] <EOL> if project . dependencies : <EOL> group = [ '<STR_LIT>' ] <EOL> for dependency in project . dependencies : <EOL> guid = dependency . guid <EOL> project_dir = os . path . split ( project . path ) [ <NUM_LIT:0> ] <EOL> relative_path = gyp . common . RelativePath ( dependency . path , project_dir ) <EOL> project_ref = [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : relative_path } , <EOL> [ '<STR_LIT>' , guid ] , <EOL> [ '<STR_LIT>' , '<STR_LIT:false>' ] <EOL> ] <EOL> for config in dependency . spec . get ( '<STR_LIT>' , { } ) . itervalues ( ) : <EOL> if config . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> project_ref . append ( [ '<STR_LIT>' , '<STR_LIT:false>' ] ) <EOL> break <EOL> group . append ( project_ref ) <EOL> references . append ( group ) <EOL> return references <EOL> def _GenerateMSBuildProject ( project , options , version , generator_flags ) : <EOL> spec = project . spec <EOL> configurations = spec [ '<STR_LIT>' ] <EOL> project_dir , project_file_name = os . path . split ( project . path ) <EOL> gyp . common . EnsureDirExists ( project . path ) <EOL> gyp_path = _NormalizedSource ( project . build_file ) <EOL> relative_path_of_gyp_file = gyp . common . RelativePath ( gyp_path , project_dir ) <EOL> gyp_file = os . path . split ( project . build_file ) [ <NUM_LIT:1> ] <EOL> sources , excluded_sources = _PrepareListOfSources ( spec , generator_flags , <EOL> gyp_file ) <EOL> actions_to_add = { } <EOL> props_files_of_rules = set ( ) <EOL> targets_files_of_rules = set ( ) <EOL> rule_dependencies = set ( ) <EOL> extension_to_rule_name = { } <EOL> list_excluded = generator_flags . get ( '<STR_LIT>' , True ) <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> _GenerateRulesForMSBuild ( project_dir , options , spec , <EOL> sources , excluded_sources , <EOL> props_files_of_rules , targets_files_of_rules , <EOL> actions_to_add , rule_dependencies , <EOL> extension_to_rule_name ) <EOL> else : <EOL> rules = spec . get ( '<STR_LIT>' , [ ] ) <EOL> _AdjustSourcesForRules ( rules , sources , excluded_sources , True ) <EOL> sources , excluded_sources , excluded_idl = ( <EOL> _AdjustSourcesAndConvertToFilterHierarchy ( spec , options , <EOL> project_dir , sources , <EOL> excluded_sources , <EOL> list_excluded , version ) ) <EOL> if not spec . get ( '<STR_LIT>' ) : <EOL> _AddActions ( actions_to_add , spec , project . build_file ) <EOL> _AddCopies ( actions_to_add , spec ) <EOL> excluded_sources = _FilterActionsFromExcluded ( <EOL> excluded_sources , actions_to_add ) <EOL> exclusions = _GetExcludedFilesFromBuild ( spec , excluded_sources , excluded_idl ) <EOL> actions_spec , sources_handled_by_action = _GenerateActionsForMSBuild ( <EOL> spec , actions_to_add ) <EOL> _GenerateMSBuildFiltersFile ( project . path + '<STR_LIT>' , sources , <EOL> rule_dependencies , <EOL> extension_to_rule_name ) <EOL> missing_sources = _VerifySourcesExist ( sources , project_dir ) <EOL> for configuration in configurations . itervalues ( ) : <EOL> _FinalizeMSBuildSettings ( spec , configuration ) <EOL> import_default_section = [ <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : r'<STR_LIT>' } ] ] <EOL> import_cpp_props_section = [ <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : r'<STR_LIT>' } ] ] <EOL> import_cpp_targets_section = [ <EOL> [ '<STR_LIT>' , { '<STR_LIT>' : r'<STR_LIT>' } ] ] <EOL> import_masm_props_section = [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : r'<STR_LIT>' } ] ] <EOL> import_masm_targets_section = [ <EOL> [ '<STR_LIT>' , <EOL> { '<STR_LIT>' : r'<STR_LIT>' } ] ] <EOL> macro_section = [ [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ] ] <EOL> content = [ <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : version . ProjectVersion ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> content += _GetMSBuildProjectConfigurations ( configurations ) <EOL> content += _GetMSBuildGlobalProperties ( spec , project . guid , project_file_name ) <EOL> content += import_default_section <EOL> content += _GetMSBuildConfigurationDetails ( spec , project . build_file ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> content += _GetMSBuildLocalProperties ( '<STR_LIT>' ) <EOL> else : <EOL> content += _GetMSBuildLocalProperties ( project . msbuild_toolset ) <EOL> content += import_cpp_props_section <EOL> content += import_masm_props_section <EOL> content += _GetMSBuildExtensions ( props_files_of_rules ) <EOL> content += _GetMSBuildPropertySheets ( configurations ) <EOL> content += macro_section <EOL> content += _GetMSBuildConfigurationGlobalProperties ( spec , configurations , <EOL> project . build_file ) <EOL> content += _GetMSBuildToolSettingsSections ( spec , configurations ) <EOL> content += _GetMSBuildSources ( <EOL> spec , sources , exclusions , rule_dependencies , extension_to_rule_name , <EOL> actions_spec , sources_handled_by_action , list_excluded ) <EOL> content += _GetMSBuildProjectReferences ( project ) <EOL> content += import_cpp_targets_section <EOL> content += import_masm_targets_section <EOL> content += _GetMSBuildExtensionTargets ( targets_files_of_rules ) <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> content += _GetMSBuildExternalBuilderTargets ( spec ) <EOL> easy_xml . WriteXmlIfChanged ( content , project . path , pretty = True , win32 = True ) <EOL> return missing_sources <EOL> def _GetMSBuildExternalBuilderTargets ( spec ) : <EOL> """<STR_LIT>""" <EOL> build_cmd = _BuildCommandLineForRuleRaw ( <EOL> spec , spec [ '<STR_LIT>' ] , <EOL> False , False , False , False ) <EOL> build_target = [ '<STR_LIT>' , { '<STR_LIT:Name>' : '<STR_LIT>' } ] <EOL> build_target . append ( [ '<STR_LIT>' , { '<STR_LIT>' : build_cmd } ] ) <EOL> clean_cmd = _BuildCommandLineForRuleRaw ( <EOL> spec , spec [ '<STR_LIT>' ] , <EOL> False , False , False , False ) <EOL> clean_target = [ '<STR_LIT>' , { '<STR_LIT:Name>' : '<STR_LIT>' } ] <EOL> clean_target . append ( [ '<STR_LIT>' , { '<STR_LIT>' : clean_cmd } ] ) <EOL> targets = [ build_target , clean_target ] <EOL> if spec . get ( '<STR_LIT>' ) : <EOL> clcompile_cmd = _BuildCommandLineForRuleRaw ( <EOL> spec , spec [ '<STR_LIT>' ] , <EOL> False , False , False , False ) <EOL> clcompile_target = [ '<STR_LIT>' , { '<STR_LIT:Name>' : '<STR_LIT>' } ] <EOL> clcompile_target . append ( [ '<STR_LIT>' , { '<STR_LIT>' : clcompile_cmd } ] ) <EOL> targets . append ( clcompile_target ) <EOL> return targets <EOL> def _GetMSBuildExtensions ( props_files_of_rules ) : <EOL> extensions = [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> for props_file in props_files_of_rules : <EOL> extensions . append ( [ '<STR_LIT>' , { '<STR_LIT>' : props_file } ] ) <EOL> return [ extensions ] <EOL> def _GetMSBuildExtensionTargets ( targets_files_of_rules ) : <EOL> targets_node = [ '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> for targets_file in sorted ( targets_files_of_rules ) : <EOL> targets_node . append ( [ '<STR_LIT>' , { '<STR_LIT>' : targets_file } ] ) <EOL> return [ targets_node ] <EOL> def _GenerateActionsForMSBuild ( spec , actions_to_add ) : <EOL> """<STR_LIT>""" <EOL> sources_handled_by_action = OrderedSet ( ) <EOL> actions_spec = [ ] <EOL> for primary_input , actions in actions_to_add . iteritems ( ) : <EOL> inputs = OrderedSet ( ) <EOL> outputs = OrderedSet ( ) <EOL> descriptions = [ ] <EOL> commands = [ ] <EOL> for action in actions : <EOL> inputs . update ( OrderedSet ( action [ '<STR_LIT>' ] ) ) <EOL> outputs . update ( OrderedSet ( action [ '<STR_LIT>' ] ) ) <EOL> descriptions . append ( action [ '<STR_LIT:description>' ] ) <EOL> cmd = action [ '<STR_LIT>' ] <EOL> if action . get ( '<STR_LIT>' , True ) : <EOL> cmd = '<STR_LIT>' + cmd <EOL> commands . append ( cmd ) <EOL> description = '<STR_LIT>' . join ( descriptions ) <EOL> command = '<STR_LIT:\r\n>' . join ( [ c + '<STR_LIT>' <EOL> for c in commands ] ) <EOL> _AddMSBuildAction ( spec , <EOL> primary_input , <EOL> inputs , <EOL> outputs , <EOL> command , <EOL> description , <EOL> sources_handled_by_action , <EOL> actions_spec ) <EOL> return actions_spec , sources_handled_by_action <EOL> def _AddMSBuildAction ( spec , primary_input , inputs , outputs , cmd , description , <EOL> sources_handled_by_action , actions_spec ) : <EOL> command = MSVSSettings . ConvertVCMacrosToMSBuild ( cmd ) <EOL> primary_input = _FixPath ( primary_input ) <EOL> inputs_array = _FixPaths ( inputs ) <EOL> outputs_array = _FixPaths ( outputs ) <EOL> additional_inputs = '<STR_LIT:;>' . join ( [ i for i in inputs_array <EOL> if i != primary_input ] ) <EOL> outputs = '<STR_LIT:;>' . join ( outputs_array ) <EOL> sources_handled_by_action . add ( primary_input ) <EOL> action_spec = [ '<STR_LIT>' , { '<STR_LIT>' : primary_input } ] <EOL> action_spec . extend ( <EOL> [ [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , command ] , <EOL> [ '<STR_LIT>' , description ] , <EOL> [ '<STR_LIT>' , outputs ] <EOL> ] ) <EOL> if additional_inputs : <EOL> action_spec . append ( [ '<STR_LIT>' , additional_inputs ] ) <EOL> actions_spec . append ( action_spec ) </s>
