1#!/usr/bin/env python 2# 3# Copyright (C) 2015 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17"""Packages the platform's LLVM for the NDK.""" 18import os 19import site 20import subprocess 21import sys 22 23site.addsitedir(os.path.join(os.path.dirname(__file__), '../lib')) 24 25import build_support # pylint: disable=import-error 26 27 28def get_llvm_prebuilt_path(host): 29 rel_prebuilt_path = 'prebuilts/clang/host/{}'.format(host) 30 prebuilt_path = os.path.join(build_support.android_path(), 31 rel_prebuilt_path) 32 if not os.path.isdir(prebuilt_path): 33 sys.exit('Could not find prebuilt LLVM at {}'.format(prebuilt_path)) 34 return prebuilt_path 35 36 37def main(args): 38 LLVM_VERSION = 'clang-2481030' 39 40 host = args.host 41 package_dir = args.dist_dir 42 43 # TODO(danalbert): Fix 64-bit Windows LLVM. 44 # This wrongly packages 32-bit Windows LLVM for 64-bit as well, but the 45 # real bug here is that we don't have a 64-bit Windows LLVM. 46 # http://b/22414702 47 os_name = host 48 if os_name == 'windows64': 49 os_name = 'windows' 50 prebuilt_path = get_llvm_prebuilt_path(os_name + '-x86') 51 52 if host == 'darwin': 53 host = 'darwin-x86_64' 54 elif host == 'linux': 55 host = 'linux-x86_64' 56 elif host == 'windows': 57 host = 'windows' 58 elif host == 'windows64': 59 host = 'windows-x86_64' 60 61 package_name = 'llvm-{}.zip'.format(host) 62 package_path = os.path.join(package_dir, package_name) 63 if os.path.exists(package_path): 64 os.unlink(package_path) 65 os.chdir(prebuilt_path) 66 args = ['zip', '-9qr', package_path, LLVM_VERSION] 67 if not host.startswith('windows'): 68 args.append('--symlinks') 69 subprocess.check_call(args) 70 71if __name__ == '__main__': 72 build_support.run(main) 73