aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-01-13 13:49:18 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-30 16:22:22 +0000
commit7f660e84189adc92b1996b4b2e0f5a1ad897dff9 (patch)
treefb961ad0fede10261599e8ae108426f5ed84b0f5 /bin
parent877b15b301d798a0eb7aeb9ad36db383ef63ace9 (diff)
bin/fetch-gn is 3.5x faster
Change-Id: I8098a38eb81efe0a73201c1f00dff8363b9c2075 Reviewed-on: https://skia-review.googlesource.com/7025 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fetch-gn32
1 files changed, 22 insertions, 10 deletions
diff --git a/bin/fetch-gn b/bin/fetch-gn
index 16e287513e..d5de7e4fd6 100755
--- a/bin/fetch-gn
+++ b/bin/fetch-gn
@@ -5,25 +5,37 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import hashlib
import os
import shutil
import stat
import sys
import urllib2
-def gn_path():
- if 'linux' in sys.platform:
- return 'buildtools/linux64/gn'
- if 'darwin' in sys.platform:
- return 'buildtools/mac/gn'
- return 'buildtools/win/gn.exe'
+os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
-sha1 = open(gn_path() + '.sha1').read()
+gn_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
+ 'buildtools/mac/gn' if 'darwin' in sys.platform else \
+ 'buildtools/win/gn.exe'
-with open(gn_path(), 'wb') as f:
+sha1 = open(gn_path + '.sha1').read().strip()
+
+def sha1_of_file(path):
+ h = hashlib.sha1()
+ if os.path.isfile(path):
+ with open(path, 'rb') as f:
+ h.update(f.read())
+ return h.hexdigest()
+
+if sha1_of_file(gn_path) != sha1:
+ with open(gn_path, 'wb') as f:
f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
-os.chmod(gn_path(), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
+ os.chmod(gn_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
stat.S_IRGRP | stat.S_IXGRP |
stat.S_IROTH | stat.S_IXOTH )
-shutil.copy(gn_path(), 'bin');
+
+gn_copy_path = os.path.join('bin', os.path.basename(gn_path))
+if sha1_of_file(gn_copy_path) != sha1:
+ shutil.copy(gn_path, gn_copy_path)
+