blob: 469c84e8f865ed1dbb4e4e0de8ace9cb22544be1 [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
halcanary117672d2016-02-17 08:39:23 -080026# To retreive and use all optional deps:
27#
28# python bin/sync-and-gyp --deps=all
29# ninja -C out/Debug && out/Debug/dm
30
halcanarya4c26c02015-11-09 08:28:13 -080031import fnmatch
32import hashlib
halcanarya4c26c02015-11-09 08:28:13 -080033import os
halcanary117672d2016-02-17 08:39:23 -080034import subprocess
mtkleindc469ad2016-02-17 06:37:51 -080035import sys
halcanary135b7ec2015-03-27 12:11:49 -070036
halcanarya4c26c02015-11-09 08:28:13 -080037skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
halcanary135b7ec2015-03-27 12:11:49 -070038
halcanarya4c26c02015-11-09 08:28:13 -080039skia_out = os.environ.get("SKIA_OUT")
40if skia_out:
41 skia_out = os.path.abspath(skia_out)
42 hash_path = os.path.join(skia_out, 'gyp_hash')
43else:
44 hash_path = os.path.join('out', 'gyp_hash')
halcanary135b7ec2015-03-27 12:11:49 -070045
halcanarya4c26c02015-11-09 08:28:13 -080046os.chdir(skia_dir)
halcanary135b7ec2015-03-27 12:11:49 -070047
halcanary21736bd2016-04-25 13:34:06 -070048if 0 != subprocess.call(['python', 'bin/sync'] + sys.argv[1:]):
49 sys.stderr.write('sync failed.')
halcanarya4c26c02015-11-09 08:28:13 -080050 exit(1)
halcanary135b7ec2015-03-27 12:11:49 -070051
halcanarya4c26c02015-11-09 08:28:13 -080052hasher = hashlib.sha1()
53
54for var in ['AR', 'AR_host', 'AR_target',
55 'CC', 'CC_host', 'CC_target',
56 'CFLAGS', 'CFLAGS_host',
57 'CPPFLAGS', 'CPPFLAGS_host',
58 'CXX', 'CXX_host', 'CXX_target',
59 'GYP_DEFINES', 'GYP_GENERATORS',
60 'NM', 'NM_host', 'NM_target',
61 'READELF', 'READELF_host', 'READELF_target']:
62 hasher.update(os.environ.get(var, '') + '\n')
63
64def listfiles(folder, matchfilter):
65 for root, folders, files in os.walk(folder):
66 for filename in files:
67 if fnmatch.fnmatch(filename, matchfilter):
68 yield os.path.join(root, filename)
69
70for filename in sorted(listfiles('gyp', '*')):
71 with open(filename, 'r') as f:
72 hasher.update(f.read())
73
halcanary5c4685e2016-04-25 12:39:39 -070074find_dirs = [
75 'bench',
76 'fuzz',
77 'gm',
78 'tests',
79 'third_party/externals/icu/source/common',
halcanary5c4685e2016-04-25 12:39:39 -070080 'third_party/externals/sfntly/sfntly',
81 'third_party/externals/shaderc2',
82 'tools/VisualBench',
83 'tools/gpu',
84 'tools/kilobench',
85 'tools/skiaserve',
86 'tools/skiaserve/urlhandlers',
87 'tools/vulkan',
88]
89
90for dir in find_dirs:
halcanarya4c26c02015-11-09 08:28:13 -080091 for filename in sorted(listfiles(dir, '*.c*')):
92 hasher.update(filename + '\n')
93
94gyp_hash = hasher.hexdigest()
95
96def cat_if_exists(path):
97 if os.path.exists(path):
98 with open(path, 'r') as f:
99 return f.read()
100 return ''
101
102if cat_if_exists(hash_path).strip() != gyp_hash:
103 env = os.environ.copy()
104 if skia_out:
105 env['SKIA_OUT'] = skia_out
106 subprocess.call(['python', './gyp_skia'], env=env)
107 with open(hash_path, 'w') as o:
108 o.write(gyp_hash)