fetch-gn 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. # Copyright 2016 Google Inc.
  3. #
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. import hashlib
  7. import os
  8. import shutil
  9. import stat
  10. import sys
  11. import urllib2
  12. os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
  13. dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
  14. sha1 = '2f27ff0b6118e5886df976da5effa6003d19d1ce' if 'linux' in sys.platform else \
  15. '9be792dd9010ce303a9c3a497a67bcc5ac8c7666' if 'darwin' in sys.platform else \
  16. 'eb69be2d984b4df60a8c21f598135991f0ad1742' # Windows
  17. def sha1_of_file(path):
  18. h = hashlib.sha1()
  19. if os.path.isfile(path):
  20. with open(path, 'rb') as f:
  21. h.update(f.read())
  22. return h.hexdigest()
  23. if sha1_of_file(dst) != sha1:
  24. with open(dst, 'wb') as f:
  25. f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
  26. os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
  27. stat.S_IRGRP | stat.S_IXGRP |
  28. stat.S_IROTH | stat.S_IXOTH )
  29. # We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
  30. copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
  31. 'buildtools/mac/gn' if 'darwin' in sys.platform else \
  32. 'buildtools/win/gn.exe'
  33. if os.path.isdir(os.path.dirname(copy_path)):
  34. shutil.copy(dst, copy_path)