• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import codecs, httplib, json, optparse, os, urllib, shutil, subprocess, sys
4
5upstream_git = 'https://github.com/catapult-project/catapult.git'
6PACKAGE_DIRS = ['common', 'dependency_manager', 'devil', 'systrace', 'telemetry']
7IGNORE_PATTERNS = ['OWNERS'] # doesn't make sense to sync owners files
8
9script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
10catapult_src_dir = os.path.join(script_dir, 'catapult-upstream')
11catapult_dst_dir = os.path.join(script_dir, 'catapult')
12
13parser = optparse.OptionParser()
14parser.add_option('--local', dest='local_dir', metavar='DIR',
15                  help='use a local catapult')
16parser.add_option('--no-min', dest='no_min', default=False, action='store_true',
17                  help='skip minification')
18options, args = parser.parse_args()
19
20# Update the source if needed.
21if options.local_dir is None:
22  # Remove the old source tree.
23  shutil.rmtree(catapult_src_dir, True)
24
25  # Pull the latest source from the upstream git.
26  git_args = ['git', 'clone', upstream_git, catapult_src_dir]
27  p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=script_dir)
28  p.communicate()
29  if p.wait() != 0:
30    print 'Failed to checkout source from upstream git.'
31    sys.exit(1)
32
33  catapult_git_dir = os.path.join(catapult_src_dir, '.git')
34  # Update the UPSTREAM_REVISION file
35  git_args = ['git', 'rev-parse', 'HEAD']
36  p = subprocess.Popen(git_args,
37                       stdout=subprocess.PIPE,
38                       cwd=catapult_src_dir,
39                       env={"GIT_DIR":catapult_git_dir})
40  out, err = p.communicate()
41  if p.wait() != 0:
42    print 'Failed to get revision.'
43    sys.exit(1)
44
45  shutil.rmtree(catapult_git_dir, True)
46
47  rev = out.strip()
48  with open('UPSTREAM_REVISION', 'wt') as f:
49    f.write(rev + '\n')
50else:
51  catapult_src_dir = options.local_dir
52
53
54# Update systrace_trace_viewer.html
55systrace_dir = os.path.join(catapult_src_dir, 'systrace', 'systrace')
56sys.path.append(systrace_dir)
57import update_systrace_trace_viewer
58update_systrace_trace_viewer.update(no_auto_update=True, no_min=options.no_min)
59
60# Package the result
61shutil.rmtree(catapult_dst_dir)
62for d in PACKAGE_DIRS:
63  shutil.copytree(os.path.join(catapult_src_dir, d),
64                  os.path.join(catapult_dst_dir, d),
65                  ignore=shutil.ignore_patterns(*IGNORE_PATTERNS))
66