1#!/bin/bash 2# Copyright (c) 2024 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14set -e 15 16 17script_path=$(cd $(dirname $0);pwd) 18code_dir=$(dirname ${script_path}) 19home_path=$HOME 20config_file="$script_path/prebuilts_config.json" 21# 获取当前系统类型和CPU类型 22target_os=$(uname -s | tr '[:upper:]' '[:lower:]') 23target_cpu=$(uname -m | tr '[:upper:]' '[:lower:]') 24 25# 运行Python命令 26python3 "${script_path}/prebuilts_config.py" --code_path $code_dir --home_path $home_path --config_file $config_file --repo_https https://repo.huaweicloud.com --target_os $target_os --target_cpu $target_cpu 27 28PYTHON_PATH=$(realpath ${code_dir}/prebuilts/python/${target_os}-*/*/bin | tail -1) 29 30while [ $# -gt 0 ]; do 31 case "$1" in 32 --download-sdk) # Download the SDK if this flag is set 33 DOWNLOAD_SDK=YES 34 ;; 35 *) 36 echo "$0: Warning: unsupported parameter: $1" >&2 37 ;; 38 esac 39 shift 40done 41 42if [[ "$DOWNLOAD_SDK" == "YES" ]] && [[ ! -d "${code_dir}/prebuilts/ohos-sdk/linux" ]]; then 43 $PYTHON_PATH/python3 ${code_dir}/build/scripts/download_sdk.py --branch master --product-name ohos-sdk-full-linux --api-version 18 44fi 45 46 47 48if [[ "${target_os}" == "linux" ]]; then 49 sed -i "1s%.*%#!/usr/bin/env python3%" "${PYTHON_PATH}/pip3" 50elif [[ "${target_os}" == "darwin" ]]; then 51 sed -i "" "1s%.*%#!/usr/bin/env python3%" "${PYTHON_PATH}/pip3" 52fi 53 54# llvm_ndk is merged form llvm and libcxx-ndk for compiling the native of hap 55llvm_dir="${code_dir}/prebuilts/clang/ohos/linux-x86_64" 56llvm_dir_win="${code_dir}/prebuilts/clang/ohos/windows-x86_64" 57llvm_dir_mac_x86="${code_dir}/prebuilts/clang/ohos/darwin-x86_64" 58llvm_dir_mac_arm64="${code_dir}/prebuilts/clang/ohos/darwin-arm64" 59llvm_dir_list=($llvm_dir $llvm_dir_win $llvm_dir_mac_x86 $llvm_dir_mac_arm64) 60 61# copy libcxx-ndk library outside c++ 62function copy_inside_cxx(){ 63for i in ${llvm_dir_list[@]} 64do 65 libcxx_dir="${i}/libcxx-ndk/lib" 66 if [[ -d "${i}/libcxx-ndk" ]]; then 67 for file in $(ls ${libcxx_dir}) 68 do 69 if [ ! -d "${libcxx_dir}/${file}/c++" ];then 70 $(mkdir -p ${libcxx_dir}/c++) 71 $(cp -r ${libcxx_dir}/${file}/* ${libcxx_dir}/c++) 72 $(mv ${libcxx_dir}/c++ ${libcxx_dir}/${file}/c++) 73 fi 74 done 75 fi 76done 77} 78 79function update_llvm_ndk(){ 80if [[ -e "${llvm_dir}/llvm_ndk" ]];then 81 rm -rf "${llvm_dir}/llvm_ndk" 82fi 83mkdir -p "${llvm_dir}/llvm_ndk" 84cp -af "${llvm_dir}/llvm/include" "${llvm_dir}/llvm_ndk" 85cp -rfp "${llvm_dir}/libcxx-ndk/include" "${llvm_dir}/llvm_ndk" 86} 87 88function change_rustlib_name(){ 89rust_dir="${code_dir}/prebuilts/rustc/linux-x86_64/current/lib/rustlib/" 90for file in $(find "$rust_dir" -path "$rust_dir/x86_64-unknown-linux-gnu" -prune -o -name "lib*.*") 91do 92 dir_name=${file%/*} 93 file_name=${file##*/} 94 file_prefix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[1]}') 95 file_prefix=$(echo "$file_prefix" | awk '{split($1, arr, "-"); print arr[1]}') 96 file_suffix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[2]}') 97 if [[ "$file_suffix" != "rlib" && "$file_suffix" != "so" || "$file_prefix" == "librustc_demangle" || "$file_prefix" == "libcfg_if" || "$file_prefix" == "libunwind" ]] 98 then 99 continue 100 fi 101 if [[ "$file_suffix" == "rlib" ]] 102 then 103 if [[ "$file_prefix" == "libstd" || "$file_prefix" == "libtest" ]] 104 then 105 newfile_name="$file_prefix.dylib.rlib" 106 else 107 newfile_name="$file_prefix.rlib" 108 fi 109 fi 110 111 if [[ "$file_suffix" == "so" ]] 112 then 113 newfile_name="$file_prefix.dylib.so" 114 fi 115 if [[ "$file_name" == "$newfile_name" ]] 116 then 117 continue 118 fi 119 mv $file "$dir_name/$newfile_name" 120done 121} 122copy_inside_cxx 123echo "======copy inside cxx finished!======" 124