blob: 34bfc643f45efe29e2f001137e0b5b403e883d0a [file] [log] [blame]
halcanary21736bd2016-04-25 13:34:06 -07001#!/usr/bin/env python
2
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8# This script will update Skia's dependencies as necessary.
9
10# Depends on: Python, Git, and depot_tools.
11
12# To retreive and use all optional deps:
13#
14# python bin/sync --deps=all
15
16import hashlib
17import os
18import subprocess
19import sys
20
21skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
22
23skia_opt_deps = [arg for arg in sys.argv[1:] if arg.startswith('--deps=')]
24
25os.chdir(skia_dir)
26
27if not os.path.isfile('DEPS'):
28 sys.stderr.write('DEPS file missing')
29 exit(1)
30
31deps_hasher = hashlib.sha1()
32with open('DEPS', 'r') as f:
33 deps_hasher.update(f.read())
34deps_hasher.update(repr(skia_opt_deps))
35deps_hash = deps_hasher.hexdigest()
36current_deps_hash = None
37if os.path.isfile('.deps_sha1'):
38 with open('.deps_sha1', 'r') as f:
39 current_deps_hash = f.read().strip()
40
41default_gclient_config = '''
42solutions = [
43 { "name" : ".",
44 "url" : "https://skia.googlesource.com/skia.git",
45 "deps_file" : "DEPS",
46 "managed" : False,
47 "custom_deps" : {
48 },
49 "safesync_url": "",
50 },
51]
52cache_dir = None
53'''
54
55# Must use gclient.bat rather than gclient on windows (at least on mingw)
56gclient = 'gclient'
57if sys.platform == 'win32' or sys.platform == 'cygwin':
58 gclient = 'gclient.bat'
59
60if current_deps_hash != deps_hash:
61 # `gclient sync` is very slow, so skip whenever we can.
62 try:
63 subprocess.call([gclient, '--version'])
64 except:
65 sys.stdout.write('gclient missing from $PATH, please install ' +
66 'depot_tools\n https://skia.org/user/quick/desktop\n')
67 exit(1)
68 if not os.path.isfile('.gclient'):
69 with open('.gclient', 'w') as o:
70 o.write(default_gclient_config)
71 gclient_sync_command = [gclient, 'sync'] + skia_opt_deps
72 try:
73 sys.stdout.write('%r\n' % gclient_sync_command)
74 subprocess.check_call(gclient_sync_command)
75 except:
76 sys.stderr.write('\n`gclient sync` failed.\n')
77 try:
78 os.remove('.deps_sha1') # Unknown state.
79 except:
80 pass
81 exit(1)
82 # Only write hash after a successful sync.
83 with open('.deps_sha1', 'w') as o:
84 o.write(deps_hash)