
    0hn                     x   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK	J
r
Jr  S SKJr  S SKJrJr  S SKJr  S SKJrJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SK J!r!J"r"  S SK#J$r$  SSK%J&r&  S r'S r(S r)S r*S r+S r,S r-S r.S r/S r0S r1S r2S r3S r4S r5S r6S  r7S! r8S" r9S# r:g)$    N)message	pkgconfig)GtkDocCommentBlockParser)Include	Namespace)compile_introspection_binary)GDumpParserIntrospectionBinary)IntrospectablePass)	GIRParser	GIRWriter)MainTransformer)resolve_shlibs)SourceScannerALL_EXTS)Transformer   )utilsc                    [        UR                  U R                  5      n[        UR                  5      S:  a  UR                  S   S:w  a  UR                  R                  S5      nUS:X  aA  UR                  (       a0  UR                  S   S:w  a  XSR                  R                  S5      -  nUR                  [        R                  " U5      5        [        UR                  5      S:  a  UR                  S   S:w  a  M  g g g g )Nr   --cflags-end-I)	getattrvaluesdestlenrargspopappendr   cflag_real_include_path)optionoptvalueparsercflagsargs         3/lib/gobject-introspection/giscanner/scannermain.pyprocess_cflags_beginr(   0   s    V]]FKK0F
fll
a
FLLO~$Ellq!$;6<<FLLO~,M<<##A&&Ce33C89 fll
a
FLLO~$E
$E
    c                     g N )r!   r"   r#   r$   s       r'   process_cflags_endr-   :   s    r)   c                     [        UR                  U R                  5      nUR                  [        R
                  R                  U5      5        g r+   )r   r   r   r   ospathrealpath)r!   r"   r#   r$   cpp_includess        r'   process_cpp_includesr3   >   s3    6==&++6L((/0r)   c           
      4   [         R                  " U S5      nUR                  SSSS/ S[        S9  UR                  SSS	S[        S
9  UR                  SSS/ SS[
        S9  UR                  SSSS/ S9  UR                  SSSS/ S9  UR                  SSSS9  U$ )NzPreprocessor options z--cflags-beginz!Start preprocessor/compiler flagsr%   callback)helpr   defaultactionr6   r   zEnd preprocessor/compiler flags)r7   r9   r6   r   zPre-processor include filer2   string)r7   r   r8   typer9   r6   -DzPre-processor definer   cpp_definesr7   r9   r   r8   -UzPre-processor undefinecpp_undefinesz-pIgnored)r   r7   )optparseOptionGroup
