Add an annotation tool
[platform/upstream/gobject-introspection.git] / giscanner / annotationmain.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2010 Johan Dahlin
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
19 #
20
21 import optparse
22
23 from giscanner.annotationparser import AnnotationParser
24 from giscanner.scannermain import (get_preprocessor_option_group,
25                                    create_source_scanner,
26                                    process_packages)
27
28 def annotation_main(args):
29     parser = optparse.OptionParser('%prog [options] sources')
30
31     group = optparse.OptionGroup(parser, "Tool modes, one is required")
32     group.add_option("-e", "--extract",
33                      action="store_true", dest="extract",
34                      help="Extract annotations from the input files")
35     parser.add_option_group(group)
36
37     group = get_preprocessor_option_group(parser)
38     group.add_option("-L", "--library-path",
39                      action="append", dest="library_paths", default=[],
40                      help="directories to search for libraries")
41     group.add_option("", "--pkg",
42                      action="append", dest="packages", default=[],
43                      help="pkg-config packages to get cflags from")
44     parser.add_option_group(group)
45
46     options, args = parser.parse_args(args)
47
48     if not options.extract:
49         raise SystemExit("ERROR: Nothing to do")
50
51     if options.packages:
52         process_packages(options, options.packages)
53
54     ss = create_source_scanner(options, args)
55
56     if options.extract:
57         ap = AnnotationParser()
58         blocks = ap.parse(ss.get_comments())
59         for block in blocks.values():
60             print block.to_gtk_doc()
61             print
62     elif options.validate:
63         transformer = create_transformer(namespace, options)
64         transformer.parse(ss.get_symbols())
65
66         shlibs = create_binary(transformer, options, args)
67
68         ap = AnnotationParser()
69         blocks = ap.parse(ss.get_comments())
70
71         main = MainTransformer(transformer, blocks)
72         main.transform()
73
74         final = IntrospectablePass(transformer)
75         final.validate()
76
77
78     return 0