Handle dependencies and output file ext overrides

- corrected basic dependencies (builds and 'scons -c' seem to work now)
- added support for output file EXTENSION override variables (HTML and MAN pages)
- TODOs: 1.) targets for MAN output don't work yet, 2.) more testing
This commit is contained in:
Dirk Baechle 2012-01-19 23:56:29 +01:00 committed by Ichthyostega
parent 56cedc74f3
commit 495765024c

View file

@ -25,6 +25,22 @@ import os.path
import glob
from fnmatch import fnmatch
# Currently supported output formats and their default
# values and output locations.
# From left to right:
# 1. default setting YES|NO
# 2. default output folder for this format
# 3. name of the (main) output file
# 4. default extension "
# 5. field for overriding the output file extension
output_formats = {
"HTML": ("YES", "html", "index", ".html", "HTML_FILE_EXTENSION"),
"LATEX": ("YES", "latex", "refman", ".tex", ""),
"RTF": ("NO", "rtf", "refman", ".rtf", ""),
"MAN": ("YES", "man", "", ".3", "MAN_EXTENSION"),
"XML": ("NO", "xml", "index", ".xml", ""),
}
def DoxyfileParse(file_contents):
"""
Parse a Doxygen source file and return a dictionary of all the values.
@ -130,25 +146,42 @@ def DoxySourceScan(node, env, path):
# go onto the sources list
conf_dir = os.path.dirname(str(node))
for node in data.get("INPUT", []):
if not os.path.isabs(node):
node = os.path.join(conf_dir, node)
if os.path.isfile(node):
sources.append(node)
elif os.path.isdir(node):
if recursive:
for root, dirs, files in os.walk(node):
for f in files:
filename = os.path.join(root, f)
input = data.get("INPUT")
if input:
for node in data.get("INPUT", []):
if not os.path.isabs(node):
node = os.path.join(conf_dir, node)
if os.path.isfile(node):
sources.append(node)
elif os.path.isdir(node):
if recursive:
for root, dirs, files in os.walk(node):
for f in files:
filename = os.path.join(root, f)
pattern_check = reduce(lambda x, y: x or bool(fnmatch(filename, y)), file_patterns, False)
exclude_check = reduce(lambda x, y: x and fnmatch(filename, y), exclude_patterns, True)
pattern_check = reduce(lambda x, y: x or bool(fnmatch(filename, y)), file_patterns, False)
exclude_check = reduce(lambda x, y: x and fnmatch(filename, y), exclude_patterns, True)
if pattern_check and not exclude_check:
sources.append(filename)
else:
for pattern in file_patterns:
sources.extend(glob.glob("/".join([node, pattern])))
if pattern_check and not exclude_check:
sources.append(filename)
else:
for pattern in file_patterns:
sources.extend(glob.glob("/".join([node, pattern])))
else:
# No INPUT specified, so apply plain patterns only
if recursive:
for root, dirs, files in os.walk('.'):
for f in files:
filename = os.path.join(root, f)
pattern_check = reduce(lambda x, y: x or bool(fnmatch(filename, y)), file_patterns, False)
exclude_check = reduce(lambda x, y: x and fnmatch(filename, y), exclude_patterns, True)
if pattern_check and not exclude_check:
sources.append(filename)
else:
for pattern in file_patterns:
sources.extend(glob.glob(pattern))
# Add tagfiles to the list of source files:
for node in data.get("TAGFILES", []):
@ -158,17 +191,20 @@ def DoxySourceScan(node, env, path):
sources.append(file)
# Add additional files to the list of source files:
def append_additional_source(option):
file = data.get(option, "")
if file != "":
if not os.path.isabs(file):
file = os.path.join(conf_dir, file)
if os.path.isfile(file):
sources.append(file)
def append_additional_source(option, formats):
for f in formats:
if data.get('GENERATE_'+f, output_formats[f][0]) == "YES":
file = data.get(option, "")
if file != "":
if not os.path.isabs(file):
file = os.path.join(conf_dir, file)
if os.path.isfile(file):
sources.append(file)
break;
append_additional_source("HTML_STYLESHEET")
append_additional_source("HTML_HEADER")
append_additional_source("HTML_FOOTER")
append_additional_source("HTML_STYLESHEET",['HTML'])
append_additional_source("HTML_HEADER",['HTML'])
append_additional_source("HTML_FOOTER",['HTML'])
sources = map( lambda path: env.File(path), sources )
return sources
@ -178,17 +214,8 @@ def DoxySourceScanCheck(node, env):
"""Check if we should scan this file"""
return os.path.isfile(node.path)
def DoxyEmitter(source, target, env):
def DoxyEmitter(target, source, env):
"""Doxygen Doxyfile emitter"""
# possible output formats and their default values and output locations
output_formats = {
"HTML": ("YES", "html"),
"LATEX": ("YES", "latex"),
"RTF": ("NO", "rtf"),
"MAN": ("YES", "man"),
"XML": ("NO", "xml"),
}
data = DoxyfileParse(source[0].get_contents())
targets = []
@ -200,8 +227,29 @@ def DoxyEmitter(source, target, env):
# add our output locations
for (k, v) in output_formats.items():
if data.get("GENERATE_" + k, v[0]) == "YES":
targets.append(env.Dir( os.path.join(out_dir, data.get(k + "_OUTPUT", v[1]))) )
od = env.Dir( os.path.join(out_dir, data.get(k + "_OUTPUT", v[1])))
# don't clobber target folders
env.Precious(od)
# set up cleaning stuff
env.Clean(od, od)
# Add target files
if k != "MAN":
# Is an extension override var given?
if v[4]:
fname = v[2]+data.get(v[4])
else:
fname = v[2]+v[3]
of = env.File(os.path.join(out_dir, data.get(k + "_OUTPUT", v[1]), fname))
targets.append(of)
# don't clean single files, we remove the complete output folders (see above)
env.NoClean(of)
else:
# Special case: man files
# We have to add a target file docs/man/man3/foo.h.3
# for each input file foo.h :(
pass
# add the tag file if neccessary:
tagfile = data.get("GENERATE_TAGFILE", "")
if tagfile != "":
@ -210,14 +258,6 @@ def DoxyEmitter(source, target, env):
tagfile = os.path.join(conf_dir, tagfile)
targets.append(env.File(tagfile))
# don't clobber targets
for node in targets:
env.Precious(node)
# set up cleaning stuff
for node in targets:
env.Clean(node, node)
return (targets, source)
def generate(env):