1#!/usr/bin/env python 2# Copyright 2017 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Script to download llvm-objdump and related utils from google storage.""" 7 8import os 9import re 10import subprocess 11import sys 12import urllib2 13 14import update 15 16LLVM_BUILD_DIR = update.LLVM_BUILD_DIR 17OBJDUMP_PATH = os.path.join(LLVM_BUILD_DIR, 'bin', 'llvm-objdump') 18STAMP_FILE = os.path.normpath( 19 os.path.join(LLVM_BUILD_DIR, 'llvmobjdump_build_revision')) 20 21 22def AlreadyUpToDate(): 23 if not os.path.exists(OBJDUMP_PATH) or not os.path.exists(STAMP_FILE): 24 return False 25 stamp = update.ReadStampFile(STAMP_FILE) 26 return stamp.rstrip() == update.PACKAGE_VERSION 27 28 29def DownloadAndUnpackLlvmObjDumpPackage(platform): 30 cds_file = 'llvmobjdump-%s.tgz' % update.PACKAGE_VERSION 31 cds_full_url = update.GetPlatformUrlPrefix(platform) + cds_file 32 try: 33 update.DownloadAndUnpack(cds_full_url, update.LLVM_BUILD_DIR) 34 except urllib2.URLError: 35 print 'Failed to download prebuilt utils %s' % cds_file 36 print 'Use --force-local-build if you want to build locally.' 37 print 'Exiting.' 38 sys.exit(1) 39 40 41def main(): 42 if not AlreadyUpToDate(): 43 DownloadAndUnpackLlvmObjDumpPackage(sys.platform) 44 return 0 45 46if __name__ == '__main__': 47 sys.exit(main()) 48