aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/recipe_modules/skia/resources/generate_and_upload_doxygen.py
blob: 019fbdc5b9c1b10108200e1b450fad5398da7bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


"""Generate Doxygen documentation."""


import datetime
import os
import shutil
import subprocess
import sys

from common.skia import global_constants


DOXYFILE_BASENAME = 'Doxyfile'  # must match name of Doxyfile in skia root
DOXYGEN_BINARY = 'doxygen'
WORKDIR = os.path.join(os.pardir, 'doxygen_workdir')
DOXYGEN_CONFIG_DIR = os.path.join(WORKDIR, 'doxygen-config')
DOXYGEN_WORKING_DIR = os.path.join(WORKDIR, 'doxygen')
DOXYGEN_GS_PATH = '/'.join(['gs:/', global_constants.GS_GM_BUCKET, 'doxygen'])

IFRAME_FOOTER_TEMPLATE = """
<html><body><address style="text-align: right;"><small>
Generated at %s for skia
by <a href="http://www.doxygen.org/index.html">doxygen</a>
%s </small></address></body></html>
"""


def recreate_dir(path):
  """Delete and recreate the directory."""
  try:
    shutil.rmtree(path)
  except OSError:
    if os.path.exists(path):
      raise Exception('Could not remove %s' % path)
  os.makedirs(path)


def generate_and_upload_doxygen(gsutil_path):
  """Generate Doxygen."""
  # Create empty dir and add static_footer.txt
  recreate_dir(DOXYGEN_WORKING_DIR)
  static_footer_path = os.path.join(DOXYGEN_WORKING_DIR, 'static_footer.txt')
  shutil.copyfile(os.path.join('tools', 'doxygen_footer.txt'),
                  static_footer_path)

  # Make copy of doxygen config file, overriding any necessary configs,
  # and run doxygen.
  recreate_dir(DOXYGEN_CONFIG_DIR)
  modified_doxyfile = os.path.join(DOXYGEN_CONFIG_DIR, DOXYFILE_BASENAME)
  with open(DOXYFILE_BASENAME, 'r') as reader:
    with open(modified_doxyfile, 'w') as writer:
      shutil.copyfileobj(reader, writer)
      writer.write('OUTPUT_DIRECTORY = %s\n' % DOXYGEN_WORKING_DIR)
      writer.write('HTML_FOOTER = %s\n' % static_footer_path)
  subprocess.check_call([DOXYGEN_BINARY, modified_doxyfile])

  # Create iframe_footer.html
  with open(os.path.join(DOXYGEN_WORKING_DIR, 'iframe_footer.html'), 'w') as f:
    f.write(IFRAME_FOOTER_TEMPLATE % (
        datetime.datetime.now().isoformat(' '),
        subprocess.check_output([DOXYGEN_BINARY, '--version']).rstrip()))

  # Upload.
  cmd = [gsutil_path, 'cp', '-a', 'public-read', '-R',
         DOXYGEN_WORKING_DIR, DOXYGEN_GS_PATH]
  subprocess.check_call(cmd)


if '__main__' == __name__:
  generate_and_upload_doxygen(*sys.argv[1:])