1 # Astxx, the Asterisk C++ API and Utility Library.
2 # Copyright (C) 2005, 2006 Matthew A. Nicholson
3 # Copyright (C) 2006 Tim Blechmann
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License version 2.1 as published by the Free Software Foundation.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 import os, sys, traceback
21 from fnmatch import fnmatch
23 def DoxyfileParse(file_contents, dir, data = None):
25 Parse a Doxygen source file and return a dictionary of all the values.
26 Values will be strings and lists of strings.
29 if data is None : data = {}
32 lex = shlex.shlex(instream = file_contents, posix = True)
33 lex.wordchars += "*+./-:"
34 lex.whitespace = lex.whitespace.replace("\n", "")
38 token = lex.get_token()
45 def append_data(data, key, new_data, token):
46 if new_data or len(data[key]) == 0:
47 data[key].append(token)
49 data[key][-1] += token
53 if last_token not in ['\\']:
58 if key == '@' : key += token
60 if token != '@' : key_token = False
62 if token == "+=" or (token == "==" and key == "@INCLUDE"):
63 if not data.has_key(key):
68 append_data( data, key, new_data, token )
71 inc = os.path.join(dir,data['@INCLUDE'][-1])
72 if os.path.exists(inc) :
73 DoxyfileParse(open(inc).read(),dir,data)
76 token = lex.get_token()
78 if last_token == '\\' and token != '\n':
80 append_data( data, key, new_data, '\\' )
82 # compress lists of len 1 into single strings
83 for (k, v) in data.items():
84 if k == "@INCLUDE" : continue
88 # items in the following list will be kept as lists and not converted to strings
89 if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS"]:
99 def DoxySourceScan(node, env, path):
101 Doxygen Doxyfile source scanner. This should scan the Doxygen file and add
102 any files used to generate docs to the list of source files.
104 default_file_patterns = [
105 '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx',
106 '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++',
107 '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm',
111 default_exclude_patterns = [
117 data = DoxyfileParse(node.get_contents(), str(node.dir))
119 if data.get("RECURSIVE", "NO") == "YES":
124 file_patterns = data.get("FILE_PATTERNS", default_file_patterns)
125 exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns)
127 for i in data.get("INPUT", [ "." ]):
128 input = os.path.normpath(os.path.join(str(node.dir),i))
129 if os.path.isfile(input):
130 sources.append(input)
131 elif os.path.isdir(input):
133 entries = os.walk(input)
135 entries = [ (input, [], os.listdir(input)) ]
136 for root, dirs, files in entries:
138 filename = os.path.join(root, f)
140 pattern_check = reduce(lambda x, y: x or bool(fnmatch(filename, y)), file_patterns, False)
141 exclude_check = reduce(lambda x, y: x and fnmatch(filename, y), exclude_patterns, True)
143 if pattern_check and not exclude_check:
144 sources.append(filename)
146 sources.extend([ os.path.normpath(os.path.join(str(node.dir),x))
147 for x in data.get("@INCLUDE",[]) ])
149 for key in ('HTML_HEADER','HTML_FOOTER','TAGFILES'):
150 if data.has_key(key):
152 if type(elt) is type ("") : elt = [ elt ]
153 sources.extend([ os.path.normpath(os.path.join(str(node.dir),f))
156 sources = map( lambda path: env.File(path), sources )
159 def DoxySourceScanCheck(node, env):
160 """Check if we should scan this file"""
161 return os.path.isfile(node.path)
163 def DoxyEmitter(source, target, env):
164 """Doxygen Doxyfile emitter"""
165 # possible output formats and their default values and output locations
167 "HTML": ("YES", "html"),
168 "LATEX": ("YES", "latex"),
169 "RTF": ("NO", "rtf"),
170 "MAN": ("YES", "man"),
171 "XML": ("NO", "xml"),
174 data = DoxyfileParse(source[0].get_contents(), str(source[0].dir))
177 out_dir = data.get("OUTPUT_DIRECTORY", ".")
179 # add our output locations
180 for (k, v) in output_formats.items():
181 if data.get("GENERATE_" + k, v[0]) == "YES":
182 # Grmpf ... need to use a File object here. The problem is, that
183 # Dir.scan() is implemented to just return the directory entries
184 # and does *not* invoke the source-file scanners .. ARGH !!
185 node = env.File( os.path.join(str(source[0].dir), out_dir, data.get(k + "_OUTPUT", v[1]), ".stamp" ))
186 targets.append( node )
188 if data.has_key("GENERATE_TAGFILE"):
189 targets.append(env.File( os.path.join(str(source[0].dir), data["GENERATE_TAGFILE"]) ))
191 # don't clobber targets
195 # set up cleaning stuff
197 env.Clean(node, node)
199 return (targets, source)
203 Add builders and construction variables for the
204 Doxygen tool. This is currently for Doxygen 1.4.6.
206 doxyfile_scanner = env.Scanner(
209 scan_check = DoxySourceScanCheck,
212 doxyfile_builder = env.Builder(
213 # scons 0.96.93 hang on the next line but I don't know hot to FIX the problem
214 action = env.Action("( cd ${SOURCE.dir} && ${DOXYGEN} ${SOURCE.file} ) && touch $TARGETS"),
215 emitter = DoxyEmitter,
216 target_factory = env.fs.Entry,
217 single_source = True,
218 source_scanner = doxyfile_scanner
221 env.Append(BUILDERS = {
222 'Doxygen': doxyfile_builder,
231 Make sure doxygen exists.
233 return env.Detect("doxygen")