add_optionr(   r-   r3   r$   groups     r'   get_preprocessor_option_grouprG   C   s      )?@E	R)="B&1E  G 
R;&1C  E 
T <("8&1E  G 
T 6$=  ! 
T 8$?  ! 
T3Lr)   c                 Z    [         R                  " U S5      nUR                  SSSS/ S9  U$ )NzMachine Dependent Optionsz-mzsome machine dependent optionr   m_optionr>   )rB   rC   rD   rE   s     r'   get_windows_option_grouprJ   Y   s<      )DEE	T ?$:  ! Lr)   c            	         [         R                  " SS[        R                  -   S9n U R	                  SSSSSS	S
9  U R	                  SSSSSSS
9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SSSSS SS
9  U R	                  SSSSS S S
9  U R	                  SS!SS"S S#S
9  U R	                  SS$SS%S S&S
9  U R	                  SS'SS(/ S)S
9  U R	                  SS*SS+S S,S
9  U R	                  SS-SS.SS/S
9  U R	                  SS0SS1SS2S
9  U R	                  S3S4SS5/ S6S
9  U R	                  SS7SS8/ S9S
9  U R	                  S:S;SS</ S=S
9  U R	                  SS>SS?/ S@S
9  U R	                  SASBSSCSDSE9  U R	                  SSFSSGSHSE9  U R	                  SSISSJSKSE9  U R	                  SSLSSM/ SNS
9  U R	                  SSOSSPSSQS
9  U R	                  SSRSSS/ STS
9  U R	                  SSUSSVSSWS
9  U R	                  SSXSSYSSZS
9  U R	                  SS[SS\/ S]S
9  U R	                  S^S_SS`SaSbS
9  U R	                  SScSSd/ SeS
9  U R	                  SSfSSg/ ShS
9  U R	                  SSiSSjSSkS
9  U R	                  SSlSSmSnSE9  U R	                  SSoSSpSSqS
9  U R	                  SrSsSStSuSE9  U R	                  SSvSSw/ SxS
9  U R	                  SSySSz/ S{S
9  U R	                  SS|SS}S S~S
9  U R	                  SSSSSSE9  [        U 5      nU R                  U5        [        R                  R                  S5      nU(       a2  UR                  S5      (       a  [        U 5      nU R                  U5        U R	                  SSSSS [         R                  S
9  U R	                  SSSSS [         R                  S
9  U R	                  SSSSS[         R                  S
9  U R	                  SSSS[         R                  SE9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SSSS/ SS
9  U R	                  SS/ SSS9  U $ )Nz%prog [options] sourcesz%prog )versionr5   z--quiet
store_truequietFz3If passed, do not print details of normal operation)r9   r   r8   r7   z--formatstoreformatgirzformat to use, one of gidl, girz-iz	--includer   includesz$Add specified gir file as dependencyz--include-uninstalledincludes_uninstalledzA file path to a dependency; only use this "
                            "when building multiple .gir files inside a "
                            "single module.z--add-include-pathinclude_pathsz!include paths for other GIR filesz	--programprogramzprogram to executez--use-binary-wrapperwrapperzAwrapper to use for running programs (useful when cross-compiling)z--use-ldd-wrapperldd_wrapperz;wrapper to use instead of ldd (useful when cross-compiling)z--lib-dirs-envvarlib_dirs_envvarzenvironment variable to write a list of library directories to (for running the transient binary), instead of standard LD_LIBRARY_PATHz--program-argprogram_argszextra arguments to programz	--libtoollibtool_pathzfull path to libtoolz--no-libtool	nolibtoolzdo not use libtoolz--external-libraryexternal_libraryzJIf true, the library is located on the system,not in the current directory-lz	--library	librarieszlibraries of this unitz--extra-libraryextra_librariesz*Extra libraries to link the binary against-Lz--library-pathlibrary_pathsz#directories to search for librariesz--header-onlyheader_onlyz<If specified, just generate a GIR for the given header filesz-nz--namespacenamespace_namez]name of namespace for this unit, also used to compute --identifier-prefix and --symbol-prefix)r9   r   r7   z--nsversionnamespace_versionz"version of namespace for this unitz--strip-prefixstrip_prefixzXOption --strip-prefix is deprecated, please see --identifier-prefix
and --symbol-prefix.z--identifier-prefixidentifier_prefixeszRemove this prefix from C identifiers (structure typedefs, etc.).
May be specified multiple times.  This is also used as the default for --symbol-prefix if
the latter is not specified.z--identifier-filter-cmdidentifier_filter_cmdzFilter identifiers (struct and union typedefs) through the given shell command which will receive the identifier name as input to stdin and is expected to output the filtered results to stdout.z--symbol-prefixsymbol_prefixesz2Remove this prefix from C symbols (function names)z--symbol-filter-cmdsymbol_filter_cmdzFilter symbols (function names) through the given shell command which will receive the symbol name as input to stdin and is expected to output the filtered results to stdout.z--accept-unprefixedaccept_unprefixedzTIf specified, accept symbols and identifiers that do not
match the namespace prefix.z--add-init-sectioninit_sectionsz:add extra initialization code in the introspection programz-oz--outputoutput-z3output filename to write to, defaults to - (stdout)z--pkgpackagesz&pkg-config packages to get cflags fromz--pkg-exportpackages_exportz/Associated pkg-config packages for this libraryz
--warn-allwarn_allz.If true, enable all warnings for introspectionz--warn-error
warn_fatalzTurn warnings into fatal errorsz--strictwarn_strictz1If true, enable strict warnings for introspectionz-vz	--verboseverbosez
be verbosez--c-include
c_includesz.headers which should be included in C programsz
--filelistfilelistz1file containing headers and sources to be scannedz
--compilercompilerz the C compiler to use internallyz--doc-format
doc_formatz}name of the documentation format used in the project, should be one of gi-docgen, gtk-doc-docbook, gtk-doc-markdown or hotdocMSYSTEMMINGWz--generate-typelib-teststest_codegenz--passthrough-girpassthrough_girz--reparse-validatereparse_validate_girz--typelib-xmltypelib_xmlz--function-decorationfunction_decorationz-Macro to decorate functions in generated codez--include-first-in-headerinclude_first_headerz+Header to include first in generated headerz--include-last-in-headerinclude_last_headerz=Header to include after the other headers in generated headerz--include-first-in-srcinclude_first_srcz,Header to include first in generated sourcesz--include-last-in-srcinclude_last_srcz>Header to include after the other headers in generated sourcesz--sources-top-dirszPaths to the sources directories used to determine relative files locations to be used in the gir file. This is especially useful when build dir and source dir are different and mirrored.)r8   r9   r7   )rB   OptionParser	giscanner__version__rD   rG   add_option_groupr/   environget
startswithrJ   SUPPRESS_HELP)r$   rF   
msystemenvs      r'   _get_option_parserr   b   sX   ""#<+3i6K6K+KMF
b))#P  R b*$8#<  > dK%JA  C b1%,BB/  1
 b.%OR>  @ b+$9d/  1 b0$9d^  ` b-$=$X  Z b-$+<d d  e b/%NB7  9 b+$>41  3 b.)U/  1 b.)0BE?  A dK%K3  5 b+%,=rG  I d,%OR@  B b/)rY  [ dM$+;V  X b-$+>?  A b*$>   b/%,A2   !
 b3$+BB`  a
 b+%,=rO  Q b/$+>`  a
 b/)0CU    b.%ORM  O dJ$8SP  R b'%JC  E b.%,=rL  N b,)
