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 | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 39 | skia_out = os.environ.get("SKIA_OUT") |
| 40 | if skia_out: |
| 41 | skia_out = os.path.abspath(skia_out) |
| 42 | hash_path = os.path.join(skia_out, 'gyp_hash') |
| 43 | else: |
| 44 | hash_path = os.path.join('out', 'gyp_hash') |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 45 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 46 | os.chdir(skia_dir) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 47 | |
halcanary | 21736bd | 2016-04-25 13:34:06 -0700 | [diff] [blame] | 48 | if 0 != subprocess.call(['python', 'bin/sync'] + sys.argv[1:]): |
| 49 | sys.stderr.write('sync failed.') |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 50 | exit(1) |
halcanary | 135b7ec | 2015-03-27 12:11:49 -0700 | [diff] [blame] | 51 | |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 52 | hasher = hashlib.sha1() |
| 53 | |
| 54 | for var in ['AR', 'AR_host', 'AR_target', |
| 55 | 'CC', 'CC_host', 'CC_target', |
| 56 | 'CFLAGS', 'CFLAGS_host', |
| 57 | 'CPPFLAGS', 'CPPFLAGS_host', |
| 58 | 'CXX', 'CXX_host', 'CXX_target', |
| 59 | 'GYP_DEFINES', 'GYP_GENERATORS', |
| 60 | 'NM', 'NM_host', 'NM_target', |
| 61 | 'READELF', 'READELF_host', 'READELF_target']: |
| 62 | hasher.update(os.environ.get(var, '') + '\n') |
| 63 | |
| 64 | def listfiles(folder, matchfilter): |
| 65 | for root, folders, files in os.walk(folder): |
| 66 | for filename in files: |
| 67 | if fnmatch.fnmatch(filename, matchfilter): |
| 68 | yield os.path.join(root, filename) |
| 69 | |
| 70 | for filename in sorted(listfiles('gyp', '*')): |
| 71 | with open(filename, 'r') as f: |
| 72 | hasher.update(f.read()) |
| 73 | |
halcanary | 5c4685e | 2016-04-25 12:39:39 -0700 | [diff] [blame] | 74 | find_dirs = [ |
| 75 | 'bench', |
| 76 | 'fuzz', |
| 77 | 'gm', |
| 78 | 'tests', |
| 79 | 'third_party/externals/icu/source/common', |
halcanary | 5c4685e | 2016-04-25 12:39:39 -0700 | [diff] [blame] | 80 | 'third_party/externals/sfntly/sfntly', |
| 81 | 'third_party/externals/shaderc2', |
| 82 | 'tools/VisualBench', |
| 83 | 'tools/gpu', |
| 84 | 'tools/kilobench', |
| 85 | 'tools/skiaserve', |
| 86 | 'tools/skiaserve/urlhandlers', |
| 87 | 'tools/vulkan', |
| 88 | ] |
| 89 | |
| 90 | for dir in find_dirs: |
halcanary | a4c26c0 | 2015-11-09 08:28:13 -0800 | [diff] [blame] | 91 | for filename in sorted(listfiles(dir, '*.c*')): |
| 92 | hasher.update(filename + '\n') |
| 93 | |
| 94 | gyp_hash = hasher.hexdigest() |
| 95 | |
| 96 | def cat_if_exists(path): |
| 97 | if os.path.exists(path): |
| 98 | with open(path, 'r') as f: |
| 99 | return f.read() |
| 100 | return '' |
| 101 | |
| 102 | if cat_if_exists(hash_path).strip() != gyp_hash: |
| 103 | env = os.environ.copy() |
| 104 | if skia_out: |
| 105 | env['SKIA_OUT'] = skia_out |
| 106 | subprocess.call(['python', './gyp_skia'], env=env) |
| 107 | with open(hash_path, 'w') as o: |
| 108 | o.write(gyp_hash) |