Bug 1115278 - Move Sphinx build scanning into moztreedocs; r=glandium
authorGregory Szorc <gps@mozilla.com>
Tue, 23 Dec 2014 22:53:50 -0800
changeset 221520 8656f5cdba468b33286bdc1201cf82dd7bd13774
parent 221519 4e513b69ee913adf0c737c6a5c477ce4ea22512b
child 221521 01ece2e26ef9af43271594094b2d8fc93933aaec
push id28032
push userkwierso@gmail.com
push dateTue, 30 Dec 2014 01:28:14 +0000
treeherdermozilla-central@67872ce17918 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1115278
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1115278 - Move Sphinx build scanning into moztreedocs; r=glandium In order for Sphinx documentation to work with Read The Docs, we need the code for scanning the build config for Sphinx documentation to live in an importable module. This patch moves some code from the |build-docs| mach command into an importable module.
tools/docs/mach_commands.py
tools/docs/moztreedocs/__init__.py
--- a/tools/docs/mach_commands.py
+++ b/tools/docs/mach_commands.py
@@ -33,34 +33,11 @@ class Documentation(MachCommandBase):
         from moztreedocs import SphinxManager
 
         if outdir == '<DEFAULT>':
             outdir = os.path.join(self.topobjdir, 'docs')
 
         manager = SphinxManager(self.topsrcdir, os.path.join(self.topsrcdir,
             'tools', 'docs'), outdir)
 
-        # We don't care about GYP projects, so don't process them. This makes
-        # scanning faster and may even prevent an exception.
-        def remove_gyp_dirs(context):
-            context['GYP_DIRS'][:] = []
-
-        # Reading the Sphinx variables doesn't require a full build context.
-        # Only define the parts we need.
-        class fakeconfig(object):
-            def __init__(self, topsrcdir):
-                self.topsrcdir = topsrcdir
-
-        config = fakeconfig(self.topsrcdir)
-        reader = BuildReader(config)
-
-        for path, name, key, value in reader.find_sphinx_variables():
-            reldir = os.path.dirname(path)
-
-            if name == 'SPHINX_TREES':
-                assert key
-                manager.add_tree(os.path.join(reldir, value),
-                        os.path.join(reldir, key))
-
-            if name == 'SPHINX_PYTHON_PACKAGE_DIRS':
-                manager.add_python_package_dir(os.path.join(reldir, value))
+        manager.read_build_config()
 
         return manager.generate_docs(format)
--- a/tools/docs/moztreedocs/__init__.py
+++ b/tools/docs/moztreedocs/__init__.py
@@ -1,16 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import unicode_literals
 
 import os
 
+from mozbuild.frontend.reader import BuildReader
 from mozpack.copier import FileCopier
 from mozpack.files import FileFinder
 from mozpack.manifests import InstallManifest
 
 import sphinx
 import sphinx.apidoc
 
 
@@ -20,16 +21,39 @@ class SphinxManager(object):
     def __init__(self, topsrcdir, main_path, output_dir):
         self._topsrcdir = topsrcdir
         self._output_dir = output_dir
         self._conf_py_path = os.path.join(main_path, 'conf.py')
         self._index_path = os.path.join(main_path, 'index.rst')
         self._trees = {}
         self._python_package_dirs = set()
 
+    def read_build_config(self):
+        """Read the active build config and add docs to this instance."""
+
+        # Reading the Sphinx variables doesn't require a full build context.
+        # Only define the parts we need.
+        class fakeconfig(object):
+            def __init__(self, topsrcdir):
+                self.topsrcdir = topsrcdir
+
+        config = fakeconfig(self._topsrcdir)
+        reader = BuildReader(config)
+
+        for path, name, key, value in reader.find_sphinx_variables():
+            reldir = os.path.dirname(path)
+
+            if name == 'SPHINX_TREES':
+                assert key
+                self.add_tree(os.path.join(reldir, value),
+                    os.path.join(reldir, key))
+
+            if name == 'SPHINX_PYTHON_PACKAGE_DIRS':
+                self.add_python_package_dir(os.path.join(reldir, value))
+
     def add_tree(self, source_dir, dest_dir):
         """Add a directory from where docs should be sourced."""
         if dest_dir in self._trees:
             raise Exception('%s has already been registered as a destination.'
                 % dest_dir)
 
         self._trees[dest_dir] = source_dir