blob: 80dead97583504399f7cbe32b5692482eba1dbd7 [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
halcanarya4c26c02015-11-09 08:28:13 -080011# Depends on: Python, and Git.
halcanary135b7ec2015-03-27 12:11:49 -070012#
mtklein143fd552015-11-03 12:07:47 -080013# Example usage:
14#
halcanary135b7ec2015-03-27 12:11:49 -070015# git clone https://skia.googlesource.com/skia
16# cd skia
halcanarya4c26c02015-11-09 08:28:13 -080017# python bin/sync-and-gyp
mtklein143fd552015-11-03 12:07:47 -080018# ninja -C out/Debug && out/Debug/dm
halcanary135b7ec2015-03-27 12:11:49 -070019#
mtklein143fd552015-11-03 12:07:47 -080020# Once changes are made to DEPS or gyp/ or the source, call:
halcanary135b7ec2015-03-27 12:11:49 -070021#
halcanarya4c26c02015-11-09 08:28:13 -080022# python bin/sync-and-gyp
mtklein143fd552015-11-03 12:07:47 -080023
halcanarya4c26c02015-11-09 08:28:13 -080024import fnmatch
25import hashlib
26import subprocess
27import os
halcanary135b7ec2015-03-27 12:11:49 -070028
halcanarya4c26c02015-11-09 08:28:13 -080029skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
halcanary135b7ec2015-03-27 12:11:49 -070030
halcanarya4c26c02015-11-09 08:28:13 -080031skia_out = os.environ.get("SKIA_OUT")
32if skia_out:
33 skia_out = os.path.abspath(skia_out)
34 hash_path = os.path.join(skia_out, 'gyp_hash')
35else:
36 hash_path = os.path.join('out', 'gyp_hash')
halcanary135b7ec2015-03-27 12:11:49 -070037
halcanarya4c26c02015-11-09 08:28:13 -080038os.chdir(skia_dir)
halcanary135b7ec2015-03-27 12:11:49 -070039
halcanarya4c26c02015-11-09 08:28:13 -080040if not os.path.isfile('DEPS'):
41 sys.stderr.write('DEPS file missing')
42 exit(1)
halcanary135b7ec2015-03-27 12:11:49 -070043
halcanarya4c26c02015-11-09 08:28:13 -080044env = os.environ.copy()
45env["GIT_SYNC_DEPS_QUIET"] = "1"
46subprocess.call(['python', 'tools/git-sync-deps'], env=env)
halcanary135b7ec2015-03-27 12:11:49 -070047
halcanarya4c26c02015-11-09 08:28:13 -080048hasher = hashlib.sha1()
49
50for var in ['AR', 'AR_host', 'AR_target',
51 'CC', 'CC_host', 'CC_target',
52 'CFLAGS', 'CFLAGS_host',
53 'CPPFLAGS', 'CPPFLAGS_host',
54 'CXX', 'CXX_host', 'CXX_target',
55 'GYP_DEFINES', 'GYP_GENERATORS',
56 'NM', 'NM_host', 'NM_target',
57 'READELF', 'READELF_host', 'READELF_target']:
58 hasher.update(os.environ.get(var, '') + '\n')
59
60def listfiles(folder, matchfilter):
61 for root, folders, files in os.walk(folder):
62 for filename in files:
63 if fnmatch.fnmatch(filename, matchfilter):
64 yield os.path.join(root, filename)
65
66for filename in sorted(listfiles('gyp', '*')):
67 with open(filename, 'r') as f:
68 hasher.update(f.read())
69
70for dir in ['bench', 'gm', 'tests']:
71 for filename in sorted(listfiles(dir, '*.c*')):
72 hasher.update(filename + '\n')
73
74gyp_hash = hasher.hexdigest()
75
76def cat_if_exists(path):
77 if os.path.exists(path):
78 with open(path, 'r') as f:
79 return f.read()
80 return ''
81
82if cat_if_exists(hash_path).strip() != gyp_hash:
83 env = os.environ.copy()
84 if skia_out:
85 env['SKIA_OUT'] = skia_out
86 subprocess.call(['python', './gyp_skia'], env=env)
87 with open(hash_path, 'w') as o:
88 o.write(gyp_hash)