blob: 469c84e8f865ed1dbb4e4e0de8ace9cb22544be1 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 Google Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script will update Skia's dependencies as necessary and run
# gyp if needed.
# Depends on: Python, Git, and depot_tools.
# Example usage:
# git clone
# export PATH="${PWD}/depot_tools:${PATH}"
# git clone
# cd skia
# python bin/sync-and-gyp
# ninja -C out/Debug && out/Debug/dm
# Once changes are made to DEPS or gyp/ or the source, call:
# python bin/sync-and-gyp
# To retreive and use all optional deps:
# python bin/sync-and-gyp --deps=all
# ninja -C out/Debug && out/Debug/dm
import fnmatch
import hashlib
import os
import subprocess
import sys
skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
skia_out = os.environ.get("SKIA_OUT")
if skia_out:
skia_out = os.path.abspath(skia_out)
hash_path = os.path.join(skia_out, 'gyp_hash')
hash_path = os.path.join('out', 'gyp_hash')
if 0 !=['python', 'bin/sync'] + sys.argv[1:]):
sys.stderr.write('sync failed.')
hasher = hashlib.sha1()
for var in ['AR', 'AR_host', 'AR_target',
'CC', 'CC_host', 'CC_target',
'CFLAGS', 'CFLAGS_host',
'CXX', 'CXX_host', 'CXX_target',
'NM', 'NM_host', 'NM_target',
'READELF', 'READELF_host', 'READELF_target']:
hasher.update(os.environ.get(var, '') + '\n')
def listfiles(folder, matchfilter):
for root, folders, files in os.walk(folder):
for filename in files:
if fnmatch.fnmatch(filename, matchfilter):
yield os.path.join(root, filename)
for filename in sorted(listfiles('gyp', '*')):
with open(filename, 'r') as f:
find_dirs = [
for dir in find_dirs:
for filename in sorted(listfiles(dir, '*.c*')):
hasher.update(filename + '\n')
gyp_hash = hasher.hexdigest()
def cat_if_exists(path):
if os.path.exists(path):
with open(path, 'r') as f:
return ''
if cat_if_exists(hash_path).strip() != gyp_hash:
env = os.environ.copy()
if skia_out:
env['SKIA_OUT'] = skia_out['python', './gyp_skia'], env=env)
with open(hash_path, 'w') as o: