build_info.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. def substitute(build, output_dir):
  3. # setup the template engine
  4. template_dir = os.path.join(os.path.dirname(__file__), 'templates')
  5. jtemplate = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True)
  6. # add the filters
  7. jtemplate.filters['csv'] = csv
  8. jtemplate.filters['stripExtraSpaces'] = stripExtraSpaces
  9. # load the template
  10. template = jtemplate.get_template('template_build_info.m')
  11. # create the build directory
  12. output_dir = output_dir+'/+cv'
  13. if not os.path.isdir(output_dir):
  14. os.mkdir(output_dir)
  15. # populate template
  16. populated = template.render(build=build, time=time)
  17. with open(os.path.join(output_dir, 'buildInformation.m'), 'wb') as f:
  18. f.write(populated.encode('utf-8'))
  19. if __name__ == "__main__":
  20. """
  21. Usage: python build_info.py
  22. --os os_version_string
  23. --arch [bitness processor]
  24. --compiler [id version]
  25. --mex_arch arch_string
  26. --mex_script /path/to/mex/script
  27. --cxx_flags [-list -of -flags -to -passthrough]
  28. --opencv_version version_string
  29. --commit commit_hash_if_using_git
  30. --modules [core imgproc highgui etc]
  31. --configuration Debug/Release
  32. --outdir /path/to/write/build/info
  33. build_info.py generates a Matlab function that can be invoked with a call to
  34. >> cv.buildInformation();
  35. This function prints a summary of the user's OS, OpenCV and Matlab build
  36. given the information passed to this module. build_info.py invokes Jinja2
  37. on the template_build_info.m template.
  38. """
  39. # parse the input options
  40. import sys, re, os, time
  41. from argparse import ArgumentParser
  42. parser = ArgumentParser()
  43. parser.add_argument('--os')
  44. parser.add_argument('--arch', nargs=2)
  45. parser.add_argument('--compiler', nargs='+')
  46. parser.add_argument('--mex_arch')
  47. parser.add_argument('--mex_script')
  48. parser.add_argument('--mex_opts', default=['-largeArrayDims'], nargs='*')
  49. parser.add_argument('--cxx_flags', default=[], nargs='*')
  50. parser.add_argument('--opencv_version', default='', nargs='?')
  51. parser.add_argument('--commit', default='Not in working git tree', nargs='?')
  52. parser.add_argument('--modules', nargs='+')
  53. parser.add_argument('--configuration')
  54. parser.add_argument('--outdir')
  55. build = parser.parse_args()
  56. from filters import *
  57. from jinja2 import Environment, FileSystemLoader
  58. # populate the build info template
  59. substitute(build, build.outdir)