aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/sync-and-gyp
blob: 80dead97583504399f7cbe32b5692482eba1dbd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python

# Copyright 2015 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script will update Skia's dependencies as necessary and run
# gyp if needed.

# Depends on: Python, and Git.
#
# Example usage:
#
#   git clone https://skia.googlesource.com/skia
#   cd skia
#   python bin/sync-and-gyp
#   ninja -C out/Debug && out/Debug/dm
#
# Once changes are made to DEPS or gyp/ or the source, call:
#
#   python bin/sync-and-gyp

import fnmatch
import hashlib
import subprocess
import os

skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)

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)

env = os.environ.copy()
env["GIT_SYNC_DEPS_QUIET"] = "1"
subprocess.call(['python', 'tools/git-sync-deps'], env=env)

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)