proc.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /usr/bin/env python
  2. # per rosengren 2011
  3. from os import environ, path
  4. from waflib import TaskGen, Utils
  5. def options(opt):
  6. grp = opt.add_option_group('Oracle ProC Options')
  7. grp.add_option('--oracle_home', action='store', default=environ.get('PROC_ORACLE'), help='Path to Oracle installation home (has bin/lib)')
  8. grp.add_option('--tns_admin', action='store', default=environ.get('TNS_ADMIN'), help='Directory containing server list (TNS_NAMES.ORA)')
  9. grp.add_option('--connection', action='store', default='dummy-user/dummy-password@dummy-server', help='Format: user/password@server')
  10. def configure(cnf):
  11. env = cnf.env
  12. if not env.PROC_ORACLE:
  13. env.PROC_ORACLE = cnf.options.oracle_home
  14. if not env.PROC_TNS_ADMIN:
  15. env.PROC_TNS_ADMIN = cnf.options.tns_admin
  16. if not env.PROC_CONNECTION:
  17. env.PROC_CONNECTION = cnf.options.connection
  18. cnf.find_program('proc', var='PROC', path_list=env.PROC_ORACLE + path.sep + 'bin')
  19. def proc(tsk):
  20. env = tsk.env
  21. gen = tsk.generator
  22. inc_nodes = gen.to_incnodes(Utils.to_list(getattr(gen,'includes',[])) + env['INCLUDES'])
  23. cmd = (
  24. [env.PROC] +
  25. ['SQLCHECK=SEMANTICS'] +
  26. (['SYS_INCLUDE=(' + ','.join(env.PROC_INCLUDES) + ')']
  27. if env.PROC_INCLUDES else []) +
  28. ['INCLUDE=(' + ','.join(
  29. [i.bldpath() for i in inc_nodes]
  30. ) + ')'] +
  31. ['userid=' + env.PROC_CONNECTION] +
  32. ['INAME=' + tsk.inputs[0].bldpath()] +
  33. ['ONAME=' + tsk.outputs[0].bldpath()]
  34. )
  35. exec_env = {
  36. 'ORACLE_HOME': env.PROC_ORACLE,
  37. 'LD_LIBRARY_PATH': env.PROC_ORACLE + path.sep + 'lib',
  38. }
  39. if env.PROC_TNS_ADMIN:
  40. exec_env['TNS_ADMIN'] = env.PROC_TNS_ADMIN
  41. return tsk.exec_command(cmd, env=exec_env)
  42. TaskGen.declare_chain(
  43. name = 'proc',
  44. rule = proc,
  45. ext_in = '.pc',
  46. ext_out = '.c',
  47. )