<s> from pypy . tool . autopath import pypydir <EOL> from pypy . translator . platform import platform , CompilationError <EOL> from pypy . translator . tool . cbuild import ExternalCompilationInfo <EOL> from pypy . tool . compat import md5 <EOL> import py <EOL> cache_dir_root = py . path . local ( pypydir ) . join ( '<STR_LIT>' ) . ensure ( dir = <NUM_LIT:1> ) <EOL> def cache_file_path ( c_files , eci , cachename ) : <EOL> cache_dir = cache_dir_root . join ( cachename ) . ensure ( dir = <NUM_LIT:1> ) <EOL> filecontents = [ c_file . read ( ) for c_file in c_files ] <EOL> key = repr ( ( filecontents , eci ) ) <EOL> hash = md5 ( key ) . hexdigest ( ) <EOL> return cache_dir . join ( hash ) <EOL> def build_executable_cache ( c_files , eci ) : <EOL> path = cache_file_path ( c_files , eci , '<STR_LIT>' ) <EOL> try : <EOL> return path . read ( ) <EOL> except py . error . Error : <EOL> result = platform . execute ( platform . compile ( c_files , eci ) ) <EOL> path . write ( result . out ) <EOL> return result . out <EOL> def try_compile_cache ( c_files , eci ) : <EOL> path = cache_file_path ( c_files , eci , '<STR_LIT>' ) <EOL> try : <EOL> data = path . read ( ) <EOL> except py . error . Error : <EOL> data = '<STR_LIT>' <EOL> if not ( data . startswith ( '<STR_LIT:True>' ) or data . startswith ( '<STR_LIT>' ) ) : <EOL> try : <EOL> platform . compile ( c_files , eci ) <EOL> data = '<STR_LIT:True>' <EOL> except CompilationError , e : <EOL> data = '<STR_LIT>' % ( e , ) <EOL> path . write ( data ) <EOL> if data . startswith ( '<STR_LIT:True>' ) : <EOL> return True <EOL> else : <EOL> assert data . startswith ( '<STR_LIT>' ) <EOL> msg = data [ len ( '<STR_LIT>' ) : ] <EOL> raise CompilationError ( msg . strip ( ) , '<STR_LIT>' ) </s>
