blob: fadfff84e941429a685a7b98860fdcd12e1005f0 [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
halcanary135b7ec2015-03-27 12:11:49 -070030
halcanarya4c26c02015-11-09 08:28:13 -080031skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
halcanary135b7ec2015-03-27 12:11:49 -070032
halcanarya4c26c02015-11-09 08:28:13 -080033skia_out = os.environ.get("SKIA_OUT")
34if skia_out:
35 skia_out = os.path.abspath(skia_out)
36 hash_path = os.path.join(skia_out, 'gyp_hash')
37else:
38 hash_path = os.path.join('out', 'gyp_hash')
halcanary135b7ec2015-03-27 12:11:49 -070039
halcanarya4c26c02015-11-09 08:28:13 -080040os.chdir(skia_dir)
halcanary135b7ec2015-03-27 12:11:49 -070041
halcanarya4c26c02015-11-09 08:28:13 -080042if not os.path.isfile('DEPS'):
43 sys.stderr.write('DEPS file missing')
44 exit(1)
halcanary135b7ec2015-03-27 12:11:49 -070045
halcanary2362c472016-02-16 11:48:06 -080046deps_hasher = hashlib.sha1()
47with open('DEPS', 'r') as f:
48 deps_hasher.update(f.read())
49deps_hash = deps_hasher.hexdigest()
50current_deps_hash = None
51if os.path.isfile('.deps_sha1'):
52 with open('.deps_sha1', 'r') as f:
53 current_deps_hash = f.read().strip()
54
55default_gclient_config = '''
56solutions = [
57 { "name" : ".",
58 "url" : "https://skia.googlesource.com/skia.git",
59 "deps_file" : "DEPS",
60 "managed" : False,
61 "custom_deps" : {
62 },
63 "safesync_url": "",
64 },
65]
66cache_dir = None
67'''
68if current_deps_hash != deps_hash:
69 # `gclient sync` is very slow, so skip whenever we can.
70 if not os.path.isfile('.gclient'):
71 with open('.gclient', 'w') as o:
72 o.write(default_gclient_config)
73 try:
74 subprocess.check_call(['gclient', 'sync'])
75 except:
76 sys.stderr.write('\n`gclient sync` failed.\n')
77 os.remove('.deps_sha1') # Unknown state.
78 exit(1)
79 # Only write hash after a successful sync.
80 with open('.deps_sha1', 'w') as o:
81 o.write(deps_hash)
halcanary135b7ec2015-03-27 12:11:49 -070082
halcanarya4c26c02015-11-09 08:28:13 -080083hasher = hashlib.sha1()
84
85for var in ['AR', 'AR_host', 'AR_target',
86 'CC', 'CC_host', 'CC_target',
87 'CFLAGS', 'CFLAGS_host',
88 'CPPFLAGS', 'CPPFLAGS_host',
89 'CXX', 'CXX_host', 'CXX_target',
90 'GYP_DEFINES', 'GYP_GENERATORS',
91 'NM', 'NM_host', 'NM_target',
92 'READELF', 'READELF_host', 'READELF_target']:
93 hasher.update(os.environ.get(var, '') + '\n')
94
95def listfiles(folder, matchfilter):
96 for root, folders, files in os.walk(folder):
97 for filename in files:
98 if fnmatch.fnmatch(filename, matchfilter):
99 yield os.path.join(root, filename)
100
101for filename in sorted(listfiles('gyp', '*')):
102 with open(filename, 'r') as f:
103 hasher.update(f.read())
104
105for dir in ['bench', 'gm', 'tests']:
106 for filename in sorted(listfiles(dir, '*.c*')):
107 hasher.update(filename + '\n')
108
109gyp_hash = hasher.hexdigest()
110
111def cat_if_exists(path):
112 if os.path.exists(path):
113 with open(path, 'r') as f:
114 return f.read()
115 return ''
116
117if cat_if_exists(hash_path).strip() != gyp_hash:
118 env = os.environ.copy()
119 if skia_out:
120 env['SKIA_OUT'] = skia_out
121 subprocess.call(['python', './gyp_skia'], env=env)
122 with open(hash_path, 'w') as o:
123 o.write(gyp_hash)