def run(self): run_str = 'rm -f .running && cp ' + self.generator.si_env.abspath( ) + ' si.env && cp si.env ${BRICK_RESULTS} && ${CADENCE_SI} -batch -command netlist' (f, dvars) = Task.compile_fun(run_str, False) return f(self)
def run(self): """Checking logfile for critical warnings line by line""" run_str = '${PLANAHEAD} -mode batch -source ${SRC[0].abspath()}' (f, dvars) = Task.compile_fun(run_str, False) return_value = f(self) found_error = 0 with open(self.inputs[0].abspath(), 'r') as logfile: pass # put critical warnings here #for line in logfile: # # always_ff does not infer sequential logic # m0 = re.match('@W: CL216',line) # if m0: # print line # found_error = 1 # # always_comb does not infer combinatorial logic # m0 = re.match('@W: CL217',line) # if m0: # print line # found_error = 1 # # always_latch does not infer latch logic # m0 = re.match('@W: CL218',line) # if m0: # print line # found_error = 1 return found_error
def make_pytest(self): """ Creates a ``utest`` task with a modified PYTHONPATH environment for Python. """ nodes = self.to_nodes(self.pytest_source) tsk = self.create_task('utest', nodes) tsk.dep_nodes.extend(self.pytest_dep_nodes) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: if tsk.inputs: self.ut_cwd = tsk.inputs[0].parent else: raise Errors.WafError("no valid input files for pytest task, check pytest_source value") if not self.ut_cwd.exists(): self.ut_cwd.mkdir() self.ut_env = dict(os.environ) self.ut_env['PYTHONPATH'] = os.pathsep.join(self.pytest_paths) + self.ut_env.get('PYTHONPATH', '')
class tex(texmodule.tex): biber_fun, _ = Task.compile_fun("${BIBER} ${BIBERFLAGS} ${SRCFILE}", shell=False) biber_fun.__doc__ = """ Execute the program **biber** """ def bibfile(self): return None def bibunits(self): self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ "BIBINPUTS": self.texinputs(), "BSTINPUTS": self.texinputs() }) self.env.SRCFILE = self.aux_nodes[0].name[:-4] if not self.env["PROMPT_LATEX"]: self.env.append_unique("BIBERFLAGS", "--quiet") path = self.aux_nodes[0].abspath()[:-4] + ".bcf" if os.path.isfile(path): Logs.warn("calling biber") self.check_status( "error when calling biber, check %s.blg for errors" % (self.env.SRCFILE), self.biber_fun(), ) else: super().bibfile() super().bibunits()
def make_interpreted_test(self): """Create interpreted unit tests.""" for x in ['test_scripts_source', 'test_scripts_template']: if not hasattr(self, x): Logs.warn('a test_scripts taskgen i missing %s' % x) return self.ut_run, lst = Task.compile_fun(self.test_scripts_template, shell=getattr(self, 'test_scripts_shell', False)) script_nodes = self.to_nodes(self.test_scripts_source) for script_node in script_nodes: tsk = self.create_task('utest', [script_node]) tsk.vars = lst + tsk.vars tsk.env['SCRIPT'] = script_node.path_from(tsk.get_cwd()) self.handle_ut_cwd('test_scripts_cwd') env = getattr(self, 'test_scripts_env', None) if env: self.ut_env = env else: self.ut_env = dict(os.environ) paths = getattr(self, 'test_scripts_paths', {}) for (k,v) in paths.items(): p = self.ut_env.get(k, '').split(os.pathsep) if isinstance(v, str): v = v.split(os.pathsep) self.ut_env[k] = os.pathsep.join(p + v)
def make_interpreted_test(self): """Create interpreted unit tests.""" for x in ["test_scripts_source", "test_scripts_template"]: if not hasattr(self, x): Logs.warn("a test_scripts taskgen i missing %s" % x) return self.ut_run, lst = Task.compile_fun(self.test_scripts_template, shell=getattr(self, "test_scripts_shell", False)) script_nodes = self.to_nodes(self.test_scripts_source) for script_node in script_nodes: tsk = self.create_task("utest", [script_node]) tsk.vars = lst + tsk.vars tsk.env["SCRIPT"] = script_node.path_from(tsk.get_cwd()) self.handle_ut_cwd("test_scripts_cwd") env = getattr(self, "test_scripts_env", None) if env: self.ut_env = env else: self.ut_env = dict(os.environ) paths = getattr(self, "test_scripts_paths", {}) for (k, v) in paths.items(): p = self.ut_env.get(k, "").split(os.pathsep) if isinstance(v, str): v = v.split(os.pathsep) self.ut_env[k] = os.pathsep.join(p + v)
def make_test(self): if not getattr(self,'link_task',None): return tsk=self.create_task('utest',self.link_task.outputs) if getattr(self,'ut_str',None): self.ut_run,lst=Task.compile_fun(self.ut_str,shell=getattr(self,'ut_shell',False)) tsk.vars=lst+tsk.vars self.handle_ut_cwd('ut_cwd') if not hasattr(self,'ut_paths'): paths=[] for x in self.tmp_use_sorted: try: y=self.bld.get_tgen_by_name(x).link_task except AttributeError: pass else: if not isinstance(y,ccroot.stlink_task): paths.append(y.outputs[0].parent.abspath()) self.ut_paths=os.pathsep.join(paths)+os.pathsep if not hasattr(self,'ut_env'): self.ut_env=dct=dict(os.environ) def add_path(var): dct[var]=self.ut_paths+dct.get(var,'') if Utils.is_win32: add_path('PATH') elif Utils.unversioned_sys_platform()=='darwin': add_path('DYLD_LIBRARY_PATH') add_path('LD_LIBRARY_PATH') else: add_path('LD_LIBRARY_PATH') if not hasattr(self,'ut_cmd'): self.ut_cmd=getattr(Options.options,'testcmd',False)
def make_interpreted_test(self): """Create interpreted unit tests.""" for x in ['test_scripts_source', 'test_scripts_template']: if not hasattr(self, x): Logs.warn('a test_scripts taskgen i missing %s' % x) return self.ut_run, lst = Task.compile_fun(self.test_scripts_template, shell=getattr(self, 'test_scripts_shell', False)) script_nodes = self.to_nodes(self.test_scripts_source) for script_node in script_nodes: tsk = self.create_task('utest', [script_node]) tsk.vars = lst + tsk.vars tsk.env['SCRIPT'] = script_node.path_from(tsk.get_cwd()) self.handle_ut_cwd('test_scripts_cwd') env = getattr(self, 'test_scripts_env', None) if env: self.ut_env = env else: self.ut_env = dict(os.environ) paths = getattr(self, 'test_scripts_paths', {}) for (k,v) in list(paths.items()): p = self.ut_env.get(k, '').split(os.pathsep) if isinstance(v, str): v = v.split(os.pathsep) self.ut_env[k] = os.pathsep.join(p + v)
class tex(texmodule.tex): biber_fun, _ = Task.compile_fun('${BIBER} ${BIBERFLAGS} ${SRCFILE}', shell=False) biber_fun.__doc__ = """ Execute the program **biber** """ def bibfile(self): return None def bibunits(self): self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() }) self.env.SRCFILE = self.aux_nodes[0].name[:-4] if not self.env['PROMPT_LATEX']: self.env.append_unique('BIBERFLAGS', '--quiet') path = self.aux_nodes[0].abspath()[:-4] + '.bcf' if os.path.isfile(path): Logs.warn('calling biber') self.check_status( 'error when calling biber, check %s.blg for errors' % (self.env.SRCFILE), self.biber_fun()) else: super(tex, self).bibfile() super(tex, self).bibunits()
def make_pytest(self): """ Creates a ``utest`` task with a modified PYTHONPATH environment for Python. """ nodes = self.to_nodes(self.pytest_source) tsk = self.create_task('utest', nodes) tsk.dep_nodes.extend(self.pytest_dep_nodes) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr( self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = tsk.inputs[0].parent if not self.ut_cwd.exists(): self.ut_cwd.mkdir() self.ut_env = dict(os.environ) self.ut_env['PYTHONPATH'] = os.pathsep.join( self.pytest_paths) + self.ut_env.get('PYTHONPATH', '')
def make_javatest(self): """ Creates a ``utest`` task with a populated environment for Java Unit test execution """ tsk = self.create_task('utest') tsk.set_run_after(self.javac_task) # Dependencies from recursive use analysis tsk.dep_nodes.extend(self.javatest_dep_nodes) # Put test input files as waf_unit_test relies on that for some prints and log generation # If jtest_source is there, this is specially useful for passing XML for TestNG # that contain test specification, use that as inputs, otherwise test sources if getattr(self, 'jtest_source', None): tsk.inputs = self.to_nodes(self.jtest_source) else: if self.javac_task.srcdir[0].exists(): tsk.inputs = self.javac_task.srcdir[0].ant_glob('**/*.java', remove=False) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = self.bld.bldnode # Get parent CLASSPATH and add output dir of test, we run from wscript dir # We have to change it from list to the standard java -cp format (: separated) tsk.env.CLASSPATH = ':'.join(self.env.CLASSPATH) + ':' + self.outdir.abspath() if not self.ut_cwd.exists(): self.ut_cwd.mkdir() if not hasattr(self, 'ut_env'): self.ut_env = dict(os.environ) def add_paths(var, lst): # Add list of paths to a variable, lst can contain strings or nodes lst = [ str(n) for n in lst ] Logs.debug("ut: %s: Adding paths %s=%s", self, var, lst) self.ut_env[var] = os.pathsep.join(lst) + os.pathsep + self.ut_env.get(var, '') add_paths('PYTHONPATH', self.javatest_pypaths) if Utils.is_win32: add_paths('PATH', self.javatest_libpaths) elif Utils.unversioned_sys_platform() == 'darwin': add_paths('DYLD_LIBRARY_PATH', self.javatest_libpaths) add_paths('LD_LIBRARY_PATH', self.javatest_libpaths) else: add_paths('LD_LIBRARY_PATH', self.javatest_libpaths)
def run(self): run_str = """mkdir -p ${TGT[0].parent.abspath()} && echo '<?xml version="1.0"?> <Library DMSystem="oaDMFileSys"> <oaDMFileSys libReadOnly="No" origFileSystem="Unix"/> </Library>' >> ${TGT[0].abspath()}""" (f, dvars) = Task.compile_fun(run_str, False) return f(self)
def make_pytest(self): """ Creates a ``utest`` task with a populated environment for Python if not specified in ``ut_env``: - Paths in `pytest_paths` attribute are used to populate PYTHONPATH - Paths in `pytest_libpaths` attribute are used to populate the system library path (e.g. LD_LIBRARY_PATH) """ nodes = self.to_nodes(self.pytest_source) tsk = self.create_task("utest", nodes) tsk.dep_nodes.extend(self.pytest_dep_nodes) if getattr(self, "ut_str", None): self.ut_run, lst = Task.compile_fun( self.ut_str, shell=getattr(self, "ut_shell", False) ) tsk.vars = lst + tsk.vars if getattr(self, "ut_cwd", None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: if tsk.inputs: self.ut_cwd = tsk.inputs[0].parent else: raise Errors.WafError( "no valid input files for pytest task, check pytest_source value" ) if not self.ut_cwd.exists(): self.ut_cwd.mkdir() if not hasattr(self, "ut_env"): self.ut_env = dict(os.environ) def add_paths(var, lst): # Add list of paths to a variable, lst can contain strings or nodes lst = [str(n) for n in lst] Logs.debug("ut: %s: Adding paths %s=%s", self, var, lst) self.ut_env[var] = ( os.pathsep.join(lst) + os.pathsep + self.ut_env.get(var, "") ) # Prepend dependency paths to PYTHONPATH and LD_LIBRARY_PATH add_paths("PYTHONPATH", self.pytest_paths) if Utils.is_win32: add_paths("PATH", self.pytest_libpaths) elif Utils.unversioned_sys_platform() == "darwin": add_paths("DYLD_LIBRARY_PATH", self.pytest_libpaths) add_paths("LD_LIBRARY_PATH", self.pytest_libpaths) else: add_paths("LD_LIBRARY_PATH", self.pytest_libpaths)
def make_pytest(self): """ Creates a ``utest`` task with a populated environment for Python if not specified in ``ut_env``: - Paths in `pytest_paths` attribute are used to populate PYTHONPATH - Paths in `pytest_libpaths` attribute are used to populate the system library path (e.g. LD_LIBRARY_PATH) """ nodes = self.to_nodes(self.pytest_source) tsk = self.create_task('utest', nodes) tsk.dep_nodes.extend(self.pytest_dep_nodes) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: if tsk.inputs: self.ut_cwd = tsk.inputs[0].parent else: raise Errors.WafError("no valid input files for pytest task, check pytest_source value") if not self.ut_cwd.exists(): self.ut_cwd.mkdir() if not hasattr(self, 'ut_env'): self.ut_env = dict(os.environ) def add_paths(var, lst): # Add list of paths to a variable, lst can contain strings or nodes lst = [ str(n) for n in lst ] Logs.debug("ut: %s: Adding paths %s=%s", self, var, lst) self.ut_env[var] = os.pathsep.join(lst) + os.pathsep + self.ut_env.get(var, '') # Prepend dependency paths to PYTHONPATH and LD_LIBRARY_PATH add_paths('PYTHONPATH', self.pytest_paths) if Utils.is_win32: add_paths('PATH', self.pytest_libpaths) elif Utils.unversioned_sys_platform() == 'darwin': add_paths('DYLD_LIBRARY_PATH', self.pytest_libpaths) add_paths('LD_LIBRARY_PATH', self.pytest_libpaths) else: add_paths('LD_LIBRARY_PATH', self.pytest_libpaths)
def make_test(self): """Create the unit test task. There can be only one unit test task by task generator.""" if not getattr(self, 'link_task', None): return tsk = self.create_task('utest', self.link_task.outputs) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr( self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = tsk.inputs[0].parent if not hasattr(self, 'ut_paths'): paths = [] for x in self.tmp_use_sorted: try: y = self.bld.get_tgen_by_name(x).link_task except AttributeError: pass else: if not isinstance(y, ccroot.stlink_task): paths.append(y.outputs[0].parent.abspath()) self.ut_paths = os.pathsep.join(paths) + os.pathsep if not hasattr(self, 'ut_env'): self.ut_env = dct = dict(os.environ) def add_path(var): dct[var] = self.ut_paths + dct.get(var, '') if Utils.is_win32: add_path('PATH') elif Utils.unversioned_sys_platform() == 'darwin': add_path('DYLD_LIBRARY_PATH') add_path('LD_LIBRARY_PATH') else: add_path('LD_LIBRARY_PATH')
class ZPyTask_Patch(ZPyTaskBase): color = 'CYAN' before = [] after = [] x, vars = Task.compile_fun(' '.join([ '${GIT}', # effectively disables git commands *requiring* a repo and prevents # git from doing nothing in the event it's within an unrelated repo '--git-dir=', 'apply', '--whitespace=nowarn', '${SRC[0].abspath()}', ])) def run(self): return self.x()
def make_javatest(self): """ Creates a ``utest`` task with a populated environment for Java Unit test execution """ tsk = self.create_task('utest') tsk.set_run_after(self.javac_task) # Put test input files as waf_unit_test relies on that for some prints and log generation # If jtest_source is there, this is specially useful for passing XML for TestNG # that contain test specification, use that as inputs, otherwise test sources if getattr(self, 'jtest_source', None): tsk.inputs = self.to_nodes(self.jtest_source) else: if self.javac_task.srcdir[0].exists(): tsk.inputs = self.javac_task.srcdir[0].ant_glob('**/*.java', remove=False) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr( self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = self.bld.bldnode # Get parent CLASSPATH and add output dir of test, we run from wscript dir # We have to change it from list to the standard java -cp format (: separated) tsk.env.CLASSPATH = ':'.join( self.env.CLASSPATH) + ':' + self.outdir.abspath() if not self.ut_cwd.exists(): self.ut_cwd.mkdir() if not hasattr(self, 'ut_env'): self.ut_env = dict(os.environ)
def make_test(self): """Create the unit test task. There can be only one unit test task by task generator.""" if not getattr(self, 'link_task', None): return tsk = self.create_task('utest', self.link_task.outputs) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = tsk.inputs[0].parent if not hasattr(self, 'ut_paths'): paths = [] for x in self.tmp_use_sorted: try: y = self.bld.get_tgen_by_name(x).link_task except AttributeError: pass else: if not isinstance(y, ccroot.stlink_task): paths.append(y.outputs[0].parent.abspath()) self.ut_paths = os.pathsep.join(paths) + os.pathsep if not hasattr(self, 'ut_env'): self.ut_env = dct = dict(os.environ) def add_path(var): dct[var] = self.ut_paths + dct.get(var,'') if Utils.is_win32: add_path('PATH') elif Utils.unversioned_sys_platform() == 'darwin': add_path('DYLD_LIBRARY_PATH') add_path('LD_LIBRARY_PATH') else: add_path('LD_LIBRARY_PATH')
def make_test(self): """Create the unit test task. There can be only one unit test task by task generator.""" if not getattr(self, "link_task", None): return tsk = self.create_task("utest", self.link_task.outputs) if getattr(self, "ut_str", None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr( self, "ut_shell", False)) tsk.vars = lst + tsk.vars self.handle_ut_cwd("ut_cwd") if not hasattr(self, "ut_paths"): paths = [] for x in self.tmp_use_sorted: try: y = self.bld.get_tgen_by_name(x).link_task except AttributeError: pass else: if not isinstance(y, ccroot.stlink_task): paths.append(y.outputs[0].parent.abspath()) self.ut_paths = os.pathsep.join(paths) + os.pathsep if not hasattr(self, "ut_env"): self.ut_env = dct = dict(os.environ) def add_path(var): dct[var] = self.ut_paths + dct.get(var, "") if Utils.is_win32: add_path("PATH") elif Utils.unversioned_sys_platform() == "darwin": add_path("DYLD_LIBRARY_PATH") add_path("LD_LIBRARY_PATH") else: add_path("LD_LIBRARY_PATH") if not hasattr(self, "ut_cmd"): self.ut_cmd = getattr(Options.options, "testcmd", False)
def make_javatest(self): """ Creates a ``utest`` task with a populated environment for Java Unit test execution """ tsk = self.create_task('utest') tsk.set_run_after(self.javac_task) # Put test input files as waf_unit_test relies on that for some prints and log generation # If jtest_source is there, this is specially useful for passing XML for TestNG # that contain test specification, use that as inputs, otherwise test sources if getattr(self, 'jtest_source', None): tsk.inputs = self.to_nodes(self.jtest_source) else: if self.javac_task.srcdir[0].exists(): tsk.inputs = self.javac_task.srcdir[0].ant_glob('**/*.java', remove=False) if getattr(self, 'ut_str', None): self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False)) tsk.vars = lst + tsk.vars if getattr(self, 'ut_cwd', None): if isinstance(self.ut_cwd, str): # we want a Node instance if os.path.isabs(self.ut_cwd): self.ut_cwd = self.bld.root.make_node(self.ut_cwd) else: self.ut_cwd = self.path.make_node(self.ut_cwd) else: self.ut_cwd = self.bld.bldnode # Get parent CLASSPATH and add output dir of test, we run from wscript dir # We have to change it from list to the standard java -cp format (: separated) tsk.env.CLASSPATH = ':'.join(self.env.CLASSPATH) + ':' + self.outdir.abspath() if not self.ut_cwd.exists(): self.ut_cwd.mkdir() if not hasattr(self, 'ut_env'): self.ut_env = dict(os.environ)
def run(self): run_str = '${M4} '+(''.join([ ' -I '+i for i in self.generator.includes]))+' ${SRC} > ${TGT}' (f, dvars) = Task.compile_fun(run_str, False) return f(self)
def run(self): run_str = 'rm -f .running && cp '+self.generator.si_env.abspath()+' si.env && cp si.env ${BRICK_RESULTS} && ${CADENCE_SI} -batch -command netlist' (f, dvars) = Task.compile_fun(run_str, False) return f(self)
#!/usr/bin/env python # encoding: utf-8 # Mark Coggeshall, 2010 "SAS support" import os from waflib import Task, Errors, Logs from waflib.TaskGen import feature, before_method sas_fun, _ = Task.compile_fun('sas -sysin ${SRCFILE} -log ${LOGFILE} -print ${LSTFILE}', shell=False) class sas(Task.Task): vars = ['SAS', 'SASFLAGS'] def run(task): command = 'SAS' fun = sas_fun node = task.inputs[0] logfilenode = node.change_ext('.log') lstfilenode = node.change_ext('.lst') # set the cwd task.cwd = task.inputs[0].parent.get_src().abspath() Logs.debug('runner: %s on %s' % (command, node.abspath)) SASINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep task.env.env = {'SASINPUTS': SASINPUTS} task.env.SRCFILE = node.abspath() task.env.LOGFILE = logfilenode.abspath()
class pclint(lint,Task.Task): color = 'CYAN' run_str_pclint = '${PCLINT} ${PCLINTOPTS} ${SRC}' run_str_cc = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} -E -dM -dD -v ${CC_SRC_F}${SRC[0].abspath()}' (run_pclint, pclint_vars) = Task.compile_fun(run_str_pclint) (run_cc, cc_vars) = Task.compile_fun(run_str_cc) vars = pclint_vars + cc_vars + [ 'PCLINT_OPT_WARNINGLEVEL', 'PCLINT_OPT_PASSES', 'PCLINT_OPT_OPTIONS', 'PCLINT_OPT_ADDITIONALRULES', ] log_str = '[PCLINT] $name $out' sizeflags = [ ('__SIZEOF_INT__' , '-si'), ('__SIZEOF_LONG__', '-sl'), ('__SIZEOF_LONG_LONG__', '-sll'), ('__SIZEOF_SHORT__', '-ss'), ('__SIZEOF_FLOAT__', '-sf'), ('__SIZEOF_DOUBLE__', '-sd'), ('__SIZEOF_LONG_DOUBLE__', '-sld'), ('__SIZEOF_WCHAR_T__', '-sw'), ('__SIZEOF_POINTER__', '-sp'), ] @property def name(self): return self.generator.name @property def out(self): return self.outputs[1].nice_path() def run(self): global stdout_sep, stderr_sep tgen = self.generator bld = tgen.bld env = self.env inputs = self.inputs outputs = self.outputs for x in outputs: x.delete() source_nodes = inputs[:] pclintlnt_template_node = inputs[0] pclint_output_lnt_node = inputs[1] pclint_rules_lnt_nodes = [x for x in inputs[2:] if x.suffix().lower() == '.lnt'] source_nodes = [x for x in inputs[2:] if x.suffix().lower() != '.lnt'] pclintlnt_node, output_node = outputs defines, includes = self.extract_compiler_params() # pclint specific header files includes.insert(0, os.path.join(module_path, "pclint_includes")) tgenincludes = set(x.abspath() for x in tgen.to_incnodes(getattr(tgen, 'includes', []))) dct = dict() dct['INCPATHFLAGS'] = '\n'.join('-"i%s"' % x for x in includes) dct['LIBPATHFLAGS'] = '\n'.join('-libdir("%s")' % x for x in tgenincludes) dct['DEFINEFLAGS'] = '\n'.join(('-d%s=%s' if v[0] in '"' else '-"d%s=%s"') % (n, v) for n, v in defines) dct['OUTPUTFORMATFLAGS'] = pclint_output_lnt_node.read() defines_map = dict(defines) if env['CC_NAME'] in ('gcc', 'clang', 'xpic-llvm'): if '__SIZEOF_INT__' in defines_map: dct['SIZEFLAGS'] = '\n'.join('%s%s' % (f, defines_map.get(d,'0')) for d,f in self.sizeflags) else: # probably an old gcc: compiler_32bit_sizes = ( ('-si', 4), ('-sl', 4), ('-sll', 8), ('-ss', 2), ('-sf', 4), ('-sd', 8), ('-sld', 8), ('-sw', 4), ('-sp', 4), ) dct['SIZEFLAGS'] = '/* Unable to extract type sizes from compiler, using built in 32 bit type size */\n' +\ '\n'.join('%s%d' % x for x in compiler_32bit_sizes) else: dct['SIZEFLAGS'] = '/* Unable to extract type sizes from compiler "%s" */\n' % env['CC_NAME'] dct['WARNINGLEVELFLAGS'] = '-w%u' % self.opts.warninglevel dct['PASSESFLAGS'] = '-passes(%u)' % self.opts.passes sep = '/*{0:*^76}*/\n' dct['RULEFLAGS'] = '\n'.join((sep.format(' %s ' % x.nice_path()) + x.read() + '\n' + sep.format(' %s ' % x.nice_path())) for x in pclint_rules_lnt_nodes) dct['SOURCEFILES'] = '\n'.join('"%s"' % x.path_from(bld.bldnode) for x in source_nodes) env.stash() try: template_string = string.Template(pclintlnt_template_node.read()) pclintlnt_node.parent.mkdir() pclintlnt_node.write(template_string.substitute(dct)) try: self.inputs = [pclintlnt_node] out, err = self.run_pclint() except Exception, e: out = getattr(e, 'stdout', None) err = getattr(e, 'stderr', None) finally: self.inputs = inputs finally:
#!/usr/bin/env python # encoding: utf-8 # Mark Coggeshall, 2010 "SAS support" import os from waflib import Task, Errors, Logs from waflib.TaskGen import feature, before_method sas_fun, _ = Task.compile_fun( 'sas -sysin ${SRCFILE} -log ${LOGFILE} -print ${LSTFILE}', shell=False) class sas(Task.Task): vars = ['SAS', 'SASFLAGS'] def run(task): command = 'SAS' fun = sas_fun node = task.inputs[0] logfilenode = node.change_ext('.log') lstfilenode = node.change_ext('.lst') # set the cwd task.cwd = task.inputs[0].parent.get_src().abspath() Logs.debug('runner: %s on %s' % (command, node.abspath)) SASINPUTS = node.parent.get_bld().abspath( ) + os.pathsep + node.parent.get_src().abspath() + os.pathsep
class xelatex(tex): texfun, vars = Task.compile_fun('${XELATEX} ${XELATEXFLAGS} ${SRCFILE}', shell=False)
if path: for k in ['', '.tex', '.ltx', '.bib']: # add another loop for the tex include paths? debug('tex: trying %s%s' % (path, k)) fi = node.parent.find_resource(path + k) if fi: nodes.append(fi) # no break, people are crazy else: debug('tex: could not find %s' % path) names.append(path) debug("tex: found the following : %s and names %s" % (nodes, names)) return (nodes, names) latex_fun, _ = Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}', shell=False) pdflatex_fun, _ = Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun, _ = Task.compile_fun('${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) g_bibtex_re = re.compile('bibdata', re.M) def tex_build(task, command='LATEX'): env = task.env bld = task.generator.bld if not env['PROMPT_LATEX']: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') fun = latex_fun if command == 'PDFLATEX':
class tex(Task.Task): bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun( '${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ def scan(self): node = self.inputs[0] env = self.env nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() global re_tex for match in re_tex.finditer(code): for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: debug('tex: trying %s%s' % (path, k)) found = node.parent.find_resource(path + k) if found and not found in self.outputs: nodes.append(found) add_name = False if found.name.endswith( '.tex') or found.name.endswith('.ltx'): parse_node(found) if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() debug("tex: found the following : %s and names %s" % (nodes, names)) return (nodes, names) def check_status(self, msg, retcode): if retcode != 0: raise Errors.WafError("%r command exit status %r" % (msg, retcode)) def bibfile(self): try: ct = self.aux_node.read() except (OSError, IOError): error('error bibtex scan') else: fo = g_bibtex_re.findall(ct) if fo: warn('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS }) self.env.SRCFILE = self.aux_node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): try: bibunits = bibunitscan(self) except FSError: error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in xrange(1, len(bibunits) + 1)] if fn: warn('calling bibtex on bibunits') for f in fn: self.env.env = { 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS } self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: warn('index file %s absent, not calling makeindex' % idx_path) else: warn('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def run(self): env = self.env bld = self.generator.bld if not env['PROMPT_LATEX']: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') fun = self.texfun node = self.inputs[0] srcfile = node.abspath() self.TEXINPUTS = node.parent.get_bld().abspath( ) + os.pathsep + node.parent.get_src().abspath() + os.pathsep self.aux_node = node.change_ext('.aux') self.idx_node = node.change_ext('.idx') self.cwd = self.inputs[0].parent.get_bld().abspath() warn('first pass on %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status('error when calling latex', fun()) self.bibfile() self.bibunits() self.makeindex() hash = '' for i in range(10): prev_hash = hash try: hash = Utils.h_file(self.aux_node.abspath()) except (OSError, IOError): error('could not read aux.h -> %s' % self.aux_node.abspath()) pass if hash and hash == prev_hash: break warn('calling %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status( 'error when calling %s' % self.__class__.__name__, fun())
def run(self): run_str = '${M4} ' + (''.join( [' -I ' + i for i in self.generator.includes])) + ' ${SRC} > ${TGT}' (f, dvars) = Task.compile_fun(run_str, False) return f(self)
def py_fun(self): in_script = self.inputs[0].abspath() fun_str = '{} {}'.format(self.env.PY3CMD, in_script) return Task.compile_fun(fun_str, shell=True)[0]
class tex(Task.Task): bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun( '${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ makeglossaries_fun, _ = Task.compile_fun('${MAKEGLOSSARIES} ${SRCFILE}', shell=False) makeglossaries_fun.__doc__ = """ Execute the program **makeglossaries** """ def exec_command(self, cmd, **kw): kw['stdout'] = kw['stderr'] = None return super(tex, self).exec_command(cmd, **kw) def scan_aux(self, node): nodes = [node] re_aux = re.compile(r'\\@input{(?P<file>[^{}]*)}', re.M) def parse_node(node): code = node.read() for match in re_aux.finditer(code): path = match.group('file') found = node.parent.find_or_declare(path) if found and found not in nodes: Logs.debug('tex: found aux node %r', found) nodes.append(found) parse_node(found) parse_node(node) return nodes def scan(self): node = self.inputs[0] nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() global re_tex for match in re_tex.finditer(code): multibib = match.group('type') if multibib and multibib.startswith('bibliography'): multibib = multibib[len('bibliography'):] if multibib.startswith('style'): continue else: multibib = None for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: for up in self.texinputs_nodes: Logs.debug('tex: trying %s%s', path, k) found = up.find_resource(path + k) if found: break for tsk in self.generator.tasks: if not found or found in tsk.outputs: break else: nodes.append(found) add_name = False for ext in exts_tex: if found.name.endswith(ext): parse_node(found) break if found and multibib and found.name.endswith( '.bib'): try: self.multibibs.append(found) except AttributeError: self.multibibs = [found] if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() Logs.debug("tex: found the following : %s and names %s", nodes, names) return (nodes, names) def check_status(self, msg, retcode): if retcode != 0: raise Errors.WafError('%r command exit status %r' % (msg, retcode)) def bibfile(self): for aux_node in self.aux_nodes: try: ct = aux_node.read() except EnvironmentError: Logs.error('Error reading %s: %r', aux_node.abspath()) continue if g_bibtex_re.findall(ct): Logs.info('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() }) self.env.SRCFILE = aux_node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) for node in getattr(self, 'multibibs', []): self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() }) self.env.SRCFILE = node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): try: bibunits = bibunitscan(self) except OSError: Logs.error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in range(1, len(bibunits) + 1)] if fn: Logs.info('calling bibtex on bibunits') for f in fn: self.env.env = { 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() } self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): self.idx_node = self.inputs[0].change_ext('.idx') try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: Logs.info('index file %s absent, not calling makeindex', idx_path) else: Logs.info('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def bibtopic(self): p = self.inputs[0].parent.get_bld() if os.path.exists(os.path.join(p.abspath(), 'btaux.aux')): self.aux_nodes += p.ant_glob('*[0-9].aux') def makeglossaries(self): src_file = self.inputs[0].abspath() base_file = os.path.basename(src_file) base, _ = os.path.splitext(base_file) for aux_node in self.aux_nodes: try: ct = aux_node.read() except EnvironmentError: Logs.error('Error reading %s: %r', aux_node.abspath()) continue if g_glossaries_re.findall(ct): if not self.env.MAKEGLOSSARIES: raise Errors.WafError( "The program 'makeglossaries' is missing!") Logs.warn('calling makeglossaries') self.env.SRCFILE = base self.check_status( 'error when calling makeglossaries %s' % base, self.makeglossaries_fun()) return def texinputs(self): return os.pathsep.join([k.abspath() for k in self.texinputs_nodes]) + os.pathsep def run(self): env = self.env if not env.PROMPT_LATEX: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') self.cwd = self.inputs[0].parent.get_bld() Logs.info('first pass on %s', self.__class__.__name__) cur_hash = self.hash_aux_nodes() self.call_latex() self.hash_aux_nodes() self.bibtopic() self.bibfile() self.bibunits() self.makeindex() self.makeglossaries() for i in range(10): prev_hash = cur_hash cur_hash = self.hash_aux_nodes() if not cur_hash: Logs.error('No aux.h to process') if cur_hash and cur_hash == prev_hash: break Logs.info('calling %s', self.__class__.__name__) self.call_latex() def hash_aux_nodes(self): try: self.aux_nodes except AttributeError: try: self.aux_nodes = self.scan_aux( self.inputs[0].change_ext('.aux')) except IOError: return None return Utils.h_list( [Utils.h_file(x.abspath()) for x in self.aux_nodes]) def call_latex(self): self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.texinputs()}) self.env.SRCFILE = self.inputs[0].abspath() self.check_status('error when calling latex', self.texfun())
class xelatex(tex): "XeLaTeX files" texfun, vars = Task.compile_fun( "${XELATEX} ${XELATEXFLAGS} ${SRCFILE}", shell=False )
class tex(Task.Task): """ Compile a tex/latex file. .. inheritance-diagram:: waflib.Tools.tex.latex waflib.Tools.tex.xelatex waflib.Tools.tex.pdflatex """ bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun('${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ makenomen_fun, _ = Task.compile_fun('${MAKEINDEX} ${MAKENOMENFLAGS} ${SRCFILE} -o ${TARGETFILE}', shell=False) makenomen_fun.__doc__ = """ Execute the program **makeindex** to create a list of abbreviations """ def exec_command(self, cmd, **kw): """ Override :py:meth:`waflib.Task.Task.exec_command` to execute the command without buffering (latex may prompt for inputs) :return: the return code :rtype: int """ bld = self.generator.bld try: if not kw.get('cwd', None): kw['cwd'] = bld.cwd except AttributeError: bld.cwd = kw['cwd'] = bld.variant_dir return Utils.subprocess.Popen(cmd, **kw).wait() def scan_aux(self, node): """ A recursive regex-based scanner that finds included auxiliary files. """ nodes = [node] re_aux = re.compile(r'\\@input{(?P<file>[^{}]*)}', re.M) def parse_node(node): code = node.read() for match in re_aux.finditer(code): path = match.group('file') found = node.parent.find_or_declare(path) if found and found not in nodes: Logs.debug('tex: found aux node ' + found.abspath()) nodes.append(found) parse_node(found) parse_node(node) return nodes def scan(self): """ A recursive regex-based scanner that finds latex dependencies. It uses :py:attr:`waflib.Tools.tex.re_tex` Depending on your needs you might want: * to change re_tex:: from waflib.Tools import tex tex.re_tex = myregex * or to change the method scan from the latex tasks:: from waflib.Task import classes classes['latex'].scan = myscanfunction """ node = self.inputs[0] nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() global re_tex for match in re_tex.finditer(code): for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: Logs.debug('tex: trying %s%s' % (path, k)) found = node.parent.find_resource(path + k) for tsk in self.generator.tasks: if not found or found in tsk.outputs: break else: nodes.append(found) add_name = False for ext in exts_tex: if found.name.endswith(ext): parse_node(found) break # no break, people are crazy if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() Logs.debug("tex: found the following : %s and names %s" % (nodes, names)) return (nodes, names) def check_status(self, msg, retcode): """ Check an exit status and raise an error with a particular message :param msg: message to display if the code is non-zero :type msg: string :param retcode: condition :type retcode: boolean """ if retcode != 0: raise Errors.WafError("%r command exit status %r" % (msg, retcode)) def bibfile(self): """ Parse the *.aux* files to find bibfiles to process. If yes, execute :py:meth:`waflib.Tools.tex.tex.bibtex_fun` """ for aux_node in self.aux_nodes: try: ct = aux_node.read() except (OSError, IOError): Logs.error('Error reading %s: %r' % aux_node.abspath()) continue if g_bibtex_re.findall(ct): Logs.warn('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS}) self.env.SRCFILE = aux_node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): """ Parse the *.aux* file to find bibunit files. If there are bibunit files, execute :py:meth:`waflib.Tools.tex.tex.bibtex_fun`. """ try: bibunits = bibunitscan(self) except OSError: Logs.error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in xrange(1, len(bibunits) + 1)] if fn: Logs.warn('calling bibtex on bibunits') for f in fn: self.env.env = {'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS} self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): """ Look on the filesystem if there is a *.idx* file to process. If yes, execute :py:meth:`waflib.Tools.tex.tex.makeindex_fun` """ try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: Logs.warn('index file %s absent, not calling makeindex' % idx_path) else: Logs.warn('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def makenomen(self): """ Look on the filesystem if there is a *.nlo* file to process. If yes, execute :py:meth:`waflib.Tools.tex.tex.makenomen_fun` """ try: nlo_path = self.nlo_node.abspath() os.stat(nlo_path) except OSError: Logs.warn('nomen file %s absent, not calling makenomen' % nlo_path) else: Logs.warn('calling makenomen') self.env.TARGETFILE = self.nls_node.name self.env.SRCFILE = self.nlo_node.name self.env.env = {} self.check_status('error when calling makenomen %s' % nlo_path, self.makenomen_fun()) def bibtopic(self): """ Additional .aux files from the bibtopic package """ p = self.inputs[0].parent.get_bld() if os.path.exists(os.path.join(p.abspath(), 'btaux.aux')): self.aux_nodes += p.ant_glob('*[0-9].aux') def run(self): """ Runs the TeX build process. It may require multiple passes, depending on the usage of cross-references, bibliographies, content susceptible of needing such passes. The appropriate TeX compiler is called until the *.aux* files stop changing. Makeindex and bibtex are called if necessary. """ env = self.env if not env['PROMPT_LATEX']: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') fun = self.texfun node = self.inputs[0] srcfile = node.abspath() texinputs = self.env.TEXINPUTS or '' self.TEXINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep + texinputs + os.pathsep # important, set the cwd for everybody self.cwd = self.inputs[0].parent.get_bld().abspath() Logs.warn('first pass on %s' % self.__class__.__name__) hash = '' try: self.aux_nodes = self.scan_aux(node.change_ext('.aux')) hashes = [Utils.h_file(x.abspath()) for x in self.aux_nodes] hash = Utils.h_list(hashes) except (OSError, IOError): pass hash_bcf = '' try: self.bcf_node = node.change_ext('.bcf') hashes = [Utils.h_file(self.bcf_node.abspath())] hash_bcf = Utils.h_list(hashes) except (OSError, IOError): pass hash_bbl = '' try: self.bbl_node = node.change_ext('.bbl') hashes = [Utils.h_file(self.bbl_node.abspath())] hash_bbl = Utils.h_list(hashes) except (OSError, IOError): pass hash_idx = '' try: self.idx_node = node.change_ext('.idx') hashes = [Utils.h_file(self.idx_node.abspath())] hash_idx = Utils.h_list(hashes) except (OSError, IOError): pass hash_ind = '' try: self.ind_node = node.change_ext('.ind') hashes = [Utils.h_file(self.ind_node.abspath())] hash_ind = Utils.h_list(hashes) except (OSError, IOError): pass hash_nlo = '' try: self.nlo_node = node.change_ext('.nlo') hashes = [Utils.h_file(self.nlo_node.abspath())] hash_nlo = Utils.h_list(hashes) except (OSError, IOError): pass hash_nls = '' self.nls_node = node.change_ext('.nls') try: hashes = [Utils.h_file(self.nls_node.abspath())] hash_nls = Utils.h_list(hashes) except (OSError, IOError): pass self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status('error when calling latex', fun()) self.aux_nodes = self.scan_aux(node.change_ext('.aux')) self.idx_node = node.change_ext('.idx') self.bibtopic() self.bibfile() prev_bcf_hash = hash_bcf try: self.bcf_node = node.change_ext('.bcf') hashes = [Utils.h_file(self.bcf_node.abspath())] hash_bcf = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read bcf.h') pass if hash_bcf and hash_bcf != prev_bcf_hash: self.bibunits() else: Logs.warn('%s unchanged, not calling bibliography engine' % (self.bcf_node)) prev_idx_hash = hash_idx try: self.idx_node = node.change_ext('.idx') hashes = [Utils.h_file(self.idx_node.abspath())] hash_idx = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read idx.h') pass if hash_idx and hash_idx != prev_idx_hash: self.makeindex() else: Logs.warn('%s unchanged, not calling indexing engine' % (self.idx_node)) prev_nlo_hash = hash_nlo try: self.nlo_node = node.change_ext('.nlo') hashes = [Utils.h_file(self.nlo_node.abspath())] hash_nlo = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read nlo.h') pass if hash_nlo and hash_nlo != prev_nlo_hash: self.makenomen() else: Logs.warn('%s unchanged, not calling nomenclature engine' % (self.nlo_node)) for i in range(10): # prevent against infinite loops - one never knows # watch the contents of file.aux and stop if file.aux does not change anymore prev_hash = hash try: hashes = [Utils.h_file(x.abspath()) for x in self.aux_nodes] hash = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read aux.h') pass prev_hash_bbl = hash_bbl try: hashes = [Utils.h_file(self.bbl_node.abspath())] hash_bbl = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read bbl.h') pass prev_hash_ind = hash_ind try: hashes = [Utils.h_file(self.ind_node.abspath())] hash_ind = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read ind.h') pass prev_hash_nls = hash_nls try: hashes = [Utils.h_file(self.nls_node.abspath())] hash_nls = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read nls.h') pass if hash and hash == prev_hash: Logs.warn('.aux files unchanged') if hash_bbl and hash_bbl == prev_hash_bbl: Logs.warn('%s unchanged' % (self.bcf_node)) if hash_ind and hash_ind == prev_hash_ind: Logs.warn('%s unchanged' % (self.ind_node)) if hash_nls and hash_nls == prev_hash_nls: Logs.warn('%s unchanged' % (self.nls_node)) if hash and hash == prev_hash and hash_bbl and hash_bbl == prev_hash_bbl and hash_ind and hash_ind == prev_hash_ind and hash_nls and hash_nls == prev_hash_nls: Logs.warn('Breaking loop now.') break # run the command Logs.warn('calling %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status('error when calling %s' % self.__class__.__name__, fun())
class pdflatex(tex): "Compiles PdfLaTeX files" texfun, vars = Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}', shell=False)
class pdflatex(tex): texfun, vars = Task.compile_fun("${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}", shell=False)
class tex(Task.Task): """ Compiles a tex/latex file. .. inheritance-diagram:: waflib.Tools.tex.latex waflib.Tools.tex.xelatex waflib.Tools.tex.pdflatex """ bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun( '${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ makeglossaries_fun, _ = Task.compile_fun('${MAKEGLOSSARIES} ${SRCFILE}', shell=False) makeglossaries_fun.__doc__ = """ Execute the program **makeglossaries** """ def exec_command(self, cmd, **kw): """ Executes TeX commands without buffering (latex may prompt for inputs) :return: the return code :rtype: int """ if self.env.PROMPT_LATEX: # capture the outputs in configuration tests kw['stdout'] = kw['stderr'] = None return super(tex, self).exec_command(cmd, **kw) def scan_aux(self, node): """ Recursive regex-based scanner that finds included auxiliary files. """ nodes = [node] re_aux = re.compile(r'\\@input{(?P<file>[^{}]*)}', re.M) def parse_node(node): code = node.read() for match in re_aux.finditer(code): path = match.group('file') found = node.parent.find_or_declare(path) if found and found not in nodes: Logs.debug('tex: found aux node %r', found) nodes.append(found) parse_node(found) parse_node(node) return nodes def scan(self): """ Recursive regex-based scanner that finds latex dependencies. It uses :py:attr:`waflib.Tools.tex.re_tex` Depending on your needs you might want: * to change re_tex:: from waflib.Tools import tex tex.re_tex = myregex * or to change the method scan from the latex tasks:: from waflib.Task import classes classes['latex'].scan = myscanfunction """ node = self.inputs[0] nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() for match in re_tex.finditer(code): multibib = match.group('type') if multibib and multibib.startswith('bibliography'): multibib = multibib[len('bibliography'):] if multibib.startswith('style'): continue else: multibib = None for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: # issue 1067, scan in all texinputs folders for up in self.texinputs_nodes: Logs.debug('tex: trying %s%s', path, k) found = up.find_resource(path + k) if found: break for tsk in self.generator.tasks: if not found or found in tsk.outputs: break else: nodes.append(found) add_name = False for ext in exts_tex: if found.name.endswith(ext): parse_node(found) break # multibib stuff if found and multibib and found.name.endswith( '.bib'): try: self.multibibs.append(found) except AttributeError: self.multibibs = [found] # no break, people are crazy if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() Logs.debug("tex: found the following : %s and names %s", nodes, names) return (nodes, names) def check_status(self, msg, retcode): """ Checks an exit status and raise an error with a particular message :param msg: message to display if the code is non-zero :type msg: string :param retcode: condition :type retcode: boolean """ if retcode != 0: raise Errors.WafError('%r command exit status %r' % (msg, retcode)) def info(self, *k, **kw): try: info = self.generator.bld.conf.logger.info except AttributeError: info = Logs.info info(*k, **kw) def bibfile(self): """ Parses *.aux* files to find bibfiles to process. If present, execute :py:meth:`waflib.Tools.tex.tex.bibtex_fun` """ for aux_node in self.aux_nodes: try: ct = aux_node.read() except EnvironmentError: Logs.error('Error reading %s: %r', aux_node.abspath()) continue if g_bibtex_re.findall(ct): self.info('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() }) self.env.SRCFILE = aux_node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) for node in getattr(self, 'multibibs', []): self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() }) self.env.SRCFILE = node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): """ Parses *.aux* file to find bibunit files. If there are bibunit files, runs :py:meth:`waflib.Tools.tex.tex.bibtex_fun`. """ try: bibunits = bibunitscan(self) except OSError: Logs.error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in range(1, len(bibunits) + 1)] if fn: self.info('calling bibtex on bibunits') for f in fn: self.env.env = { 'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs() } self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): """ Searches the filesystem for *.idx* files to process. If present, runs :py:meth:`waflib.Tools.tex.tex.makeindex_fun` """ self.idx_node = self.inputs[0].change_ext('.idx') try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: self.info('index file %s absent, not calling makeindex', idx_path) else: self.info('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def bibtopic(self): """ Lists additional .aux files from the bibtopic package """ p = self.inputs[0].parent.get_bld() if os.path.exists(os.path.join(p.abspath(), 'btaux.aux')): self.aux_nodes += p.ant_glob('*[0-9].aux') def makeglossaries(self): """ Lists additional glossaries from .aux files. If present, runs the makeglossaries program. """ src_file = self.inputs[0].abspath() base_file = os.path.basename(src_file) base, _ = os.path.splitext(base_file) for aux_node in self.aux_nodes: try: ct = aux_node.read() except EnvironmentError: Logs.error('Error reading %s: %r', aux_node.abspath()) continue if g_glossaries_re.findall(ct): if not self.env.MAKEGLOSSARIES: raise Errors.WafError( "The program 'makeglossaries' is missing!") Logs.warn('calling makeglossaries') self.env.SRCFILE = base self.check_status( 'error when calling makeglossaries %s' % base, self.makeglossaries_fun()) return def texinputs(self): """ Returns the list of texinput nodes as a string suitable for the TEXINPUTS environment variables :rtype: string """ return os.pathsep.join([k.abspath() for k in self.texinputs_nodes]) + os.pathsep def run(self): """ Runs the whole TeX build process Multiple passes are required depending on the usage of cross-references, bibliographies, glossaries, indexes and additional contents The appropriate TeX compiler is called until the *.aux* files stop changing. """ env = self.env if not env.PROMPT_LATEX: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') # important, set the cwd for everybody self.cwd = self.inputs[0].parent.get_bld() self.info('first pass on %s', self.__class__.__name__) # Hash .aux files before even calling the LaTeX compiler cur_hash = self.hash_aux_nodes() self.call_latex() # Find the .aux files again since bibtex processing can require it self.hash_aux_nodes() self.bibtopic() self.bibfile() self.bibunits() self.makeindex() self.makeglossaries() for i in range(10): # There is no need to call latex again if the .aux hash value has not changed prev_hash = cur_hash cur_hash = self.hash_aux_nodes() if not cur_hash: Logs.error('No aux.h to process') if cur_hash and cur_hash == prev_hash: break # run the command self.info('calling %s', self.__class__.__name__) self.call_latex() def hash_aux_nodes(self): """ Returns a hash of the .aux file contents :rtype: string or bytes """ try: self.aux_nodes except AttributeError: try: self.aux_nodes = self.scan_aux( self.inputs[0].change_ext('.aux')) except IOError: return None return Utils.h_list( [Utils.h_file(x.abspath()) for x in self.aux_nodes]) def call_latex(self): """ Runs the TeX compiler once """ self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.texinputs()}) self.env.SRCFILE = self.inputs[0].abspath() self.check_status('error when calling latex', self.texfun())
class tex(Task.Task): """ Compile a tex/latex file. .. inheritance-diagram:: waflib.Tools.tex.latex waflib.Tools.tex.xelatex waflib.Tools.tex.pdflatex """ bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun( '${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ def scan_aux(self, node): """ A recursive regex-based scanner that finds included auxiliary files. """ nodes = [node] re_aux = re.compile(r'\\@input{(?P<file>[^{}]*)}', re.M) def parse_node(node): code = node.read() for match in re_aux.finditer(code): path = match.group('file') found = node.parent.find_or_declare(path) if found and found not in nodes: debug('tex: found aux node ' + found.abspath()) nodes.append(found) parse_node(found) parse_node(node) return nodes def scan(self): """ A recursive regex-based scanner that finds latex dependencies. It uses :py:attr:`waflib.Tools.tex.re_tex` Depending on your needs you might want: * to change re_tex:: from waflib.Tools import tex tex.re_tex = myregex * or to change the method scan from the latex tasks:: from waflib.Task import classes classes['latex'].scan = myscanfunction """ node = self.inputs[0] nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() global re_tex for match in re_tex.finditer(code): for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: debug('tex: trying %s%s' % (path, k)) found = node.parent.find_resource(path + k) if found and not found in self.outputs: nodes.append(found) add_name = False for ext in exts_tex: if found.name.endswith(ext): parse_node(found) break # no break, people are crazy if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() debug("tex: found the following : %s and names %s" % (nodes, names)) return (nodes, names) def check_status(self, msg, retcode): """ Check an exit status and raise an error with a particular message :param msg: message to display if the code is non-zero :type msg: string :param retcode: condition :type retcode: boolean """ if retcode != 0: raise Errors.WafError("%r command exit status %r" % (msg, retcode)) def bibfile(self): """ Parse the *.aux* files to find a bibfile to process. If yes, execute :py:meth:`waflib.Tools.tex.tex.bibtex_fun` """ need_bibtex = False try: for aux_node in self.aux_nodes: ct = aux_node.read() if g_bibtex_re.findall(ct): need_bibtex = True break except (OSError, IOError): error('error bibtex scan') else: # only the main .aux file needs to be processed if need_bibtex: warn('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS }) self.env.SRCFILE = self.aux_nodes[0].name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): """ Parse the *.aux* file to find bibunit files. If there are bibunit files, execute :py:meth:`waflib.Tools.tex.tex.bibtex_fun`. """ try: bibunits = bibunitscan(self) except FSError: error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in xrange(1, len(bibunits) + 1)] if fn: warn('calling bibtex on bibunits') for f in fn: self.env.env = { 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS } self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): """ Look on the filesystem if there is a *.idx* file to process. If yes, execute :py:meth:`waflib.Tools.tex.tex.makeindex_fun` """ try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: warn('index file %s absent, not calling makeindex' % idx_path) else: warn('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def run(self): """ Runs the TeX build process. It may require multiple passes, depending on the usage of cross-references, bibliographies, content susceptible of needing such passes. The appropriate TeX compiler is called until the *.aux* files stop changing. Makeindex and bibtex are called if necessary. """ env = self.env if not env['PROMPT_LATEX']: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') fun = self.texfun node = self.inputs[0] srcfile = node.abspath() texinputs = self.env.TEXINPUTS or '' self.TEXINPUTS = node.parent.get_bld().abspath( ) + os.pathsep + node.parent.get_src().abspath( ) + os.pathsep + texinputs + os.pathsep self.aux_node = node.change_ext( '.aux') # TODO waf 1.7 remove (left for compatibility) # important, set the cwd for everybody self.cwd = self.inputs[0].parent.get_bld().abspath() warn('first pass on %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status('error when calling latex', fun()) self.aux_nodes = self.scan_aux(node.change_ext('.aux')) self.idx_node = node.change_ext('.idx') self.bibfile() self.bibunits() self.makeindex() hash = '' for i in range(10): # prevent against infinite loops - one never knows # watch the contents of file.aux and stop if file.aux does not change anymore prev_hash = hash try: hashes = [Utils.h_file(x.abspath()) for x in self.aux_nodes] hash = Utils.h_list(hashes) except (OSError, IOError): error('could not read aux.h') pass if hash and hash == prev_hash: break # run the command warn('calling %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status( 'error when calling %s' % self.__class__.__name__, fun())
class tex(Task.Task): bibtex_fun, _ = Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}', shell=False) bibtex_fun.__doc__ = """ Execute the program **bibtex** """ makeindex_fun, _ = Task.compile_fun( '${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}', shell=False) makeindex_fun.__doc__ = """ Execute the program **makeindex** """ def exec_command(self, cmd, **kw): bld = self.generator.bld try: if not kw.get('cwd', None): kw['cwd'] = bld.cwd except AttributeError: bld.cwd = kw['cwd'] = bld.variant_dir return Utils.subprocess.Popen(cmd, **kw).wait() def scan_aux(self, node): nodes = [node] re_aux = re.compile(r'\\@input{(?P<file>[^{}]*)}', re.M) def parse_node(node): code = node.read() for match in re_aux.finditer(code): path = match.group('file') found = node.parent.find_or_declare(path) if found and found not in nodes: Logs.debug('tex: found aux node ' + found.abspath()) nodes.append(found) parse_node(found) parse_node(node) return nodes def scan(self): node = self.inputs[0] nodes = [] names = [] seen = [] if not node: return (nodes, names) def parse_node(node): if node in seen: return seen.append(node) code = node.read() global re_tex for match in re_tex.finditer(code): for path in match.group('file').split(','): if path: add_name = True found = None for k in exts_deps_tex: Logs.debug('tex: trying %s%s' % (path, k)) found = node.parent.find_resource(path + k) for tsk in self.generator.tasks: if not found or found in tsk.outputs: break else: nodes.append(found) add_name = False for ext in exts_tex: if found.name.endswith(ext): parse_node(found) break if add_name: names.append(path) parse_node(node) for x in nodes: x.parent.get_bld().mkdir() Logs.debug("tex: found the following : %s and names %s" % (nodes, names)) return (nodes, names) def check_status(self, msg, retcode): if retcode != 0: raise Errors.WafError("%r command exit status %r" % (msg, retcode)) def bibfile(self): for aux_node in self.aux_nodes: try: ct = aux_node.read() except (OSError, IOError): Logs.error('Error reading %s: %r' % aux_node.abspath()) continue if g_bibtex_re.findall(ct): Logs.warn('calling bibtex') self.env.env = {} self.env.env.update(os.environ) self.env.env.update({ 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS }) self.env.SRCFILE = aux_node.name[:-4] self.check_status('error when calling bibtex', self.bibtex_fun()) def bibunits(self): try: bibunits = bibunitscan(self) except OSError: Logs.error('error bibunitscan') else: if bibunits: fn = ['bu' + str(i) for i in xrange(1, len(bibunits) + 1)] if fn: Logs.warn('calling bibtex on bibunits') for f in fn: self.env.env = { 'BIBINPUTS': self.TEXINPUTS, 'BSTINPUTS': self.TEXINPUTS } self.env.SRCFILE = f self.check_status('error when calling bibtex', self.bibtex_fun()) def makeindex(self): try: idx_path = self.idx_node.abspath() os.stat(idx_path) except OSError: Logs.warn('index file %s absent, not calling makeindex' % idx_path) else: Logs.warn('calling makeindex') self.env.SRCFILE = self.idx_node.name self.env.env = {} self.check_status('error when calling makeindex %s' % idx_path, self.makeindex_fun()) def bibtopic(self): p = self.inputs[0].parent.get_bld() if os.path.exists(os.path.join(p.abspath(), 'btaux.aux')): self.aux_nodes += p.ant_glob('*[0-9].aux') def run(self): env = self.env if not env['PROMPT_LATEX']: env.append_value('LATEXFLAGS', '-interaction=batchmode') env.append_value('PDFLATEXFLAGS', '-interaction=batchmode') env.append_value('XELATEXFLAGS', '-interaction=batchmode') fun = self.texfun node = self.inputs[0] srcfile = node.abspath() texinputs = self.env.TEXINPUTS or '' self.TEXINPUTS = node.parent.get_bld().abspath( ) + os.pathsep + node.parent.get_src().abspath( ) + os.pathsep + texinputs + os.pathsep self.cwd = self.inputs[0].parent.get_bld().abspath() Logs.warn('first pass on %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status('error when calling latex', fun()) self.aux_nodes = self.scan_aux(node.change_ext('.aux')) self.idx_node = node.change_ext('.idx') self.bibtopic() self.bibfile() self.bibunits() self.makeindex() hash = '' for i in range(10): prev_hash = hash try: hashes = [Utils.h_file(x.abspath()) for x in self.aux_nodes] hash = Utils.h_list(hashes) except (OSError, IOError): Logs.error('could not read aux.h') pass if hash and hash == prev_hash: break Logs.warn('calling %s' % self.__class__.__name__) self.env.env = {} self.env.env.update(os.environ) self.env.env.update({'TEXINPUTS': self.TEXINPUTS}) self.env.SRCFILE = srcfile self.check_status( 'error when calling %s' % self.__class__.__name__, fun())
class splint(lint,Task.Task): color = 'CYAN' run_str_splint = '${SPLINT} ${SPLINTOPTS} ${SPLINTCPPPATH_ST:INCPATHS} ${SPLINTDEFINES_ST:DEFINES} ${SPLINTDUMPOPTS} ${SRC}' run_str_cc = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} -E -dM -dD -v ${CC_SRC_F}${SRC[0].abspath()}' (run_splint, splint_vars) = Task.compile_fun(run_str_splint) (run_cc, cc_vars) = Task.compile_fun(run_str_cc) vars = splint_vars + cc_vars log_str = '[SPLINT] $name $out' @property def name(self): return self.generator.name @property def out(self): return self.outputs[1].nice_path() def run(self): global stdout_sep, stderr_sep tgen = self.generator env = self.env inputs = self.inputs outputs = self.outputs for x in outputs: x.delete() splintrc_template_node = inputs[0] source_nodes = inputs[1:] splintrc_node, output_node = outputs defines, includes = self.extract_compiler_params() # for some reason splint seems to completely ignore stdint.h from gcc # I have no idea why. Therefore we must supply our own stdint.h # in order to have splint run properly includes.insert(0, os.path.join(module_path, "splint_includes")) tgenincludes = set(x.abspath() for x in tgen.to_incnodes(getattr(tgen, 'includes', []))) sysincludes = list(x for x in includes if x not in tgenincludes) # splint seems to have problems with resolving some headers: # It seems to completely ignore stdint.h from compiler files. dct = dict() # the following does not work # splint does not support spaces in splintrc dct['INCPATHFLAGS'] = '' dct['SYSDIRSFLAG'] = '' #dct['INCPATHFLAGS'] = os.linesep.join('+I"%s"' % x.replace(' ', '\\\\ ') for x in gccincludes) #dct['SYSDIRSFLAG'] = '-sys-dirs %s' % os.pathsep.join(sysincludes) env.stash() try: template_string = string.Template(splintrc_template_node.read()) splintrc_node.write(template_string.substitute(dct)) env.append_value('SPLINTOPTS', ['-f',splintrc_node.abspath()]) # the following two are required beccause auf splint problems # currently it seems not to work when they are specified via # splintrc if not dct['INCPATHFLAGS']: env['INCPATHS'] = includes if not dct['SYSDIRSFLAG']: env.append_value('SPLINTOPTS', ['-systemdirs', os.pathsep.join(sysincludes)]) try: self.inputs = source_nodes out, err = self.run_splint() except Exception, e: out = getattr(e, 'stdout', None) err = getattr(e, 'stderr', None) finally: self.inputs = inputs finally: