sas.py 1.9 KB

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