Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: bin/sync-and-gyp

Issue 1425593011: bin/sync-and-gyp: sh->py (make more cross-platform) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-11-06 (Friday) 17:47:08 EST Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/sh 1 #!/usr/bin/env python
2 2
3 # Copyright 2015 Google Inc. 3 # Copyright 2015 Google Inc.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license that can be 5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file. 6 # found in the LICENSE file.
7 7
8 # This script will update Skia's dependenciess as necessary and run 8 # This script will update Skia's dependencies as necessary and run
9 # gyp if needed. 9 # gyp if needed.
10 10
11 # Depends on: Posix-compliant shell, Python, and Git. 11 # Depends on: Python, and Git.
bungeman-skia 2015/11/09 15:30:09 Extra comma. Also, aside from the call to git-sync
12 # 12 #
13 # Example usage: 13 # Example usage:
14 # 14 #
15 # git clone https://skia.googlesource.com/skia 15 # git clone https://skia.googlesource.com/skia
16 # cd skia 16 # cd skia
17 # bin/sync-and-gyp 17 # python bin/sync-and-gyp
18 # ninja -C out/Debug && out/Debug/dm 18 # ninja -C out/Debug && out/Debug/dm
19 # 19 #
20 # Once changes are made to DEPS or gyp/ or the source, call: 20 # Once changes are made to DEPS or gyp/ or the source, call:
21 # 21 #
22 # bin/sync-and-gyp 22 # python bin/sync-and-gyp
23 23
24 if [ "$SKIA_OUT" ]; then 24 import fnmatch
25 mkdir -p "$SKIA_OUT" || exit 25 import hashlib
26 # get non-relative path of $SKIA_OUT before changing directory. 26 import subprocess
27 SKIA_OUT="$(cd "$SKIA_OUT"; pwd)" 27 import os
28 fi
29 28
30 cd "$(dirname "$0")/.." 29 skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
31 30
32 if ! [ -f DEPS ]; then 31 skia_out = os.environ.get("SKIA_OUT")
33 echo DEPS file missing >&2 32 if skia_out:
34 exit 1 33 skia_out = os.path.abspath(skia_out)
35 fi 34 else:
35 skia_out = 'out'
mtklein 2015/11/09 15:14:20 Seems like we'd want to abspath this too?
hal.canary 2015/11/09 15:21:51 No need. It will be relative to `skia_dir`.
36 36
37 GIT_SYNC_DEPS_QUIET=1 python tools/git-sync-deps || exit 37 os.chdir(skia_dir)
38 38
39 catifexists() { if [ -f "$1" ]; then cat "$1"; fi; } 39 if not os.path.isfile('DEPS'):
40 sys.stderr.write('DEPS file missing')
41 exit(1)
40 42
41 gyp_hasher() { 43 env = os.environ.copy()
42 { 44 env["GIT_SYNC_DEPS_QUIET"] = "1"
43 echo "$CC" 45 subprocess.call(['python', 'tools/git-sync-deps'], env=env)
44 echo "$CXX"
45 echo "$GYP_GENERATORS"
46 echo "$GYP_DEFINES"
47 find gyp -type f -print -exec git hash-object {} \;
48 find bench gm tests -name '*.c*' | LANG= sort
49 } | git hash-object --stdin
50 }
51 46
52 : ${SKIA_OUT:=out} 47 hasher = hashlib.sha1()
53 GYP_HASH=$(gyp_hasher) 48
54 HASH_PATH="${SKIA_OUT}/gyp_hash" 49 for var in ['CC', 'CXX', 'GYP_GENERATORS', 'GYP_DEFINES']:
mtklein 2015/11/09 15:14:20 Might add in CFLAGS, CPPFLAGS, CXXFLAGS? (Alterna
hal.canary 2015/11/09 15:21:51 Does gyp respect those? If so, yes.
bungeman-skia 2015/11/09 15:30:08 The environment variables which at least the ninja
55 if [ "$GYP_HASH" != "$(catifexists "$HASH_PATH")" ]; then 50 hasher.update(os.environ.get(var, '') + '\n')
56 python ./gyp_skia || exit 51
57 echo "$GYP_HASH" > "$HASH_PATH" 52 def listfiles(folder, filter):
58 fi 53 for root, folders, files in os.walk(folder):
54 for filename in folders + files:
55 if fnmatch.fnmatch(filename, filter):
56 yield os.path.join(root, filename)
57
58 for filename in sorted(listfiles('gyp', '*')):
59 with open(filename, 'r') as f:
60 hasher.update(f.read())
bungeman-skia 2015/11/09 15:30:08 It seems unfortunate to need to read the content,
hal.canary 2015/11/09 16:16:26 I don't have a better solution. How does git do t
61
62 for dir in ['bench', 'gm', 'tests']:
mtklein 2015/11/09 15:14:20 Think it makes sense to generalize this to all dir
bungeman-skia 2015/11/09 15:30:08 It does seem unfortunate that this file needs to b
mtklein 2015/11/09 15:36:55 Being able to skip re-Gyping Skia on Windows seems
63 for filename in sorted(listfiles(dir, '*.c*')):
64 hasher.update(filename + '\n')
65
66 gyp_hash = hasher.hexdigest()
67
68 hash_path = os.path.join(skia_out, 'gyp_hash')
69
70 def cat_if_exists(path):
71 if os.path.exists(path):
72 with open(path, 'r') as f:
73 return f.read()
74 return ''
75
76 if cat_if_exists(hash_path).strip() != gyp_hash:
77 env = os.environ.copy()
78 env['SKIA_OUT'] = skia_out
bungeman-skia 2015/11/09 15:30:08 Before this created this directory, but this no lo
hal.canary 2015/11/09 16:16:26 I created the directory because $(cd "$dir"; pwd)
79 subprocess.call(['python', './gyp_skia'], env=env)
80 with open(hash_path, 'w') as o:
81 o.write(gyp_hash)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698