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 | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 11 | # Depends on: Python, and Git. |
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 | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 15 | # git clone https://skia.googlesource.com/skia |
| 16 | # cd skia |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 17 | # python bin/sync-and-gyp |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 18 | # ninja -C out/Debug && out/Debug/dm |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 19 | # |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 20 | # Once changes are made to DEPS or gyp/ or the source, call: |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 21 | # |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 22 | # python bin/sync-and-gyp |
mtklein | 143fd55 | 2015-11-03 12:07:47 -0800 | [diff] [blame] | 23 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 24 | import fnmatch |
| 25 | import hashlib |
| 26 | import subprocess |
| 27 | import os |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 28 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 29 | skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) |
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_out = os.environ.get("SKIA_OUT") |
| 32 | if skia_out: |
| 33 | skia_out = os.path.abspath(skia_out) |
| 34 | hash_path = os.path.join(skia_out, 'gyp_hash') |
| 35 | else: |
| 36 | hash_path = os.path.join('out', 'gyp_hash') |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 37 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 38 | os.chdir(skia_dir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 39 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 40 | if not os.path.isfile('DEPS'): |
| 41 | sys.stderr.write('DEPS file missing') |
| 42 | exit(1) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 43 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 44 | env = os.environ.copy() |
| 45 | env["GIT_SYNC_DEPS_QUIET"] = "1" |
| 46 | subprocess.call(['python', 'tools/git-sync-deps'], env=env) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 47 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 48 | hasher = hashlib.sha1() |
| 49 | |
| 50 | for var in ['AR', 'AR_host', 'AR_target', |
| 51 | 'CC', 'CC_host', 'CC_target', |
| 52 | 'CFLAGS', 'CFLAGS_host', |
| 53 | 'CPPFLAGS', 'CPPFLAGS_host', |
| 54 | 'CXX', 'CXX_host', 'CXX_target', |
| 55 | 'GYP_DEFINES', 'GYP_GENERATORS', |
| 56 | 'NM', 'NM_host', 'NM_target', |
| 57 | 'READELF', 'READELF_host', 'READELF_target']: |
| 58 | hasher.update(os.environ.get(var, '') + '\n') |
| 59 | |
| 60 | def listfiles(folder, matchfilter): |
| 61 | for root, folders, files in os.walk(folder): |
| 62 | for filename in files: |
| 63 | if fnmatch.fnmatch(filename, matchfilter): |
| 64 | yield os.path.join(root, filename) |
| 65 | |
| 66 | for filename in sorted(listfiles('gyp', '*')): |
| 67 | with open(filename, 'r') as f: |
| 68 | hasher.update(f.read()) |
| 69 | |
| 70 | for dir in ['bench', 'gm', 'tests']: |
| 71 | for filename in sorted(listfiles(dir, '*.c*')): |
| 72 | hasher.update(filename + '\n') |
| 73 | |
| 74 | gyp_hash = hasher.hexdigest() |
| 75 | |
| 76 | def cat_if_exists(path): |
| 77 | if os.path.exists(path): |
| 78 | with open(path, 'r') as f: |
| 79 | return f.read() |
| 80 | return '' |
| 81 | |
| 82 | if cat_if_exists(hash_path).strip() != gyp_hash: |
| 83 | env = os.environ.copy() |
| 84 | if skia_out: |
| 85 | env['SKIA_OUT'] = skia_out |
| 86 | subprocess.call(['python', './gyp_skia'], env=env) |
| 87 | with open(hash_path, 'w') as o: |
| 88 | o.write(gyp_hash) |