]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix the Sphinx configuration and port it to Python3
authorArnaud Charlet <charlet@adacore.com>
Wed, 7 Apr 2021 09:11:57 +0000 (05:11 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 28 Apr 2021 09:37:53 +0000 (05:37 -0400)
gcc/ada/

* .gitignore: New.
* doc/share/conf.py: Add Python 3 compatibility.
* doc/share/gnat.sty: Add missing file.

gcc/ada/.gitignore [new file with mode: 0644]
gcc/ada/doc/share/conf.py
gcc/ada/doc/share/gnat.sty [new file with mode: 0644]

diff --git a/gcc/ada/.gitignore b/gcc/ada/.gitignore
new file mode 100644 (file)
index 0000000..36a0db0
--- /dev/null
@@ -0,0 +1,2 @@
+# Sphinx build artifacts
+doc/build
index e6fafcfaec071dd08647db660019c18b3404e270..debd71688b895c9380e4a72fba6ec0f4117bbc0a 100644 (file)
@@ -37,45 +37,45 @@ def get_copyright():
 
 
 def get_gnat_version():
-    m = re.search(r'Gnat_Static_Version_String : ' +
-                  r'constant String := "([^\(\)]+)\(.*\)?";',
+    m = re.search(br'Gnat_Static_Version_String : ' +
+                  br'constant String := "([^\(\)]+)\(.*\)?";',
                   gnatvsn_content)
     if m:
-        return m.group(1).strip()
+        return m.group(1).strip().decode()
     else:
         if texi_fsf and os.path.exists(basever):
             return ''
 
         try:
-            with open(basever, 'rb') as fd:
+            with open(basever) as fd:
                 return fd.read()
-        except:
+        except Exception:
             pass
 
-    print 'cannot find GNAT version in gnatvsn.ads or in ' + basever
+    print('cannot find GNAT version in gnatvsn.ads or in ' + basever)
     sys.exit(1)
 
 
 def get_gnat_build_type():
-    m = re.search(r'Build_Type : constant Gnat_Build_Type := (.+);',
+    m = re.search(br'Build_Type : constant Gnat_Build_Type := (.+);',
                   gnatvsn_content)
     if m:
-        return {'Gnatpro': 'PRO',
-                'FSF': 'FSF',
-                'GPL': 'GPL'}[m.group(1).strip()]
+        return {b'Gnatpro': 'PRO',
+                b'FSF': 'FSF',
+                b'GPL': 'GPL'}[m.group(1).strip()]
     else:
-        print 'cannot compute GNAT build type'
+        print('cannot compute GNAT build type')
         sys.exit(1)
 
 
 # First retrieve the name of the documentation we are building
 doc_name = os.environ.get('DOC_NAME', None)
 if doc_name is None:
-    print 'DOC_NAME environment variable should be set'
+    print('DOC_NAME environment variable should be set')
     sys.exit(1)
 
 if doc_name not in DOCS:
-    print '%s is not a valid documentation name' % doc_name
+    print('%s is not a valid documentation name' % doc_name)
     sys.exit(1)
 
 
@@ -84,11 +84,11 @@ exclude_patterns = []
 for d in os.listdir(root_source_dir):
     if d not in ('share', doc_name, doc_name + '.rst'):
         exclude_patterns.append(d)
-        print 'ignoring %s' % d
+        print('ignoring %s' % d)
 
 if doc_name == 'gnat_rm':
     exclude_patterns.append('share/gnat_project_manager.rst')
-    print 'ignoring share/gnat_project_manager.rst'
+    print('ignoring share/gnat_project_manager.rst')
 
 extensions = []
 templates_path = ['_templates']
@@ -103,7 +103,7 @@ copyright = get_copyright()
 version = get_gnat_version()
 release = get_gnat_version()
 
-pygments_style = 'sphinx'
+pygments_style = None
 tags.add(get_gnat_build_type())
 html_theme = 'sphinxdoc'
 if os.path.isfile('adacore_transparent.png'):
diff --git a/gcc/ada/doc/share/gnat.sty b/gcc/ada/doc/share/gnat.sty
new file mode 100644 (file)
index 0000000..1a152fb
--- /dev/null
@@ -0,0 +1,72 @@
+% Needed to generate footers with total number of pages
+\RequirePackage{lastpage}
+
+% AdaCore specific maketitle
+\renewcommand{\maketitle}{%
+  \begin{titlepage}%
+    \let\footnotesize\small
+    \let\footnoterule\relax
+    \rule{\textwidth}{1pt}%
+    \ifsphinxpdfoutput
+      \begingroup
+      % These \defs are required to deal with multi-line authors; it
+      % changes \\ to ', ' (comma-space), making it pass muster for
+      % generating document info in the PDF file.
+      \def\\{, }
+      \def\and{and }
+      \pdfinfo{
+        /Author (\@author)
+        /Title (\@title)
+      }
+      \endgroup
+    \fi
+    \begin{flushright}%
+      \sphinxlogo%
+      {\rm\Huge \@title \par}%
+      {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par}
+      \vfill
+      {\LARGE\py@HeaderFamily
+        \par}
+      \vfill\vfill
+      {\large
+       \@date \par
+       \vfill
+       \py@authoraddress \par
+      }%
+    \end{flushright}%\par
+    \@thanks
+  \end{titlepage}%
+  \cleardoublepage%
+  \setcounter{footnote}{0}%
+  \let\thanks\relax\let\maketitle\relax
+}
+
+% AdaCore specific headers/footers
+% Redefine the 'normal' header/footer style when using "fancyhdr" package:
+\@ifundefined{fancyhf}{}{
+  % Use \pagestyle{normal} as the primary pagestyle for text.
+  \fancypagestyle{normal}{
+    \fancyhf{}
+    \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage\ of \pageref*{LastPage}}}
+    \fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
+    \fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
+    \fancyhead[LE,RO]{{\py@HeaderFamily \@title, \py@release}}
+    \renewcommand{\headrulewidth}{0.4pt}
+    \renewcommand{\footrulewidth}{0.4pt}
+    % define chaptermark with \@chappos when \@chappos is available for Japanese
+    \ifx\@chappos\undefined\else
+      \def\chaptermark##1{\markboth{\@chapapp\space\thechapter\space\@chappos\space ##1}{}}
+    \fi
+  }
+  % Update the plain style so we get the page number & footer line,
+  % but not a chapter or section title.  This is to keep the first
+  % page of a chapter and the blank page between chapters `clean.'
+  \fancypagestyle{plain}{
+    \fancyhf{}
+    \fancyfoot[LE,RO]{{\py@HeaderFamily\thepage\ of \pageref*{LastPage}}}
+    \fancyfoot[LO,RE]{{\py@HeaderFamily \GNATFullDocumentName}}
+    \fancyhead[LE,RO]{{\py@HeaderFamily \@title\ \GNATVersion}}
+    \renewcommand{\headrulewidth}{0.0pt}
+    \renewcommand{\footrulewidth}{0.4pt}
+  }
+}