wscript 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Nanomsgxx doc build script.
  5. from waflib.Task import Task
  6. import os
  7. class ronn(Task):
  8. def make_ronn_command(self):
  9. cmd = [
  10. 'RONN_STYLE=' + self.env.basename,
  11. 'ronn',
  12. '--organization', "'achille.roussel@gmail.com'",
  13. '--manual', 'nanomsgxx',
  14. self.inputs[0].abspath(),
  15. ]
  16. if self.env.docstyle == 'dark':
  17. cmd += ['--style', 'dark,nnxx,highlight-dark']
  18. else:
  19. cmd += ['--style', 'nnxx,highlight-light']
  20. return cmd
  21. def make_mv_command(self):
  22. return [
  23. 'mv',
  24. self.outputs[0].abspath(),
  25. self.outputs[0].abspath() + '.tmp',
  26. ]
  27. def make_colorsyntax_command(self):
  28. return [
  29. os.path.join(self.env.basename, 'colorsyntax'),
  30. '-s',
  31. 'monokai',
  32. '<',
  33. self.outputs[0].abspath() + '.tmp',
  34. '>',
  35. self.outputs[0].abspath(),
  36. ]
  37. def make_rm_command(self):
  38. return [
  39. 'rm',
  40. '-f',
  41. self.outputs[0].abspath() + '.tmp',
  42. ]
  43. def make_command(self):
  44. return \
  45. self.make_ronn_command() + ['&&'] + \
  46. self.make_mv_command() + ['&&'] + \
  47. self.make_colorsyntax_command() + ['&&'] + \
  48. self.make_rm_command()
  49. def run(self):
  50. return self.exec_command(' '.join(self.make_command()))
  51. class gzip(Task):
  52. def run(self):
  53. return self.exec_command('gzip -c %s > %s' % (
  54. self.inputs[0].abspath(),
  55. self.outputs[0].abspath(),
  56. ))
  57. def relative_parent_path(waf, file_node):
  58. return file_node.parent.abspath()[len(waf.path.abspath()):].lstrip('/')
  59. def html_output_file(waf, input_file):
  60. name = input_file.name.replace('.ronn', '.html')
  61. path = relative_parent_path(waf, input_file)
  62. return waf.path.make_node(os.path.join(path, name))
  63. def roff_output_file(waf, input_file):
  64. name = input_file.name.replace('.ronn', '')
  65. path = relative_parent_path(waf, input_file)
  66. return waf.path.make_node(os.path.join(path, name))
  67. def gzip_output_file(waf, input_file):
  68. name = input_file.name + '.gz'
  69. path = relative_parent_path(waf, input_file)
  70. return waf.path.make_node(os.path.join(path, name))
  71. def gzip_install_file(waf, gzip_file):
  72. name = gzip_file.name
  73. path = relative_parent_path(waf, gzip_file)
  74. symbol, section, _ = name.split('.')
  75. if len(path) == 0:
  76. where = name
  77. elif path == 'nnxx':
  78. where = 'nnxx::' + name
  79. else:
  80. where = 'nanomsgxx-' + name
  81. return os.path.join('man' + section, where)
  82. def build(waf):
  83. waf.env.basename = waf.path.abspath()
  84. wscript = waf.path.ant_glob('wscript')
  85. colorsyntax = waf.path.ant_glob('colorsyntax')
  86. css_files = waf.path.ant_glob('**/*.css')
  87. idx_files = waf.path.ant_glob('**/index.txt')
  88. html_files = []
  89. roff_files = []
  90. gzip_files = []
  91. for input_file in waf.path.ant_glob('**/*.ronn'):
  92. html_file = html_output_file(waf, input_file)
  93. html_files.append(html_file)
  94. roff_file = roff_output_file(waf, input_file)
  95. roff_files.append(roff_file)
  96. ronn_task = ronn(env=waf.env)
  97. ronn_task.set_inputs([input_file] + css_files + idx_files + colorsyntax + wscript)
  98. ronn_task.set_outputs([html_file, roff_file])
  99. waf.add_to_group(ronn_task)
  100. gzip_file = gzip_output_file(waf, roff_file)
  101. gzip_task = gzip(env=waf.env)
  102. gzip_task.set_inputs([roff_file])
  103. gzip_task.set_outputs([gzip_file])
  104. gzip_files.append(gzip_file)
  105. waf.add_to_group(gzip_task)
  106. if waf.env.install_html_path:
  107. for hf in html_files:
  108. waf.install_as(os.path.join(waf.env.install_html_path, relative_parent_path(waf, hf), hf.name), hf)
  109. if waf.env.install_man_path:
  110. for gf in gzip_files:
  111. waf.install_as(os.path.join(waf.env.install_man_path, gzip_install_file(waf, gf)), gf)
  112. def configure(waf):
  113. assert waf.options.docstyle in ('dark', 'light')
  114. waf.load('python')
  115. waf.find_program('cat')
  116. waf.find_program('gzip')
  117. waf.find_program('ronn')
  118. waf.check_python_version((2,6,0))
  119. waf.check_python_module('bs4')
  120. waf.check_python_module('pygments')
  121. waf.env.docstyle = waf.options.docstyle
  122. waf.env.install_html_path = waf.options.install_html_path
  123. waf.env.install_man_path = waf.options.install_man_path
  124. def options(waf):
  125. waf.add_option('--docstyle', nargs=1, default='dark', help='the doc style (dark or light)')
  126. waf.add_option('--install-html-path', nargs=1, default='/usr/local/share/doc/nanomsgxx', help='where to install html doc')
  127. waf.add_option('--install-man-path', nargs=1, default='/usr/local/share/man', help='where to install man pages')