2015-11-09 16:28:13 +00:00
|
|
|
#!/usr/bin/env python
|
2015-03-27 19:11:49 +00:00
|
|
|
|
|
|
|
# Copyright 2015 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2015-11-09 16:28:13 +00:00
|
|
|
# This script will update Skia's dependencies as necessary and run
|
2015-03-27 19:11:49 +00:00
|
|
|
# gyp if needed.
|
|
|
|
|
2016-02-16 19:48:06 +00:00
|
|
|
# Depends on: Python, Git, and depot_tools.
|
2015-11-03 20:07:47 +00:00
|
|
|
#
|
|
|
|
# Example usage:
|
2015-03-27 19:11:49 +00:00
|
|
|
#
|
2016-02-16 19:48:06 +00:00
|
|
|
# git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
|
|
|
|
# export PATH="${PWD}/depot_tools:${PATH}"
|
2015-03-27 19:11:49 +00:00
|
|
|
# git clone https://skia.googlesource.com/skia
|
|
|
|
# cd skia
|
2015-11-09 16:28:13 +00:00
|
|
|
# python bin/sync-and-gyp
|
2015-11-03 20:07:47 +00:00
|
|
|
# ninja -C out/Debug && out/Debug/dm
|
2015-03-27 19:11:49 +00:00
|
|
|
#
|
2015-11-03 20:07:47 +00:00
|
|
|
# Once changes are made to DEPS or gyp/ or the source, call:
|
2015-03-27 19:11:49 +00:00
|
|
|
#
|
2015-11-09 16:28:13 +00:00
|
|
|
# python bin/sync-and-gyp
|
|
|
|
|
2016-02-17 16:39:23 +00:00
|
|
|
# To retreive and use all optional deps:
|
|
|
|
#
|
|
|
|
# python bin/sync-and-gyp --deps=all
|
|
|
|
# ninja -C out/Debug && out/Debug/dm
|
|
|
|
|
2015-11-09 16:28:13 +00:00
|
|
|
import fnmatch
|
|
|
|
import hashlib
|
|
|
|
import os
|
2016-02-17 16:39:23 +00:00
|
|
|
import subprocess
|
2016-02-17 14:37:51 +00:00
|
|
|
import sys
|
2015-11-09 16:28:13 +00:00
|
|
|
|
|
|
|
skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
|
|
|
|
|
2016-02-17 16:39:23 +00:00
|
|
|
skia_opt_deps = [arg for arg in sys.argv[1:] if arg.startswith('--deps=')]
|
|
|
|
|
2015-11-09 16:28:13 +00:00
|
|
|
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')
|
|
|
|
else:
|
|
|
|
hash_path = os.path.join('out', 'gyp_hash')
|
|
|
|
|
|
|
|
os.chdir(skia_dir)
|
|
|
|
|
|
|
|
if not os.path.isfile('DEPS'):
|
|
|
|
sys.stderr.write('DEPS file missing')
|
|
|
|
exit(1)
|
|
|
|
|
2016-02-16 19:48:06 +00:00
|
|
|
deps_hasher = hashlib.sha1()
|
|
|
|
with open('DEPS', 'r') as f:
|
|
|
|
deps_hasher.update(f.read())
|
2016-02-17 16:39:23 +00:00
|
|
|
deps_hasher.update(repr(skia_opt_deps))
|
2016-02-16 19:48:06 +00:00
|
|
|
deps_hash = deps_hasher.hexdigest()
|
|
|
|
current_deps_hash = None
|
|
|
|
if os.path.isfile('.deps_sha1'):
|
|
|
|
with open('.deps_sha1', 'r') as f:
|
|
|
|
current_deps_hash = f.read().strip()
|
|
|
|
|
|
|
|
default_gclient_config = '''
|
|
|
|
solutions = [
|
|
|
|
{ "name" : ".",
|
|
|
|
"url" : "https://skia.googlesource.com/skia.git",
|
|
|
|
"deps_file" : "DEPS",
|
|
|
|
"managed" : False,
|
|
|
|
"custom_deps" : {
|
|
|
|
},
|
|
|
|
"safesync_url": "",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
cache_dir = None
|
|
|
|
'''
|
|
|
|
if current_deps_hash != deps_hash:
|
|
|
|
# `gclient sync` is very slow, so skip whenever we can.
|
|
|
|
if not os.path.isfile('.gclient'):
|
|
|
|
with open('.gclient', 'w') as o:
|
|
|
|
o.write(default_gclient_config)
|
2016-02-17 16:39:23 +00:00
|
|
|
gclient_sync_command = ['gclient', 'sync'] + skia_opt_deps
|
2016-02-16 19:48:06 +00:00
|
|
|
try:
|
2016-02-17 16:39:23 +00:00
|
|
|
sys.stdout.write('%r\n' % gclient_sync_command)
|
|
|
|
subprocess.check_call(gclient_sync_command)
|
2016-02-16 19:48:06 +00:00
|
|
|
except:
|
|
|
|
sys.stderr.write('\n`gclient sync` failed.\n')
|
|
|
|
os.remove('.deps_sha1') # Unknown state.
|
|
|
|
exit(1)
|
|
|
|
# Only write hash after a successful sync.
|
|
|
|
with open('.deps_sha1', 'w') as o:
|
|
|
|
o.write(deps_hash)
|
2015-11-09 16:28:13 +00:00
|
|
|
|
|
|
|
hasher = hashlib.sha1()
|
|
|
|
|
|
|
|
for var in ['AR', 'AR_host', 'AR_target',
|
|
|
|
'CC', 'CC_host', 'CC_target',
|
|
|
|
'CFLAGS', 'CFLAGS_host',
|
|
|
|
'CPPFLAGS', 'CPPFLAGS_host',
|
|
|
|
'CXX', 'CXX_host', 'CXX_target',
|
|
|
|
'GYP_DEFINES', 'GYP_GENERATORS',
|
|
|
|
'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:
|
|
|
|
hasher.update(f.read())
|
|
|
|
|
|
|
|
for dir in ['bench', 'gm', 'tests']:
|
|
|
|
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 f.read()
|
|
|
|
return ''
|
|
|
|
|
|
|
|
if cat_if_exists(hash_path).strip() != gyp_hash:
|
|
|
|
env = os.environ.copy()
|
|
|
|
if skia_out:
|
|
|
|
env['SKIA_OUT'] = skia_out
|
|
|
|
subprocess.call(['python', './gyp_skia'], env=env)
|
|
|
|
with open(hash_path, 'w') as o:
|
|
|
|
o.write(gyp_hash)
|