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 | |
| 10 | # Depends on: Python, Git, and depot_tools. |
| 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 | skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) |
| 22 | |
| 23 | skia_opt_deps = [arg for arg in sys.argv[1:] if arg.startswith('--deps=')] |
| 24 | |
| 25 | os.chdir(skia_dir) |
| 26 | |
| 27 | if not os.path.isfile('DEPS'): |
| 28 | sys.stderr.write('DEPS file missing') |
| 29 | exit(1) |
| 30 | |
| 31 | deps_hasher = hashlib.sha1() |
| 32 | with open('DEPS', 'r') as f: |
| 33 | deps_hasher.update(f.read()) |
| 34 | deps_hasher.update(repr(skia_opt_deps)) |
| 35 | deps_hash = deps_hasher.hexdigest() |
| 36 | current_deps_hash = None |
| 37 | if os.path.isfile('.deps_sha1'): |
| 38 | with open('.deps_sha1', 'r') as f: |
| 39 | current_deps_hash = f.read().strip() |
| 40 | |
| 41 | default_gclient_config = ''' |
| 42 | solutions = [ |
| 43 | { "name" : ".", |
| 44 | "url" : "https://skia.googlesource.com/skia.git", |
| 45 | "deps_file" : "DEPS", |
| 46 | "managed" : False, |
| 47 | "custom_deps" : { |
| 48 | }, |
| 49 | "safesync_url": "", |
| 50 | }, |
| 51 | ] |
| 52 | cache_dir = None |
| 53 | ''' |
| 54 | |
| 55 | # Must use gclient.bat rather than gclient on windows (at least on mingw) |
| 56 | gclient = 'gclient' |
| 57 | if sys.platform == 'win32' or sys.platform == 'cygwin': |
| 58 | gclient = 'gclient.bat' |
| 59 | |
| 60 | if current_deps_hash != deps_hash: |
| 61 | # `gclient sync` is very slow, so skip whenever we can. |
| 62 | try: |
| 63 | subprocess.call([gclient, '--version']) |
| 64 | except: |
| 65 | sys.stdout.write('gclient missing from $PATH, please install ' + |
| 66 | 'depot_tools\n https://skia.org/user/quick/desktop\n') |
| 67 | exit(1) |
| 68 | if not os.path.isfile('.gclient'): |
| 69 | with open('.gclient', 'w') as o: |
| 70 | o.write(default_gclient_config) |
Hal Canary | 23510f2 | 2016-10-25 11:04:57 -0400 | [diff] [blame] | 71 | for command in [[gclient, 'sync'] + skia_opt_deps, |
| 72 | ['python', os.path.join('bin', 'fetch-gn')]]: |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 73 | try: |
Hal Canary | 23510f2 | 2016-10-25 11:04:57 -0400 | [diff] [blame] | 74 | sys.stdout.write('%r\n' % command) |
| 75 | subprocess.check_call(command) |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 76 | except: |
Hal Canary | 23510f2 | 2016-10-25 11:04:57 -0400 | [diff] [blame] | 77 | sys.stderr.write('\n%r failed.\n' % command) |
| 78 | try: |
| 79 | os.remove('.deps_sha1') # Unknown state. |
| 80 | except: |
| 81 | pass |
| 82 | exit(1) |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 83 | # Only write hash after a successful sync. |
| 84 | with open('.deps_sha1', 'w') as o: |
| 85 | o.write(deps_hash) |