B
    0ªa¼*  ã               @   sÐ   d dl mZ d dl mZ d dl mZ d dl mZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ ddlmZ dd	lmZ dd
lmZ dZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ ZdS )é    )Úabsolute_import)Údivision)Úprint_function)Úunicode_literalsN)Ú	LinkErroré   )ÚIntrospectionBinary)Úutils)Ú	CCompilera  /* This file is generated, do not edit */
#include <glib.h>
#include <string.h>
#include <stdlib.h>

%(gdump_include)s

int
main(int argc, char **argv)
{
  GError *error = NULL;
  const char *introspect_dump_prefix = "--introspect-dump=";

#if !GLIB_CHECK_VERSION(2,35,0)
  g_type_init ();
#endif

  %(init_sections)s

  if (argc != 2 || !g_str_has_prefix (argv[1], introspect_dump_prefix))
    {
      g_printerr ("Usage: %%s --introspect-dump=input,output", argv[0]);
      exit (1);
    }

  if (!dump_irepository (argv[1] + strlen(introspect_dump_prefix), &error))
    {
      g_printerr ("%%s\n", error->message);
      exit (1);
    }
  exit (0);
}
c               @   s   e Zd ZdS )ÚCompilerErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú2/usr/lib/gobject-introspection/giscanner/dumper.pyr   N   s   r   c               @   s   e Zd ZdS )ÚLinkerErrorN)r   r   r   r   r   r   r   r   R   s   r   c               @   sB   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dS )ÚDumpCompilerNc             C   s|   || _ || _|| _tƒ | _tj dd¡| _tj d¡| _	dg| _
| j
 |j¡ | j ¡ rbdg| _nt tj dd¡¡| _d S )NZ
PKG_CONFIGz
pkg-configZ UNINSTALLED_INTROSPECTION_SRCDIRzgio-2.0 gmodule-2.0zlink.exeZCCZcc)Ú_optionsÚ_get_type_functionsÚ_error_quark_functionsr
   Ú	_compilerÚosÚenvironÚgetÚ_pkgconfig_cmdÚ_uninst_srcdirÚ	_packagesÚextendZpackagesÚcheck_is_msvcÚ_linker_cmdÚshlexÚsplit)ÚselfÚoptionsÚget_type_functionsÚerror_quark_functionsr   r   r   Ú__init__Z   s    

zDumpCompiler.__init__c          
   C   sÐ  t jddt ¡ d}t tj |d¡¡ i }| jd k	rJtj | jdd¡}ntj tj t¡dd¡}tj 	|¡s|t
d|f ƒ‚t|ƒ}| ¡ }W d Q R X ||d	< d
 | jj¡|d< |  |d¡}t|dƒ}| t| ¡ t| jƒdkrZx | jD ]}| d| d ¡ qòW | d¡ d}	x4| jD ]*}|	r2d}	n
| d¡ | d| ¡ q"W | d¡ t| jƒdkrÜx"| jD ]}| d| d ¡ qrW | d¡ d}	x4| jD ]*}|	r´d}	n
| d¡ | d| ¡ q¤W | d¡ W d Q R X | jjjrþ| jjj}
nd}
|  ||
¡}y|  |¡}W nJ tk
rf } z*t d¡sFt |¡ t
dt|ƒ ƒ‚W d d }~X Y nX y|  ||¡ W nJ t k
rÂ } z*t d¡s¢t |¡ t
dt|ƒ ƒ‚W d d }~X Y nX t!|g|ƒS )NÚ ztmp-introspect)Údirz.libsZgirepositoryzgdump.czgobject-introspection-1.0zCouldn't find %rZgdump_includeÚ
Úinit_sectionsz.cÚwr   zextern GType z(void);
z(GType (*GI_GET_TYPE_FUNCS_[])(void) = {
TFz,
z  z
};
zextern GQuark z,GQuark (*GI_ERROR_QUARK_FUNCS_[])(void) = {
z
save-tempsz'compilation of temporary binary failed:z$linking of temporary binary failed: )"ÚtempfileZmkdtempr   ÚgetcwdÚmkdirÚpathÚjoinr   ZDATADIRÚisfileÚ
SystemExitÚopenÚreadr   r*   Ú_generate_tempfileÚwriteÚ_PROGRAM_TEMPLATEÚlenr   r   r   ZcompilerZexe_extensionÚ_compiler   r	   Zhave_debug_flagÚshutilZrmtreeÚstrÚ_linkr   r   )r"   ÚtmpdirZtpl_argsZ
gdump_pathZ
gdump_fileZgdump_contentsZc_pathÚfÚfuncÚfirstZextZbin_pathZintrospection_objÚer   r   r   Úrunm   sn    







"
"zDumpCompiler.runr'   c             C   s$   d| j j| j j|f }tj ||¡S )Nz%s-%s%s)r   Znamespace_nameZnamespace_versionr   r/   r0   )r"   r=   ÚsuffixZtmplr   r   r   r5   ¹   s    zDumpCompiler._generate_tempfilec             C   sR   | j  ¡ r| jd|g}n
| j|g}tj|| j tjd}| ¡ \}}| d¡ 	¡ S )Nz--msvc-syntax)ÚstdoutÚascii)
r   r   r   Ú
subprocessÚPopenr   ÚPIPEZcommunicateÚdecoder!   )r"   ÚflagÚcmdÚprocÚoutÚerrr   r   r   Ú_run_pkgconfig¾   s    


