michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: from __future__ import unicode_literals michael@0: michael@0: import os michael@0: michael@0: from mach.decorators import ( michael@0: CommandArgument, michael@0: CommandProvider, michael@0: Command, michael@0: ) michael@0: michael@0: from mozbuild.base import MachCommandBase michael@0: from mozbuild.frontend.reader import BuildReader michael@0: michael@0: michael@0: @CommandProvider michael@0: class Documentation(MachCommandBase): michael@0: """Helps manage in-tree documentation.""" michael@0: michael@0: @Command('build-docs', category='build-dev', michael@0: description='Generate documentation for the tree.') michael@0: @CommandArgument('--format', default='html', michael@0: help='Documentation format to write.') michael@0: @CommandArgument('outdir', default='', nargs='?', michael@0: help='Where to write output.') michael@0: def build_docs(self, format=None, outdir=None): michael@0: self._activate_virtualenv() michael@0: self.virtualenv_manager.install_pip_package('mdn-sphinx-theme==0.4') michael@0: michael@0: from moztreedocs import SphinxManager michael@0: michael@0: if outdir == '': michael@0: outdir = os.path.join(self.topobjdir, 'docs') michael@0: michael@0: manager = SphinxManager(self.topsrcdir, os.path.join(self.topsrcdir, michael@0: 'tools', 'docs'), outdir) michael@0: michael@0: # We don't care about GYP projects, so don't process them. This makes michael@0: # scanning faster and may even prevent an exception. michael@0: def remove_gyp_dirs(sandbox): michael@0: sandbox['GYP_DIRS'][:] = [] michael@0: michael@0: reader = BuildReader(self.config_environment, michael@0: sandbox_post_eval_cb=remove_gyp_dirs) michael@0: michael@0: for sandbox in reader.walk_topsrcdir(): michael@0: for dest_dir, source_dir in sandbox['SPHINX_TREES'].items(): michael@0: manager.add_tree(os.path.join(sandbox['RELATIVEDIR'], michael@0: source_dir), dest_dir) michael@0: michael@0: for entry in sandbox['SPHINX_PYTHON_PACKAGE_DIRS']: michael@0: manager.add_python_package_dir(os.path.join(sandbox['RELATIVEDIR'], michael@0: entry)) michael@0: michael@0: return manager.generate_docs(format)