1#!/usr/bin/env python 2 3import codecs, httplib, json, optparse, os, urllib, shutil, subprocess, sys 4 5output_html_file = 'systrace_trace_viewer.html' 6 7upstream_git = 'https://github.com/google/trace-viewer.git' 8 9script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 10trace_viewer_dir = os.path.join(script_dir, 'trace-viewer') 11 12parser = optparse.OptionParser() 13parser.add_option('--local', dest='local_dir', metavar='DIR', 14 help='use a local trace-viewer') 15parser.add_option('--no-min', dest='no_min', default=False, action='store_true', 16 help='skip minification') 17options, args = parser.parse_args() 18 19# Update the source if needed. 20if options.local_dir is None: 21 # Remove the old source tree. 22 shutil.rmtree(trace_viewer_dir, True) 23 24 # Pull the latest source from the upstream git. 25 git_args = ['git', 'clone', upstream_git, trace_viewer_dir] 26 p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=script_dir) 27 p.communicate() 28 if p.wait() != 0: 29 print 'Failed to checkout source from upstream git.' 30 sys.exit(1) 31 32 trace_viewer_git_dir = os.path.join(trace_viewer_dir, '.git') 33 # Update the UPSTREAM_REVISION file 34 git_args = ['git', 'rev-parse', 'HEAD'] 35 p = subprocess.Popen(git_args, 36 stdout=subprocess.PIPE, 37 cwd=trace_viewer_dir, 38 env={"GIT_DIR":trace_viewer_git_dir}) 39 out, err = p.communicate() 40 if p.wait() != 0: 41 print 'Failed to get revision.' 42 sys.exit(1) 43 44 shutil.rmtree(trace_viewer_git_dir, True) 45 46 rev = out.strip() 47 with open('UPSTREAM_REVISION', 'wt') as f: 48 f.write(rev + '\n') 49else: 50 trace_viewer_dir = options.local_dir 51 52 53# Generate the vulcanized result. 54build_dir = os.path.join(trace_viewer_dir) 55sys.path.append(build_dir) 56 57from tracing.build import vulcanize_trace_viewer 58with codecs.open(output_html_file, encoding='utf-8', mode='w') as f: 59 vulcanize_trace_viewer.WriteTraceViewer( 60 f, 61 config_name='systrace', 62 minify=(not options.no_min), 63 output_html_head_and_body=False) 64print 'Generated %s' % output_html_file 65