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 | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 26 | import fnmatch |
| 27 | import hashlib |
| 28 | import subprocess |
| 29 | import os |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 30 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 31 | skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 32 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 33 | skia_out = os.environ.get("SKIA_OUT") |
| 34 | if skia_out: |
| 35 | skia_out = os.path.abspath(skia_out) |
| 36 | hash_path = os.path.join(skia_out, 'gyp_hash') |
| 37 | else: |
| 38 | hash_path = os.path.join('out', 'gyp_hash') |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 39 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 40 | os.chdir(skia_dir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 41 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 42 | if not os.path.isfile('DEPS'): |
| 43 | sys.stderr.write('DEPS file missing') |
| 44 | exit(1) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 45 | |
halcanary | 2362c47 | 2016-02-16 11:48:06 -0800 | [diff] [blame] | 46 | deps_hasher = hashlib.sha1() |
| 47 | with open('DEPS', 'r') as f: |
| 48 | deps_hasher.update(f.read()) |
| 49 | deps_hash = deps_hasher.hexdigest() |
| 50 | current_deps_hash = None |
| 51 | if os.path.isfile('.deps_sha1'): |
| 52 | with open('.deps_sha1', 'r') as f: |
| 53 | current_deps_hash = f.read().strip() |
| 54 | |
| 55 | default_gclient_config = ''' |
| 56 | solutions = [ |
| 57 | { "name" : ".", |
| 58 | "url" : "https://skia.googlesource.com/skia.git", |
| 59 | "deps_file" : "DEPS", |
| 60 | "managed" : False, |
| 61 | "custom_deps" : { |
| 62 | }, |
| 63 | "safesync_url": "", |
| 64 | }, |
| 65 | ] |
| 66 | cache_dir = None |
| 67 | ''' |
| 68 | if current_deps_hash != deps_hash: |
| 69 | # `gclient sync` is very slow, so skip whenever we can. |
| 70 | if not os.path.isfile('.gclient'): |
| 71 | with open('.gclient', 'w') as o: |
| 72 | o.write(default_gclient_config) |
| 73 | try: |
| 74 | subprocess.check_call(['gclient', 'sync']) |
| 75 | except: |
| 76 | sys.stderr.write('\n`gclient sync` failed.\n') |
| 77 | os.remove('.deps_sha1') # Unknown state. |
| 78 | exit(1) |
| 79 | # Only write hash after a successful sync. |
| 80 | with open('.deps_sha1', 'w') as o: |
| 81 | o.write(deps_hash) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 82 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 83 | hasher = hashlib.sha1() |
| 84 | |
| 85 | for var in ['AR', 'AR_host', 'AR_target', |
| 86 | 'CC', 'CC_host', 'CC_target', |
| 87 | 'CFLAGS', 'CFLAGS_host', |
| 88 | 'CPPFLAGS', 'CPPFLAGS_host', |
| 89 | 'CXX', 'CXX_host', 'CXX_target', |
| 90 | 'GYP_DEFINES', 'GYP_GENERATORS', |
| 91 | 'NM', 'NM_host', 'NM_target', |
| 92 | 'READELF', 'READELF_host', 'READELF_target']: |
| 93 | hasher.update(os.environ.get(var, '') + '\n') |
| 94 | |
| 95 | def listfiles(folder, matchfilter): |
| 96 | for root, folders, files in os.walk(folder): |
| 97 | for filename in files: |
| 98 | if fnmatch.fnmatch(filename, matchfilter): |
| 99 | yield os.path.join(root, filename) |
| 100 | |
| 101 | for filename in sorted(listfiles('gyp', '*')): |
| 102 | with open(filename, 'r') as f: |
| 103 | hasher.update(f.read()) |
| 104 | |
| 105 | for dir in ['bench', 'gm', 'tests']: |
| 106 | for filename in sorted(listfiles(dir, '*.c*')): |
| 107 | hasher.update(filename + '\n') |
| 108 | |
| 109 | gyp_hash = hasher.hexdigest() |
| 110 | |
| 111 | def cat_if_exists(path): |
| 112 | if os.path.exists(path): |
| 113 | with open(path, 'r') as f: |
| 114 | return f.read() |
| 115 | return '' |
| 116 | |
| 117 | if cat_if_exists(hash_path).strip() != gyp_hash: |
| 118 | env = os.environ.copy() |
| 119 | if skia_out: |
| 120 | env['SKIA_OUT'] = skia_out |
| 121 | subprocess.call(['python', './gyp_skia'], env=env) |
| 122 | with open(hash_path, 'w') as o: |
| 123 | o.write(gyp_hash) |