aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/sync
blob: 163584d6e1d8a04a99ce835bf57daa5fff3c7f94 (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
#!/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 and Git

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

import hashlib
import os
import subprocess
import sys

HASH_FILE = '.deps_sha1'
DEPS_FLAG = '--deps='
DEPS_FILE = 'DEPS'

skia_opt_deps = [arg[len(DEPS_FLAG):] for arg in sys.argv[1:] if arg.startswith(DEPS_FLAG)]

os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))

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

deps_hasher = hashlib.sha1()
with open(DEPS_FILE, '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(HASH_FILE):
  with open(HASH_FILE, 'r') as f:
    current_deps_hash = f.read().strip()

if current_deps_hash != deps_hash:
  if os.path.isfile(HASH_FILE):
    os.remove(HASH_FILE)
  command = [sys.executable, os.path.join('tools', 'git-sync-deps')]
  command.extend(skia_opt_deps)
  sys.stdout.write('%r\n' % command)
  sys.stdout.flush()
  subprocess.check_call(command)
  # Only write hash after a successful sync.
  with open(HASH_FILE, 'w') as o:
    o.write(deps_hash)