You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 regels
2.5 KiB

  1. # Copyright (c) 2015, Google Inc.
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. import os.path
  15. import shutil
  16. import sys
  17. import tarfile
  18. import tempfile
  19. import urllib
  20. # CLANG_REVISION and CLANG_SUB_REVISION determine the build of clang
  21. # to use. These should be synced with tools/clang/scripts/update.py in
  22. # Chromium.
  23. CLANG_REVISION = "284979"
  24. CLANG_SUB_REVISION = "1"
  25. PACKAGE_VERSION = "%s-%s" % (CLANG_REVISION, CLANG_SUB_REVISION)
  26. LLVM_BUILD_DIR = os.path.join(os.path.dirname(__file__), "llvm-build")
  27. STAMP_FILE = os.path.join(LLVM_BUILD_DIR, "cr_build_revision")
  28. CDS_URL = "https://commondatastorage.googleapis.com/chromium-browser-clang"
  29. def DownloadFile(url, path):
  30. """DownloadFile fetches |url| to |path|."""
  31. last_progress = [0]
  32. def report(a, b, c):
  33. progress = int(a * b * 100.0 / c)
  34. if progress != last_progress[0]:
  35. print >> sys.stderr, "Downloading... %d%%" % progress
  36. last_progress[0] = progress
  37. urllib.urlretrieve(url, path, reporthook=report)
  38. def main(args):
  39. # For now, only download clang on Linux.
  40. if not sys.platform.startswith("linux"):
  41. return 0
  42. if os.path.exists(STAMP_FILE):
  43. with open(STAMP_FILE) as f:
  44. if f.read().strip() == PACKAGE_VERSION:
  45. print >> sys.stderr, "Clang already at %s" % (PACKAGE_VERSION,)
  46. return 0
  47. if os.path.exists(LLVM_BUILD_DIR):
  48. shutil.rmtree(LLVM_BUILD_DIR)
  49. print >> sys.stderr, "Downloading Clang %s" % (PACKAGE_VERSION,)
  50. cds_full_url = "%s/Linux_x64/clang-%s.tgz" % (CDS_URL, PACKAGE_VERSION)
  51. with tempfile.NamedTemporaryFile() as temp:
  52. DownloadFile(cds_full_url, temp.name)
  53. with tarfile.open(temp.name, "r:gz") as tar_file:
  54. tar_file.extractall(LLVM_BUILD_DIR)
  55. with open(STAMP_FILE, "wb") as stamp_file:
  56. stamp_file.write(PACKAGE_VERSION)
  57. return 0
  58. if __name__ == "__main__":
  59. sys.exit(main(sys.argv[1:]))