<s> from pypy . translator . platform import Platform , log , CompilationError <EOL> import py , sys , os <EOL> from pypy . translator . tool import stdoutcapture <EOL> def log_spawned_cmd ( spawn ) : <EOL> def spawn_and_log ( cmd , * args , ** kwds ) : <EOL> log . execute ( '<STR_LIT:U+0020>' . join ( cmd ) ) <EOL> return spawn ( cmd , * args , ** kwds ) <EOL> return spawn_and_log <EOL> CFLAGS = [ '<STR_LIT>' ] <EOL> if os . name != '<STR_LIT>' : <EOL> so_ext = '<STR_LIT>' <EOL> else : <EOL> so_ext = '<STR_LIT>' <EOL> class DistutilsPlatform ( Platform ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> def __init__ ( self , cc = None ) : <EOL> self . cc = cc <EOL> if self . name == "<STR_LIT>" : <EOL> self . name = sys . platform <EOL> def _ensure_correct_math ( self ) : <EOL> if self . name != '<STR_LIT:win32>' : <EOL> return <EOL> from distutils import sysconfig <EOL> gcv = sysconfig . get_config_vars ( ) <EOL> opt = gcv . get ( '<STR_LIT>' ) <EOL> if opt and '<STR_LIT>' not in opt : <EOL> opt += '<STR_LIT>' <EOL> gcv [ '<STR_LIT>' ] = opt <EOL> def compile ( self , cfilenames , eci , outputfilename = None , standalone = True ) : <EOL> self . _ensure_correct_math ( ) <EOL> self . cfilenames = cfilenames <EOL> if standalone : <EOL> ext = '<STR_LIT>' <EOL> else : <EOL> ext = so_ext <EOL> self . standalone = standalone <EOL> self . libraries = list ( eci . libraries ) <EOL> self . include_dirs = list ( eci . include_dirs ) <EOL> self . library_dirs = list ( eci . library_dirs ) <EOL> self . compile_extra = list ( eci . compile_extra ) <EOL> self . link_extra = list ( eci . link_extra ) <EOL> self . frameworks = list ( eci . frameworks ) <EOL> if not self . name in ( '<STR_LIT:win32>' , '<STR_LIT>' ) : <EOL> if '<STR_LIT:m>' not in self . libraries : <EOL> self . libraries . append ( '<STR_LIT:m>' ) <EOL> self . compile_extra += CFLAGS + [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in self . libraries : <EOL> self . libraries . append ( '<STR_LIT>' ) <EOL> if self . name != '<STR_LIT>' : <EOL> self . compile_extra += [ '<STR_LIT>' ] <EOL> self . link_extra += [ '<STR_LIT>' ] <EOL> else : <EOL> self . compile_extra += [ '<STR_LIT>' ] <EOL> self . link_extra += [ '<STR_LIT>' ] <EOL> if self . name == '<STR_LIT:win32>' : <EOL> self . link_extra += [ '<STR_LIT>' ] <EOL> if self . name == '<STR_LIT>' : <EOL> for s in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if s + '<STR_LIT>' not in self . include_dirs and os . path . exists ( s + '<STR_LIT>' ) : <EOL> self . include_dirs . append ( s + '<STR_LIT>' ) <EOL> if s + '<STR_LIT>' not in self . library_dirs and os . path . exists ( s + '<STR_LIT>' ) : <EOL> self . library_dirs . append ( s + '<STR_LIT>' ) <EOL> self . compile_extra += CFLAGS + [ '<STR_LIT>' ] <EOL> for framework in self . frameworks : <EOL> self . link_extra += [ '<STR_LIT>' , framework ] <EOL> if outputfilename is None : <EOL> self . outputfilename = py . path . local ( cfilenames [ <NUM_LIT:0> ] ) . new ( ext = ext ) <EOL> else : <EOL> self . outputfilename = py . path . local ( outputfilename ) <EOL> self . eci = eci <EOL> import distutils . errors <EOL> basename = self . outputfilename . new ( ext = '<STR_LIT>' ) <EOL> data = '<STR_LIT>' <EOL> try : <EOL> saved_environ = os . environ . copy ( ) <EOL> c = stdoutcapture . Capture ( mixed_out_err = True ) <EOL> try : <EOL> self . _build ( ) <EOL> finally : <EOL> for key , value in saved_environ . items ( ) : <EOL> if os . environ . get ( key ) != value : <EOL> os . environ [ key ] = value <EOL> foutput , foutput = c . done ( ) <EOL> data = foutput . read ( ) <EOL> if data : <EOL> fdump = basename . new ( ext = '<STR_LIT>' ) . open ( "<STR_LIT:wb>" ) <EOL> fdump . write ( data ) <EOL> fdump . close ( ) <EOL> except ( distutils . errors . CompileError , <EOL> distutils . errors . LinkError ) , e : <EOL> raise CompilationError ( '<STR_LIT>' , data ) <EOL> except : <EOL> print >> sys . stderr , data <EOL> raise <EOL> return self . outputfilename <EOL> def _build ( self ) : <EOL> from distutils . ccompiler import new_compiler <EOL> from distutils import sysconfig <EOL> compiler = new_compiler ( force = <NUM_LIT:1> ) <EOL> if self . cc is not None : <EOL> for c in '''<STR_LIT>''' . split ( ) : <EOL> compiler . executables [ c ] [ <NUM_LIT:0> ] = self . cc <EOL> if not self . standalone : <EOL> sysconfig . customize_compiler ( compiler ) <EOL> compiler . spawn = log_spawned_cmd ( compiler . spawn ) <EOL> objects = [ ] <EOL> for cfile in self . cfilenames : <EOL> cfile = py . path . local ( cfile ) <EOL> compile_extra = self . compile_extra [ : ] <EOL> if <NUM_LIT:0> and self . fix_gcc_random_seed : <EOL> compile_extra . append ( '<STR_LIT>' % ( cfile . basename , ) ) <EOL> if '<STR_LIT>' in cfile . read ( ) : <EOL> compile_extra = [ arg for arg in compile_extra <EOL> if not arg . startswith ( '<STR_LIT>' ) ] <EOL> old = cfile . dirpath ( ) . chdir ( ) <EOL> try : <EOL> res = compiler . compile ( [ cfile . basename ] , <EOL> include_dirs = self . eci . include_dirs , <EOL> extra_preargs = compile_extra ) <EOL> assert len ( res ) == <NUM_LIT:1> <EOL> cobjfile = py . path . local ( res [ <NUM_LIT:0> ] ) <EOL> assert cobjfile . check ( ) <EOL> objects . append ( str ( cobjfile ) ) <EOL> finally : <EOL> old . chdir ( ) <EOL> if self . standalone : <EOL> cmd = compiler . link_executable <EOL> else : <EOL> cmd = compiler . link_shared_object <EOL> cmd ( objects , str ( self . outputfilename ) , <EOL> libraries = self . eci . libraries , <EOL> extra_preargs = self . link_extra , <EOL> library_dirs = self . eci . library_dirs ) <EOL> def include_dirs_for_libffi ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> def library_dirs_for_libffi ( self ) : <EOL> return [ '<STR_LIT>' ] </s>
