1 ! Copyright (C) 2010 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators environment gobject-introspection.common
4 gobject-introspection.ffi gobject-introspection.loader
5 gobject-introspection.types io io.files io.pathnames kernel lexer
6 locals make namespaces parser sequences splitting summary vocabs
8 FROM: namespaces => change-global ;
9 IN: gobject-introspection
11 ERROR: gir-not-found name paths ;
13 M: gir-not-found summary
14 [ name>> "“" "” file not found on paths:\n" surround ]
15 [ paths>> "\n" join ] bi
16 "\n\nUse the existing path or declare GIR_DIRS environment variable"
21 : system-gir-dirs ( -- dirs )
22 "XDG_DATA_DIRS" os-env "/usr/local/share/:/usr/share/" or
23 ":" split [ "gir-1.0" append-path ] map ;
25 : custom-gir-dirs ( -- dirs )
26 "GIR_DIRS" os-env ":" split ;
28 : current-vocab-path ( -- path )
29 current-vocab vocab-name "." split "/" join vocab-path ;
31 : current-vocab-dirs ( -- dirs )
34 [ , ] [ "/ffi" ?tail [ , ] [ drop ] if ] bi
37 :: resolve-gir-path ( path -- path )
40 current-vocab-dirs custom-gir-dirs system-gir-dirs
42 paths [ path append-path exists? ] find nip
43 [ path append-path ] [ path paths gir-not-found ] if*
46 : define-gir-vocab ( path -- )
47 resolve-gir-path dup "Loading " write print
48 file>xml xml>repository
50 [ namespace>> name>> current-namespace-name set-global ]
51 [ def-ffi-repository ]
53 V{ } clone implement-structs set-global ;
57 SYNTAX: GIR: scan define-gir-vocab ;
59 SYNTAX: IMPLEMENT-STRUCTS:
61 implement-structs [ swap append! ] change-global ;
63 SYNTAX: FOREIGN-ATOMIC-TYPE:
64 scan-token scan-object swap register-atomic-type ;
66 SYNTAX: FOREIGN-ENUM-TYPE:
67 scan-token scan-object swap register-enum-type ;
69 SYNTAX: FOREIGN-RECORD-TYPE:
70 scan-token scan-object swap register-record-type ;