| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 """Generate Doxygen documentation.""" | 7 """Generate Doxygen documentation.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import datetime | 10 import datetime |
| 11 import os | 11 import os |
| 12 import shutil | 12 import shutil |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 | 15 |
| 16 | 16 |
| 17 DOXYFILE_BASENAME = 'Doxyfile' # must match name of Doxyfile in skia root | 17 DOXYFILE_BASENAME = 'Doxyfile' # must match name of Doxyfile in skia root |
| 18 DOXYGEN_BINARY = 'doxygen' | 18 DOXYGEN_BINARY = 'doxygen' |
| 19 WORKDIR = os.path.join(os.pardir, 'doxygen_workdir') | 19 WORKDIR = os.path.join(os.pardir, 'doxygen_workdir') |
| 20 DOXYGEN_CONFIG_DIR = os.path.join(WORKDIR, 'doxygen-config') | 20 DOXYGEN_CONFIG_DIR = os.path.join(WORKDIR, 'doxygen-config') |
| 21 DOXYGEN_WORKING_DIR = os.path.join(WORKDIR, 'doxygen') | 21 DOXYGEN_WORKING_DIR = os.path.join(WORKDIR, 'doxygen') |
| 22 DOXYGEN_GS_PATH = '/'.join(['gs://chromium-skia-gm', 'doxygen']) | 22 DOXYGEN_GS_PATH = '/'.join(['gs://skia-doc', 'doxygen']) |
| 23 | 23 |
| 24 IFRAME_FOOTER_TEMPLATE = """ | 24 IFRAME_FOOTER_TEMPLATE = """ |
| 25 <html><body><address style="text-align: right;"><small> | 25 <html><body><address style="text-align: right;"><small> |
| 26 Generated at %s for skia | 26 Generated at %s for skia |
| 27 by <a href="http://www.doxygen.org/index.html">doxygen</a> | 27 by <a href="http://www.doxygen.org/index.html">doxygen</a> |
| 28 %s </small></address></body></html> | 28 %s </small></address></body></html> |
| 29 """ | 29 """ |
| 30 | 30 |
| 31 | 31 |
| 32 def recreate_dir(path): | 32 def recreate_dir(path): |
| 33 """Delete and recreate the directory.""" | 33 """Delete and recreate the directory.""" |
| 34 try: | 34 try: |
| 35 shutil.rmtree(path) | 35 shutil.rmtree(path) |
| 36 except OSError: | 36 except OSError: |
| 37 if os.path.exists(path): | 37 if os.path.exists(path): |
| 38 raise Exception('Could not remove %s' % path) | 38 raise Exception('Could not remove %s' % path) |
| 39 os.makedirs(path) | 39 os.makedirs(path) |
| 40 | 40 |
| 41 | 41 |
| 42 def generate_and_upload_doxygen(gsutil_path): | 42 def generate_and_upload_doxygen(): |
| 43 """Generate Doxygen.""" | 43 """Generate Doxygen.""" |
| 44 # Create empty dir and add static_footer.txt | 44 # Create empty dir and add static_footer.txt |
| 45 recreate_dir(DOXYGEN_WORKING_DIR) | 45 recreate_dir(DOXYGEN_WORKING_DIR) |
| 46 static_footer_path = os.path.join(DOXYGEN_WORKING_DIR, 'static_footer.txt') | 46 static_footer_path = os.path.join(DOXYGEN_WORKING_DIR, 'static_footer.txt') |
| 47 shutil.copyfile(os.path.join('tools', 'doxygen_footer.txt'), | 47 shutil.copyfile(os.path.join('tools', 'doxygen_footer.txt'), |
| 48 static_footer_path) | 48 static_footer_path) |
| 49 | 49 |
| 50 # Make copy of doxygen config file, overriding any necessary configs, | 50 # Make copy of doxygen config file, overriding any necessary configs, |
| 51 # and run doxygen. | 51 # and run doxygen. |
| 52 recreate_dir(DOXYGEN_CONFIG_DIR) | 52 recreate_dir(DOXYGEN_CONFIG_DIR) |
| 53 modified_doxyfile = os.path.join(DOXYGEN_CONFIG_DIR, DOXYFILE_BASENAME) | 53 modified_doxyfile = os.path.join(DOXYGEN_CONFIG_DIR, DOXYFILE_BASENAME) |
| 54 with open(DOXYFILE_BASENAME, 'r') as reader: | 54 with open(DOXYFILE_BASENAME, 'r') as reader: |
| 55 with open(modified_doxyfile, 'w') as writer: | 55 with open(modified_doxyfile, 'w') as writer: |
| 56 shutil.copyfileobj(reader, writer) | 56 shutil.copyfileobj(reader, writer) |
| 57 writer.write('OUTPUT_DIRECTORY = %s\n' % DOXYGEN_WORKING_DIR) | 57 writer.write('OUTPUT_DIRECTORY = %s\n' % DOXYGEN_WORKING_DIR) |
| 58 writer.write('HTML_FOOTER = %s\n' % static_footer_path) | 58 writer.write('HTML_FOOTER = %s\n' % static_footer_path) |
| 59 subprocess.check_call([DOXYGEN_BINARY, modified_doxyfile]) | 59 subprocess.check_call([DOXYGEN_BINARY, modified_doxyfile]) |
| 60 | 60 |
| 61 # Create iframe_footer.html | 61 # Create iframe_footer.html |
| 62 with open(os.path.join(DOXYGEN_WORKING_DIR, 'iframe_footer.html'), 'w') as f: | 62 with open(os.path.join(DOXYGEN_WORKING_DIR, 'iframe_footer.html'), 'w') as f: |
| 63 f.write(IFRAME_FOOTER_TEMPLATE % ( | 63 f.write(IFRAME_FOOTER_TEMPLATE % ( |
| 64 datetime.datetime.now().isoformat(' '), | 64 datetime.datetime.now().isoformat(' '), |
| 65 subprocess.check_output([DOXYGEN_BINARY, '--version']).rstrip())) | 65 subprocess.check_output([DOXYGEN_BINARY, '--version']).rstrip())) |
| 66 | 66 |
| 67 # Upload. | 67 # Upload. |
| 68 cmd = [gsutil_path, 'cp', '-a', 'public-read', '-R', | 68 cmd = ['gsutil', 'cp', '-a', 'public-read', '-R', |
| 69 DOXYGEN_WORKING_DIR, DOXYGEN_GS_PATH] | 69 DOXYGEN_WORKING_DIR, DOXYGEN_GS_PATH] |
| 70 subprocess.check_call(cmd) | 70 subprocess.check_call(cmd) |
| 71 | 71 |
| 72 | 72 |
| 73 if '__main__' == __name__: | 73 if '__main__' == __name__: |
| 74 generate_and_upload_doxygen(*sys.argv[1:]) | 74 generate_and_upload_doxygen() |
| 75 | 75 |
| OLD | NEW |