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 16import hashlib 17import os 18import subprocess 19import sys 20 21HASH_FILE = '.deps_sha1' 22DEPS_FLAG = '--deps=' 23DEPS_FILE = 'DEPS' 24 25skia_opt_deps = [arg[len(DEPS_FLAG):] for arg in sys.argv[1:] if arg.startswith(DEPS_FLAG)] 26 27os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) 28 29if not os.path.isfile(DEPS_FILE): 30 sys.stderr.write('DEPS file missing') 31 exit(1) 32 33deps_hasher = hashlib.sha1() 34with open(DEPS_FILE, 'r') as f: 35 deps_hasher.update(f.read()) 36deps_hasher.update(repr(skia_opt_deps)) 37deps_hash = deps_hasher.hexdigest() 38current_deps_hash = None 39if os.path.isfile(HASH_FILE): 40 with open(HASH_FILE, 'r') as f: 41 current_deps_hash = f.read().strip() 42 43if 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