blob: 154acbc300a867c5b8d3687227fefddec97595bc [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)
Hal Canary23510f22016-10-25 11:04:57 -040071 for command in [[gclient, 'sync'] + skia_opt_deps,
72 ['python', os.path.join('bin', 'fetch-gn')]]:
halcanary21736bd2016-04-25 13:34:06 -070073 try:
Hal Canary23510f22016-10-25 11:04:57 -040074 sys.stdout.write('%r\n' % command)
75 subprocess.check_call(command)
halcanary21736bd2016-04-25 13:34:06 -070076 except:
Hal Canary23510f22016-10-25 11:04:57 -040077 sys.stderr.write('\n%r failed.\n' % command)
78 try:
79 os.remove('.deps_sha1') # Unknown state.
80 except:
81 pass
82 exit(1)
halcanary21736bd2016-04-25 13:34:06 -070083 # Only write hash after a successful sync.
84 with open('.deps_sha1', 'w') as o:
85 o.write(deps_hash)