1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/docs/mach_commands.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, # You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +from __future__ import unicode_literals 1.9 + 1.10 +import os 1.11 + 1.12 +from mach.decorators import ( 1.13 + CommandArgument, 1.14 + CommandProvider, 1.15 + Command, 1.16 +) 1.17 + 1.18 +from mozbuild.base import MachCommandBase 1.19 +from mozbuild.frontend.reader import BuildReader 1.20 + 1.21 + 1.22 +@CommandProvider 1.23 +class Documentation(MachCommandBase): 1.24 + """Helps manage in-tree documentation.""" 1.25 + 1.26 + @Command('build-docs', category='build-dev', 1.27 + description='Generate documentation for the tree.') 1.28 + @CommandArgument('--format', default='html', 1.29 + help='Documentation format to write.') 1.30 + @CommandArgument('outdir', default='<DEFAULT>', nargs='?', 1.31 + help='Where to write output.') 1.32 + def build_docs(self, format=None, outdir=None): 1.33 + self._activate_virtualenv() 1.34 + self.virtualenv_manager.install_pip_package('mdn-sphinx-theme==0.4') 1.35 + 1.36 + from moztreedocs import SphinxManager 1.37 + 1.38 + if outdir == '<DEFAULT>': 1.39 + outdir = os.path.join(self.topobjdir, 'docs') 1.40 + 1.41 + manager = SphinxManager(self.topsrcdir, os.path.join(self.topsrcdir, 1.42 + 'tools', 'docs'), outdir) 1.43 + 1.44 + # We don't care about GYP projects, so don't process them. This makes 1.45 + # scanning faster and may even prevent an exception. 1.46 + def remove_gyp_dirs(sandbox): 1.47 + sandbox['GYP_DIRS'][:] = [] 1.48 + 1.49 + reader = BuildReader(self.config_environment, 1.50 + sandbox_post_eval_cb=remove_gyp_dirs) 1.51 + 1.52 + for sandbox in reader.walk_topsrcdir(): 1.53 + for dest_dir, source_dir in sandbox['SPHINX_TREES'].items(): 1.54 + manager.add_tree(os.path.join(sandbox['RELATIVEDIR'], 1.55 + source_dir), dest_dir) 1.56 + 1.57 + for entry in sandbox['SPHINX_PYTHON_PACKAGE_DIRS']: 1.58 + manager.add_python_package_dir(os.path.join(sandbox['RELATIVEDIR'], 1.59 + entry)) 1.60 + 1.61 + return manager.generate_docs(format)