blob: 163584d6e1d8a04a99ce835bf57daa5fff3c7f94 [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
Hal Canary4d3adb62017-01-27 10:59:40 -050010# Depends on: Python and Git
halcanary21736bd2016-04-25 13:34:06 -070011
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
Hal Canary4d3adb62017-01-27 10:59:40 -050021HASH_FILE = '.deps_sha1'
22DEPS_FLAG = '--deps='
23DEPS_FILE = 'DEPS'
halcanary21736bd2016-04-25 13:34:06 -070024
Hal Canary4d3adb62017-01-27 10:59:40 -050025skia_opt_deps = [arg[len(DEPS_FLAG):] for arg in sys.argv[1:] if arg.startswith(DEPS_FLAG)]
halcanary21736bd2016-04-25 13:34:06 -070026
Hal Canary4d3adb62017-01-27 10:59:40 -050027os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
halcanary21736bd2016-04-25 13:34:06 -070028
Hal Canary4d3adb62017-01-27 10:59:40 -050029if not os.path.isfile(DEPS_FILE):
halcanary21736bd2016-04-25 13:34:06 -070030 sys.stderr.write('DEPS file missing')
31 exit(1)
32
33deps_hasher = hashlib.sha1()
Hal Canary4d3adb62017-01-27 10:59:40 -050034with open(DEPS_FILE, 'r') as f:
halcanary21736bd2016-04-25 13:34:06 -070035 deps_hasher.update(f.read())
36deps_hasher.update(repr(skia_opt_deps))
37deps_hash = deps_hasher.hexdigest()
38current_deps_hash = None
Hal Canary4d3adb62017-01-27 10:59:40 -050039if os.path.isfile(HASH_FILE):
40 with open(HASH_FILE, 'r') as f:
halcanary21736bd2016-04-25 13:34:06 -070041 current_deps_hash = f.read().strip()
42
halcanary21736bd2016-04-25 13:34:06 -070043if current_deps_hash != deps_hash:
Hal Canary4d3adb62017-01-27 10:59:40 -050044 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)
halcanary21736bd2016-04-25 13:34:06 -070051 # Only write hash after a successful sync.
Hal Canary4d3adb62017-01-27 10:59:40 -050052 with open(HASH_FILE, 'w') as o:
halcanary21736bd2016-04-25 13:34:06 -070053 o.write(deps_hash)