aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/sync
blob: 34bfc643f45efe29e2f001137e0b5b403e883d0a (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python

# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script will update Skia's dependencies as necessary.

# Depends on: Python, Git, and depot_tools.

# To retreive and use all optional deps:
#
#   python bin/sync --deps=all

import hashlib
import os
import subprocess
import sys

skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)

skia_opt_deps = [arg for arg in sys.argv[1:] if arg.startswith('--deps=')]

os.chdir(skia_dir)

if not os.path.isfile('DEPS'):
  sys.stderr.write('DEPS file missing')
  exit(1)

deps_hasher = hashlib.sha1()
with open('DEPS', 'r') as f:
  deps_hasher.update(f.read())
deps_hasher.update(repr(skia_opt_deps))
deps_hash = deps_hasher.hexdigest()
current_deps_hash = None
if os.path.isfile('.deps_sha1'):
  with open('.deps_sha1', 'r') as f:
    current_deps_hash = f.read().strip()

default_gclient_config = '''
solutions = [
  { "name"        : ".",
    "url"         : "https://skia.googlesource.com/skia.git",
    "deps_file"   : "DEPS",
    "managed"     : False,
    "custom_deps" : {
    },
    "safesync_url": "",
  },
]
cache_dir = None
'''

# Must use gclient.bat rather than gclient on windows (at least on mingw)
gclient = 'gclient'
if sys.platform == 'win32' or sys.platform == 'cygwin':
  gclient = 'gclient.bat'

if current_deps_hash != deps_hash:
  # `gclient sync` is very slow, so skip whenever we can.
  try:
    subprocess.call([gclient, '--version'])
  except:
    sys.stdout.write('gclient missing from $PATH, please install ' +
                     'depot_tools\n    https://skia.org/user/quick/desktop\n')
    exit(1)
  if not os.path.isfile('.gclient'):
    with open('.gclient', 'w') as o:
      o.write(default_gclient_config)
  gclient_sync_command = [gclient, 'sync'] + skia_opt_deps
  try:
    sys.stdout.write('%r\n' % gclient_sync_command)
    subprocess.check_call(gclient_sync_command)
  except:
    sys.stderr.write('\n`gclient sync` failed.\n')
    try:
      os.remove('.deps_sha1')  # Unknown state.
    except:
      pass
    exit(1)
  # Only write hash after a successful sync.
  with open('.deps_sha1', 'w') as o:
    o.write(deps_hash)