EK  M b.)<  > b*)uN  P dK)	'  ) b-%L"K  M b,$:rN  P b,$:t=  ? b.$<9  ; *&1E
E"	*Jj++G44(0& b4$>4#11  3 b-$+<d#11  3 b.)0FPU#11  3 b/)#11  3 b1%,A2J  L b5%,BBH  J b4%,A2Z  \ b2%,?I  K b1%,>[  ] b.8'  ( Mr)   c                      [        SU < 35      e)NzERROR: )
SystemExit)msgs    r'   _errorr     s    
C*
++r)   c                     [        5       nUR                  U 5        [        UR                  5       5      nUR	                  UR                  5       5        g r+   )r   parser   get_namespacewriteget_encoded_xml)r0   fr$   writers       r'   r{   r{     s=    [F
LLv++-.FGGF""$%r)   c           	          U R                  S5      u  pgnUS:X  a%  SSKJn	  U	" UUUUUUU5      n
U
R                  5         g[	        SU< S35        g)N,
Everythingr   )EverythingCodeGeneratorzInvalid namespace ''r   )splittestcodegenr   r   r   )	optstringr~   r   r   r   r   	namespaceout_h_filenameout_c_filenamer   gens              r'   rz   rz     s`     3<//#2F/YL 8%n&4&9&:&9&7&68 			  	978r)   c              #   j   #    U  H)  nU H   nUR                  U5      (       d  M  Uv     M'     M+     g 7fr+   )r   )rl   allowed_flagsr!   flags       r'   process_optionsr   4  s5     !D$$T**L	 " s   13c                    [         R                  " U5      n/ SQn[        [        X#5      5      n[	        5       nUR                  U5      u  pgU R                  R                  UR                   Vs/ s H"  n[        R                  R                  U5      PM$     sn5        U R                  R                  UR                  5        U R                  R                  UR                  5        g s  snf )N)r   r<   r?   r]   r`   )r   r%   listr   r   
parse_argsr2   extendr/   r0   r1   r=   r@   )	optionsrn   flagsoptions_whitelistfiltered_outputr$   pkg_optionsunusedr   s	            r'   process_packagesr   =  s    X&E 7?5DEO!F ++O<Kk>V>V W>V!1!1!!4>V WX{667  !:!:; !Xs   /)C*c                     / nU  Hs  n[         R                  R                  U5      S   [        ;   d  M/  [         R                  R	                  U5      (       d  [        U< S35        UR                  U5        Mu     U$ )Nr   z: no such a file or directory)r/   r0   splitextr   existsr   r   )args	filenamesr&   s      r'   extract_filenamesr   J  se    I 77C #x/77>>#&&CBC S!  r)   c                 
   / n[         R                  R                  U R                  5      (       d  [	        U R                  < S35        [        U R                  SS S9 nUR                  5       nS S S 5        W H  nUR                  5       nUR                  S5      (       d  UR                  S5      (       dp  UR                  S5      (       dZ  UR                  S5      (       dD  UR                  S5      (       d.  UR                  S	5      (       d  UR                  S
5      (       d  M  [         R                  R                  U5      (       d  [	        U< S35        UR                  U5        M     U$ ! , (       d  f       GN
= f)Nz: no such filelist filer)encodingz.cz.cppz.ccz.cxxz.hz.hppz.hxxz2: Invalid filelist entry-no such file or directory)
r/   r0   r   ru   r   open	readlinesstripendswithr   )r   r   filelist_filelineslinefilenames         r'   extract_filelistr   X  s#   I77>>'**++g.>.>AB	gd	3}'') 
4 ::<d##x'8'8'@'@U##x'8'8'@'@T""h&7&7&?&?V$$77>>(++QUXY X&   
4	3s   E33
Fc                    U R                   (       a0  [        S5        U R                  R                  U R                   5        U R                  (       a  U R                  nOS nU R                  (       aA  U R                   H$  nUR                  5       U:w  d  M  [        S5        M&     U R                  nOS n[        U R                  U R                  UUS9$ )Nzng-ir-scanner: warning: Option --strip-prefix has been deprecated;
see --identifier-prefix and --symbol-prefix.z5Values for --symbol-prefix must be entirely lowercase)rf   rh   )
re   printrf   r   rh   lowerr   r   rc   rd   )r   rf   prefixrh   s       r'   create_namespacer   n  s     0 	1##**7+?+?@
 ""%99"--F ||~'NO	 .
 "11W++..)<%46 6r)   c                    [         R                  " UR                  5      n[         R                  " UR                  5      n[	        U UR
                  UUS9nUR                  UR                  5        UR                  (       d  UR                  (       a   UR                  5         UR                  5         UR                   HO  n[        R                  U;   a  [        SU< S35         [         R"                  " U5      nUR'                  W5        MQ     UR(                   H  nUR+                  U5        M     U$ ! [$         a    [        SU< S35         NWf = f)N)rj   rg   ri   zInvalid include path 'r   zMalformed include 'z'
)shlexr   rg   ri   r   rj   set_include_pathsrT   r{   r|   disable_cacheset_passthrough_moderR   r/   sepr   r   from_string	Exceptionregister_includerS   register_include_uninstalled)r   r   rg   ri   transformerincludeinclude_objinclude_paths           r'   create_transformerr     s   !KK(E(EFG$=$=>i070I0I4I0ACK !!'"7"78'">">!!#((*##66W'<=	=!--g6K 	$$[1 $  4400> 5   	=;<	=s   (D99EEc                 H   [        U 5      nUR                  5         UR                  (       a4  UR                  /nUR                  UR                  5        [        U5      nO)[        UUR                  5       UR                  5       5      n[        XUR                  5      nUR                  (       aP  UR                  /UR                  -   Ul        [        R                  " U5      nUb  US/-   UR                  -   Ul        UR                  U5        UR!                  5         U$ )Nz--mode=execute)r	   
init_parserU   r   rY   r
   r   get_get_type_functionsget_error_quark_functionsr   r^   rV   r   r   get_libtool_commandset_introspection_binaryr   )r   r   r   gdump_parserbinaryshlibslibtools          r'   create_binaryr     s     {+L  G(()$T*-g.:.Q.Q.S.:.T.T.VX GW->->?F'&++5++G4!%5$66DFK))&1Mr)   c                    [        U S5      (       a  U R                  (       a  [        U 5      nO[        U5      nU Vs/ s H"  n[        R
                  R                  U5      PM$     nn[        R                  " 5       S:X  a  U R                  R                  S5        [        5       n[        U S5      (       a,  U R                  (       a  UR                  U R                  5        UR                  U R                  U R                   U R                  U R"                  S9   UR%                  U5        UR'                  U5        UR)                  5        H  n[+        U[,        R.                  S9  M     UR)                  5       (       a  U R0                  (       a  [3        S5        XB4$ s  snf ! UR)                  5        H  n[+        U[,        R.                  S9  M     f = f)Nru   Darwin
__BLOCKS__rv   )r%   )filez#error caught during scanner parsing)hasattrru   r   r   r/   r0   r1   platformsystemr@   r   r   rv   set_compilerset_cpp_optionsr2   r=   r%   parse_filesparse_macros
get_errorsr   sysstderrrq   r   )r   r   r   r   sserrors         r'   create_source_scannerr     s]   w
##(8(8$W-	%d+	.78i!!!$iI8H$$$\2 
Bw
##(8(8
(()w++**,,%nn  .*
y!
	"]]_E%cjj) % 
}}7--45=1 9$ ]]_E%cjj) %s   )F$"F) )1Gc                    UR                   S:X  a-  [        R                  R                  n UR	                  U 5        gUR                  (       Ga  [        R                  " SS9u  pE[        R                  R                  UR                   5      (       a"  [        R                  " UR                   U5        OX[        R                   " U["        R$                  ["        R&                  -  ["        R(                  -  ["        R*                  -  5        [        R,                  " US5       nUR	                  U 5        SSS5        [        R                  " SS9u  pg[        R,                  " US5       n[/        XV5        SSS5        [0        R2                  " XW5      (       d  [        SU< SU< S	35        [        R4                  " U5         [        R6                  " XQR                   5        g
 [?        UR                   S5       nUR	                  U 5        SSS5        g! [
         a#  n[        SUR                  < 35         SnAgSnAff = f! , (       d  f       GN= f! , (       d  f       N= f! [8         a:  nUR:                  [:        R<                  :X  a  [        R4                  " U5        e SnAff = f! , (       d  f       g= f! [
         a#  n[        SUR                  < 35         SnAgSnAff = f)z@Write encoded XML 'data' to the filename specified in 'options'.rm   zwhile writing output: Nz.gir)suffixwbz&Failed to re-parse gir file; scanned='z' passthrough='r   r   zopening/writing output: ) rl   r   stdoutbufferr   IOErrorr   strerrorr|   tempfilemkstempr/   r0   isfileshutilcopystatchmodstatS_IWUSRS_IRUSRS_IRGRPS_IROTHfdopenr{   r   files_are_identicalunlinkmoveOSErrorerrnoEPERMr   )datar   rl   emain_fmain_f_nametemp_ftemp_f_names           r'   write_outputr    s   ~~""	@LL 
	%	%	%&..f=GGNN7>>**OOGNNK8HH[\\DLL04<<?$,,NP YYvt$LL % '..f=YYvt$K0 %((BB[* +
		+	KK^^4
 	Bgnnd+vT" ,+=  	@>??	@ %$ %$  	ww%++%		+&	 ,+ 	B1::@AA	Bs}   H %I	,I I, (K >J3K 
I#II	
I
I),
J065J++J03
K=K K 
K1K,,K1c           
         U R                   (       a:  U R                    Vs/ s H"  n[        R                  R                  U5      PM$     sn$ U Vs/ s H"  n[        R                  R                  U5      PM$     nn[	        [        U Vs/ s H"  n[        R                  R                  U5      PM$     sn5      5      n[        [        R                  S5      (       d  U$ U(       d  / $  [        R                  R                  U5      n[        R                  R                  U5      U:X  a  U$ U/$ s  snf s  snf s  snf ! [         a    Us $ f = f)N
commonpath)
sources_top_dirsr/   r0   r1   sortedsetdirnamer   r  
ValueError)r   r   pr   dirscommons         r'   get_source_root_dirsr    s   -4-E-EF-E  #-EFF /88i!!!$iI8#9=9arwwq)9=>?D 277L))	##D) 
wwv&(8O/ G 9=  s#   )D/)D4	)D9(D> >EEc                 B
   [        5       nUR                  U 5      u  p UR                  (       a3  SS KnUR                  R                  UR                  R                  5        UR                  (       a$  [        UR                  [        R                  5        UR                  (       aL  [        UR                  UR                  UR                  UR                  UR                  UR                  5      $ [!        US5      (       a+  UR"                  (       d  [%        U 5      S::  a  ['        S5        UR(                  (       d  ['        S5        UR*                  S:X  a  SSKJn  O['        SUR*                  < 35        UR0                  (       d-  UR2                  (       d  UR4                  (       d  ['        S	5        / S
QnUR6                  (       a)  UR6                  U;  a  ['        SUR6                  < 35        [9        U5      n[:        R<                  R?                  US9nUR@                  (       a  URC                  S5        URD                  (       a  URG                  S5        [I        Xb5      n[K        URL                  5      n	U	RO                  URQ                  5       5        U	(       a   [S        X)5        [[        X 5      u  p[]        5       nUR_                  URa                  5       5      nURc                  URe                  5       5        UR4                  (       d  [g        XU 5      nO/ nXRh                  l5        [m        X5      nURo                  5         [p        Rr                  " S5        [u        X5      nURw                  5         UR@                  SL =(       a#    URD                  SL =(       a    URx                  SL nUR{                  5       nUR|                  (       a  US:  a  [:        R~                  " S5        gUS:  a+  U(       a$  [        SURh                  R                  U4-  5        UR                  (       a  UR                  nOURL                  nUR                  URh                  lC        UURh                  lD        UR6                  (       a  UR6                  URh                  l        [        X,5      nW" URh                  U5      nUR                  5       n[        UU5        g! [T        RV                   a  n
['        [Y        U
5      5         S n
A
GNcS n
A
ff = f)Nr   ru   r   zNeed at least one filenamezNamespace name missingrQ   r   zUnknown format: z#Must specify --program or --library)z	gi-docgenhotdoczgtk-doc-markdownzgtk-doc-docbookzUnknown doc-format: )r   TtreeFzwarnings configured as fatalzNg-ir-scanner: %s: warning: %d warnings suppressed (use --warn-all to see them))Hr   r   rs   	distutilslogset_thresholdDEBUGr{   r   r   rz   r~   r   r   r   r   r   ru   r   r   rc   rP   giscanner.girwriterr   r^   rU   rb   rw   r   r   MessageLoggerr   rp   enable_warningsrr   enable_strictr   r  rn   updateget_pkgconfig_packagesr   r   PkgConfigErrorstrr   r   parse_comment_blocksget_commentsr   get_symbolsr   r   shared_librariesr   	transformr   break_on_debug_flagr   validaterN   get_warning_countrq   fatalr   namero   rt   exported_packagesr  r   r  )r   r$   r   r#  WriterDOC_FORMATSr   loggerr   rn   r  r   r   cbpblocksr   mainfinalshow_suppressionwarning_countr9  r  r   r  s                           r'   scanner_mainrC  +  s   !F''-OW##IMM$7$78//<G00#77#88#77#55#446 	6 w
##G,<,<t9>/0!!'(~~;w~~89""45K g00C7+=+=@A )I""&&&;Ft$T"$Y8K7##$HOOK6689	W/ *'8MB
"
$C%%boo&78F bnn&'{T:-3*;/DNN	f%{3E	NN''50lW5H5HE5QlV]VcVcglVl,,.Mma/45		/ -$$))=;< 	=
 #33#,,'.'9'9K$.?K++2+=+=(+G?K))+;<F!!#Dwk '' 	3q6NN	s   +S+ +T?TT);r  rB   r/   r   r  r   r   r   r   r   r   r   giscanner.annotationparserr   giscanner.astr   r   giscanner.dumperr   giscanner.gdumpparserr	   r
   giscanner.introspectablepassr   giscanner.girparserr   r'  r   giscanner.maintransformerr   giscanner.shlibsr   giscanner.sourcescannerr   r   giscanner.transformerr   r5   r   r(   r-   r3   rG   rJ   r   r   r{   rz   r   r   r   r   r   r   r   r   r  r  rC  r,   r)   r'   <module>rN     s   ,   	   
     ( ? , 9 B ; ) ) 5 + ; - :	1
,m`,&,
<,6:4@@'BT8nr)   