<s> """<STR_LIT>""" <EOL> import os . path <EOL> import glob <EOL> import yaml <EOL> from collections import OrderedDict <EOL> from mod import log , util , dep <EOL> from mod . tools import cmake , make , ninja , xcodebuild <EOL> from mod import emscripten , nacl , android <EOL> native_platforms = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:win32>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> generators = [ <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> ] <EOL> build_tools = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> build_types = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> default_config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def valid_generator ( name ) : <EOL> """<STR_LIT>""" <EOL> return name in generators <EOL> def valid_build_tool ( name ) : <EOL> """<STR_LIT>""" <EOL> return name in build_tools <EOL> def valid_build_type ( name ) : <EOL> """<STR_LIT>""" <EOL> return name in build_types <EOL> def get_default_config ( ) : <EOL> """<STR_LIT>""" <EOL> return default_config [ util . get_host_platform ( ) ] <EOL> def get_toolchain ( fips_dir , proj_dir , cfg ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in cfg : <EOL> if cfg [ '<STR_LIT>' ] in native_platforms : <EOL> return None <EOL> else : <EOL> log . error ( "<STR_LIT>" ) <EOL> toolchain = None <EOL> if '<STR_LIT>' in cfg : <EOL> toolchain = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> toolchain = '<STR_LIT>' . format ( cfg [ '<STR_LIT>' ] ) <EOL> toolchain_path = '<STR_LIT>' . format ( proj_dir , toolchain ) <EOL> if os . path . isfile ( toolchain_path ) : <EOL> return toolchain_path <EOL> else : <EOL> _ , imported_projs = dep . get_all_imports_exports ( fips_dir , proj_dir ) <EOL> for imported_proj_name in imported_projs : <EOL> imported_proj_dir = util . get_project_dir ( fips_dir , imported_proj_name ) <EOL> toolchain_path = '<STR_LIT>' . format ( imported_proj_dir , toolchain ) <EOL> if os . path . isfile ( toolchain_path ) : <EOL> return toolchain_path <EOL> else : <EOL> toolchain_path = '<STR_LIT>' . format ( fips_dir , toolchain ) <EOL> if os . path . isfile ( toolchain_path ) : <EOL> return toolchain_path <EOL> return None <EOL> def exists ( pattern , proj_dirs ) : <EOL> """<STR_LIT>""" <EOL> for curDir in proj_dirs : <EOL> if len ( glob . glob ( '<STR_LIT>' . format ( curDir , pattern ) ) ) > <NUM_LIT:0> : <EOL> return True <EOL> return False <EOL> def get_config_dirs ( fips_dir , proj_dir ) : <EOL> """<STR_LIT>""" <EOL> dirs = [ fips_dir + '<STR_LIT>' ] <EOL> if fips_dir != proj_dir : <EOL> success , result = dep . get_all_imports_exports ( fips_dir , proj_dir ) <EOL> if success : <EOL> for dep_proj_name in result : <EOL> dep_proj_dir = util . get_project_dir ( fips_dir , dep_proj_name ) <EOL> dep_configs_dir = dep_proj_dir + '<STR_LIT>' <EOL> if os . path . isdir ( dep_configs_dir ) : <EOL> dirs . append ( dep_configs_dir ) <EOL> else : <EOL> log . warn ( "<STR_LIT>" ) <EOL> return dirs <EOL> def list ( fips_dir , proj_dir , pattern ) : <EOL> """<STR_LIT>""" <EOL> dirs = get_config_dirs ( fips_dir , proj_dir ) <EOL> res = OrderedDict ( ) <EOL> for curDir in dirs : <EOL> res [ curDir ] = [ ] <EOL> paths = glob . glob ( '<STR_LIT>' . format ( curDir ) ) <EOL> for path in paths : <EOL> fname = os . path . split ( path ) [ <NUM_LIT:1> ] <EOL> fname = os . path . splitext ( fname ) [ <NUM_LIT:0> ] <EOL> res [ curDir ] . append ( fname ) <EOL> return res <EOL> def load ( fips_dir , proj_dir , pattern ) : <EOL> """<STR_LIT>""" <EOL> dirs = get_config_dirs ( fips_dir , proj_dir ) <EOL> configs = [ ] <EOL> for curDir in dirs : <EOL> paths = glob . glob ( '<STR_LIT>' . format ( curDir , pattern ) ) <EOL> for path in paths : <EOL> try : <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> cfg = yaml . load ( f ) <EOL> folder , fname = os . path . split ( path ) <EOL> cfg [ '<STR_LIT:path>' ] = path <EOL> cfg [ '<STR_LIT>' ] = folder <EOL> cfg [ '<STR_LIT:name>' ] = os . path . splitext ( fname ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT>' not in cfg : <EOL> cfg [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in cfg : <EOL> cfg [ '<STR_LIT>' ] = None <EOL> if '<STR_LIT>' not in cfg : <EOL> cfg [ '<STR_LIT>' ] = None <EOL> if '<STR_LIT>' not in cfg : <EOL> cfg [ '<STR_LIT>' ] = None <EOL> configs . append ( cfg ) <EOL> except yaml . error . YAMLError as e : <EOL> log . error ( '<STR_LIT>' , e . message ) <EOL> return configs <EOL> def check_build_tool ( fips_dir , tool_name ) : <EOL> """<STR_LIT>""" <EOL> if tool_name == '<STR_LIT>' : <EOL> return cmake . check_exists ( fips_dir ) <EOL> elif tool_name == '<STR_LIT>' : <EOL> return make . check_exists ( fips_dir ) <EOL> elif tool_name == '<STR_LIT>' : <EOL> return ninja . check_exists ( fips_dir ) <EOL> elif tool_name == '<STR_LIT>' : <EOL> return xcodebuild . check_exists ( fips_dir ) <EOL> else : <EOL> return False ; <EOL> def check_sdk ( fips_dir , platform_name ) : <EOL> """<STR_LIT>""" <EOL> if platform_name == '<STR_LIT>' : <EOL> return emscripten . check_exists ( fips_dir ) <EOL> elif platform_name == '<STR_LIT>' : <EOL> return nacl . check_exists ( fips_dir ) <EOL> elif platform_name == '<STR_LIT>' : <EOL> return android . check_exists ( fips_dir ) <EOL> else : <EOL> return True <EOL> def check_config_valid ( fips_dir , proj_dir , cfg , print_errors = False ) : <EOL> """<STR_LIT>""" <EOL> messages = [ ] <EOL> valid = True <EOL> required_fields = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for field in required_fields : <EOL> if field not in cfg : <EOL> messages . append ( "<STR_LIT>" . format ( field , cfg [ '<STR_LIT:path>' ] ) ) <EOL> valid = False <EOL> if not check_sdk ( fips_dir , cfg [ '<STR_LIT>' ] ) : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT>' ] ) ) <EOL> valid = False <EOL> if not valid_generator ( cfg [ '<STR_LIT>' ] ) : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT>' ] , cfg [ '<STR_LIT:path>' ] ) ) <EOL> valid = False <EOL> if not valid_build_tool ( cfg [ '<STR_LIT>' ] ) : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT>' ] , cfg [ '<STR_LIT:path>' ] ) ) <EOL> valid = False <EOL> if not check_build_tool ( fips_dir , cfg [ '<STR_LIT>' ] ) : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT>' ] ) ) <EOL> valid = False <EOL> if not valid_build_type ( cfg [ '<STR_LIT>' ] ) : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT>' ] , cfg [ '<STR_LIT:path>' ] ) ) <EOL> valid = False <EOL> if cfg [ '<STR_LIT>' ] not in native_platforms : <EOL> toolchain_path = get_toolchain ( fips_dir , proj_dir , cfg ) <EOL> if not toolchain_path : <EOL> messages . append ( "<STR_LIT>" . format ( cfg [ '<STR_LIT:name>' ] ) ) <EOL> valid = False <EOL> if print_errors : <EOL> for msg in messages : <EOL> log . error ( msg , False ) <EOL> return ( valid , messages ) </s>
