halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 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 | |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 10 | # Depends on: Python and Git |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 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 | |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 21 | HASH_FILE = '.deps_sha1' |
| 22 | DEPS_FLAG = '--deps=' |
| 23 | DEPS_FILE = 'DEPS' |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 24 | |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 25 | skia_opt_deps = [arg[len(DEPS_FLAG):] for arg in sys.argv[1:] if arg.startswith(DEPS_FLAG)] |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 26 | |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 27 | os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 28 | |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 29 | if not os.path.isfile(DEPS_FILE): |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 30 | sys.stderr.write('DEPS file missing') |
| 31 | exit(1) |
| 32 | |
| 33 | deps_hasher = hashlib.sha1() |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 34 | with open(DEPS_FILE, 'r') as f: |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 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 |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 39 | if os.path.isfile(HASH_FILE): |
| 40 | with open(HASH_FILE, 'r') as f: |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 41 | current_deps_hash = f.read().strip() |
| 42 | |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 43 | if current_deps_hash != deps_hash: |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 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) |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 51 | # Only write hash after a successful sync. |
Hal Canary | 4d3adb6 | 2017-01-27 10:59:40 -0500 | [diff] [blame] | 52 | with open(HASH_FILE, 'w') as o: |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 53 | o.write(deps_hash) |