Home | History | Annotate | Download | only in bin
      1 #!/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 and Git
     11 
     12 # To retreive and use all optional deps:
     13 #
     14 #   python bin/sync --deps=all
     15 
     16 import hashlib
     17 import os
     18 import subprocess
     19 import sys
     20 
     21 HASH_FILE = '.deps_sha1'
     22 DEPS_FLAG = '--deps='
     23 DEPS_FILE = 'DEPS'
     24 
     25 skia_opt_deps = [arg[len(DEPS_FLAG):] for arg in sys.argv[1:] if arg.startswith(DEPS_FLAG)]
     26 
     27 os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
     28 
     29 if not os.path.isfile(DEPS_FILE):
     30   sys.stderr.write('DEPS file missing')
     31   exit(1)
     32 
     33 deps_hasher = hashlib.sha1()
     34 with open(DEPS_FILE, 'r') as f:
     35   deps_hasher.update(f.read())
     36 deps_hasher.update(repr(skia_opt_deps))
     37 deps_hash = deps_hasher.hexdigest()
     38 current_deps_hash = None
     39 if os.path.isfile(HASH_FILE):
     40   with open(HASH_FILE, 'r') as f:
     41     current_deps_hash = f.read().strip()
     42 
     43 if current_deps_hash != deps_hash:
     44   if os.path.isfile(HASH_FILE):
     45     os.remove(HASH_FILE)
     46   command = [sys.executable, os.path.join('tools', 'git-sync-deps')]
     47   command.extend(skia_opt_deps)
     48   sys.stdout.write('%r\n' % command)
     49   sys.stdout.flush()
     50   subprocess.check_call(command)
     51   # Only write hash after a successful sync.
     52   with open(HASH_FILE, 'w') as o:
     53     o.write(deps_hash)
     54