<s> from compiler . ast import Const <EOL> from compiler . ast import Dict <EOL> from compiler . ast import Discard <EOL> from compiler . ast import List <EOL> from compiler . ast import Module <EOL> from compiler . ast import Node <EOL> from compiler . ast import Stmt <EOL> import compiler <EOL> import gyp . common <EOL> import gyp . simple_copy <EOL> import multiprocessing <EOL> import optparse <EOL> import os . path <EOL> import re <EOL> import shlex <EOL> import signal <EOL> import subprocess <EOL> import sys <EOL> import threading <EOL> import time <EOL> import traceback <EOL> from gyp . common import GypError <EOL> from gyp . common import OrderedSet <EOL> linkable_types = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> dependency_sections = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> base_path_sections = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> path_sections = set ( ) <EOL> per_process_data = { } <EOL> per_process_aux_data = { } <EOL> def IsPathSection ( section ) : <EOL> while section and section [ - <NUM_LIT:1> : ] in '<STR_LIT>' : <EOL> section = section [ : - <NUM_LIT:1> ] <EOL> if section in path_sections : <EOL> return True <EOL> if "<STR_LIT:_>" in section : <EOL> tail = section [ - <NUM_LIT:6> : ] <EOL> if tail [ - <NUM_LIT:1> ] == '<STR_LIT:s>' : <EOL> tail = tail [ : - <NUM_LIT:1> ] <EOL> if tail [ - <NUM_LIT:5> : ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return True <EOL> return tail [ - <NUM_LIT:4> : ] == '<STR_LIT>' <EOL> return False <EOL> base_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> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:type>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> non_configuration_keys = [ ] <EOL> invalid_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:type>' , <EOL> ] <EOL> multiple_toolsets = False <EOL> generator_filelist_paths = None <EOL> def GetIncludedBuildFiles ( build_file_path , aux_data , included = None ) : <EOL> """<STR_LIT>""" <EOL> if included == None : <EOL> included = [ ] <EOL> if build_file_path in included : <EOL> return included <EOL> included . append ( build_file_path ) <EOL> for included_build_file in aux_data [ build_file_path ] . get ( '<STR_LIT>' , [ ] ) : <EOL> GetIncludedBuildFiles ( included_build_file , aux_data , included ) <EOL> return included <EOL> def CheckedEval ( file_contents ) : <EOL> """<STR_LIT>""" <EOL> ast = compiler . parse ( file_contents ) <EOL> assert isinstance ( ast , Module ) <EOL> c1 = ast . getChildren ( ) <EOL> assert c1 [ <NUM_LIT:0> ] is None <EOL> assert isinstance ( c1 [ <NUM_LIT:1> ] , Stmt ) <EOL> c2 = c1 [ <NUM_LIT:1> ] . getChildren ( ) <EOL> assert isinstance ( c2 [ <NUM_LIT:0> ] , Discard ) <EOL> c3 = c2 [ <NUM_LIT:0> ] . getChildren ( ) <EOL> assert len ( c3 ) == <NUM_LIT:1> <EOL> return CheckNode ( c3 [ <NUM_LIT:0> ] , [ ] ) <EOL> def CheckNode ( node , keypath ) : <EOL> if isinstance ( node , Dict ) : <EOL> c = node . getChildren ( ) <EOL> dict = { } <EOL> for n in range ( <NUM_LIT:0> , len ( c ) , <NUM_LIT:2> ) : <EOL> assert isinstance ( c [ n ] , Const ) <EOL> key = c [ n ] . getChildren ( ) [ <NUM_LIT:0> ] <EOL> if key in dict : <EOL> raise GypError ( "<STR_LIT>" + key + "<STR_LIT>" + <EOL> repr ( len ( keypath ) + <NUM_LIT:1> ) + "<STR_LIT>" + <EOL> '<STR_LIT:.>' . join ( keypath ) + "<STR_LIT:'>" ) <EOL> kp = list ( keypath ) <EOL> kp . append ( key ) <EOL> dict [ key ] = CheckNode ( c [ n + <NUM_LIT:1> ] , kp ) <EOL> return dict <EOL> elif isinstance ( node , List ) : <EOL> c = node . getChildren ( ) <EOL> children = [ ] <EOL> for index , child in enumerate ( c ) : <EOL> kp = list ( keypath ) <EOL> kp . append ( repr ( index ) ) <EOL> children . append ( CheckNode ( child , kp ) ) <EOL> return children <EOL> elif isinstance ( node , Const ) : <EOL> return node . getChildren ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" + '<STR_LIT:.>' . join ( keypath ) + <EOL> "<STR_LIT>" + repr ( node ) ) <EOL> def LoadOneBuildFile ( build_file_path , data , aux_data , includes , <EOL> is_target , check ) : <EOL> if build_file_path in data : <EOL> return data [ build_file_path ] <EOL> if os . path . exists ( build_file_path ) : <EOL> build_file_contents = open ( build_file_path ) . read ( ) <EOL> else : <EOL> raise GypError ( "<STR_LIT>" % ( build_file_path , os . getcwd ( ) ) ) <EOL> build_file_data = None <EOL> try : <EOL> if check : <EOL> build_file_data = CheckedEval ( build_file_contents ) <EOL> else : <EOL> build_file_data = eval ( build_file_contents , { '<STR_LIT>' : None } , <EOL> None ) <EOL> except SyntaxError , e : <EOL> e . filename = build_file_path <EOL> raise <EOL> except Exception , e : <EOL> gyp . common . ExceptionAppend ( e , '<STR_LIT>' + build_file_path ) <EOL> raise <EOL> if type ( build_file_data ) is not dict : <EOL> raise GypError ( "<STR_LIT>" % build_file_path ) <EOL> data [ build_file_path ] = build_file_data <EOL> aux_data [ build_file_path ] = { } <EOL> if ( '<STR_LIT>' not in build_file_data or <EOL> not build_file_data [ '<STR_LIT>' ] ) : <EOL> try : <EOL> if is_target : <EOL> LoadBuildFileIncludesIntoDict ( build_file_data , build_file_path , data , <EOL> aux_data , includes , check ) <EOL> else : <EOL> LoadBuildFileIncludesIntoDict ( build_file_data , build_file_path , data , <EOL> aux_data , None , check ) <EOL> except Exception , e : <EOL> gyp . common . ExceptionAppend ( e , <EOL> '<STR_LIT>' + build_file_path ) <EOL> raise <EOL> return build_file_data <EOL> def LoadBuildFileIncludesIntoDict ( subdict , subdict_path , data , aux_data , <EOL> includes , check ) : <EOL> includes_list = [ ] <EOL> if includes != None : <EOL> includes_list . extend ( includes ) <EOL> if '<STR_LIT>' in subdict : <EOL> for include in subdict [ '<STR_LIT>' ] : <EOL> relative_include = os . path . normpath ( os . path . join ( os . path . dirname ( subdict_path ) , include ) ) <EOL> includes_list . append ( relative_include ) <EOL> del subdict [ '<STR_LIT>' ] <EOL> for include in includes_list : <EOL> if not '<STR_LIT>' in aux_data [ subdict_path ] : <EOL> aux_data [ subdict_path ] [ '<STR_LIT>' ] = [ ] <EOL> aux_data [ subdict_path ] [ '<STR_LIT>' ] . append ( include ) <EOL> gyp . DebugOutput ( gyp . DEBUG_INCLUDES , "<STR_LIT>" , include ) <EOL> MergeDicts ( subdict , <EOL> LoadOneBuildFile ( include , data , aux_data , None , False , check ) , <EOL> subdict_path , include ) <EOL> for k , v in subdict . iteritems ( ) : <EOL> if type ( v ) is dict : <EOL> LoadBuildFileIncludesIntoDict ( v , subdict_path , data , aux_data , <EOL> None , check ) <EOL> elif type ( v ) is list : <EOL> LoadBuildFileIncludesIntoList ( v , subdict_path , data , aux_data , <EOL> check ) <EOL> def LoadBuildFileIncludesIntoList ( sublist , sublist_path , data , aux_data , check ) : <EOL> for item in sublist : <EOL> if type ( item ) is dict : <EOL> LoadBuildFileIncludesIntoDict ( item , sublist_path , data , aux_data , <EOL> None , check ) <EOL> elif type ( item ) is list : <EOL> LoadBuildFileIncludesIntoList ( item , sublist_path , data , aux_data , check ) <EOL> def ProcessToolsetsInDict ( data ) : <EOL> if '<STR_LIT>' in data : <EOL> target_list = data [ '<STR_LIT>' ] <EOL> new_target_list = [ ] <EOL> for target in target_list : <EOL> if '<STR_LIT>' in target and '<STR_LIT>' not in target : <EOL> new_target_list . append ( target ) <EOL> continue <EOL> if multiple_toolsets : <EOL> toolsets = target . get ( '<STR_LIT>' , [ '<STR_LIT:target>' ] ) <EOL> else : <EOL> toolsets = [ '<STR_LIT:target>' ] <EOL> if '<STR_LIT>' in target : <EOL> del target [ '<STR_LIT>' ] <EOL> if len ( toolsets ) > <NUM_LIT:0> : <EOL> for build in toolsets [ <NUM_LIT:1> : ] : <EOL> new_target = gyp . simple_copy . deepcopy ( target ) <EOL> new_target [ '<STR_LIT>' ] = build <EOL> new_target_list . append ( new_target ) <EOL> target [ '<STR_LIT>' ] = toolsets [ <NUM_LIT:0> ] <EOL> new_target_list . append ( target ) <EOL> data [ '<STR_LIT>' ] = new_target_list <EOL> if '<STR_LIT>' in data : <EOL> for condition in data [ '<STR_LIT>' ] : <EOL> if type ( condition ) is list : <EOL> for condition_dict in condition [ <NUM_LIT:1> : ] : <EOL> if type ( condition_dict ) is dict : <EOL> ProcessToolsetsInDict ( condition_dict ) <EOL> def LoadTargetBuildFile ( build_file_path , data , aux_data , variables , includes , <EOL> depth , check , load_dependencies ) : <EOL> if depth : <EOL> d = gyp . common . RelativePath ( depth , os . path . dirname ( build_file_path ) ) <EOL> if d == '<STR_LIT>' : <EOL> variables [ '<STR_LIT>' ] = '<STR_LIT:.>' <EOL> else : <EOL> variables [ '<STR_LIT>' ] = d . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> if '<STR_LIT>' in data : <EOL> if build_file_path in data [ '<STR_LIT>' ] : <EOL> return False <EOL> data [ '<STR_LIT>' ] . add ( build_file_path ) <EOL> gyp . DebugOutput ( gyp . DEBUG_INCLUDES , <EOL> "<STR_LIT>" , build_file_path ) <EOL> build_file_data = LoadOneBuildFile ( build_file_path , data , aux_data , <EOL> includes , True , check ) <EOL> build_file_data [ '<STR_LIT>' ] = depth <EOL> if '<STR_LIT>' in build_file_data : <EOL> raise GypError ( build_file_path + '<STR_LIT>' ) <EOL> included = GetIncludedBuildFiles ( build_file_path , aux_data ) <EOL> build_file_data [ '<STR_LIT>' ] = [ ] <EOL> for included_file in included : <EOL> included_relative = gyp . common . RelativePath ( included_file , <EOL> os . path . dirname ( build_file_path ) ) <EOL> build_file_data [ '<STR_LIT>' ] . append ( included_relative ) <EOL> ProcessToolsetsInDict ( build_file_data ) <EOL> ProcessVariablesAndConditionsInDict ( <EOL> build_file_data , PHASE_EARLY , variables , build_file_path ) <EOL> ProcessToolsetsInDict ( build_file_data ) <EOL> if '<STR_LIT>' in build_file_data : <EOL> if '<STR_LIT>' not in build_file_data : <EOL> raise GypError ( "<STR_LIT>" % <EOL> build_file_path ) <EOL> index = <NUM_LIT:0> <EOL> while index < len ( build_file_data [ '<STR_LIT>' ] ) : <EOL> old_target_dict = build_file_data [ '<STR_LIT>' ] [ index ] <EOL> new_target_dict = gyp . simple_copy . deepcopy ( <EOL> build_file_data [ '<STR_LIT>' ] ) <EOL> MergeDicts ( new_target_dict , old_target_dict , <EOL> build_file_path , build_file_path ) <EOL> build_file_data [ '<STR_LIT>' ] [ index ] = new_target_dict <EOL> index += <NUM_LIT:1> <EOL> del build_file_data [ '<STR_LIT>' ] <EOL> dependencies = [ ] <EOL> if '<STR_LIT>' in build_file_data : <EOL> for target_dict in build_file_data [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' not in target_dict : <EOL> continue <EOL> for dependency in target_dict [ '<STR_LIT>' ] : <EOL> dependencies . append ( <EOL> gyp . common . ResolveTarget ( build_file_path , dependency , None ) [ <NUM_LIT:0> ] ) <EOL> if load_dependencies : <EOL> for dependency in dependencies : <EOL> try : <EOL> LoadTargetBuildFile ( dependency , data , aux_data , variables , <EOL> includes , depth , check , load_dependencies ) <EOL> except Exception , e : <EOL> gyp . common . ExceptionAppend ( <EOL> e , '<STR_LIT>' % build_file_path ) <EOL> raise <EOL> else : <EOL> return ( build_file_path , dependencies ) <EOL> def CallLoadTargetBuildFile ( global_flags , <EOL> build_file_path , variables , <EOL> includes , depth , check , <EOL> generator_input_info ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> signal . signal ( signal . SIGINT , signal . SIG_IGN ) <EOL> for key , value in global_flags . iteritems ( ) : <EOL> globals ( ) [ key ] = value <EOL> SetGeneratorGlobals ( generator_input_info ) <EOL> result = LoadTargetBuildFile ( build_file_path , per_process_data , <EOL> per_process_aux_data , variables , <EOL> includes , depth , check , False ) <EOL> if not result : <EOL> return result <EOL> ( build_file_path , dependencies ) = result <EOL> build_file_data = per_process_data . pop ( build_file_path ) <EOL> return ( build_file_path , <EOL> build_file_data , <EOL> dependencies ) <EOL> except GypError , e : <EOL> sys . stderr . write ( "<STR_LIT>" % e ) <EOL> return None <EOL> except Exception , e : <EOL> print >> sys . stderr , '<STR_LIT>' , e <EOL> print >> sys . stderr , traceback . format_exc ( ) <EOL> return None <EOL> class ParallelProcessingError ( Exception ) : <EOL> pass <EOL> class ParallelState ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . pool = None <EOL> self . condition = None <EOL> self . data = None <EOL> self . pending = <NUM_LIT:0> <EOL> self . scheduled = set ( ) <EOL> self . dependencies = [ ] <EOL> self . error = False <EOL> def LoadTargetBuildFileCallback ( self , result ) : <EOL> """<STR_LIT>""" <EOL> self . condition . acquire ( ) <EOL> if not result : <EOL> self . error = True <EOL> self . condition . notify ( ) <EOL> self . condition . release ( ) <EOL> return <EOL> ( build_file_path0 , build_file_data0 , dependencies0 ) = result <EOL> self . data [ build_file_path0 ] = build_file_data0 <EOL> self . data [ '<STR_LIT>' ] . add ( build_file_path0 ) <EOL> for new_dependency in dependencies0 : <EOL> if new_dependency not in self . scheduled : <EOL> self . scheduled . add ( new_dependency ) <EOL> self . dependencies . append ( new_dependency ) <EOL> self . pending -= <NUM_LIT:1> <EOL> self . condition . notify ( ) <EOL> self . condition . release ( ) <EOL> def LoadTargetBuildFilesParallel ( build_files , data , variables , includes , depth , <EOL> check , generator_input_info ) : <EOL> parallel_state = ParallelState ( ) <EOL> parallel_state . condition = threading . Condition ( ) <EOL> parallel_state . dependencies = list ( build_files ) <EOL> parallel_state . scheduled = set ( build_files ) <EOL> parallel_state . pending = <NUM_LIT:0> <EOL> parallel_state . data = data <EOL> try : <EOL> parallel_state . condition . acquire ( ) <EOL> while parallel_state . dependencies or parallel_state . pending : <EOL> if parallel_state . error : <EOL> break <EOL> if not parallel_state . dependencies : <EOL> parallel_state . condition . wait ( ) <EOL> continue <EOL> dependency = parallel_state . dependencies . pop ( ) <EOL> parallel_state . pending += <NUM_LIT:1> <EOL> global_flags = { <EOL> '<STR_LIT>' : globals ( ) [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : globals ( ) [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : globals ( ) [ '<STR_LIT>' ] } <EOL> if not parallel_state . pool : <EOL> parallel_state . pool = multiprocessing . Pool ( multiprocessing . cpu_count ( ) ) <EOL> parallel_state . pool . apply_async ( <EOL> CallLoadTargetBuildFile , <EOL> args = ( global_flags , dependency , <EOL> variables , includes , depth , check , generator_input_info ) , <EOL> callback = parallel_state . LoadTargetBuildFileCallback ) <EOL> except KeyboardInterrupt , e : <EOL> parallel_state . pool . terminate ( ) <EOL> raise e <EOL> parallel_state . condition . release ( ) <EOL> parallel_state . pool . close ( ) <EOL> parallel_state . pool . join ( ) <EOL> parallel_state . pool = None <EOL> if parallel_state . error : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> LBRACKETS = set ( '<STR_LIT>' ) <EOL> BRACKETS = { '<STR_LIT:}>' : '<STR_LIT:{>' , '<STR_LIT:]>' : '<STR_LIT:[>' , '<STR_LIT:)>' : '<STR_LIT:(>' } <EOL> def FindEnclosingBracketGroup ( input_str ) : <EOL> stack = [ ] <EOL> start = - <NUM_LIT:1> <EOL> for index , char in enumerate ( input_str ) : <EOL> if char in LBRACKETS : <EOL> stack . append ( char ) <EOL> if start == - <NUM_LIT:1> : <EOL> start = index <EOL> elif char in BRACKETS : <EOL> if not stack : <EOL> return ( - <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> if stack . pop ( ) != BRACKETS [ char ] : <EOL> return ( - <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> if not stack : <EOL> return ( start , index + <NUM_LIT:1> ) <EOL> return ( - <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> def IsStrCanonicalInt ( string ) : <EOL> """<STR_LIT>""" <EOL> if type ( string ) is str : <EOL> if string : <EOL> if string == "<STR_LIT:0>" : <EOL> return True <EOL> if string [ <NUM_LIT:0> ] == "<STR_LIT:->" : <EOL> string = string [ <NUM_LIT:1> : ] <EOL> if not string : <EOL> return False <EOL> if '<STR_LIT:1>' <= string [ <NUM_LIT:0> ] <= '<STR_LIT>' : <EOL> return string . isdigit ( ) <EOL> return False <EOL> early_variable_re = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> late_variable_re = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> latelate_variable_re = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> cached_command_results = { } <EOL> def FixupPlatformCommand ( cmd ) : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> if type ( cmd ) is list : <EOL> cmd = [ re . sub ( '<STR_LIT>' , '<STR_LIT>' , cmd [ <NUM_LIT:0> ] ) ] + cmd [ <NUM_LIT:1> : ] <EOL> else : <EOL> cmd = re . sub ( '<STR_LIT>' , '<STR_LIT>' , cmd ) <EOL> return cmd <EOL> PHASE_EARLY = <NUM_LIT:0> <EOL> PHASE_LATE = <NUM_LIT:1> <EOL> PHASE_LATELATE = <NUM_LIT:2> <EOL> def ExpandVariables ( input , phase , variables , build_file ) : <EOL> if phase == PHASE_EARLY : <EOL> variable_re = early_variable_re <EOL> expansion_symbol = '<STR_LIT:<>' <EOL> elif phase == PHASE_LATE : <EOL> variable_re = late_variable_re <EOL> expansion_symbol = '<STR_LIT:>>' <EOL> elif phase == PHASE_LATELATE : <EOL> variable_re = latelate_variable_re <EOL> expansion_symbol = '<STR_LIT>' <EOL> else : <EOL> assert False <EOL> input_str = str ( input ) <EOL> if IsStrCanonicalInt ( input_str ) : <EOL> return int ( input_str ) <EOL> if expansion_symbol not in input_str : <EOL> return input_str <EOL> matches = list ( variable_re . finditer ( input_str ) ) <EOL> if not matches : <EOL> return input_str <EOL> output = input_str <EOL> matches . reverse ( ) <EOL> for match_group in matches : <EOL> match = match_group . groupdict ( ) <EOL> gyp . DebugOutput ( gyp . DEBUG_VARIABLES , "<STR_LIT>" , match ) <EOL> run_command = '<STR_LIT:!>' in match [ '<STR_LIT:type>' ] <EOL> command_string = match [ '<STR_LIT>' ] <EOL> file_list = '<STR_LIT:|>' in match [ '<STR_LIT:type>' ] <EOL> replace_start = match_group . start ( '<STR_LIT:replace>' ) <EOL> replace_end = match_group . end ( '<STR_LIT:replace>' ) <EOL> ( c_start , c_end ) = FindEnclosingBracketGroup ( input_str [ replace_start : ] ) <EOL> replace_end = replace_start + c_end <EOL> replacement = input_str [ replace_start : replace_end ] <EOL> contents_start = replace_start + c_start + <NUM_LIT:1> <EOL> contents_end = replace_end - <NUM_LIT:1> <EOL> contents = input_str [ contents_start : contents_end ] <EOL> if file_list : <EOL> processed_variables = gyp . simple_copy . deepcopy ( variables ) <EOL> ProcessListFiltersInDict ( contents , processed_variables ) <EOL> contents = ExpandVariables ( contents , phase , <EOL> processed_variables , build_file ) <EOL> else : <EOL> contents = ExpandVariables ( contents , phase , variables , build_file ) <EOL> contents = contents . strip ( ) <EOL> expand_to_list = '<STR_LIT:@>' in match [ '<STR_LIT:type>' ] and input_str == replacement <EOL> if run_command or file_list : <EOL> build_file_dir = os . path . dirname ( build_file ) <EOL> if build_file_dir == '<STR_LIT>' and not file_list : <EOL> build_file_dir = None <EOL> if file_list : <EOL> if type ( contents ) is list : <EOL> contents_list = contents <EOL> else : <EOL> contents_list = contents . split ( '<STR_LIT:U+0020>' ) <EOL> replacement = contents_list [ <NUM_LIT:0> ] <EOL> if os . path . isabs ( replacement ) : <EOL> raise GypError ( '<STR_LIT>' % replacement ) <EOL> if not generator_filelist_paths : <EOL> path = os . path . join ( build_file_dir , replacement ) <EOL> else : <EOL> if os . path . isabs ( build_file_dir ) : <EOL> toplevel = generator_filelist_paths [ '<STR_LIT>' ] <EOL> rel_build_file_dir = gyp . common . RelativePath ( build_file_dir , toplevel ) <EOL> else : <EOL> rel_build_file_dir = build_file_dir <EOL> qualified_out_dir = generator_filelist_paths [ '<STR_LIT>' ] <EOL> path = os . path . join ( qualified_out_dir , rel_build_file_dir , replacement ) <EOL> gyp . common . EnsureDirExists ( path ) <EOL> replacement = gyp . common . RelativePath ( path , build_file_dir ) <EOL> f = gyp . common . WriteOnDiff ( path ) <EOL> for i in contents_list [ <NUM_LIT:1> : ] : <EOL> f . write ( '<STR_LIT>' % i ) <EOL> f . close ( ) <EOL> elif run_command : <EOL> use_shell = True <EOL> if match [ '<STR_LIT>' ] : <EOL> contents = eval ( contents ) <EOL> use_shell = False <EOL> cache_key = ( str ( contents ) , build_file_dir ) <EOL> cached_value = cached_command_results . get ( cache_key , None ) <EOL> if cached_value is None : <EOL> gyp . DebugOutput ( gyp . DEBUG_VARIABLES , <EOL> "<STR_LIT>" , <EOL> contents , build_file_dir ) <EOL> replacement = '<STR_LIT>' <EOL> if command_string == '<STR_LIT>' : <EOL> oldwd = os . getcwd ( ) <EOL> if build_file_dir : <EOL> os . chdir ( build_file_dir ) <EOL> try : <EOL> parsed_contents = shlex . split ( contents ) <EOL> try : <EOL> py_module = __import__ ( parsed_contents [ <NUM_LIT:0> ] ) <EOL> except ImportError as e : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( parsed_contents [ <NUM_LIT:0> ] , e ) ) <EOL> replacement = str ( py_module . DoMain ( parsed_contents [ <NUM_LIT:1> : ] ) ) . rstrip ( ) <EOL> finally : <EOL> os . chdir ( oldwd ) <EOL> assert replacement != None <EOL> elif command_string : <EOL> raise GypError ( "<STR_LIT>" % <EOL> ( command_string , contents ) ) <EOL> else : <EOL> contents = FixupPlatformCommand ( contents ) <EOL> try : <EOL> p = subprocess . Popen ( contents , shell = use_shell , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stdin = subprocess . PIPE , <EOL> cwd = build_file_dir ) <EOL> except Exception , e : <EOL> raise GypError ( "<STR_LIT>" % <EOL> ( e , contents , build_file ) ) <EOL> p_stdout , p_stderr = p . communicate ( '<STR_LIT>' ) <EOL> if p . wait ( ) != <NUM_LIT:0> or p_stderr : <EOL> sys . stderr . write ( p_stderr ) <EOL> raise GypError ( "<STR_LIT>" % <EOL> ( contents , p . returncode , build_file ) ) <EOL> replacement = p_stdout . rstrip ( ) <EOL> cached_command_results [ cache_key ] = replacement <EOL> else : <EOL> gyp . DebugOutput ( gyp . DEBUG_VARIABLES , <EOL> "<STR_LIT>" , <EOL> contents , build_file_dir ) <EOL> replacement = cached_value <EOL> else : <EOL> if not contents in variables : <EOL> if contents [ - <NUM_LIT:1> ] in [ '<STR_LIT:!>' , '<STR_LIT:/>' ] : <EOL> replacement = [ ] <EOL> else : <EOL> raise GypError ( '<STR_LIT>' + contents + <EOL> '<STR_LIT>' + build_file ) <EOL> else : <EOL> replacement = variables [ contents ] <EOL> if type ( replacement ) is list : <EOL> for item in replacement : <EOL> if not contents [ - <NUM_LIT:1> ] == '<STR_LIT:/>' and type ( item ) not in ( str , int ) : <EOL> raise GypError ( '<STR_LIT>' + contents + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> item . __class__ . __name__ ) <EOL> ProcessVariablesAndConditionsInList ( replacement , phase , variables , <EOL> build_file ) <EOL> elif type ( replacement ) not in ( str , int ) : <EOL> raise GypError ( '<STR_LIT>' + contents + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + replacement . __class__ . __name__ ) <EOL> if expand_to_list : <EOL> if type ( replacement ) is list : <EOL> output = replacement [ : ] <EOL> else : <EOL> output = shlex . split ( str ( replacement ) ) <EOL> else : <EOL> encoded_replacement = '<STR_LIT>' <EOL> if type ( replacement ) is list : <EOL> encoded_replacement = gyp . common . EncodePOSIXShellList ( replacement ) <EOL> else : <EOL> encoded_replacement = replacement <EOL> output = output [ : replace_start ] + str ( encoded_replacement ) + output [ replace_end : ] <EOL> input_str = output <EOL> if output == input : <EOL> gyp . DebugOutput ( gyp . DEBUG_VARIABLES , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> output ) <EOL> else : <EOL> gyp . DebugOutput ( gyp . DEBUG_VARIABLES , "<STR_LIT>" , output ) <EOL> if type ( output ) is list : <EOL> if output and type ( output [ <NUM_LIT:0> ] ) is list : <EOL> pass <EOL> else : <EOL> new_output = [ ] <EOL> for item in output : <EOL> new_output . append ( <EOL> ExpandVariables ( item , phase , variables , build_file ) ) <EOL> output = new_output <EOL> else : <EOL> output = ExpandVariables ( output , phase , variables , build_file ) <EOL> if type ( output ) is list : <EOL> for index in xrange ( <NUM_LIT:0> , len ( output ) ) : <EOL> if IsStrCanonicalInt ( output [ index ] ) : <EOL> output [ index ] = int ( output [ index ] ) <EOL> elif IsStrCanonicalInt ( output ) : <EOL> output = int ( output ) <EOL> return output <EOL> cached_conditions_asts = { } <EOL> def EvalCondition ( condition , conditions_key , phase , variables , build_file ) : <EOL> """<STR_LIT>""" <EOL> if type ( condition ) is not list : <EOL> raise GypError ( conditions_key + '<STR_LIT>' ) <EOL> if len ( condition ) < <NUM_LIT:2> : <EOL> raise GypError ( conditions_key + '<STR_LIT:U+0020>' + condition [ <NUM_LIT:0> ] + <EOL> '<STR_LIT>' + str ( len ( condition ) ) ) <EOL> i = <NUM_LIT:0> <EOL> result = None <EOL> while i < len ( condition ) : <EOL> cond_expr = condition [ i ] <EOL> true_dict = condition [ i + <NUM_LIT:1> ] <EOL> if type ( true_dict ) is not dict : <EOL> raise GypError ( '<STR_LIT>' . format ( <EOL> conditions_key , cond_expr , type ( true_dict ) ) ) <EOL> if len ( condition ) > i + <NUM_LIT:2> and type ( condition [ i + <NUM_LIT:2> ] ) is dict : <EOL> false_dict = condition [ i + <NUM_LIT:2> ] <EOL> i = i + <NUM_LIT:3> <EOL> if i != len ( condition ) : <EOL> raise GypError ( '<STR_LIT>' . format ( <EOL> conditions_key , cond_expr , len ( condition ) - i ) ) <EOL> else : <EOL> false_dict = None <EOL> i = i + <NUM_LIT:2> <EOL> if result == None : <EOL> result = EvalSingleCondition ( <EOL> cond_expr , true_dict , false_dict , phase , variables , build_file ) <EOL> return result <EOL> def EvalSingleCondition ( <EOL> cond_expr , true_dict , false_dict , phase , variables , build_file ) : <EOL> """<STR_LIT>""" <EOL> cond_expr_expanded = ExpandVariables ( cond_expr , phase , variables , <EOL> build_file ) <EOL> if type ( cond_expr_expanded ) not in ( str , int ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' + '<STR_LIT>' + cond_expr_expanded . __class__ . __name__ ) <EOL> try : <EOL> if cond_expr_expanded in cached_conditions_asts : <EOL> ast_code = cached_conditions_asts [ cond_expr_expanded ] <EOL> else : <EOL> ast_code = compile ( cond_expr_expanded , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cached_conditions_asts [ cond_expr_expanded ] = ast_code <EOL> if eval ( ast_code , { '<STR_LIT>' : None } , variables ) : <EOL> return true_dict <EOL> return false_dict <EOL> except SyntaxError , e : <EOL> syntax_error = SyntaxError ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( str ( e . args [ <NUM_LIT:0> ] ) , e . text , build_file , e . offset ) , <EOL> e . filename , e . lineno , e . offset , e . text ) <EOL> raise syntax_error <EOL> except NameError , e : <EOL> gyp . common . ExceptionAppend ( e , '<STR_LIT>' % <EOL> ( cond_expr_expanded , build_file ) ) <EOL> raise GypError ( e ) <EOL> def ProcessConditionsInDict ( the_dict , phase , variables , build_file ) : <EOL> if phase == PHASE_EARLY : <EOL> conditions_key = '<STR_LIT>' <EOL> elif phase == PHASE_LATE : <EOL> conditions_key = '<STR_LIT>' <EOL> elif phase == PHASE_LATELATE : <EOL> return <EOL> else : <EOL> assert False <EOL> if not conditions_key in the_dict : <EOL> return <EOL> conditions_list = the_dict [ conditions_key ] <EOL> del the_dict [ conditions_key ] <EOL> for condition in conditions_list : <EOL> merge_dict = EvalCondition ( condition , conditions_key , phase , variables , <EOL> build_file ) <EOL> if merge_dict != None : <EOL> ProcessVariablesAndConditionsInDict ( merge_dict , phase , <EOL> variables , build_file ) <EOL> MergeDicts ( the_dict , merge_dict , build_file , build_file ) <EOL> def LoadAutomaticVariablesFromDict ( variables , the_dict ) : <EOL> for key , value in the_dict . iteritems ( ) : <EOL> if type ( value ) in ( str , int , list ) : <EOL> variables [ '<STR_LIT:_>' + key ] = value <EOL> def LoadVariablesFromVariablesDict ( variables , the_dict , the_dict_key ) : <EOL> for key , value in the_dict . get ( '<STR_LIT>' , { } ) . iteritems ( ) : <EOL> if type ( value ) not in ( str , int , list ) : <EOL> continue <EOL> if key . endswith ( '<STR_LIT:%>' ) : <EOL> variable_name = key [ : - <NUM_LIT:1> ] <EOL> if variable_name in variables : <EOL> continue <EOL> if the_dict_key is '<STR_LIT>' and variable_name in the_dict : <EOL> value = the_dict [ variable_name ] <EOL> else : <EOL> variable_name = key <EOL> variables [ variable_name ] = value <EOL> def ProcessVariablesAndConditionsInDict ( the_dict , phase , variables_in , <EOL> build_file , the_dict_key = None ) : <EOL> """<STR_LIT>""" <EOL> variables = variables_in . copy ( ) <EOL> LoadAutomaticVariablesFromDict ( variables , the_dict ) <EOL> if '<STR_LIT>' in the_dict : <EOL> for key , value in the_dict [ '<STR_LIT>' ] . iteritems ( ) : <EOL> variables [ key ] = value <EOL> ProcessVariablesAndConditionsInDict ( the_dict [ '<STR_LIT>' ] , phase , <EOL> variables , build_file , '<STR_LIT>' ) <EOL> LoadVariablesFromVariablesDict ( variables , the_dict , the_dict_key ) <EOL> for key , value in the_dict . iteritems ( ) : <EOL> if key != '<STR_LIT>' and type ( value ) is str : <EOL> expanded = ExpandVariables ( value , phase , variables , build_file ) <EOL> if type ( expanded ) not in ( str , int ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' + '<STR_LIT>' + expanded . __class__ . __name__ + '<STR_LIT>' + key ) <EOL> the_dict [ key ] = expanded <EOL> variables = variables_in . copy ( ) <EOL> LoadAutomaticVariablesFromDict ( variables , the_dict ) <EOL> LoadVariablesFromVariablesDict ( variables , the_dict , the_dict_key ) <EOL> ProcessConditionsInDict ( the_dict , phase , variables , build_file ) <EOL> variables = variables_in . copy ( ) <EOL> LoadAutomaticVariablesFromDict ( variables , the_dict ) <EOL> LoadVariablesFromVariablesDict ( variables , the_dict , the_dict_key ) <EOL> for key , value in the_dict . iteritems ( ) : <EOL> if key == '<STR_LIT>' or type ( value ) is str : <EOL> continue <EOL> if type ( value ) is dict : <EOL> ProcessVariablesAndConditionsInDict ( value , phase , variables , <EOL> build_file , key ) <EOL> elif type ( value ) is list : <EOL> ProcessVariablesAndConditionsInList ( value , phase , variables , <EOL> build_file ) <EOL> elif type ( value ) is not int : <EOL> raise TypeError ( '<STR_LIT>' + value . __class__ . __name__ + '<STR_LIT>' + key ) <EOL> def ProcessVariablesAndConditionsInList ( the_list , phase , variables , <EOL> build_file ) : <EOL> index = <NUM_LIT:0> <EOL> while index < len ( the_list ) : <EOL> item = the_list [ index ] <EOL> if type ( item ) is dict : <EOL> ProcessVariablesAndConditionsInDict ( item , phase , variables , build_file ) <EOL> elif type ( item ) is list : <EOL> ProcessVariablesAndConditionsInList ( item , phase , variables , build_file ) <EOL> elif type ( item ) is str : <EOL> expanded = ExpandVariables ( item , phase , variables , build_file ) <EOL> if type ( expanded ) in ( str , int ) : <EOL> the_list [ index ] = expanded <EOL> elif type ( expanded ) is list : <EOL> the_list [ index : index + <NUM_LIT:1> ] = expanded <EOL> index += len ( expanded ) <EOL> continue <EOL> else : <EOL> raise ValueError ( <EOL> '<STR_LIT>' + '<STR_LIT>' + expanded . __class__ . __name__ + '<STR_LIT>' + index ) <EOL> elif type ( item ) is not int : <EOL> raise TypeError ( '<STR_LIT>' + item . __class__ . __name__ + '<STR_LIT>' + index ) <EOL> index = index + <NUM_LIT:1> <EOL> def BuildTargetsDict ( data ) : <EOL> """<STR_LIT>""" <EOL> targets = { } <EOL> for build_file in data [ '<STR_LIT>' ] : <EOL> for target in data [ build_file ] . get ( '<STR_LIT>' , [ ] ) : <EOL> target_name = gyp . common . QualifiedTarget ( build_file , <EOL> target [ '<STR_LIT>' ] , <EOL> target [ '<STR_LIT>' ] ) <EOL> if target_name in targets : <EOL> raise GypError ( '<STR_LIT>' + target_name ) <EOL> targets [ target_name ] = target <EOL> return targets <EOL> def QualifyDependencies ( targets ) : <EOL> """<STR_LIT>""" <EOL> all_dependency_sections = [ dep + op <EOL> for dep in dependency_sections <EOL> for op in ( '<STR_LIT>' , '<STR_LIT:!>' , '<STR_LIT:/>' ) ] <EOL> for target , target_dict in targets . iteritems ( ) : <EOL> target_build_file = gyp . common . BuildFile ( target ) <EOL> toolset = target_dict [ '<STR_LIT>' ] <EOL> for dependency_key in all_dependency_sections : <EOL> dependencies = target_dict . get ( dependency_key , [ ] ) <EOL> for index in xrange ( <NUM_LIT:0> , len ( dependencies ) ) : <EOL> dep_file , dep_target , dep_toolset = gyp . common . ResolveTarget ( <EOL> target_build_file , dependencies [ index ] , toolset ) <EOL> if not multiple_toolsets : <EOL> dep_toolset = toolset <EOL> dependency = gyp . common . QualifiedTarget ( dep_file , <EOL> dep_target , <EOL> dep_toolset ) <EOL> dependencies [ index ] = dependency <EOL> if dependency_key != '<STR_LIT>' and dependency not in target_dict [ '<STR_LIT>' ] : <EOL> raise GypError ( '<STR_LIT>' + dependency + '<STR_LIT>' + dependency_key + <EOL> '<STR_LIT>' + target + '<STR_LIT>' ) <EOL> def ExpandWildcardDependencies ( targets , data ) : <EOL> """<STR_LIT>""" <EOL> for target , target_dict in targets . iteritems ( ) : <EOL> toolset = target_dict [ '<STR_LIT>' ] <EOL> target_build_file = gyp . common . BuildFile ( target ) <EOL> for dependency_key in dependency_sections : <EOL> dependencies = target_dict . get ( dependency_key , [ ] ) <EOL> index = <NUM_LIT:0> <EOL> while index < len ( dependencies ) : <EOL> ( dependency_build_file , dependency_target , dependency_toolset ) = gyp . common . ParseQualifiedTarget ( dependencies [ index ] ) <EOL> if dependency_target != '<STR_LIT:*>' and dependency_toolset != '<STR_LIT:*>' : <EOL> index = index + <NUM_LIT:1> <EOL> continue <EOL> if dependency_build_file == target_build_file : <EOL> raise GypError ( '<STR_LIT>' + dependency_key + '<STR_LIT>' + <EOL> target + '<STR_LIT>' ) <EOL> del dependencies [ index ] <EOL> index = index - <NUM_LIT:1> <EOL> dependency_target_dicts = data [ dependency_build_file ] [ '<STR_LIT>' ] <EOL> for dependency_target_dict in dependency_target_dicts : <EOL> if int ( dependency_target_dict . get ( '<STR_LIT>' , False ) ) : <EOL> continue <EOL> dependency_target_name = dependency_target_dict [ '<STR_LIT>' ] <EOL> if ( dependency_target != '<STR_LIT:*>' and <EOL> dependency_target != dependency_target_name ) : <EOL> continue <EOL> dependency_target_toolset = dependency_target_dict [ '<STR_LIT>' ] <EOL> if ( dependency_toolset != '<STR_LIT:*>' and <EOL> dependency_toolset != dependency_target_toolset ) : <EOL> continue <EOL> dependency = gyp . common . QualifiedTarget ( dependency_build_file , <EOL> dependency_target_name , <EOL> dependency_target_toolset ) <EOL> index = index + <NUM_LIT:1> <EOL> dependencies . insert ( index , dependency ) <EOL> index = index + <NUM_LIT:1> <EOL> def Unify ( l ) : <EOL> """<STR_LIT>""" <EOL> seen = { } <EOL> return [ seen . setdefault ( e , e ) for e in l if e not in seen ] <EOL> def RemoveDuplicateDependencies ( targets ) : <EOL> """<STR_LIT>""" <EOL> for target_name , target_dict in targets . iteritems ( ) : <EOL> for dependency_key in dependency_sections : <EOL> dependencies = target_dict . get ( dependency_key , [ ] ) <EOL> if dependencies : <EOL> target_dict [ dependency_key ] = Unify ( dependencies ) <EOL> def Filter ( l , item ) : <EOL> """<STR_LIT>""" <EOL> res = { } <EOL> return [ res . setdefault ( e , e ) for e in l if e != item ] <EOL> def RemoveSelfDependencies ( targets ) : <EOL> """<STR_LIT>""" <EOL> for target_name , target_dict in targets . iteritems ( ) : <EOL> for dependency_key in dependency_sections : <EOL> dependencies = target_dict . get ( dependency_key , [ ] ) <EOL> if dependencies : <EOL> for t in dependencies : <EOL> if t == target_name : <EOL> if targets [ t ] . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> target_dict [ dependency_key ] = Filter ( dependencies , target_name ) <EOL> def RemoveLinkDependenciesFromNoneTargets ( targets ) : <EOL> """<STR_LIT>""" <EOL> for target_name , target_dict in targets . iteritems ( ) : <EOL> for dependency_key in dependency_sections : <EOL> dependencies = target_dict . get ( dependency_key , [ ] ) <EOL> if dependencies : <EOL> for t in dependencies : <EOL> if target_dict . get ( '<STR_LIT:type>' , None ) == '<STR_LIT:none>' : <EOL> if targets [ t ] . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> target_dict [ dependency_key ] = Filter ( target_dict [ dependency_key ] , t ) <EOL> class DependencyGraphNode ( object ) : <EOL> """<STR_LIT>""" <EOL> class CircularException ( GypError ) : <EOL> pass <EOL> def __init__ ( self , ref ) : <EOL> self . ref = ref <EOL> self . dependencies = [ ] <EOL> self . dependents = [ ] <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . ref <EOL> def FlattenToList ( self ) : <EOL> flat_list = OrderedSet ( ) <EOL> in_degree_zeros = set ( self . dependents [ : ] ) <EOL> while in_degree_zeros : <EOL> node = in_degree_zeros . pop ( ) <EOL> flat_list . add ( node . ref ) <EOL> for node_dependent in node . dependents : <EOL> is_in_degree_zero = True <EOL> for node_dependent_dependency in node_dependent . dependencies : <EOL> if not node_dependent_dependency . ref in flat_list : <EOL> is_in_degree_zero = False <EOL> break <EOL> if is_in_degree_zero : <EOL> in_degree_zeros . add ( node_dependent ) <EOL> return list ( flat_list ) <EOL> def FindCycles ( self ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> visited = set ( ) <EOL> def Visit ( node , path ) : <EOL> for child in node . dependents : <EOL> if child in path : <EOL> results . append ( [ child ] + path [ : path . index ( child ) + <NUM_LIT:1> ] ) <EOL> elif not child in visited : <EOL> visited . add ( child ) <EOL> Visit ( child , [ child ] + path ) <EOL> visited . add ( self ) <EOL> Visit ( self , [ self ] ) <EOL> return results <EOL> def DirectDependencies ( self , dependencies = None ) : <EOL> """<STR_LIT>""" <EOL> if dependencies == None : <EOL> dependencies = [ ] <EOL> for dependency in self . dependencies : <EOL> if dependency . ref != None and dependency . ref not in dependencies : <EOL> dependencies . append ( dependency . ref ) <EOL> return dependencies <EOL> def _AddImportedDependencies ( self , targets , dependencies = None ) : <EOL> """<STR_LIT>""" <EOL> if dependencies == None : <EOL> dependencies = [ ] <EOL> index = <NUM_LIT:0> <EOL> while index < len ( dependencies ) : <EOL> dependency = dependencies [ index ] <EOL> dependency_dict = targets [ dependency ] <EOL> add_index = <NUM_LIT:1> <EOL> for imported_dependency in dependency_dict . get ( '<STR_LIT>' , [ ] ) : <EOL> if imported_dependency not in dependencies : <EOL> dependencies . insert ( index + add_index , imported_dependency ) <EOL> add_index = add_index + <NUM_LIT:1> <EOL> index = index + <NUM_LIT:1> <EOL> return dependencies <EOL> def DirectAndImportedDependencies ( self , targets , dependencies = None ) : <EOL> """<STR_LIT>""" <EOL> dependencies = self . DirectDependencies ( dependencies ) <EOL> return self . _AddImportedDependencies ( targets , dependencies ) <EOL> def DeepDependencies ( self , dependencies = None ) : <EOL> """<STR_LIT>""" <EOL> if dependencies is None : <EOL> dependencies = OrderedSet ( ) <EOL> for dependency in self . dependencies : <EOL> if dependency . ref is None : <EOL> continue <EOL> if dependency . ref not in dependencies : <EOL> dependency . DeepDependencies ( dependencies ) <EOL> dependencies . add ( dependency . ref ) <EOL> return dependencies <EOL> def _LinkDependenciesInternal ( self , targets , include_shared_libraries , <EOL> dependencies = None , initial = True ) : <EOL> """<STR_LIT>""" <EOL> if dependencies is None : <EOL> dependencies = OrderedSet ( ) <EOL> if self . ref is None : <EOL> return dependencies <EOL> if '<STR_LIT>' not in targets [ self . ref ] : <EOL> raise GypError ( "<STR_LIT>" ) <EOL> if '<STR_LIT:type>' not in targets [ self . ref ] : <EOL> raise GypError ( "<STR_LIT>" % <EOL> targets [ self . ref ] [ '<STR_LIT>' ] ) <EOL> target_type = targets [ self . ref ] [ '<STR_LIT:type>' ] <EOL> is_linkable = target_type in linkable_types <EOL> if initial and not is_linkable : <EOL> return dependencies <EOL> if ( target_type == '<STR_LIT:none>' and <EOL> not targets [ self . ref ] . get ( '<STR_LIT>' , True ) ) : <EOL> dependencies . add ( self . ref ) <EOL> return dependencies <EOL> if not initial and target_type in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> return dependencies <EOL> if ( not initial and target_type == '<STR_LIT>' and <EOL> not include_shared_libraries ) : <EOL> return dependencies <EOL> if self . ref not in dependencies : <EOL> dependencies . add ( self . ref ) <EOL> if initial or not is_linkable : <EOL> for dependency in self . dependencies : <EOL> dependency . _LinkDependenciesInternal ( targets , <EOL> include_shared_libraries , <EOL> dependencies , False ) <EOL> return dependencies <EOL> def DependenciesForLinkSettings ( self , targets ) : <EOL> """<STR_LIT>""" <EOL> include_shared_libraries = targets [ self . ref ] . get ( '<STR_LIT>' , True ) <EOL> return self . _LinkDependenciesInternal ( targets , include_shared_libraries ) <EOL> def DependenciesToLinkAgainst ( self , targets ) : <EOL> """<STR_LIT>""" <EOL> return self . _LinkDependenciesInternal ( targets , True ) <EOL> def BuildDependencyList ( targets ) : <EOL> dependency_nodes = { } <EOL> for target , spec in targets . iteritems ( ) : <EOL> if target not in dependency_nodes : <EOL> dependency_nodes [ target ] = DependencyGraphNode ( target ) <EOL> root_node = DependencyGraphNode ( None ) <EOL> for target , spec in targets . iteritems ( ) : <EOL> target_node = dependency_nodes [ target ] <EOL> target_build_file = gyp . common . BuildFile ( target ) <EOL> dependencies = spec . get ( '<STR_LIT>' ) <EOL> if not dependencies : <EOL> target_node . dependencies = [ root_node ] <EOL> root_node . dependents . append ( target_node ) <EOL> else : <EOL> for dependency in dependencies : <EOL> dependency_node = dependency_nodes . get ( dependency ) <EOL> if not dependency_node : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( dependency , target ) ) <EOL> target_node . dependencies . append ( dependency_node ) <EOL> dependency_node . dependents . append ( target_node ) <EOL> flat_list = root_node . FlattenToList ( ) <EOL> if len ( flat_list ) != len ( targets ) : <EOL> if not root_node . dependents : <EOL> target = targets . keys ( ) [ <NUM_LIT:0> ] <EOL> target_node = dependency_nodes [ target ] <EOL> target_node . dependencies . append ( root_node ) <EOL> root_node . dependents . append ( target_node ) <EOL> cycles = [ ] <EOL> for cycle in root_node . FindCycles ( ) : <EOL> paths = [ node . ref for node in cycle ] <EOL> cycles . append ( '<STR_LIT>' % '<STR_LIT>' . join ( paths ) ) <EOL> raise DependencyGraphNode . CircularException ( <EOL> '<STR_LIT>' + '<STR_LIT:\n>' . join ( cycles ) ) <EOL> return [ dependency_nodes , flat_list ] <EOL> def VerifyNoGYPFileCircularDependencies ( targets ) : <EOL> dependency_nodes = { } <EOL> for target in targets . iterkeys ( ) : <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> if not build_file in dependency_nodes : <EOL> dependency_nodes [ build_file ] = DependencyGraphNode ( build_file ) <EOL> for target , spec in targets . iteritems ( ) : <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> build_file_node = dependency_nodes [ build_file ] <EOL> target_dependencies = spec . get ( '<STR_LIT>' , [ ] ) <EOL> for dependency in target_dependencies : <EOL> try : <EOL> dependency_build_file = gyp . common . BuildFile ( dependency ) <EOL> except GypError , e : <EOL> gyp . common . ExceptionAppend ( <EOL> e , '<STR_LIT>' % build_file ) <EOL> raise <EOL> if dependency_build_file == build_file : <EOL> continue <EOL> dependency_node = dependency_nodes . get ( dependency_build_file ) <EOL> if not dependency_node : <EOL> raise GypError ( "<STR_LIT>" % dependency_build_file ) <EOL> if dependency_node not in build_file_node . dependencies : <EOL> build_file_node . dependencies . append ( dependency_node ) <EOL> dependency_node . dependents . append ( build_file_node ) <EOL> root_node = DependencyGraphNode ( None ) <EOL> for build_file_node in dependency_nodes . itervalues ( ) : <EOL> if len ( build_file_node . dependencies ) == <NUM_LIT:0> : <EOL> build_file_node . dependencies . append ( root_node ) <EOL> root_node . dependents . append ( build_file_node ) <EOL> flat_list = root_node . FlattenToList ( ) <EOL> if len ( flat_list ) != len ( dependency_nodes ) : <EOL> if not root_node . dependents : <EOL> file_node = dependency_nodes . values ( ) [ <NUM_LIT:0> ] <EOL> file_node . dependencies . append ( root_node ) <EOL> root_node . dependents . append ( file_node ) <EOL> cycles = [ ] <EOL> for cycle in root_node . FindCycles ( ) : <EOL> paths = [ node . ref for node in cycle ] <EOL> cycles . append ( '<STR_LIT>' % '<STR_LIT>' . join ( paths ) ) <EOL> raise DependencyGraphNode . CircularException ( <EOL> '<STR_LIT>' + '<STR_LIT:\n>' . join ( cycles ) ) <EOL> def DoDependentSettings ( key , flat_list , targets , dependency_nodes ) : <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> if key == '<STR_LIT>' : <EOL> dependencies = dependency_nodes [ target ] . DeepDependencies ( ) <EOL> elif key == '<STR_LIT>' : <EOL> dependencies = dependency_nodes [ target ] . DirectAndImportedDependencies ( targets ) <EOL> elif key == '<STR_LIT>' : <EOL> dependencies = dependency_nodes [ target ] . DependenciesForLinkSettings ( targets ) <EOL> else : <EOL> raise GypError ( "<STR_LIT>" <EOL> '<STR_LIT>' + key ) <EOL> for dependency in dependencies : <EOL> dependency_dict = targets [ dependency ] <EOL> if not key in dependency_dict : <EOL> continue <EOL> dependency_build_file = gyp . common . BuildFile ( dependency ) <EOL> MergeDicts ( target_dict , dependency_dict [ key ] , <EOL> build_file , dependency_build_file ) <EOL> def AdjustStaticLibraryDependencies ( flat_list , targets , dependency_nodes , <EOL> sort_dependencies ) : <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> target_type = target_dict [ '<STR_LIT:type>' ] <EOL> if target_type == '<STR_LIT>' : <EOL> if not '<STR_LIT>' in target_dict : <EOL> continue <EOL> target_dict [ '<STR_LIT>' ] = target_dict . get ( <EOL> '<STR_LIT>' , [ ] ) [ : ] <EOL> dependencies = dependency_nodes [ target ] . DirectAndImportedDependencies ( targets ) <EOL> index = <NUM_LIT:0> <EOL> while index < len ( dependencies ) : <EOL> dependency = dependencies [ index ] <EOL> dependency_dict = targets [ dependency ] <EOL> if ( dependency_dict [ '<STR_LIT:type>' ] == '<STR_LIT>' and not dependency_dict . get ( '<STR_LIT>' , False ) ) or ( dependency_dict [ '<STR_LIT:type>' ] != '<STR_LIT>' and not dependency in target_dict [ '<STR_LIT>' ] ) : <EOL> del dependencies [ index ] <EOL> else : <EOL> index = index + <NUM_LIT:1> <EOL> if len ( dependencies ) > <NUM_LIT:0> : <EOL> target_dict [ '<STR_LIT>' ] = dependencies <EOL> else : <EOL> del target_dict [ '<STR_LIT>' ] <EOL> elif target_type in linkable_types : <EOL> link_dependencies = dependency_nodes [ target ] . DependenciesToLinkAgainst ( targets ) <EOL> for dependency in link_dependencies : <EOL> if dependency == target : <EOL> continue <EOL> if not '<STR_LIT>' in target_dict : <EOL> target_dict [ '<STR_LIT>' ] = [ ] <EOL> if not dependency in target_dict [ '<STR_LIT>' ] : <EOL> target_dict [ '<STR_LIT>' ] . append ( dependency ) <EOL> if sort_dependencies and '<STR_LIT>' in target_dict : <EOL> target_dict [ '<STR_LIT>' ] = [ dep for dep in reversed ( flat_list ) <EOL> if dep in target_dict [ '<STR_LIT>' ] ] <EOL> exception_re = re . compile ( r'''<STR_LIT>''' ) <EOL> def MakePathRelative ( to_file , fro_file , item ) : <EOL> if to_file == fro_file or exception_re . match ( item ) : <EOL> return item <EOL> else : <EOL> ret = os . path . normpath ( os . path . join ( <EOL> gyp . common . RelativePath ( os . path . dirname ( fro_file ) , <EOL> os . path . dirname ( to_file ) ) , <EOL> item ) ) . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> if item [ - <NUM_LIT:1> ] == '<STR_LIT:/>' : <EOL> ret += '<STR_LIT:/>' <EOL> return ret <EOL> def MergeLists ( to , fro , to_file , fro_file , is_paths = False , append = True ) : <EOL> is_hashable = lambda val : val . __hash__ <EOL> def is_in_set_or_list ( x , s , l ) : <EOL> if is_hashable ( x ) : <EOL> return x in s <EOL> return x in l <EOL> prepend_index = <NUM_LIT:0> <EOL> hashable_to_set = set ( x for x in to if is_hashable ( x ) ) <EOL> for item in fro : <EOL> singleton = False <EOL> if type ( item ) in ( str , int ) : <EOL> if is_paths : <EOL> to_item = MakePathRelative ( to_file , fro_file , item ) <EOL> else : <EOL> to_item = item <EOL> if not ( type ( item ) is str and item . startswith ( '<STR_LIT:->' ) ) : <EOL> singleton = True <EOL> elif type ( item ) is dict : <EOL> to_item = { } <EOL> MergeDicts ( to_item , item , to_file , fro_file ) <EOL> elif type ( item ) is list : <EOL> to_item = [ ] <EOL> MergeLists ( to_item , item , to_file , fro_file ) <EOL> else : <EOL> raise TypeError ( <EOL> '<STR_LIT>' + item . __class__ . __name__ ) <EOL> if append : <EOL> if not singleton or not is_in_set_or_list ( to_item , hashable_to_set , to ) : <EOL> to . append ( to_item ) <EOL> if is_hashable ( to_item ) : <EOL> hashable_to_set . add ( to_item ) <EOL> else : <EOL> while singleton and to_item in to : <EOL> to . remove ( to_item ) <EOL> to . insert ( prepend_index , to_item ) <EOL> if is_hashable ( to_item ) : <EOL> hashable_to_set . add ( to_item ) <EOL> prepend_index = prepend_index + <NUM_LIT:1> <EOL> def MergeDicts ( to , fro , to_file , fro_file ) : <EOL> for k , v in fro . iteritems ( ) : <EOL> if k in to : <EOL> bad_merge = False <EOL> if type ( v ) in ( str , int ) : <EOL> if type ( to [ k ] ) not in ( str , int ) : <EOL> bad_merge = True <EOL> elif type ( v ) is not type ( to [ k ] ) : <EOL> bad_merge = True <EOL> if bad_merge : <EOL> raise TypeError ( <EOL> '<STR_LIT>' + v . __class__ . __name__ + '<STR_LIT>' + to [ k ] . __class__ . __name__ + '<STR_LIT>' + k ) <EOL> if type ( v ) in ( str , int ) : <EOL> is_path = IsPathSection ( k ) <EOL> if is_path : <EOL> to [ k ] = MakePathRelative ( to_file , fro_file , v ) <EOL> else : <EOL> to [ k ] = v <EOL> elif type ( v ) is dict : <EOL> if not k in to : <EOL> to [ k ] = { } <EOL> MergeDicts ( to [ k ] , v , to_file , fro_file ) <EOL> elif type ( v ) is list : <EOL> ext = k [ - <NUM_LIT:1> ] <EOL> append = True <EOL> if ext == '<STR_LIT:=>' : <EOL> list_base = k [ : - <NUM_LIT:1> ] <EOL> lists_incompatible = [ list_base , list_base + '<STR_LIT:?>' ] <EOL> to [ list_base ] = [ ] <EOL> elif ext == '<STR_LIT:+>' : <EOL> list_base = k [ : - <NUM_LIT:1> ] <EOL> lists_incompatible = [ list_base + '<STR_LIT:=>' , list_base + '<STR_LIT:?>' ] <EOL> append = False <EOL> elif ext == '<STR_LIT:?>' : <EOL> list_base = k [ : - <NUM_LIT:1> ] <EOL> lists_incompatible = [ list_base , list_base + '<STR_LIT:=>' , list_base + '<STR_LIT:+>' ] <EOL> else : <EOL> list_base = k <EOL> lists_incompatible = [ list_base + '<STR_LIT:=>' , list_base + '<STR_LIT:?>' ] <EOL> for list_incompatible in lists_incompatible : <EOL> if list_incompatible in fro : <EOL> raise GypError ( '<STR_LIT>' + k + '<STR_LIT>' + <EOL> list_incompatible ) <EOL> if list_base in to : <EOL> if ext == '<STR_LIT:?>' : <EOL> continue <EOL> elif type ( to [ list_base ] ) is not list : <EOL> raise TypeError ( <EOL> '<STR_LIT>' + v . __class__ . __name__ + '<STR_LIT>' + to [ list_base ] . __class__ . __name__ + '<STR_LIT>' + list_base + '<STR_LIT:(>' + k + '<STR_LIT:)>' ) <EOL> else : <EOL> to [ list_base ] = [ ] <EOL> is_paths = IsPathSection ( list_base ) <EOL> MergeLists ( to [ list_base ] , v , to_file , fro_file , is_paths , append ) <EOL> else : <EOL> raise TypeError ( <EOL> '<STR_LIT>' + v . __class__ . __name__ + '<STR_LIT>' + k ) <EOL> def MergeConfigWithInheritance ( new_configuration_dict , build_file , <EOL> target_dict , configuration , visited ) : <EOL> if configuration in visited : <EOL> return <EOL> configuration_dict = target_dict [ '<STR_LIT>' ] [ configuration ] <EOL> for parent in configuration_dict . get ( '<STR_LIT>' , [ ] ) : <EOL> MergeConfigWithInheritance ( new_configuration_dict , build_file , <EOL> target_dict , parent , visited + [ configuration ] ) <EOL> MergeDicts ( new_configuration_dict , configuration_dict , <EOL> build_file , build_file ) <EOL> if '<STR_LIT>' in new_configuration_dict : <EOL> del new_configuration_dict [ '<STR_LIT>' ] <EOL> def SetUpConfigurations ( target , target_dict ) : <EOL> key_suffixes = [ '<STR_LIT:=>' , '<STR_LIT:+>' , '<STR_LIT:?>' , '<STR_LIT:!>' , '<STR_LIT:/>' ] <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> if not '<STR_LIT>' in target_dict : <EOL> target_dict [ '<STR_LIT>' ] = { '<STR_LIT>' : { } } <EOL> if not '<STR_LIT>' in target_dict : <EOL> concrete = [ i for ( i , config ) in target_dict [ '<STR_LIT>' ] . iteritems ( ) <EOL> if not config . get ( '<STR_LIT>' ) ] <EOL> target_dict [ '<STR_LIT>' ] = sorted ( concrete ) [ <NUM_LIT:0> ] <EOL> merged_configurations = { } <EOL> configs = target_dict [ '<STR_LIT>' ] <EOL> for ( configuration , old_configuration_dict ) in configs . iteritems ( ) : <EOL> if old_configuration_dict . get ( '<STR_LIT>' ) : <EOL> continue <EOL> new_configuration_dict = { } <EOL> for ( key , target_val ) in target_dict . iteritems ( ) : <EOL> key_ext = key [ - <NUM_LIT:1> : ] <EOL> if key_ext in key_suffixes : <EOL> key_base = key [ : - <NUM_LIT:1> ] <EOL> else : <EOL> key_base = key <EOL> if not key_base in non_configuration_keys : <EOL> new_configuration_dict [ key ] = gyp . simple_copy . deepcopy ( target_val ) <EOL> MergeConfigWithInheritance ( new_configuration_dict , build_file , <EOL> target_dict , configuration , [ ] ) <EOL> merged_configurations [ configuration ] = new_configuration_dict <EOL> for configuration in merged_configurations . keys ( ) : <EOL> target_dict [ '<STR_LIT>' ] [ configuration ] = ( <EOL> merged_configurations [ configuration ] ) <EOL> for configuration in target_dict [ '<STR_LIT>' ] . keys ( ) : <EOL> old_configuration_dict = target_dict [ '<STR_LIT>' ] [ configuration ] <EOL> if old_configuration_dict . get ( '<STR_LIT>' ) : <EOL> del target_dict [ '<STR_LIT>' ] [ configuration ] <EOL> delete_keys = [ ] <EOL> for key in target_dict : <EOL> key_ext = key [ - <NUM_LIT:1> : ] <EOL> if key_ext in key_suffixes : <EOL> key_base = key [ : - <NUM_LIT:1> ] <EOL> else : <EOL> key_base = key <EOL> if not key_base in non_configuration_keys : <EOL> delete_keys . append ( key ) <EOL> for key in delete_keys : <EOL> del target_dict [ key ] <EOL> for configuration in target_dict [ '<STR_LIT>' ] . keys ( ) : <EOL> configuration_dict = target_dict [ '<STR_LIT>' ] [ configuration ] <EOL> for key in configuration_dict . keys ( ) : <EOL> if key in invalid_configuration_keys : <EOL> raise GypError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( key , configuration , target ) ) <EOL> def ProcessListFiltersInDict ( name , the_dict ) : <EOL> """<STR_LIT>""" <EOL> lists = [ ] <EOL> del_lists = [ ] <EOL> for key , value in the_dict . iteritems ( ) : <EOL> operation = key [ - <NUM_LIT:1> ] <EOL> if operation != '<STR_LIT:!>' and operation != '<STR_LIT:/>' : <EOL> continue <EOL> if type ( value ) is not list : <EOL> raise ValueError ( name + '<STR_LIT>' + key + '<STR_LIT>' + value . __class__ . __name__ ) <EOL> list_key = key [ : - <NUM_LIT:1> ] <EOL> if list_key not in the_dict : <EOL> del_lists . append ( key ) <EOL> continue <EOL> if type ( the_dict [ list_key ] ) is not list : <EOL> value = the_dict [ list_key ] <EOL> raise ValueError ( name + '<STR_LIT>' + list_key + '<STR_LIT>' + value . __class__ . __name__ + '<STR_LIT>' + { '<STR_LIT:!>' : '<STR_LIT>' , '<STR_LIT:/>' : '<STR_LIT>' } [ operation ] ) <EOL> if not list_key in lists : <EOL> lists . append ( list_key ) <EOL> for del_list in del_lists : <EOL> del the_dict [ del_list ] <EOL> for list_key in lists : <EOL> the_list = the_dict [ list_key ] <EOL> list_actions = list ( ( - <NUM_LIT:1> , ) * len ( the_list ) ) <EOL> exclude_key = list_key + '<STR_LIT:!>' <EOL> if exclude_key in the_dict : <EOL> for exclude_item in the_dict [ exclude_key ] : <EOL> for index in xrange ( <NUM_LIT:0> , len ( the_list ) ) : <EOL> if exclude_item == the_list [ index ] : <EOL> list_actions [ index ] = <NUM_LIT:0> <EOL> del the_dict [ exclude_key ] <EOL> regex_key = list_key + '<STR_LIT:/>' <EOL> if regex_key in the_dict : <EOL> for regex_item in the_dict [ regex_key ] : <EOL> [ action , pattern ] = regex_item <EOL> pattern_re = re . compile ( pattern ) <EOL> if action == '<STR_LIT>' : <EOL> action_value = <NUM_LIT:0> <EOL> elif action == '<STR_LIT>' : <EOL> action_value = <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + action + '<STR_LIT>' + name + '<STR_LIT>' + regex_key ) <EOL> for index in xrange ( <NUM_LIT:0> , len ( the_list ) ) : <EOL> list_item = the_list [ index ] <EOL> if list_actions [ index ] == action_value : <EOL> continue <EOL> if pattern_re . search ( list_item ) : <EOL> list_actions [ index ] = action_value <EOL> del the_dict [ regex_key ] <EOL> excluded_key = list_key + '<STR_LIT>' <EOL> if excluded_key in the_dict : <EOL> raise GypError ( name + '<STR_LIT>' + excluded_key + <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' + list_key ) <EOL> excluded_list = [ ] <EOL> for index in xrange ( len ( list_actions ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> if list_actions [ index ] == <NUM_LIT:0> : <EOL> excluded_list . insert ( <NUM_LIT:0> , the_list [ index ] ) <EOL> del the_list [ index ] <EOL> if len ( excluded_list ) > <NUM_LIT:0> : <EOL> the_dict [ excluded_key ] = excluded_list <EOL> for key , value in the_dict . iteritems ( ) : <EOL> if type ( value ) is dict : <EOL> ProcessListFiltersInDict ( key , value ) <EOL> elif type ( value ) is list : <EOL> ProcessListFiltersInList ( key , value ) <EOL> def ProcessListFiltersInList ( name , the_list ) : <EOL> for item in the_list : <EOL> if type ( item ) is dict : <EOL> ProcessListFiltersInDict ( name , item ) <EOL> elif type ( item ) is list : <EOL> ProcessListFiltersInList ( name , item ) <EOL> def ValidateTargetType ( target , target_dict ) : <EOL> """<STR_LIT>""" <EOL> VALID_TARGET_TYPES = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:none>' ) <EOL> target_type = target_dict . get ( '<STR_LIT:type>' , None ) <EOL> if target_type not in VALID_TARGET_TYPES : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target , target_type , '<STR_LIT:/>' . join ( VALID_TARGET_TYPES ) ) ) <EOL> if ( target_dict . get ( '<STR_LIT>' , <NUM_LIT:0> ) and <EOL> not target_type == '<STR_LIT>' ) : <EOL> raise GypError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( target , <EOL> target_type ) ) <EOL> def ValidateSourcesInTarget ( target , target_dict , build_file , <EOL> duplicate_basename_check ) : <EOL> if not duplicate_basename_check : <EOL> return <EOL> if target_dict . get ( '<STR_LIT:type>' , None ) != '<STR_LIT>' : <EOL> return <EOL> sources = target_dict . 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> target + error + '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise GypError ( '<STR_LIT>' ) <EOL> def ValidateRulesInTarget ( target , target_dict , extra_sources_for_rules ) : <EOL> """<STR_LIT>""" <EOL> rule_names = { } <EOL> rule_extensions = { } <EOL> rules = target_dict . get ( '<STR_LIT>' , [ ] ) <EOL> for rule in rules : <EOL> rule_name = rule [ '<STR_LIT>' ] <EOL> if rule_name in rule_names : <EOL> raise GypError ( '<STR_LIT>' % <EOL> ( rule_name , target ) ) <EOL> rule_names [ rule_name ] = rule <EOL> rule_extension = rule [ '<STR_LIT>' ] <EOL> if rule_extension . startswith ( '<STR_LIT:.>' ) : <EOL> rule_extension = rule_extension [ <NUM_LIT:1> : ] <EOL> if rule_extension in rule_extensions : <EOL> raise GypError ( ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) % <EOL> ( rule_extension , target , <EOL> rule_extensions [ rule_extension ] [ '<STR_LIT>' ] , <EOL> rule_name ) ) <EOL> rule_extensions [ rule_extension ] = rule <EOL> if '<STR_LIT>' in rule : <EOL> raise GypError ( <EOL> '<STR_LIT>' % <EOL> ( target , rule_name ) ) <EOL> rule_sources = [ ] <EOL> source_keys = [ '<STR_LIT>' ] <EOL> source_keys . extend ( extra_sources_for_rules ) <EOL> for source_key in source_keys : <EOL> for source in target_dict . get ( source_key , [ ] ) : <EOL> ( source_root , source_extension ) = os . path . splitext ( source ) <EOL> if source_extension . startswith ( '<STR_LIT:.>' ) : <EOL> source_extension = source_extension [ <NUM_LIT:1> : ] <EOL> if source_extension == rule_extension : <EOL> rule_sources . append ( source ) <EOL> if len ( rule_sources ) > <NUM_LIT:0> : <EOL> rule [ '<STR_LIT>' ] = rule_sources <EOL> def ValidateRunAsInTarget ( target , target_dict , build_file ) : <EOL> target_name = target_dict . get ( '<STR_LIT>' ) <EOL> run_as = target_dict . get ( '<STR_LIT>' ) <EOL> if not run_as : <EOL> return <EOL> if type ( run_as ) is not dict : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target_name , build_file ) ) <EOL> action = run_as . get ( '<STR_LIT:action>' ) <EOL> if not action : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target_name , build_file ) ) <EOL> if type ( action ) is not list : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target_name , build_file ) ) <EOL> working_directory = run_as . get ( '<STR_LIT>' ) <EOL> if working_directory and type ( working_directory ) is not str : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target_name , build_file ) ) <EOL> environment = run_as . get ( '<STR_LIT>' ) <EOL> if environment and type ( environment ) is not dict : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( target_name , build_file ) ) <EOL> def ValidateActionsInTarget ( target , target_dict , build_file ) : <EOL> '''<STR_LIT>''' <EOL> target_name = target_dict . get ( '<STR_LIT>' ) <EOL> actions = target_dict . get ( '<STR_LIT>' , [ ] ) <EOL> for action in actions : <EOL> action_name = action . get ( '<STR_LIT>' ) <EOL> if not action_name : <EOL> raise GypError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> target_name ) <EOL> inputs = action . get ( '<STR_LIT>' , None ) <EOL> if inputs is None : <EOL> raise GypError ( '<STR_LIT>' % target_name ) <EOL> action_command = action . get ( '<STR_LIT:action>' ) <EOL> if action_command and not action_command [ <NUM_LIT:0> ] : <EOL> raise GypError ( "<STR_LIT>" % target_name ) <EOL> def TurnIntIntoStrInDict ( the_dict ) : <EOL> """<STR_LIT>""" <EOL> for k , v in the_dict . items ( ) : <EOL> if type ( v ) is int : <EOL> v = str ( v ) <EOL> the_dict [ k ] = v <EOL> elif type ( v ) is dict : <EOL> TurnIntIntoStrInDict ( v ) <EOL> elif type ( v ) is list : <EOL> TurnIntIntoStrInList ( v ) <EOL> if type ( k ) is int : <EOL> del the_dict [ k ] <EOL> the_dict [ str ( k ) ] = v <EOL> def TurnIntIntoStrInList ( the_list ) : <EOL> """<STR_LIT>""" <EOL> for index in xrange ( <NUM_LIT:0> , len ( the_list ) ) : <EOL> item = the_list [ index ] <EOL> if type ( item ) is int : <EOL> the_list [ index ] = str ( item ) <EOL> elif type ( item ) is dict : <EOL> TurnIntIntoStrInDict ( item ) <EOL> elif type ( item ) is list : <EOL> TurnIntIntoStrInList ( item ) <EOL> def PruneUnwantedTargets ( targets , flat_list , dependency_nodes , root_targets , <EOL> data ) : <EOL> """<STR_LIT>""" <EOL> qualified_root_targets = [ ] <EOL> for target in root_targets : <EOL> target = target . strip ( ) <EOL> qualified_targets = gyp . common . FindQualifiedTargets ( target , flat_list ) <EOL> if not qualified_targets : <EOL> raise GypError ( "<STR_LIT>" % target ) <EOL> qualified_root_targets . extend ( qualified_targets ) <EOL> wanted_targets = { } <EOL> for target in qualified_root_targets : <EOL> wanted_targets [ target ] = targets [ target ] <EOL> for dependency in dependency_nodes [ target ] . DeepDependencies ( ) : <EOL> wanted_targets [ dependency ] = targets [ dependency ] <EOL> wanted_flat_list = [ t for t in flat_list if t in wanted_targets ] <EOL> for build_file in data [ '<STR_LIT>' ] : <EOL> if not '<STR_LIT>' in data [ build_file ] : <EOL> continue <EOL> new_targets = [ ] <EOL> for target in data [ build_file ] [ '<STR_LIT>' ] : <EOL> qualified_name = gyp . common . QualifiedTarget ( build_file , <EOL> target [ '<STR_LIT>' ] , <EOL> target [ '<STR_LIT>' ] ) <EOL> if qualified_name in wanted_targets : <EOL> new_targets . append ( target ) <EOL> data [ build_file ] [ '<STR_LIT>' ] = new_targets <EOL> return wanted_targets , wanted_flat_list <EOL> def VerifyNoCollidingTargets ( targets ) : <EOL> """<STR_LIT>""" <EOL> used = { } <EOL> for target in targets : <EOL> path , name = target . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> subdir , gyp = os . path . split ( path ) <EOL> if not subdir : <EOL> subdir = '<STR_LIT:.>' <EOL> key = subdir + '<STR_LIT::>' + name <EOL> if key in used : <EOL> raise GypError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( name , subdir , gyp , used [ key ] ) ) <EOL> used [ key ] = gyp <EOL> def SetGeneratorGlobals ( generator_input_info ) : <EOL> global path_sections <EOL> path_sections = set ( base_path_sections ) <EOL> path_sections . update ( generator_input_info [ '<STR_LIT>' ] ) <EOL> global non_configuration_keys <EOL> non_configuration_keys = base_non_configuration_keys [ : ] <EOL> non_configuration_keys . extend ( generator_input_info [ '<STR_LIT>' ] ) <EOL> global multiple_toolsets <EOL> multiple_toolsets = generator_input_info [ <EOL> '<STR_LIT>' ] <EOL> global generator_filelist_paths <EOL> generator_filelist_paths = generator_input_info [ '<STR_LIT>' ] <EOL> def Load ( build_files , variables , includes , depth , generator_input_info , check , <EOL> circular_check , duplicate_basename_check , parallel , root_targets ) : <EOL> SetGeneratorGlobals ( generator_input_info ) <EOL> extra_sources_for_rules = generator_input_info [ '<STR_LIT>' ] <EOL> data = { '<STR_LIT>' : set ( ) } <EOL> build_files = set ( map ( os . path . normpath , build_files ) ) <EOL> if parallel : <EOL> LoadTargetBuildFilesParallel ( build_files , data , variables , includes , depth , <EOL> check , generator_input_info ) <EOL> else : <EOL> aux_data = { } <EOL> for build_file in build_files : <EOL> try : <EOL> LoadTargetBuildFile ( build_file , data , aux_data , <EOL> variables , includes , depth , check , True ) <EOL> except Exception , e : <EOL> gyp . common . ExceptionAppend ( e , '<STR_LIT>' % build_file ) <EOL> raise <EOL> targets = BuildTargetsDict ( data ) <EOL> QualifyDependencies ( targets ) <EOL> RemoveSelfDependencies ( targets ) <EOL> ExpandWildcardDependencies ( targets , data ) <EOL> RemoveLinkDependenciesFromNoneTargets ( targets ) <EOL> for target_name , target_dict in targets . iteritems ( ) : <EOL> tmp_dict = { } <EOL> for key_base in dependency_sections : <EOL> for op in ( '<STR_LIT>' , '<STR_LIT:!>' , '<STR_LIT:/>' ) : <EOL> key = key_base + op <EOL> if key in target_dict : <EOL> tmp_dict [ key ] = target_dict [ key ] <EOL> del target_dict [ key ] <EOL> ProcessListFiltersInDict ( target_name , tmp_dict ) <EOL> for key in tmp_dict : <EOL> target_dict [ key ] = tmp_dict [ key ] <EOL> RemoveDuplicateDependencies ( targets ) <EOL> if circular_check : <EOL> VerifyNoGYPFileCircularDependencies ( targets ) <EOL> [ dependency_nodes , flat_list ] = BuildDependencyList ( targets ) <EOL> if root_targets : <EOL> targets , flat_list = PruneUnwantedTargets ( <EOL> targets , flat_list , dependency_nodes , root_targets , data ) <EOL> VerifyNoCollidingTargets ( flat_list ) <EOL> for settings_type in [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> DoDependentSettings ( settings_type , flat_list , targets , dependency_nodes ) <EOL> for target in flat_list : <EOL> if settings_type in targets [ target ] : <EOL> del targets [ target ] [ settings_type ] <EOL> gii = generator_input_info <EOL> if gii [ '<STR_LIT>' ] : <EOL> AdjustStaticLibraryDependencies ( flat_list , targets , dependency_nodes , <EOL> gii [ '<STR_LIT>' ] ) <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> ProcessVariablesAndConditionsInDict ( <EOL> target_dict , PHASE_LATE , variables , build_file ) <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> SetUpConfigurations ( target , target_dict ) <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> ProcessListFiltersInDict ( target , target_dict ) <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> ProcessVariablesAndConditionsInDict ( <EOL> target_dict , PHASE_LATELATE , variables , build_file ) <EOL> for target in flat_list : <EOL> target_dict = targets [ target ] <EOL> build_file = gyp . common . BuildFile ( target ) <EOL> ValidateTargetType ( target , target_dict ) <EOL> ValidateSourcesInTarget ( target , target_dict , build_file , <EOL> duplicate_basename_check ) <EOL> ValidateRulesInTarget ( target , target_dict , extra_sources_for_rules ) <EOL> ValidateRunAsInTarget ( target , target_dict , build_file ) <EOL> ValidateActionsInTarget ( target , target_dict , build_file ) <EOL> TurnIntIntoStrInDict ( data ) <EOL> return [ flat_list , targets , data ] </s>
