tools/docs/mach_commands.py
author Mike Hommey <mh+mozilla@glandium.org>
Fri, 15 Aug 2014 13:52:18 +0900
changeset 199700 62003f0a9b31a237e35fdfc39263ca2a6feebbbb
parent 160390 24b43ecb4cad77ed0d12f713a9d85ea669bc6ada
child 209389 e93c40d4344fcc7a2ce82bef47fc15da770d7786
permissions -rw-r--r--
Bug 1053140 part 3 - Separate out sandbox infrastructure from moz.build variables storage. r=gps

# 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('mdn-sphinx-theme==0.4')

        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'][:] = []

        reader = BuildReader(self.config_environment,
            sandbox_post_eval_cb=remove_gyp_dirs)

        for context in reader.walk_topsrcdir():
            for dest_dir, source_dir in context['SPHINX_TREES'].items():
                manager.add_tree(os.path.join(context.relsrcdir,
                    source_dir), dest_dir)

            for entry in context['SPHINX_PYTHON_PACKAGE_DIRS']:
                manager.add_python_package_dir(os.path.join(context.relsrcdir,
                    entry))

        return manager.generate_docs(format)