Flutter Engine
The Flutter Engine
gen_docs.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright 2013 The Flutter Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Generates API docs for Flutter embedders and libraries.
7import os
8import shutil
9import tempfile
10import zipfile
11import sys
12import subprocess
13from collections import namedtuple
14
15Section = namedtuple('Section', ['title', 'inputs'])
16
17SECTIONS = {
18 'ios':
19 Section(
20 'iOS Embedder', [
21 'shell/platform/darwin/ios',
22 'shell/platform/darwin/common',
23 'shell/platform/common',
24 ]
25 ),
26 'macos':
27 Section(
28 'macOS Embedder', [
29 'shell/platform/darwin/macos',
30 'shell/platform/darwin/common',
31 'shell/platform/common',
32 ]
33 ),
34 'linux':
35 Section('Linux Embedder', [
36 'shell/platform/linux',
37 'shell/platform/common',
38 ]),
39 'windows':
40 Section('Windows Embedder', [
41 'shell/platform/windows',
42 'shell/platform/common',
43 ]),
44 'impeller':
45 Section('Impeller', [
46 'impeller',
47 ]),
48}
49
50
51def generate_doxyfile(section, output_dir, log_file, doxy_file):
52 doxyfile = open('docs/Doxyfile.template', 'r').read()
53 doxyfile = doxyfile.replace('@@OUTPUT_DIRECTORY@@', output_dir)
54 doxyfile = doxyfile.replace('@@LOG_FILE@@', log_file)
55 doxyfile = doxyfile.replace('@@INPUT_DIRECTORIES@@', '"{}"'.format('" "'.join(section.inputs)))
56 doxyfile = doxyfile.replace('@@PROJECT_NAME@@', 'Flutter {}'.format(section.title))
57 doxyfile = doxyfile.replace(
58 '@@DOCSET_FEEDNAME@@', 'Flutter {} Documentation'.format(section.title)
59 )
60 with open(doxy_file, 'w') as f:
61 f.write(doxyfile)
62
63
64def process_section(name, section, destination):
65 output_dir = tempfile.mkdtemp(prefix="doxygen")
66 log_file = os.path.join(destination, '{}-doxygen.log'.format(name))
67 zip_file = os.path.join(destination, '{}-docs.zip'.format(name))
68 doxy_file = os.path.join(output_dir, 'Doxyfile')
69 generate_doxyfile(section, output_dir, log_file, doxy_file)
70 # Update the Doxyfile format to the latest format.
71 subprocess.call(['doxygen', '-u'], cwd=output_dir)
72 subprocess.call(['doxygen', doxy_file])
73 html_dir = os.path.join(output_dir, 'html')
74 with zipfile.ZipFile(zip_file, 'w') as zip:
75 for root, _, files in os.walk(html_dir):
76 for file in files:
77 filename = os.path.join(root, file)
78 zip.write(filename, os.path.relpath(filename, html_dir))
79 print('Wrote ZIP file for {} to {}'.format(section, zip_file))
80 print('Preserving log file in {}'.format(log_file))
81 shutil.rmtree(output_dir, ignore_errors=True)
82
83
84def generate_docs(argv):
85 if len(argv) != 2:
86 print(
87 'Error: Argument specifying output directory required. '
88 'Directory may be an absolute path, or a relative path from the "src" directory.'
89 )
90 exit(1)
91
92 destination = argv[1]
93 script_path = os.path.realpath(__file__)
94 src_path = os.path.dirname(os.path.dirname(os.path.dirname(script_path)))
95 # Run commands from the Flutter root dir.
96 os.chdir(os.path.join(src_path, 'flutter'))
97 # If the argument isn't an absolute path, assume that it is relative to the src dir.
98 if not os.path.isabs(destination):
99 destination = os.path.join(src_path, destination)
100 os.makedirs(destination, exist_ok=True)
101 for name, section in SECTIONS.items():
102 process_section(name, section, destination)
103
104
105if __name__ == '__main__':
106 generate_docs(sys.argv)
static bool read(SkStream *stream, void *buffer, size_t amount)
uint32_t uint32_t * format
exit(kErrorExitCode)
def process_section(name, section, destination)
Definition: gen_docs.py:64
def generate_docs(argv)
Definition: gen_docs.py:84
def generate_doxyfile(section, output_dir, log_file, doxy_file)
Definition: gen_docs.py:51
def print(*args, **kwargs)
Definition: run_tests.py:49
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741