zDumpCompiler._run_pkgconfigc             G   s$   |   d¡}| j || jj|| jj¡S )Nz--cflags)rO   r   Úcompiler   Zcpp_includesr*   )r"   ÚsourcesZpkgconfig_flagsr   r   r   r9   Ë   s
    
zDumpCompiler._compilec          
   C   sÆ  g }t  | j¡}|rD| |¡ | d¡ | d¡ | jjrD| d¡ | | j¡ | j ¡ rl| d| g¡ n2| d|g¡ |ržt	j
dkr”| d¡ n
| d¡ | j ¡ søx&t t	j d	d
¡¡D ]}| |¡ q¾W x&t t	j dd
¡¡D ]}| |¡ qæW x&|D ]}t	j |¡sþtd|f ƒ‚qþW | |¡ |  d¡}| jjsj| j ||| jj| jj| jj¡ | |¡ n| |¡ | j || jj¡ | j ¡ s¼x(t t	j dd
¡¡D ]}	| |	¡ q¨W | jjsätdt |¡f ƒ tj ¡  t	j dd ¡}
|
rlt	j dd¡}t  ¡ \}}t	 !|d¡.}d "dd„ |D ƒ¡}d #|¡}| $|¡ W d Q R X t  %|¡}|| &dd¡g}zByt '|¡ W n. tj(k
rª } zt)|ƒ‚W d d }~X Y nX W d |
rÀt	 *|¡ X d S )Nz--mode=linkz--tag=CCz--silentz-out:z-oÚntz-Wl,--export-all-symbolsz-export-dynamicZCPPFLAGSr'   ZCFLAGSzCould not find object file: %sz--libsZLDFLAGSzg-ir-scanner: link: %sZMSYSTEMZSHELLzsh.exeÚwbú c             S   s   g | ]}|  d d¡‘qS )ú\ú/)Úreplace)Ú.0Úxr   r   r   ú
<listcomp>  s    z&DumpCompiler._link.<locals>.<listcomp>z#!/bin/sh
unset PWD
{}
rU   rV   )+r	   Zget_libtool_commandr   r   ÚappendÚquietr   r   r   r   Únamer    r!   r   r   r/   Úexistsr   rO   Zexternal_libraryZget_internal_link_flagsZ	librariesZextra_librariesZlibrary_pathsZget_external_link_flagsÚprintrF   Zlist2cmdlineÚsysrD   Úflushr,   ZmkstempÚfdopenr0   Úformatr6   ZwhichrW   Z
check_callZCalledProcessErrorr   Úremove)r"   ÚoutputrQ   ÚargsZlibtoolZcppflagZcflagÚsourceZpkg_config_libsZldflagZmsysÚshellZtfZtf_namer>   ZshellcontentsZ	fcontentsrA   r   r   r   r<   Ò   sv    

















zDumpCompiler._link)r'   )
r   r   r   r   r&   rB   r5   rO   r9   r<   r   r   r   r   r   V   s   L
r   c             C   s   t | ||ƒ}| ¡ S )N)r   rB   )r#   r$   r%   Zdcr   r   r   Úcompile_introspection_binary+  s    ri   )Z
__future__r   r   r   r   r   r`   r    rF   r:   r,   Zdistutils.errorsr   Zgdumpparserr   r'   r	   Z	ccompilerr
   r7   Ú	Exceptionr   r   Úobjectr   ri   r   r   r   r   Ú<module>   s&   & V