Debian Codegraph @

gcc/ada/doc/share/conf.py

raw
1 # -*- coding: utf-8 -*-
2 # Style_Check:Python_Fragment (meaning no pyflakes check)
3 #
4 # GNAT build configuration file
5 # --------------------------------
6 # This file defines the configuration for all files created
7 # by Sphinx. In this case, pdf (using latex) and html
8
9 import sys
10 import os
11 import time
12 import re
13
14 sys.path.append('.')
15
16 import ada_pygments
17 import latex_elements
18
19 # Define list of documents to be built and their title
20 DOCS = {
21 "gnat_rm": {"title": "GNAT Reference Manual"},
22 "gnat_ugn": {"title": "GNAT User's Guide for Native Platforms"},
23 "gnat-style": {"title": "GNAT Coding Style: A Guide for GNAT Developers"},
24 }
25
26 # Then retrieve the source directory
27 root_source_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
28 gnatvsn_spec = os.path.join(root_source_dir, '..', 'gnatvsn.ads')
29 basever = os.path.join(root_source_dir, '..', '..', 'BASE-VER')
30 texi_fsf = True # Set to False when FSF doc is switched to sphinx by default
31
32 # get vsn specs
33 with open(gnatvsn_spec, 'r') as fd:
34 gnatvsn_content = fd.read()
35
36
37 # read copyright test from .rst file (used also for sanity-checking)
38 def get_copyright():
39 return '2008-%s, Free Software Foundation' % time.strftime('%Y')
40
41
42 # get environment gnat version (used also for sanity-checking)
43 def get_gnat_version():
44 m = re.search(r'Gnat_Static_Version_String : ' +
45 r'constant String := "([^\(\)]+)\(.*\)?";',
46 gnatvsn_content)
47 if m:
48 return m.group(1).strip()
49 else:
50 if texi_fsf and os.path.exists(basever):
51 return ''
52
53 try:
54 with open(basever) as fd:
55 return fd.read()
56 except Exception:
57 pass
58
59 print('cannot find GNAT version in gnatvsn.ads or in ' + basever)
60 sys.exit(1)
61
62
63 # get gnat build type from runtime
64 def get_gnat_build_type():
65 m = re.search(r'Build_Type : constant Gnat_Build_Type := (.+);',
66 gnatvsn_content)
67 if m:
68 return {'Gnatpro': 'PRO',
69 'FSF': 'FSF',
70 'GPL': 'GPL'}[m.group(1).strip()]
71 else:
72 print('cannot compute GNAT build type')
73 sys.exit(1)
74
75
76 # Enable Sphinx extensions
77 # Note that these are active for all files to be build (see DOCS list)
78 extensions = ['sphinx_rtd_theme']
79
80 # todo interprets ".. todo::" commands in .rst files
81 # mathjax enables math equations to render correctly
82 extensions += ['sphinx.ext.todo', 'sphinx.ext.mathjax']
83 todo_include_todos = True
84
85 # define templates source folder
86 templates_path = ['_templates']
87 # define the types of files to read as source for documents
88 source_suffix = '.rst'
89
90 # enable figure, object, table numeration on documents
91 print('enabling table, code-block and figure numeration')
92 numfig = True
93 numfig_format = {
94 'figure': 'figure %s',
95 'table': 'table %s',
96 'code-block': 'listing %s',
97 'section': 'section %s',
98 }
99 print('done')
100
101
102 # Start building the documents
103 # First retrieve the name of the documentation we are building
104 print('checking doc name... ')
105 doc_name = os.environ.get('DOC_NAME', None)
106 if doc_name is None:
107 print('DOC_NAME environment variable should be set')
108 sys.exit(1)
109
110 if doc_name not in DOCS:
111 print('%s is not a valid documentation name' % doc_name)
112 sys.exit(1)
113 print('found... ' , doc_name)
114
115 # Exclude sources that are not part of the current documentation
116 exclude_patterns = []
117 for d in os.listdir(root_source_dir):
118 if d not in ('share', doc_name, doc_name + '.rst'):
119 exclude_patterns.append(d)
120 print('ignoring %s' % d)
121
122 # Special condition for gnat_rm
123 if doc_name == 'gnat_rm':
124 exclude_patterns.append('share/gnat_project_manager.rst')
125 print('ignoring share/gnat_project_manager.rst')
126
127 # General information about the project.
128 master_doc = doc_name
129 project = DOCS[doc_name]['title']
130
131 copyright = get_copyright()
132
133 version = get_gnat_version()
134 release = get_gnat_version()
135
136 pygments_style = None
137 tags.add(get_gnat_build_type())
138
139 # Define figures to be included
140 html_theme = 'sphinx_rtd_theme'
141 html_theme_options = {
142 "style_nav_header_background": "#12284c",
143 }
144 if os.path.isfile('adacore-logo-white.png'):
145 # split html and pdf logos to avoid 'same name' error in sphinx <5.2+
146 html_logo = 'adacore-logo-white.png'
147 latex_logo = 'adacore-logo-white.png'
148 if os.path.isfile('favicon.ico'):
149 html_favicon = 'favicon.ico'
150
151 html_static_path = ['_static']
152
153 # Use gnat.sty for bulding documents
154 latex_additional_files = ['gnat.sty']
155
156 # Add copyright info to file
157 copyright_macros = {
158 'date': time.strftime("%b %d, %Y"),
159 'edition': 'GNAT %s Edition' % 'Pro' if get_gnat_build_type() == 'PRO'
160 else 'GPL',
161 'name': 'GNU Ada',
162 'tool': 'GNAT',
163 'version': version
164 }
165
166 # Send info to latex for building document
167 latex_elements = {
168 'preamble': '\\usepackage{gnat}\n' # use gnat.sty format
169 + latex_elements.TOC_DEPTH # define table of contents max depth to display
170 + latex_elements.PAGE_BLANK # define blank pages and when to be used
171 + latex_elements.TOC_CMD # write table of contents
172 + latex_elements.LATEX_HYPHEN # define latex hyphen '-'
173 + '\\sloppy\n\n' # sloppy/fussy define how words are spread in a paragraph
174 # the following is used to send title and gnat version to latex
175 + latex_elements.doc_settings(DOCS[doc_name]['title'], get_gnat_version()),
176 'tableofcontents': latex_elements.TOC % copyright_macros, # build TOC
177 'papersize': 'a4paper,table', # papersize as a4, else default letter
178 'figure_align': 'H', # align figure as square and to paragraph text
179 'maketitle': '\\maketitle', # execute custom maketitle
180 }
181
182 # Show page references for cross-reference in docs
183 latex_show_pagerefs = True
184 # Define latex metadata
185 latex_documents = [
186 (master_doc, '%s.tex' % doc_name, project, 'AdaCore', 'manual')]
187 # Define .txt files metadata
188 texinfo_documents = [
189 (master_doc, doc_name, project, 'AdaCore', doc_name, doc_name, '')]
190
191
192 # setup AdaCore custom pygments
193 def setup(app):
194 app.add_lexer('ada', ada_pygments.AdaLexer)
195 app.add_lexer('gpr', ada_pygments.GNATProjectLexer)