|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 # file, # You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 |
|
5 from __future__ import unicode_literals |
|
6 |
|
7 import os |
|
8 |
|
9 from mach.decorators import ( |
|
10 CommandArgument, |
|
11 CommandProvider, |
|
12 Command, |
|
13 ) |
|
14 |
|
15 from mozbuild.base import MachCommandBase |
|
16 from mozbuild.frontend.reader import BuildReader |
|
17 |
|
18 |
|
19 @CommandProvider |
|
20 class Documentation(MachCommandBase): |
|
21 """Helps manage in-tree documentation.""" |
|
22 |
|
23 @Command('build-docs', category='build-dev', |
|
24 description='Generate documentation for the tree.') |
|
25 @CommandArgument('--format', default='html', |
|
26 help='Documentation format to write.') |
|
27 @CommandArgument('outdir', default='<DEFAULT>', nargs='?', |
|
28 help='Where to write output.') |
|
29 def build_docs(self, format=None, outdir=None): |
|
30 self._activate_virtualenv() |
|
31 self.virtualenv_manager.install_pip_package('mdn-sphinx-theme==0.4') |
|
32 |
|
33 from moztreedocs import SphinxManager |
|
34 |
|
35 if outdir == '<DEFAULT>': |
|
36 outdir = os.path.join(self.topobjdir, 'docs') |
|
37 |
|
38 manager = SphinxManager(self.topsrcdir, os.path.join(self.topsrcdir, |
|
39 'tools', 'docs'), outdir) |
|
40 |
|
41 # We don't care about GYP projects, so don't process them. This makes |
|
42 # scanning faster and may even prevent an exception. |
|
43 def remove_gyp_dirs(sandbox): |
|
44 sandbox['GYP_DIRS'][:] = [] |
|
45 |
|
46 reader = BuildReader(self.config_environment, |
|
47 sandbox_post_eval_cb=remove_gyp_dirs) |
|
48 |
|
49 for sandbox in reader.walk_topsrcdir(): |
|
50 for dest_dir, source_dir in sandbox['SPHINX_TREES'].items(): |
|
51 manager.add_tree(os.path.join(sandbox['RELATIVEDIR'], |
|
52 source_dir), dest_dir) |
|
53 |
|
54 for entry in sandbox['SPHINX_PYTHON_PACKAGE_DIRS']: |
|
55 manager.add_python_package_dir(os.path.join(sandbox['RELATIVEDIR'], |
|
56 entry)) |
|
57 |
|
58 return manager.generate_docs(format) |