<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import re <EOL> import subprocess <EOL> from qisys import ui <EOL> import qisys . error <EOL> import qisys . command <EOL> import qisys . sh <EOL> import qibuild . cmake . profiling <EOL> def get_known_cmake_generators ( ) : <EOL> """<STR_LIT>""" <EOL> build_env = qibuild . config . get_build_env ( ) <EOL> cmake_ = qisys . command . find_program ( "<STR_LIT>" , env = build_env ) <EOL> if not cmake_ : <EOL> message = """<STR_LIT>""" <EOL> raise qisys . error . Error ( message ) <EOL> process = subprocess . Popen ( [ cmake_ , "<STR_LIT>" ] , stdout = subprocess . PIPE ) <EOL> ( out , _err ) = process . communicate ( ) <EOL> intersting = False <EOL> intersting_lines = list ( ) <EOL> magic_line = "<STR_LIT>" <EOL> for line in out . splitlines ( ) : <EOL> if len ( line ) >= <NUM_LIT:3> : <EOL> if line [ <NUM_LIT:2> ] == '<STR_LIT:U+0020>' and not "<STR_LIT:=>" in line : <EOL> continue <EOL> if line == magic_line : <EOL> intersting = True <EOL> continue <EOL> if intersting : <EOL> intersting_lines . append ( line ) <EOL> to_parse = "<STR_LIT>" <EOL> for line in intersting_lines : <EOL> to_parse += line . strip ( ) <EOL> if "<STR_LIT:=>" in line : <EOL> to_parse += "<STR_LIT:\n>" <EOL> res = list ( ) <EOL> for line in to_parse . splitlines ( ) : <EOL> generator = line . split ( "<STR_LIT:=>" ) [ <NUM_LIT:0> ] <EOL> res . append ( generator . strip ( ) ) <EOL> fixed_list = list ( ) <EOL> for generator in res : <EOL> if "<STR_LIT>" in generator and "<STR_LIT>" in generator : <EOL> fixed_list . append ( generator . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> fixed_list . append ( generator . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> fixed_list . append ( generator . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> else : <EOL> fixed_list . append ( generator ) <EOL> return fixed_list <EOL> def get_cmake_version ( cmake_binary ) : <EOL> """<STR_LIT>""" <EOL> output = subprocess . check_output ( [ cmake_binary , "<STR_LIT>" ] ) <EOL> first_line = output . splitlines ( ) [ <NUM_LIT:0> ] <EOL> words = first_line . split ( ) <EOL> return words [ - <NUM_LIT:1> ] <EOL> def get_cached_var ( build_dir , var , default = None ) : <EOL> """<STR_LIT>""" <EOL> cmakecache = os . path . join ( build_dir , "<STR_LIT>" ) <EOL> if not os . path . exists ( cmakecache ) : <EOL> mess = "<STR_LIT>" % build_dir <EOL> raise qisys . error . Error ( mess ) <EOL> res = read_cmake_cache ( cmakecache ) <EOL> return res . get ( var , default ) <EOL> def cmake ( source_dir , build_dir , cmake_args , env = None , <EOL> clean_first = True , profiling = False , debug_trycompile = False , <EOL> trace_cmake = False , summarize_options = False ) : <EOL> """<STR_LIT>""" <EOL> cmake_binary = qisys . command . find_program ( "<STR_LIT>" , env = env , raises = True ) <EOL> if not os . path . exists ( source_dir ) : <EOL> qisys . error . Error ( "<STR_LIT>" ) <EOL> if not os . path . exists ( build_dir ) : <EOL> mess = "<STR_LIT>" % build_dir <EOL> qisys . error . Error ( mess ) <EOL> if clean_first : <EOL> cache = os . path . join ( build_dir , "<STR_LIT>" ) <EOL> qisys . sh . rm ( cache ) <EOL> if debug_trycompile : <EOL> cmake_args . append ( "<STR_LIT>" ) <EOL> if profiling or trace_cmake : <EOL> cmake_version = get_cmake_version ( cmake_binary ) <EOL> if qisys . version . compare ( cmake_version , "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> cmake_args . append ( "<STR_LIT>" ) <EOL> else : <EOL> cmake_args . append ( "<STR_LIT>" ) <EOL> in_source_cache = os . path . join ( source_dir , "<STR_LIT>" ) <EOL> if os . path . exists ( in_source_cache ) : <EOL> mess = "<STR_LIT>" <EOL> mess += "<STR_LIT>" % in_source_cache <EOL> mess += "<STR_LIT>" <EOL> qisys . error . Error ( mess ) <EOL> root_cmake = os . path . join ( source_dir , "<STR_LIT>" ) <EOL> check_root_cmake_list ( root_cmake ) <EOL> cmake_args += [ source_dir ] <EOL> if not profiling and not trace_cmake : <EOL> qisys . command . call ( [ cmake_binary ] + cmake_args , cwd = build_dir , env = env ) <EOL> if summarize_options : <EOL> display_options ( build_dir ) <EOL> return <EOL> cmake_log = os . path . join ( build_dir , "<STR_LIT>" ) <EOL> fp = open ( cmake_log , "<STR_LIT:w>" ) <EOL> if profiling : <EOL> ui . info ( ui . green , "<STR_LIT>" ) <EOL> if trace_cmake : <EOL> ui . info ( ui . green , "<STR_LIT>" ) <EOL> ui . debug ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( cmake_args ) ) <EOL> retcode = subprocess . call ( [ cmake_binary ] + cmake_args , cwd = build_dir , env = env , <EOL> stdout = fp , stderr = fp ) <EOL> fp . close ( ) <EOL> if retcode != <NUM_LIT:0> : <EOL> mess = "<STR_LIT>" <EOL> if retcode < <NUM_LIT:0> : <EOL> mess += "<STR_LIT>" % qisys . command . str_from_signal ( - retcode ) <EOL> ui . error ( mess ) <EOL> ui . info ( ui . green , "<STR_LIT>" , ui . reset , ui . bold , cmake_log ) <EOL> if not profiling : <EOL> return <EOL> qibuild_dir = get_cmake_qibuild_dir ( ) <EOL> ui . info ( ui . green , "<STR_LIT>" ) <EOL> profiling_res = qibuild . cmake . profiling . parse_cmake_log ( cmake_log , qibuild_dir ) <EOL> outdir = os . path . join ( build_dir , "<STR_LIT>" ) <EOL> qibuild . cmake . profiling . gen_annotations ( profiling_res , outdir , qibuild_dir ) <EOL> ui . info ( ui . green , "<STR_LIT>" , outdir ) <EOL> def display_options ( build_dir ) : <EOL> """<STR_LIT>""" <EOL> cache_path = os . path . join ( build_dir , "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> cache = read_cmake_cache ( cache_path ) <EOL> opt_keys = [ x for x in cache if x . startswith ( ( "<STR_LIT>" , "<STR_LIT>" ) ) ] <EOL> if not opt_keys : <EOL> print "<STR_LIT>" <EOL> return <EOL> opt_keys . sort ( ) <EOL> padding = max ( len ( x ) for x in opt_keys ) + <NUM_LIT:3> <EOL> for key in opt_keys : <EOL> ui . info ( "<STR_LIT>" % ( key . ljust ( padding ) , cache [ key ] ) ) <EOL> def read_cmake_cache ( cache_path ) : <EOL> """<STR_LIT>""" <EOL> with open ( cache_path , "<STR_LIT:r>" ) as fp : <EOL> lines = fp . readlines ( ) <EOL> res = dict ( ) <EOL> for line in lines : <EOL> if line . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> if line . startswith ( "<STR_LIT:#>" ) : <EOL> continue <EOL> if not line : <EOL> continue <EOL> match = re . match ( r"<STR_LIT>" , line ) <EOL> if not match : <EOL> continue <EOL> else : <EOL> ( key , _type , value ) = match . groups ( ) <EOL> res [ key ] = value <EOL> return res <EOL> def get_cmake_qibuild_dir ( ) : <EOL> """<STR_LIT>""" <EOL> res = find_installed_cmake_qibuild_dir ( qibuild . QIBUILD_ROOT_DIR ) <EOL> if not res : <EOL> mess = "<STR_LIT>" <EOL> mess += "<STR_LIT>" <EOL> qisys . error . Error ( mess ) <EOL> return res <EOL> def find_installed_cmake_qibuild_dir ( python_dir ) : <EOL> ui . debug ( "<STR_LIT>" , python_dir ) <EOL> for candidate in [ <EOL> ( "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT:..>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:..>" , "<STR_LIT:..>" , "<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>" ) , <EOL> ( sys . prefix , "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] : <EOL> rel_path = os . path . join ( * candidate ) <EOL> res = os . path . join ( python_dir , rel_path ) <EOL> res = qisys . sh . to_native_path ( res ) <EOL> qibuild_config = os . path . join ( res , "<STR_LIT>" , "<STR_LIT>" ) <EOL> ui . debug ( "<STR_LIT>" , qibuild_config ) <EOL> if os . path . exists ( qibuild_config ) : <EOL> return res <EOL> def get_binutil ( name , cmake_var = None , build_dir = None , env = None ) : <EOL> """<STR_LIT>""" <EOL> res = None <EOL> if not cmake_var : <EOL> cmake_var = "<STR_LIT>" + name . upper ( ) <EOL> if build_dir : <EOL> res = get_cached_var ( build_dir , cmake_var ) <EOL> if res and not res . endswith ( "<STR_LIT>" ) : <EOL> return res <EOL> return qisys . command . find_program ( name , env = env ) <EOL> def check_root_cmake_list ( cmake_list_file ) : <EOL> """<STR_LIT>""" <EOL> dirname = os . path . dirname ( cmake_list_file ) <EOL> suggested_project_name = os . path . basename ( dirname ) <EOL> message = "<STR_LIT>" <EOL> lines = list ( ) <EOL> with open ( cmake_list_file , "<STR_LIT:r>" ) as fp : <EOL> lines = fp . readlines ( ) <EOL> project_line_number = None <EOL> find_qibuild_line_number = None <EOL> minimum_required_found = False <EOL> for ( i , line ) in enumerate ( lines ) : <EOL> if re . match ( r'<STR_LIT>' , line , re . IGNORECASE ) : <EOL> project_line_number = i <EOL> if re . match ( r'<STR_LIT>' , line , <EOL> re . IGNORECASE ) : <EOL> find_qibuild_line_number = i <EOL> if re . match ( r'<STR_LIT>' , line , <EOL> re . IGNORECASE ) : <EOL> minimum_required_found = True <EOL> if not minimum_required_found : <EOL> message += """<STR_LIT>""" <EOL> if project_line_number is None : <EOL> message += """<STR_LIT>""" . format ( <EOL> project_name = suggested_project_name ) <EOL> if find_qibuild_line_number is not None and project_line_number is not None and project_line_number > find_qibuild_line_number : <EOL> message += """<STR_LIT>""" <EOL> if message : <EOL> raise IncorrectCMakeLists ( cmake_list_file , message ) <EOL> class IncorrectCMakeLists ( qisys . error . Error ) : <EOL> def __init__ ( self , cmake_list_file , message ) : <EOL> self . cmake_list_file = cmake_list_file <EOL> self . message = message <EOL> def __str__ ( self ) : <EOL> message = "<STR_LIT>" <EOL> message += "<STR_LIT>" % self . cmake_list_file <EOL> message += self . message <EOL> return message </s>
