conf_common.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Common (non-language-specific) configuration for Read The Docs & Sphinx
  4. #
  5. # Based on a Read the Docs Template documentation build configuration file,
  6. # created by sphinx-quickstart on Tue Aug 26 14:19:49 2014.
  7. #
  8. # This file is imported from a language-specific conf.py (ie en/conf.py or
  9. # zh_CN/conf.py)
  10. #
  11. # Note that not all possible configuration values are present in this
  12. # autogenerated file.
  13. #
  14. # All configuration values have a default; values that are commented out
  15. # serve to show the default.
  16. from __future__ import print_function
  17. from __future__ import unicode_literals
  18. import sys, os
  19. import re
  20. import subprocess
  21. import shlex
  22. # Note: If extensions (or modules to document with autodoc) are in another directory,
  23. # add these directories to sys.path here. If the directory is relative to the
  24. # documentation root, use os.path.abspath to make it absolute
  25. from local_util import run_cmd_get_output, copy_if_modified
  26. # build_docs on the CI server sometimes fails under Python3. This is a workaround:
  27. sys.setrecursionlimit(3500)
  28. try:
  29. builddir = os.environ['BUILDDIR']
  30. except KeyError:
  31. builddir = '_build'
  32. # Fill in a default IDF_PATH if it's missing (ie when Read The Docs is building the docs)
  33. try:
  34. idf_path = os.environ['IDF_PATH']
  35. except KeyError:
  36. idf_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
  37. def call_with_python(cmd):
  38. # using sys.executable ensures that the scripts are called with the same Python interpreter
  39. if os.system('{} {}'.format(sys.executable, cmd)) != 0:
  40. raise RuntimeError('{} failed'.format(cmd))
  41. # Call Doxygen to get XML files from the header files
  42. print("Calling Doxygen to generate latest XML files")
  43. if os.system("doxygen ../Doxyfile") != 0:
  44. raise RuntimeError('Doxygen call failed')
  45. # Doxygen has generated XML files in 'xml' directory.
  46. # Copy them to 'xml_in', only touching the files which have changed.
  47. copy_if_modified('xml/', 'xml_in/')
  48. # Generate 'api_name.inc' files using the XML files by Doxygen
  49. call_with_python('../gen-dxd.py')
  50. def find_component_files(parent_dir, target_filename):
  51. parent_dir = os.path.abspath(parent_dir)
  52. result = []
  53. for (dirpath, dirnames, filenames) in os.walk(parent_dir):
  54. try:
  55. # note: trimming "examples" dir as MQTT submodule
  56. # has its own examples directory in the submodule, not part of IDF
  57. dirnames.remove("examples")
  58. except ValueError:
  59. pass
  60. if target_filename in filenames:
  61. result.append(os.path.join(dirpath, target_filename))
  62. print("List of %s: %s" % (target_filename, ", ".join(result)))
  63. return result
  64. # Generate 'kconfig.inc' file from components' Kconfig files
  65. print("Generating kconfig.inc from kconfig contents")
  66. kconfig_inc_path = '{}/inc/kconfig.inc'.format(builddir)
  67. temp_sdkconfig_path = '{}/sdkconfig.tmp'.format(builddir)
  68. kconfigs = find_component_files("../../components", "Kconfig")
  69. kconfig_projbuilds = find_component_files("../../components", "Kconfig.projbuild")
  70. confgen_args = [sys.executable,
  71. "../../tools/kconfig_new/confgen.py",
  72. "--kconfig", "../../Kconfig",
  73. "--config", temp_sdkconfig_path,
  74. "--create-config-if-missing",
  75. "--env", "COMPONENT_KCONFIGS={}".format(" ".join(kconfigs)),
  76. "--env", "COMPONENT_KCONFIGS_PROJBUILD={}".format(" ".join(kconfig_projbuilds)),
  77. "--env", "IDF_PATH={}".format(idf_path),
  78. "--output", "docs", kconfig_inc_path + '.in'
  79. ]
  80. subprocess.check_call(confgen_args)
  81. copy_if_modified(kconfig_inc_path + '.in', kconfig_inc_path)
  82. # Generate 'esp_err_defs.inc' file with ESP_ERR_ error code definitions
  83. esp_err_inc_path = '{}/inc/esp_err_defs.inc'.format(builddir)
  84. call_with_python('../../tools/gen_esp_err_to_name.py --rst_output ' + esp_err_inc_path + '.in')
  85. copy_if_modified(esp_err_inc_path + '.in', esp_err_inc_path)
  86. # Generate version-related includes
  87. #
  88. # (Note: this is in a function as it needs to access configuration to get the language)
  89. def generate_version_specific_includes(app):
  90. print("Generating version-specific includes...")
  91. version_tmpdir = '{}/version_inc'.format(builddir)
  92. call_with_python('../gen-version-specific-includes.py {} {}'.format(app.config.language, version_tmpdir))
  93. copy_if_modified(version_tmpdir, '{}/inc'.format(builddir))
  94. # Generate toolchain download links
  95. print("Generating toolchain download links")
  96. base_url = 'https://dl.espressif.com/dl/'
  97. toolchain_tmpdir = '{}/toolchain_inc'.format(builddir)
  98. call_with_python('../gen-toolchain-links.py ../../tools/toolchain_versions.mk {} {}'.format(base_url, toolchain_tmpdir))
  99. copy_if_modified(toolchain_tmpdir, '{}/inc'.format(builddir))
  100. # http://stackoverflow.com/questions/12772927/specifying-an-online-image-in-sphinx-restructuredtext-format
  101. #
  102. suppress_warnings = ['image.nonlocal_uri']
  103. # -- General configuration ------------------------------------------------
  104. # If your documentation needs a minimal Sphinx version, state it here.
  105. #needs_sphinx = '1.0'
  106. # Add any Sphinx extension module names here, as strings. They can be
  107. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  108. # ones.
  109. extensions = ['breathe',
  110. 'link-roles',
  111. 'sphinxcontrib.blockdiag',
  112. 'sphinxcontrib.seqdiag',
  113. 'sphinxcontrib.actdiag',
  114. 'sphinxcontrib.nwdiag',
  115. 'sphinxcontrib.rackdiag',
  116. 'sphinxcontrib.packetdiag'
  117. ]
  118. # Set up font for blockdiag, nwdiag, rackdiag and packetdiag
  119. blockdiag_fontpath = '../_static/DejaVuSans.ttf'
  120. seqdiag_fontpath = '../_static/DejaVuSans.ttf'
  121. actdiag_fontpath = '../_static/DejaVuSans.ttf'
  122. nwdiag_fontpath = '../_static/DejaVuSans.ttf'
  123. rackdiag_fontpath = '../_static/DejaVuSans.ttf'
  124. packetdiag_fontpath = '../_static/DejaVuSans.ttf'
  125. # Enabling this fixes cropping of blockdiag edge labels
  126. seqdiag_antialias = True
  127. # Breathe extension variables
  128. # Doxygen regenerates files in 'xml/' directory every time,
  129. # but we copy files to 'xml_in/' only when they change, to speed up
  130. # incremental builds.
  131. breathe_projects = { "esp32-idf": "xml_in/" }
  132. breathe_default_project = "esp32-idf"
  133. # Add any paths that contain templates here, relative to this directory.
  134. templates_path = ['_templates']
  135. # The suffix of source filenames.
  136. source_suffix = ['.rst', '.md']
  137. source_parsers = {
  138. '.md': 'recommonmark.parser.CommonMarkParser',
  139. }
  140. # The encoding of source files.
  141. #source_encoding = 'utf-8-sig'
  142. # The master toctree document.
  143. master_doc = 'index'
  144. # The version info for the project you're documenting, acts as replacement for
  145. # |version| and |release|, also used in various other places throughout the
  146. # built documents.
  147. #
  148. # Readthedocs largely ignores 'version' and 'release', and displays one of
  149. # 'latest', tag name, or branch name, depending on the build type.
  150. # Still, this is useful for non-RTD builds.
  151. # This is supposed to be "the short X.Y version", but it's the only version
  152. # visible when you open index.html.
  153. # Display full version to make things less confusing.
  154. version = run_cmd_get_output('git describe')
  155. # The full version, including alpha/beta/rc tags.
  156. # If needed, nearest tag is returned by 'git describe --abbrev=0'.
  157. release = version
  158. print('Version: {0} Release: {1}'.format(version, release))
  159. # There are two options for replacing |today|: either, you set today to some
  160. # non-false value, then it is used:
  161. #today = ''
  162. # Else, today_fmt is used as the format for a strftime call.
  163. #today_fmt = '%B %d, %Y'
  164. # List of patterns, relative to source directory, that match files and
  165. # directories to ignore when looking for source files.
  166. exclude_patterns = ['_build','README.md']
  167. # The reST default role (used for this markup: `text`) to use for all
  168. # documents.
  169. #default_role = None
  170. # If true, '()' will be appended to :func: etc. cross-reference text.
  171. #add_function_parentheses = True
  172. # If true, the current module name will be prepended to all description
  173. # unit titles (such as .. function::).
  174. #add_module_names = True
  175. # If true, sectionauthor and moduleauthor directives will be shown in the
  176. # output. They are ignored by default.
  177. #show_authors = False
  178. # The name of the Pygments (syntax highlighting) style to use.
  179. pygments_style = 'sphinx'
  180. # A list of ignored prefixes for module index sorting.
  181. #modindex_common_prefix = []
  182. # If true, keep warnings as "system message" paragraphs in the built documents.
  183. #keep_warnings = False
  184. # -- Options for HTML output ----------------------------------------------
  185. # The theme to use for HTML and HTML Help pages. See the documentation for
  186. # a list of builtin themes.
  187. html_theme = 'sphinx_rtd_theme'
  188. # Theme options are theme-specific and customize the look and feel of a theme
  189. # further. For a list of options available for each theme, see the
  190. # documentation.
  191. #html_theme_options = {}
  192. # Add any paths that contain custom themes here, relative to this directory.
  193. #html_theme_path = []
  194. # The name for this set of Sphinx documents. If None, it defaults to
  195. # "<project> v<release> documentation".
  196. #html_title = None
  197. # A shorter title for the navigation bar. Default is the same as html_title.
  198. #html_short_title = None
  199. # The name of an image file (relative to this directory) to place at the top
  200. # of the sidebar.
  201. html_logo = "../_static/espressif-logo.svg"
  202. # The name of an image file (within the static path) to use as favicon of the
  203. # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
  204. # pixels large.
  205. #html_favicon = None
  206. # Add any paths that contain custom static files (such as style sheets) here,
  207. # relative to this directory. They are copied after the builtin static files,
  208. # so a file named "default.css" will overwrite the builtin "default.css".
  209. html_static_path = ['../_static']
  210. # Add any extra paths that contain custom files (such as robots.txt or
  211. # .htaccess) here, relative to this directory. These files are copied
  212. # directly to the root of the documentation.
  213. #html_extra_path = []
  214. # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
  215. # using the given strftime format.
  216. #html_last_updated_fmt = '%b %d, %Y'
  217. # If true, SmartyPants will be used to convert quotes and dashes to
  218. # typographically correct entities.
  219. #html_use_smartypants = True
  220. # Custom sidebar templates, maps document names to template names.
  221. #html_sidebars = {}
  222. # Additional templates that should be rendered to pages, maps page names to
  223. # template names.
  224. #html_additional_pages = {}
  225. # If false, no module index is generated.
  226. #html_domain_indices = True
  227. # If false, no index is generated.
  228. #html_use_index = True
  229. # If true, the index is split into individual pages for each letter.
  230. #html_split_index = False
  231. # If true, links to the reST sources are added to the pages.
  232. #html_show_sourcelink = True
  233. # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
  234. #html_show_sphinx = True
  235. # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
  236. #html_show_copyright = True
  237. # If true, an OpenSearch description file will be output, and all pages will
  238. # contain a <link> tag referring to it. The value of this option must be the
  239. # base URL from which the finished HTML is served.
  240. #html_use_opensearch = ''
  241. # This is the file name suffix for HTML files (e.g. ".xhtml").
  242. #html_file_suffix = None
  243. # Output file base name for HTML help builder.
  244. htmlhelp_basename = 'ReadtheDocsTemplatedoc'
  245. # -- Options for LaTeX output ---------------------------------------------
  246. latex_elements = {
  247. # The paper size ('letterpaper' or 'a4paper').
  248. #'papersize': 'letterpaper',
  249. # The font size ('10pt', '11pt' or '12pt').
  250. #'pointsize': '10pt',
  251. # Additional stuff for the LaTeX preamble.
  252. #'preamble': '',
  253. }
  254. # Grouping the document tree into LaTeX files. List of tuples
  255. # (source start file, target name, title,
  256. # author, documentclass [howto, manual, or own class]).
  257. latex_documents = [
  258. ('index', 'ReadtheDocsTemplate.tex', u'Read the Docs Template Documentation',
  259. u'Read the Docs', 'manual'),
  260. ]
  261. # The name of an image file (relative to this directory) to place at the top of
  262. # the title page.
  263. #latex_logo = None
  264. # For "manual" documents, if this is true, then toplevel headings are parts,
  265. # not chapters.
  266. #latex_use_parts = False
  267. # If true, show page references after internal links.
  268. #latex_show_pagerefs = False
  269. # If true, show URL addresses after external links.
  270. #latex_show_urls = False
  271. # Documents to append as an appendix to all manuals.
  272. #latex_appendices = []
  273. # If false, no module index is generated.
  274. #latex_domain_indices = True
  275. # -- Options for manual page output ---------------------------------------
  276. # One entry per manual page. List of tuples
  277. # (source start file, name, description, authors, manual section).
  278. man_pages = [
  279. ('index', 'readthedocstemplate', u'Read the Docs Template Documentation',
  280. [u'Read the Docs'], 1)
  281. ]
  282. # If true, show URL addresses after external links.
  283. #man_show_urls = False
  284. # -- Options for Texinfo output -------------------------------------------
  285. # Grouping the document tree into Texinfo files. List of tuples
  286. # (source start file, target name, title, author,
  287. # dir menu entry, description, category)
  288. texinfo_documents = [
  289. ('index', 'ReadtheDocsTemplate', u'Read the Docs Template Documentation',
  290. u'Read the Docs', 'ReadtheDocsTemplate', 'One line description of project.',
  291. 'Miscellaneous'),
  292. ]
  293. # Documents to append as an appendix to all manuals.
  294. #texinfo_appendices = []
  295. # If false, no module index is generated.
  296. #texinfo_domain_indices = True
  297. # How to display URL addresses: 'footnote', 'no', or 'inline'.
  298. #texinfo_show_urls = 'footnote'
  299. # If true, do not generate a @detailmenu in the "Top" node's menu.
  300. #texinfo_no_detailmenu = False
  301. # Override RTD CSS theme to introduce the theme corrections
  302. # https://github.com/rtfd/sphinx_rtd_theme/pull/432
  303. def setup(app):
  304. app.add_stylesheet('theme_overrides.css')
  305. generate_version_specific_includes(app)