1#!/usr/bin/env python 2# encoding: utf-8 3# Mark Coggeshall, 2010 4 5"SAS support" 6 7import os 8from waflib import Task, Errors, Logs 9from waflib.TaskGen import feature, before_method 10 11sas_fun, _ = Task.compile_fun('sas -sysin ${SRCFILE} -log ${LOGFILE} -print ${LSTFILE}', shell=False) 12 13class sas(Task.Task): 14 vars = ['SAS', 'SASFLAGS'] 15 def run(task): 16 command = 'SAS' 17 fun = sas_fun 18 19 node = task.inputs[0] 20 logfilenode = node.change_ext('.log') 21 lstfilenode = node.change_ext('.lst') 22 23 # set the cwd 24 task.cwd = task.inputs[0].parent.get_src().abspath() 25 Logs.debug('runner: %r on %r', command, node) 26 27 SASINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep 28 task.env.env = {'SASINPUTS': SASINPUTS} 29 30 task.env.SRCFILE = node.abspath() 31 task.env.LOGFILE = logfilenode.abspath() 32 task.env.LSTFILE = lstfilenode.abspath() 33 ret = fun(task) 34 if ret: 35 Logs.error('Running %s on %r returned a non-zero exit', command, node) 36 Logs.error('SRCFILE = %r', node) 37 Logs.error('LOGFILE = %r', logfilenode) 38 Logs.error('LSTFILE = %r', lstfilenode) 39 return ret 40 41@feature('sas') 42@before_method('process_source') 43def apply_sas(self): 44 if not getattr(self, 'type', None) in ('sas',): 45 self.type = 'sas' 46 47 self.env['logdir'] = getattr(self, 'logdir', 'log') 48 self.env['lstdir'] = getattr(self, 'lstdir', 'lst') 49 50 deps_lst = [] 51 52 if getattr(self, 'deps', None): 53 deps = self.to_list(self.deps) 54 for filename in deps: 55 n = self.path.find_resource(filename) 56 if not n: 57 n = self.bld.root.find_resource(filename) 58 if not n: 59 raise Errors.WafError('cannot find input file %s for processing' % filename) 60 if not n in deps_lst: 61 deps_lst.append(n) 62 63 for node in self.to_nodes(self.source): 64 if self.type == 'sas': 65 task = self.create_task('sas', src=node) 66 task.dep_nodes = deps_lst 67 self.source = [] 68 69def configure(self): 70 self.find_program('sas', var='SAS', mandatory=False) 71 72