Chromium Code Reviews| 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 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 def run(self, text): | 23 def run(self, text): |
| 24 return text.replace('@Override', '@Override') | 24 return text.replace('@Override', '@Override') |
| 25 | 25 |
| 26 | 26 |
| 27 class CronetExtension(Extension): | 27 class CronetExtension(Extension): |
| 28 def extendMarkdown(self, md, md_globals): | 28 def extendMarkdown(self, md, md_globals): |
| 29 md.postprocessors.add('CronetPostprocessor', | 29 md.postprocessors.add('CronetPostprocessor', |
| 30 CronetPostprocessor(md), '_end') | 30 CronetPostprocessor(md), '_end') |
| 31 | 31 |
| 32 | 32 |
| 33 def GenerateJavadoc(options): | 33 def GenerateJavadoc(options, src_dir): |
| 34 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')) |
| 35 working_dir = os.path.join(options.input_dir, 'android/api') | 35 working_dir = os.path.join(options.input_dir, 'android/api') |
| 36 overview_file = os.path.abspath(options.overview_file) | 36 overview_file = os.path.abspath(options.overview_file) |
| 37 lib_java_dir = os.path.abspath(options.lib_java_dir) | 37 lib_java_dir = os.path.abspath(options.lib_java_dir) |
| 38 | 38 |
| 39 build_utils.DeleteDirectory(output_dir) | 39 build_utils.DeleteDirectory(output_dir) |
| 40 build_utils.MakeDirectory(output_dir) | 40 build_utils.MakeDirectory(output_dir) |
| 41 javadoc_cmd = ['ant', '-Dsource.dir=src', '-Ddoc.dir=' + output_dir, | 41 javadoc_cmd = ['ant', '-Dsource.dir=' + src_dir , '-Ddoc.dir=' + output_dir, |
| 42 '-Dlib.java.dir=' + lib_java_dir, '-Doverview=' + overview_file, | 42 '-Dlib.java.dir=' + lib_java_dir, '-Doverview=' + overview_file, |
| 43 'doc'] | 43 'doc'] |
| 44 stdout = build_utils.CheckOutput(javadoc_cmd, cwd=working_dir) | 44 stdout = build_utils.CheckOutput(javadoc_cmd, cwd=working_dir) |
| 45 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: |
| 46 build_utils.DeleteDirectory(output_dir) | 46 build_utils.DeleteDirectory(output_dir) |
| 47 raise build_utils.CalledProcessError(working_dir, javadoc_cmd, stdout) | 47 raise build_utils.CalledProcessError(working_dir, javadoc_cmd, stdout) |
| 48 | 48 |
| 49 | 49 |
| 50 def main(): | 50 def main(): |
| 51 parser = optparse.OptionParser() | 51 parser = optparse.OptionParser() |
| 52 build_utils.AddDepfileOption(parser) | 52 build_utils.AddDepfileOption(parser) |
| 53 parser.add_option('--output-dir', help='Directory to put javadoc') | 53 parser.add_option('--output-dir', help='Directory to put javadoc') |
| 54 parser.add_option('--input-dir', help='Root of cronet source') | 54 parser.add_option('--input-dir', help='Root of cronet source') |
| 55 parser.add_option('--input-jar', help='Cronet api source jar') | |
|
kapishnikov
2016/08/12 15:33:39
Should we rename the option to "--input-src-jar"?
mef
2016/08/12 16:00:05
Are input-dir and input-jar mutuall exclusive?
xunjieli
2016/08/12 17:52:58
Done.
xunjieli
2016/08/12 17:52:58
Yes, they currently not the same. The input-dir is
| |
| 55 parser.add_option('--overview-file', help='Path of the overview page') | 56 parser.add_option('--overview-file', help='Path of the overview page') |
| 56 parser.add_option('--readme-file', help='Path of the README.md') | 57 parser.add_option('--readme-file', help='Path of the README.md') |
| 57 parser.add_option('--lib-java-dir', help='Directory containing java libs') | 58 parser.add_option('--lib-java-dir', help='Directory containing java libs') |
| 58 | 59 |
| 59 options, _ = parser.parse_args() | 60 options, _ = parser.parse_args() |
| 61 # A temporary directory to put the output of cronet api source jar files. | |
| 62 unzipped_jar_path = os.path.abspath(os.path.join(options.output_dir, 'tmp')) | |
|
mef
2016/08/12 16:00:05
maybe use tempfile.mkdtemp for temp directory?
xunjieli
2016/08/12 17:52:58
Done. Great idea!
| |
| 63 build_utils.MakeDirectory(unzipped_jar_path) | |
|
kapishnikov
2016/08/12 15:33:39
Should we make sure that 'unzipped_jar_path' direc
xunjieli
2016/08/12 17:52:58
Acknowledged. I adopted Misha's suggestion to use
| |
| 64 if os.path.exists(options.input_jar): | |
| 65 # Need to execute the jar command inside the temporary directory, and that | |
| 66 # is why the ../../ is needed. | |
| 67 jar_cmd = ['jar', 'xf', '../../' + options.input_jar] | |
| 68 build_utils.CheckOutput(jar_cmd, cwd=unzipped_jar_path) | |
| 69 else: | |
| 70 raise Exception('Jar file does not exist: %s' % options.input_jar) | |
| 60 | 71 |
| 61 net_docs.ProcessDocs([options.readme_file], options.input_dir, | 72 net_docs.ProcessDocs([options.readme_file], options.input_dir, |
| 62 options.output_dir, extensions=[CronetExtension()]) | 73 options.output_dir, extensions=[CronetExtension()]) |
| 63 | 74 |
| 64 GenerateJavadoc(options) | 75 GenerateJavadoc(options, unzipped_jar_path) |
| 65 | 76 |
| 66 if options.depfile: | 77 if options.depfile: |
| 67 input_paths = [] | 78 input_paths = [] |
| 68 for root, _, filenames in os.walk(options.input_dir): | 79 for root, _, filenames in os.walk(options.input_dir): |
| 69 input_paths.extend(os.path.join(root, f) for f in filenames) | 80 input_paths.extend(os.path.join(root, f) for f in filenames) |
| 70 build_utils.WriteDepfile(options.depfile, | 81 build_utils.WriteDepfile(options.depfile, |
| 71 input_paths + build_utils.GetPythonDependencies()) | 82 input_paths + build_utils.GetPythonDependencies()) |
| 83 # Clean up temporary output directory. | |
| 84 build_utils.DeleteDirectory(unzipped_jar_path) | |
| 72 | 85 |
| 73 if __name__ == '__main__': | 86 if __name__ == '__main__': |
| 74 sys.exit(main()) | 87 sys.exit(main()) |
| OLD | NEW |