• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git a/bin/fetch-gn b/bin/fetch-gn
2index d5e94a2..59c4591 100755
3--- a/bin/fetch-gn
4+++ b/bin/fetch-gn
5@@ -5,39 +5,44 @@
6 # Use of this source code is governed by a BSD-style license that can be
7 # found in the LICENSE file.
8
9-import hashlib
10 import os
11+import platform
12 import shutil
13 import stat
14 import sys
15-import urllib2
16+import tempfile
17+import zipfile
18+
19+if sys.version_info[0] < 3:
20+  from urllib2 import urlopen
21+else:
22+  from urllib.request import urlopen
23
24 os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
25
26-dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
27+gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip')
28+with open(gnzip, 'wb') as f:
29+  OS  = {'darwin': 'mac', 'linux': 'linux', 'linux2': 'linux', 'win32': 'windows'}[sys.platform]
30+  cpu = {'amd64': 'amd64', 'arm64': 'arm64', 'x86_64': 'amd64', 'aarch64': 'arm64'}[platform.machine().lower()]
31
32-sha1 = '2f27ff0b6118e5886df976da5effa6003d19d1ce' if 'linux'  in sys.platform else \
33-       '9be792dd9010ce303a9c3a497a67bcc5ac8c7666' if 'darwin' in sys.platform else \
34-       'eb69be2d984b4df60a8c21f598135991f0ad1742'  # Windows
35+  rev = 'd62642c920e6a0d1756316d225a90fd6faa9e21e'
36+  url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}-{}/+/git_revision:{}'.format(
37+          OS,cpu,rev)
38+  f.write(urlopen(url).read())
39
40-def sha1_of_file(path):
41-  h = hashlib.sha1()
42-  if os.path.isfile(path):
43-    with open(path, 'rb') as f:
44-      h.update(f.read())
45-  return h.hexdigest()
46+gn = 'gn.exe' if 'win32' in sys.platform else 'gn'
47+with zipfile.ZipFile(gnzip, 'r') as f:
48+  f.extract(gn, 'bin')
49
50-if sha1_of_file(dst) != sha1:
51-  with open(dst, 'wb') as f:
52-    f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
53+gn = os.path.join('bin', gn)
54
55-  os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
56-                stat.S_IRGRP                | stat.S_IXGRP |
57-                stat.S_IROTH                | stat.S_IXOTH )
58+os.chmod(gn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
59+             stat.S_IRGRP                | stat.S_IXGRP |
60+             stat.S_IROTH                | stat.S_IXOTH )
61
62 # We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
63 copy_path = 'buildtools/linux64/gn' if 'linux'  in sys.platform else \
64             'buildtools/mac/gn'     if 'darwin' in sys.platform else \
65             'buildtools/win/gn.exe'
66 if os.path.isdir(os.path.dirname(copy_path)):
67-  shutil.copy(dst, copy_path)
68+  shutil.copy(gn, copy_path)
69