halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright 2015 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 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 8 | # This script will update Skia's dependencies as necessary and run |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 9 | # gyp if needed. |
| 10 | |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 11 | # Depends on: Python, Git, and depot_tools. |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 12 | # |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 13 | # Example usage: |
| 14 | # |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 15 | # git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 16 | # export PATH="${PWD}/depot_tools:${PATH}" |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 17 | # git clone https://skia.googlesource.com/skia |
| 18 | # cd skia |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 19 | # python bin/sync-and-gyp |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 20 | # ninja -C out/Debug && out/Debug/dm |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 21 | # |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 22 | # Once changes are made to DEPS or gyp/ or the source, call: |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 23 | # |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 24 | # python bin/sync-and-gyp |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 25 | |
halcanary | 117672d | 2016-02-17 08:39:23 -0800 | [diff] [blame] | 26 | # To retreive and use all optional deps: |
| 27 | # |
| 28 | # python bin/sync-and-gyp --deps=all |
| 29 | # ninja -C out/Debug && out/Debug/dm |
| 30 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 31 | import fnmatch |
| 32 | import hashlib |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 33 | import os |
halcanary | 117672d | 2016-02-17 08:39:23 -0800 | [diff] [blame] | 34 | import subprocess |
mtklein | dc469ad | 2016-02-17 06:37:51 -0800 | [diff] [blame] | 35 | import sys |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 36 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 37 | skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 38 | |
halcanary | 117672d | 2016-02-17 08:39:23 -0800 | [diff] [blame] | 39 | skia_opt_deps = [arg for arg in sys.argv[1:] if arg.startswith('--deps=')] |
| 40 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 41 | skia_out = os.environ.get("SKIA_OUT") |
| 42 | if skia_out: |
| 43 | skia_out = os.path.abspath(skia_out) |
| 44 | hash_path = os.path.join(skia_out, 'gyp_hash') |
| 45 | else: |
| 46 | hash_path = os.path.join('out', 'gyp_hash') |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 47 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 48 | os.chdir(skia_dir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 49 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 50 | if not os.path.isfile('DEPS'): |
| 51 | sys.stderr.write('DEPS file missing') |
| 52 | exit(1) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 53 | |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 54 | deps_hasher = hashlib.sha1() |
| 55 | with open('DEPS', 'r') as f: |
| 56 | deps_hasher.update(f.read()) |
halcanary | 117672d | 2016-02-17 08:39:23 -0800 | [diff] [blame] | 57 | deps_hasher.update(repr(skia_opt_deps)) |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 58 | deps_hash = deps_hasher.hexdigest() |
| 59 | current_deps_hash = None |
| 60 | if os.path.isfile('.deps_sha1'): |
| 61 | with open('.deps_sha1', 'r') as f: |
| 62 | current_deps_hash = f.read().strip() |
| 63 | |
| 64 | default_gclient_config = ''' |
| 65 | solutions = [ |
| 66 | { "name" : ".", |
| 67 | "url" : "https://skia.googlesource.com/skia.git", |
| 68 | "deps_file" : "DEPS", |
| 69 | "managed" : False, |
| 70 | "custom_deps" : { |
| 71 | }, |
| 72 | "safesync_url": "", |
| 73 | }, |
| 74 | ] |
| 75 | cache_dir = None |
| 76 | ''' |
bsalomon | 3d7b02c | 2016-02-22 12:59:53 -0800 | [diff] [blame] | 77 | |
| 78 | # Must use gclient.bat rather than gclient on windows (at least on mingw) |
| 79 | gclient = 'gclient' |
| 80 | if sys.platform == 'win32' or sys.platform == 'cygwin': |
| 81 | gclient = 'gclient.bat' |
| 82 | |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 83 | if current_deps_hash != deps_hash: |
| 84 | # `gclient sync` is very slow, so skip whenever we can. |
halcanary | 68af68a | 2016-02-17 13:07:37 -0800 | [diff] [blame] | 85 | try: |
bsalomon | 3d7b02c | 2016-02-22 12:59:53 -0800 | [diff] [blame] | 86 | subprocess.call([gclient, '--version']) |
halcanary | 68af68a | 2016-02-17 13:07:37 -0800 | [diff] [blame] | 87 | except: |
| 88 | sys.stdout.write('gclient missing from $PATH, please install ' + |
| 89 | 'depot_tools\n https://skia.org/user/quick/desktop\n') |
| 90 | exit(1) |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 91 | if not os.path.isfile('.gclient'): |
| 92 | with open('.gclient', 'w') as o: |
| 93 | o.write(default_gclient_config) |
bsalomon | 3d7b02c | 2016-02-22 12:59:53 -0800 | [diff] [blame] | 94 | gclient_sync_command = [gclient, 'sync'] + skia_opt_deps |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 95 | try: |
halcanary | 117672d | 2016-02-17 08:39:23 -0800 | [diff] [blame] | 96 | sys.stdout.write('%r\n' % gclient_sync_command) |
| 97 | subprocess.check_call(gclient_sync_command) |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 98 | except: |
| 99 | sys.stderr.write('\n`gclient sync` failed.\n') |
halcanary | 68af68a | 2016-02-17 13:07:37 -0800 | [diff] [blame] | 100 | try: |
| 101 | os.remove('.deps_sha1') # Unknown state. |
| 102 | except: |
| 103 | pass |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 104 | exit(1) |
| 105 | # Only write hash after a successful sync. |
| 106 | with open('.deps_sha1', 'w') as o: |
| 107 | o.write(deps_hash) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 108 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 109 | hasher = hashlib.sha1() |
| 110 | |
| 111 | for var in ['AR', 'AR_host', 'AR_target', |
| 112 | 'CC', 'CC_host', 'CC_target', |
| 113 | 'CFLAGS', 'CFLAGS_host', |
| 114 | 'CPPFLAGS', 'CPPFLAGS_host', |
| 115 | 'CXX', 'CXX_host', 'CXX_target', |
| 116 | 'GYP_DEFINES', 'GYP_GENERATORS', |
| 117 | 'NM', 'NM_host', 'NM_target', |
| 118 | 'READELF', 'READELF_host', 'READELF_target']: |
| 119 | hasher.update(os.environ.get(var, '') + '\n') |
| 120 | |
| 121 | def listfiles(folder, matchfilter): |
| 122 | for root, folders, files in os.walk(folder): |
| 123 | for filename in files: |
| 124 | if fnmatch.fnmatch(filename, matchfilter): |
| 125 | yield os.path.join(root, filename) |
| 126 | |
| 127 | for filename in sorted(listfiles('gyp', '*')): |
| 128 | with open(filename, 'r') as f: |
| 129 | hasher.update(f.read()) |
| 130 | |
| 131 | for dir in ['bench', 'gm', 'tests']: |
| 132 | for filename in sorted(listfiles(dir, '*.c*')): |
| 133 | hasher.update(filename + '\n') |
| 134 | |
| 135 | gyp_hash = hasher.hexdigest() |
| 136 | |
| 137 | def cat_if_exists(path): |
| 138 | if os.path.exists(path): |
| 139 | with open(path, 'r') as f: |
| 140 | return f.read() |
| 141 | return '' |
| 142 | |
| 143 | if cat_if_exists(hash_path).strip() != gyp_hash: |
| 144 | env = os.environ.copy() |
| 145 | if skia_out: |
| 146 | env['SKIA_OUT'] = skia_out |
| 147 | subprocess.call(['python', './gyp_skia'], env=env) |
| 148 | with open(hash_path, 'w') as o: |
| 149 | o.write(gyp_hash) |