From a98279024d2980f6193dae35726a457d62c0d629 Mon Sep 17 00:00:00 2001 From: sbund <sbund@wiback.org> Date: Fri, 7 Jul 2006 07:43:26 +0000 Subject: [PATCH] Moved satscons into SatLib library --- satscons/BoostUnitTests.py | 29 +++++++++++ satscons/Doxygen.py | 30 ++++++++++++ satscons/__init__.py | 0 satscons/nodeglob.py | 28 +++++++++++ satscons/pdflatex.py | 99 ++++++++++++++++++++++++++++++++++++++ satscons/satconf.py | 2 + 6 files changed, 188 insertions(+) create mode 100644 satscons/BoostUnitTests.py create mode 100644 satscons/Doxygen.py create mode 100644 satscons/__init__.py create mode 100644 satscons/nodeglob.py create mode 100644 satscons/pdflatex.py create mode 100644 satscons/satconf.py diff --git a/satscons/BoostUnitTests.py b/satscons/BoostUnitTests.py new file mode 100644 index 000000000..a3209287c --- /dev/null +++ b/satscons/BoostUnitTests.py @@ -0,0 +1,29 @@ +import SCons.Script.SConscript +import SCons.Defaults +import os.path +import os + +def BoostUnitTests(env, target, source, test_sources=None, **kw): + path, name = os.path.split(target) + if test_sources: + if type(test_sources) is not type([]): + test_sources = [ test_sources ] + else: + test_sources = [] + testEnv = env.Copy(**kw) + testEnv.Append(LIBS = '$BOOSTTESTLIB') + testRunner = testEnv.Program('test', env.Object(source) + test_sources) + return env.Alias(target, env.Command(os.path.join(path,'.'+name+'.stamp'), testRunner, + [ './$SOURCE $BOOSSTTESTARGS', 'touch $TARGET' ])) + + +def dispatcher(*arg,**kw): + return BoostUnitTests(*arg,**kw) + +def generate(env): + env['BOOSTTESTLIB'] = 'boost_unit_test_framework' + env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ] + env.__class__.BoostUnitTests = dispatcher + +def exists(env): + return 1 diff --git a/satscons/Doxygen.py b/satscons/Doxygen.py new file mode 100644 index 000000000..d28e3b30e --- /dev/null +++ b/satscons/Doxygen.py @@ -0,0 +1,30 @@ +import SCons.Script.SConscript +import SCons.Builder +import SCons.Defaults +import os.path + +def replace_ext(n,ext): + base,ext = os.path.splitext(n) + return base+ext + +def Doxygen(env, target, source, image): + path, name = os.path.split(str(target)) + stamp = os.path.join(path, '.'+name+'.stamp') + alias = env.Alias(target, + [ env.Command(os.path.splitext(img)[0]+".png", img, + [ 'TERM=dumb make -f imgconvert.mak $TARGET' ]) + for img in image ] + + [ env.Command(stamp, source, + [ '$DOXYGENCOM', + 'cd doc/html && (sed -ne \'1,/<table>/p\' <annotated.html && grep -F \'<tr>\' <annotated.html | sort -ft\'>\' -k4 && sed -ne \'/<\\/table>/,$$p\' <annotated.html) >annotated.html.new && mv annotated.html.new annotated.html', + 'touch $TARGET' ], + source_scanner = SCons.Defaults.ObjSourceScan) ]) + env.Clean(stamp, target) + return alias + +def generate(env): + env['DOXYGENCOM'] = 'doxygen' + env.__class__.Doxygen = Doxygen + +def exists(env): + return 1 diff --git a/satscons/__init__.py b/satscons/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/satscons/nodeglob.py b/satscons/nodeglob.py new file mode 100644 index 000000000..feb19babf --- /dev/null +++ b/satscons/nodeglob.py @@ -0,0 +1,28 @@ +import fnmatch +import os + +def glob(match): + """Similar to glob.glob, except globs SCons nodes, and thus sees + generated files and files from build directories. Basically, it sees + anything SCons knows about. A key subtlety is that since this function + operates on generated nodes as well as source nodes on the filesystem, + it needs to be called after builders that generate files you want to + include.""" + def fn_filter(node): + fn = str(node) + return fnmatch.fnmatch(os.path.basename(fn), match) + + here = Dir('.') + + children = here.all_children() + nodes = map(File, filter(fn_filter, children)) + node_srcs = [n.srcnode() for n in nodes] + + src = here.srcnode() + if src is not here: + src_children = map(File, filter(fn_filter, src.all_children())) + for s in src_children: + if s not in node_srcs: + nodes.append(File(os.path.basename(str(s)))) + + return nodes diff --git a/satscons/pdflatex.py b/satscons/pdflatex.py new file mode 100644 index 000000000..bbb129bd6 --- /dev/null +++ b/satscons/pdflatex.py @@ -0,0 +1,99 @@ +import SCons.Defaults + +import md5, os.path +import SCons.Action, SCons.Builder, SCons.Util, SCons.Errors, SCons.Environment + +PDFLaTeXAction = SCons.Action.CommandAction("$PDFLATEXCOM") + +# copied from Action.py ... changed to tage explicit path-names as +# target/source instead of node objects +def my_executeCommand(cmd_list, target, source, env): + import SCons.Util + escape = env.get('ESCAPE', lambda x: x) + if env.has_key('SHELL'): shell = env['SHELL'] + else: raise SCons.Errors.UserError('Missing SHELL construction variable.') + if env.has_key('PIPE_BUILD'): + pipe_build = 1 + if env.has_key('PSPAWN'): pspawn = env['PSPAWN'] + else: raise SCons.Errors.UserError('Missing PSPAWN construction variable.') + if env.has_key('PSTDOUT'): pstdout = env['PSTDOUT'] + else: raise SCons.Errors.UserError('Missing PSTDOUT construction variable.') + if env.has_key('PSTDERR'): pstderr = env['PSTDERR'] + else: raise SCons.Errors.UserError('Missing PSTDOUT construction variable.') + else: + pipe_build = 0 + if env.has_key('SPAWN'): spawn = env['SPAWN'] + else: raise SCons.Errors.UserError('Missing SPAWN construction variable.') + # Here, replaced the source and target argumnets with a dict argument + cmd_list = env.subst_list(cmd_list, 0, dict = { 'TARGET': target, 'TARGETS': [ target ], + 'SOURCE': source, 'SOURCES': [ source ] }) + for cmd_line in cmd_list: + if len(cmd_line): + try: ENV = env['ENV'] + except KeyError: + global default_ENV + if not default_ENV: + import SCons.Environment + default_ENV = SCons.Environment.Environment()['ENV'] + ENV = default_ENV + for key, value in ENV.items(): + if SCons.Util.is_List(value): + value = SCons.Util.flatten(value) + ENV[key] = string.join(map(str, value), os.pathsep) + elif not SCons.Util.is_String(value): + ENV[key] = str(value) + cmd_line = SCons.Util.escape_list(cmd_line, escape) + if pipe_build: ret = pspawn( shell, escape, cmd_line[0], cmd_line, + ENV, pstdout, pstderr ) + else: ret = spawn(shell, escape, cmd_line[0], cmd_line, ENV) + if ret: return ret + return 0 + +def TeXchecksum(files): + m = md5.new() + for f in files: + try: + m.update(file(f,"rb").read()) + except IOError: pass + return m.digest() + +def TeXPdfAction(target, source, env): + src = os.path.abspath(str(source[0])) + path, pdf = os.path.split(str(target[0])) + base, ext = os.path.splitext(pdf) + cwd = os.getcwd() + if path: os.chdir(path) + checkfiles = [ base + ext for ext in env["TEXCHECKEXT"] ] + checksum = TeXchecksum(checkfiles) + rv = 0 + for i in range(env["TEXMAXRECURSE"]+1): + if i==env["TEXMAXRECURSE"]: + print "\nWARNING: TeX recursion depth exceeded. They generated file may not be final.\n" + break + rv = my_executeCommand("$PDFLATEXCOM", pdf, src, env) + if rv: break + new_checksum = TeXchecksum(checkfiles) + if new_checksum == checksum: break + checksum = new_checksum + os.chdir(cwd) + return rv + +class TeXPdfBuilder(SCons.Builder.BuilderBase) : + def __call__(self, env, target = None, source = SCons.Builder._null, **kw): + tlist = SCons.Builder.BuilderBase.__call__(self, env, target, source, **kw) + exts = env["TEXCHECKEXT"] + env["TEXCLEANEXT"] + for t in tlist: + base, ext = os.path.splitext(str(t)) + for ext in exts: + env.Clean(t,base+ext) + return tlist + + +def generate(env): + env['TEXCHECKEXT'] = [ '.aux', '.toc' ] + env['TEXCLEANEXT'] = [ '.log', '.dvi' ] + env['TEXMAXRECURSE'] = 5 + env['BUILDERS']['PDF'] = TeXPdfBuilder(action = TeXPdfAction, suffix='.pdf') + +def exists(env): + return 1 diff --git a/satscons/satconf.py b/satscons/satconf.py new file mode 100644 index 000000000..bf67150ff --- /dev/null +++ b/satscons/satconf.py @@ -0,0 +1,2 @@ +import SCons.Options, SCons.SConf, SCons.Environment + -- GitLab