gecko/tools/docs/mach_commands.py
Gregory Szorc 3dda1468a5 Bug 1091722 - Don't require configure before generating docs; r=glandium
Ever since Sphinx variable reading operates at the AST level (bug
1071012), we don't technically need a fully configured environment in
order to generate the documentation!

This patch stubs out the config environment object with a fake one that
provides the only needed context to generate the Sphinx docs. This
allows us to build the Sphinx docs on a fresh clone of the tree with no
configure and with no object directory.

--HG--
extra : rebase_source : f44513f01706391a5932a20c1437fcc8697611cd
2014-10-30 10:37:00 -07:00

67 lines
2.2 KiB
Python

# 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 mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
from mozbuild.base import MachCommandBase
from mozbuild.frontend.reader import BuildReader
@CommandProvider
class Documentation(MachCommandBase):
"""Helps manage in-tree documentation."""
@Command('build-docs', category='build-dev',
description='Generate documentation for the tree.')
@CommandArgument('--format', default='html',
help='Documentation format to write.')
@CommandArgument('outdir', default='<DEFAULT>', nargs='?',
help='Where to write output.')
def build_docs(self, format=None, outdir=None):
self._activate_virtualenv()
self.virtualenv_manager.install_pip_package('sphinx_rtd_theme==0.1.6')
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))
return manager.generate_docs(format)