blob: 906b7671ba6850eb48ae7723c804c70eeb32065a [file] [log] [blame]
halcanarya4c26c02015-11-09 08:28:13 -08001#!/usr/bin/env python
halcanary135b7ec2015-03-27 12:11:49 -07002
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
halcanarya4c26c02015-11-09 08:28:13 -08008# This script will update Skia's dependencies as necessary and run
halcanary135b7ec2015-03-27 12:11:49 -07009# gyp if needed.
10
halcanary2362c472016-02-16 11:48:06 -080011# Depends on: Python, Git, and depot_tools.
halcanary135b7ec2015-03-27 12:11:49 -070012#
mtklein143fd552015-11-03 12:07:47 -080013# Example usage:
14#
halcanary2362c472016-02-16 11:48:06 -080015# git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
16# export PATH="${PWD}/depot_tools:${PATH}"
halcanary135b7ec2015-03-27 12:11:49 -070017# git clone https://skia.googlesource.com/skia
18# cd skia
halcanarya4c26c02015-11-09 08:28:13 -080019# python bin/sync-and-gyp
mtklein143fd552015-11-03 12:07:47 -080020# ninja -C out/Debug && out/Debug/dm
halcanary135b7ec2015-03-27 12:11:49 -070021#
mtklein143fd552015-11-03 12:07:47 -080022# Once changes are made to DEPS or gyp/ or the source, call:
halcanary135b7ec2015-03-27 12:11:49 -070023#
halcanarya4c26c02015-11-09 08:28:13 -080024# python bin/sync-and-gyp
mtklein143fd552015-11-03 12:07:47 -080025
halcanarya4c26c02015-11-09 08:28:13 -080026import fnmatch
27import hashlib
28import subprocess
29import os
mtkleindc469ad2016-02-17 06:37:51 -080030import sys
halcanary135b7ec2015-03-27 12:11:49 -070031
halcanarya4c26c02015-11-09 08:28:13 -080032skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
halcanary135b7ec2015-03-27 12:11:49 -070033
halcanarya4c26c02015-11-09 08:28:13 -080034skia_out = os.environ.get("SKIA_OUT")
35if skia_out:
36 skia_out = os.path.abspath(skia_out)
37 hash_path = os.path.join(skia_out, 'gyp_hash')
38else:
39 hash_path = os.path.join('out', 'gyp_hash')
halcanary135b7ec2015-03-27 12:11:49 -070040
halcanarya4c26c02015-11-09 08:28:13 -080041os.chdir(skia_dir)
halcanary135b7ec2015-03-27 12:11:49 -070042
halcanarya4c26c02015-11-09 08:28:13 -080043if not os.path.isfile('DEPS'):
44 sys.stderr.write('DEPS file missing')
45 exit(1)
halcanary135b7ec2015-03-27 12:11:49 -070046
halcanary2362c472016-02-16 11:48:06 -080047deps_hasher = hashlib.sha1()
48with open('DEPS', 'r') as f:
49 deps_hasher.update(f.read())
50deps_hash = deps_hasher.hexdigest()
51current_deps_hash = None
52if os.path.isfile('.deps_sha1'):
53 with open('.deps_sha1', 'r') as f:
54 current_deps_hash = f.read().strip()
55
56default_gclient_config = '''
57solutions = [
58 { "name" : ".",
59 "url" : "https://skia.googlesource.com/skia.git",
60 "deps_file" : "DEPS",
61 "managed" : False,
62 "custom_deps" : {
63 },
64 "safesync_url": "",
65 },
66]
67cache_dir = None
68'''
69if 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)
74 try:
75 subprocess.check_call(['gclient', 'sync'])
76 except:
77 sys.stderr.write('\n`gclient sync` failed.\n')
78 os.remove('.deps_sha1') # Unknown state.
79 exit(1)
80 # Only write hash after a successful sync.
81 with open('.deps_sha1', 'w') as o:
82 o.write(deps_hash)
halcanary135b7ec2015-03-27 12:11:49 -070083
halcanarya4c26c02015-11-09 08:28:13 -080084hasher = hashlib.sha1()
85
86for 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')
95
96def 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)
101
102for filename in sorted(listfiles('gyp', '*')):
103 with open(filename, 'r') as f:
104 hasher.update(f.read())
105
106for dir in ['bench', 'gm', 'tests']:
107 for filename in sorted(listfiles(dir, '*.c*')):
108 hasher.update(filename + '\n')
109
110gyp_hash = hasher.hexdigest()
111
112def cat_if_exists(path):
113 if os.path.exists(path):
114 with open(path, 'r') as f:
115 return f.read()
116 return ''
117
118if cat_if_exists(hash_path).strip() != gyp_hash:
119 env = os.environ.copy()
120 if skia_out:
121 env['SKIA_OUT'] = skia_out
122 subprocess.call(['python', './gyp_skia'], env=env)
123 with open(hash_path, 'w') as o:
124 o.write(gyp_hash)