| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import tempfile | |
| 11 | 10 |
| 12 REPOSITORY_ROOT = os.path.abspath(os.path.join( | 11 REPOSITORY_ROOT = os.path.abspath(os.path.join( |
| 13 os.path.dirname(__file__), '..', '..', '..')) | 12 os.path.dirname(__file__), '..', '..', '..')) |
| 14 | 13 |
| 15 sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util')) | 14 sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util')) |
| 16 sys.path.append(os.path.join(REPOSITORY_ROOT, 'net/tools/net_docs')) | 15 sys.path.append(os.path.join(REPOSITORY_ROOT, 'net/tools/net_docs')) |
| 17 import build_utils | 16 import build_utils |
| 18 import net_docs | 17 import net_docs |
| 19 from markdown.postprocessors import Postprocessor | 18 from markdown.postprocessors import Postprocessor |
| 20 from markdown.extensions import Extension | 19 from markdown.extensions import Extension |
| 21 | 20 |
| 22 | 21 |
| 23 class CronetPostprocessor(Postprocessor): | 22 class CronetPostprocessor(Postprocessor): |
| 24 def run(self, text): | 23 def run(self, text): |
| 25 return text.replace('@Override', '@Override') | 24 return text.replace('@Override', '@Override') |
| 26 | 25 |
| 27 | 26 |
| 28 class CronetExtension(Extension): | 27 class CronetExtension(Extension): |
| 29 def extendMarkdown(self, md, md_globals): | 28 def extendMarkdown(self, md, md_globals): |
| 30 md.postprocessors.add('CronetPostprocessor', | 29 md.postprocessors.add('CronetPostprocessor', |
| 31 CronetPostprocessor(md), '_end') | 30 CronetPostprocessor(md), '_end') |
| 32 | 31 |
| 33 | 32 |
| 34 def GenerateJavadoc(options, src_dir): | 33 def GenerateJavadoc(options): |
| 35 output_dir = os.path.abspath(os.path.join(options.output_dir, 'javadoc')) | 34 output_dir = os.path.abspath(os.path.join(options.output_dir, 'javadoc')) |
| 36 working_dir = os.path.join(options.input_dir, 'android/api') | 35 working_dir = os.path.join(options.input_dir, 'android/api') |
| 37 overview_file = os.path.abspath(options.overview_file) | 36 overview_file = os.path.abspath(options.overview_file) |
| 38 lib_java_dir = os.path.abspath(options.lib_java_dir) | 37 lib_java_dir = os.path.abspath(options.lib_java_dir) |
| 39 | 38 |
| 40 build_utils.DeleteDirectory(output_dir) | 39 build_utils.DeleteDirectory(output_dir) |
| 41 build_utils.MakeDirectory(output_dir) | 40 build_utils.MakeDirectory(output_dir) |
| 42 javadoc_cmd = ['ant', '-Dsource.dir=' + src_dir , '-Ddoc.dir=' + output_dir, | 41 javadoc_cmd = ['ant', '-Dsource.dir=src', '-Ddoc.dir=' + output_dir, |
| 43 '-Dlib.java.dir=' + lib_java_dir, '-Doverview=' + overview_file, | 42 '-Dlib.java.dir=' + lib_java_dir, '-Doverview=' + overview_file, |
| 44 'doc'] | 43 'doc'] |
| 45 stdout = build_utils.CheckOutput(javadoc_cmd, cwd=working_dir) | 44 stdout = build_utils.CheckOutput(javadoc_cmd, cwd=working_dir) |
| 46 if " error: " in stdout or "warning" in stdout or "javadoc: error " in stdout: | 45 if " error: " in stdout or "warning" in stdout or "javadoc: error " in stdout: |
| 47 build_utils.DeleteDirectory(output_dir) | 46 build_utils.DeleteDirectory(output_dir) |
| 48 raise build_utils.CalledProcessError(working_dir, javadoc_cmd, stdout) | 47 raise build_utils.CalledProcessError(working_dir, javadoc_cmd, stdout) |
| 49 | 48 |
| 50 | 49 |
| 51 def main(): | 50 def main(): |
| 52 parser = optparse.OptionParser() | 51 parser = optparse.OptionParser() |
| 53 build_utils.AddDepfileOption(parser) | 52 build_utils.AddDepfileOption(parser) |
| 54 parser.add_option('--output-dir', help='Directory to put javadoc') | 53 parser.add_option('--output-dir', help='Directory to put javadoc') |
| 55 parser.add_option('--input-dir', help='Root of cronet source') | 54 parser.add_option('--input-dir', help='Root of cronet source') |
| 56 parser.add_option('--input-src-jar', help='Cronet api source jar') | |
| 57 parser.add_option('--overview-file', help='Path of the overview page') | 55 parser.add_option('--overview-file', help='Path of the overview page') |
| 58 parser.add_option('--readme-file', help='Path of the README.md') | 56 parser.add_option('--readme-file', help='Path of the README.md') |
| 59 parser.add_option('--lib-java-dir', help='Directory containing java libs') | 57 parser.add_option('--lib-java-dir', help='Directory containing java libs') |
| 60 | 58 |
| 61 options, _ = parser.parse_args() | 59 options, _ = parser.parse_args() |
| 62 # A temporary directory to put the output of cronet api source jar files. | |
| 63 unzipped_jar_path = tempfile.mkdtemp(dir=options.output_dir) | |
| 64 if os.path.exists(options.input_src_jar): | |
| 65 jar_cmd = ['jar', 'xf', os.path.abspath(options.input_src_jar)] | |
| 66 build_utils.CheckOutput(jar_cmd, cwd=unzipped_jar_path) | |
| 67 else: | |
| 68 raise Exception('Jar file does not exist: %s' % options.input_src_jar) | |
| 69 | 60 |
| 70 net_docs.ProcessDocs([options.readme_file], options.input_dir, | 61 net_docs.ProcessDocs([options.readme_file], options.input_dir, |
| 71 options.output_dir, extensions=[CronetExtension()]) | 62 options.output_dir, extensions=[CronetExtension()]) |
| 72 | 63 |
| 73 GenerateJavadoc(options, os.path.abspath(unzipped_jar_path)) | 64 GenerateJavadoc(options) |
| 74 | 65 |
| 75 if options.depfile: | 66 if options.depfile: |
| 76 input_paths = [] | 67 input_paths = [] |
| 77 for root, _, filenames in os.walk(options.input_dir): | 68 for root, _, filenames in os.walk(options.input_dir): |
| 78 input_paths.extend(os.path.join(root, f) for f in filenames) | 69 input_paths.extend(os.path.join(root, f) for f in filenames) |
| 79 build_utils.WriteDepfile(options.depfile, | 70 build_utils.WriteDepfile(options.depfile, |
| 80 input_paths + build_utils.GetPythonDependencies()) | 71 input_paths + build_utils.GetPythonDependencies()) |
| 81 # Clean up temporary output directory. | |
| 82 build_utils.DeleteDirectory(unzipped_jar_path) | |
| 83 | 72 |
| 84 if __name__ == '__main__': | 73 if __name__ == '__main__': |
| 85 sys.exit(main()) | 74 sys.exit(main()) |
| OLD | NEW |