aboutsummaryrefslogtreecommitdiff
path: root/update.py
blob: 8a66066677401504fdc14c1c6a23b57c1d44183a (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
#!/usr/bin/env python

import codecs, httplib, json, optparse, os, urllib, shutil, subprocess, sys

output_html_file = 'systrace_trace_viewer.html'

upstream_git = 'https://github.com/google/trace-viewer.git'

script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
trace_viewer_dir = os.path.join(script_dir, 'trace-viewer')

parser = optparse.OptionParser()
parser.add_option('--local', dest='local_dir', metavar='DIR',
                  help='use a local trace-viewer')
parser.add_option('--no-min', dest='no_min', default=False, action='store_true',
                  help='skip minification')
options, args = parser.parse_args()

# Update the source if needed.
if options.local_dir is None:
  # Remove the old source tree.
  shutil.rmtree(trace_viewer_dir, True)

  # Pull the latest source from the upstream git.
  git_args = ['git', 'clone', upstream_git, trace_viewer_dir]
  p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=script_dir)
  p.communicate()
  if p.wait() != 0:
    print 'Failed to checkout source from upstream git.'
    sys.exit(1)

  trace_viewer_git_dir = os.path.join(trace_viewer_dir, '.git')
  # Update the UPSTREAM_REVISION file
  git_args = ['git', 'rev-parse', 'HEAD']
  p = subprocess.Popen(git_args,
                       stdout=subprocess.PIPE,
                       cwd=trace_viewer_dir,
                       env={"GIT_DIR":trace_viewer_git_dir})
  out, err = p.communicate()
  if p.wait() != 0:
    print 'Failed to get revision.'
    sys.exit(1)

  shutil.rmtree(trace_viewer_git_dir, True)

  rev = out.strip()
  with open('UPSTREAM_REVISION', 'wt') as f:
    f.write(rev + '\n')
else:
  trace_viewer_dir = options.local_dir


# Generate the vulcanized result.
build_dir = os.path.join(trace_viewer_dir)
sys.path.append(build_dir)

from trace_viewer.build import vulcanize_trace_viewer
with codecs.open(output_html_file, encoding='utf-8', mode='w') as f:
  vulcanize_trace_viewer.WriteTraceViewer(
      f,
      config_name='systrace',
      minify=(not options.no_min),
      output_html_head_and_body=False)
print 'Generated %s' % output_html_file