3 # Copyright 2015 Google Inc.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
8 # This script will update Skia's dependencies as necessary and run
11 # Depends on: Python, Git, and depot_tools.
15 # git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
16 # export PATH="${PWD}/depot_tools:${PATH}"
17 # git clone https://skia.googlesource.com/skia
19 # python bin/sync-and-gyp
20 # ninja -C out/Debug && out/Debug/dm
22 # Once changes are made to DEPS or gyp/ or the source, call:
24 # python bin/sync-and-gyp
32 skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
34 skia_out = os.environ.get("SKIA_OUT")
36 skia_out = os.path.abspath(skia_out)
37 hash_path = os.path.join(skia_out, 'gyp_hash')
39 hash_path = os.path.join('out', 'gyp_hash')
43 if not os.path.isfile('DEPS'):
44 sys.stderr.write('DEPS file missing')
47 deps_hasher = hashlib.sha1()
48 with open('DEPS', 'r') as f:
49 deps_hasher.update(f.read())
50 deps_hash = deps_hasher.hexdigest()
51 current_deps_hash = None
52 if os.path.isfile('.deps_sha1'):
53 with open('.deps_sha1', 'r') as f:
54 current_deps_hash = f.read().strip()
56 default_gclient_config = '''
59 "url" : "https://skia.googlesource.com/skia.git",
69 if current_deps_hash != deps_hash:
70 # `gclient sync` is very slow, so skip whenever we can.
71 if not os.path.isfile('.gclient'):
72 with open('.gclient', 'w') as o:
73 o.write(default_gclient_config)
75 subprocess.check_call(['gclient', 'sync'])
77 sys.stderr.write('\n`gclient sync` failed.\n')
78 os.remove('.deps_sha1') # Unknown state.
80 # Only write hash after a successful sync.
81 with open('.deps_sha1', 'w') as o:
84 hasher = hashlib.sha1()
86 for var in ['AR', 'AR_host', 'AR_target',
87 'CC', 'CC_host', 'CC_target',
88 'CFLAGS', 'CFLAGS_host',
89 'CPPFLAGS', 'CPPFLAGS_host',
90 'CXX', 'CXX_host', 'CXX_target',
91 'GYP_DEFINES', 'GYP_GENERATORS',
92 'NM', 'NM_host', 'NM_target',
93 'READELF', 'READELF_host', 'READELF_target']:
94 hasher.update(os.environ.get(var, '') + '\n')
96 def listfiles(folder, matchfilter):
97 for root, folders, files in os.walk(folder):
98 for filename in files:
99 if fnmatch.fnmatch(filename, matchfilter):
100 yield os.path.join(root, filename)
102 for filename in sorted(listfiles('gyp', '*')):
103 with open(filename, 'r') as f:
104 hasher.update(f.read())
106 for dir in ['bench', 'gm', 'tests']:
107 for filename in sorted(listfiles(dir, '*.c*')):
108 hasher.update(filename + '\n')
110 gyp_hash = hasher.hexdigest()
112 def cat_if_exists(path):
113 if os.path.exists(path):
114 with open(path, 'r') as f:
118 if cat_if_exists(hash_path).strip() != gyp_hash:
119 env = os.environ.copy()
121 env['SKIA_OUT'] = skia_out
122 subprocess.call(['python', './gyp_skia'], env=env)
123 with open(hash_path, 'w') as o: