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 16script_path=$(cd $(dirname $0);pwd) 17code_dir=$(dirname ${script_path}) 18home_path=$HOME 19config_file="$script_path/prebuilts_config.json" 20# 获取当前系统类型和CPU类型 21target_os=$(uname -s | tr '[:upper:]' '[:lower:]') 22target_cpu=$(uname -m | tr '[:upper:]' '[:lower:]') 23 24# 运行Python命令 25python3 "${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 26 27if [[ "${target_os}" == "linux" ]]; then 28 sed -i "1s%.*%#!/usr/bin/env python3%" ${code_dir}/prebuilts/python/${target_os}-x86/3.10.2/bin/pip3.10 29elif [[ "${target_os}" == "darwin" ]]; then 30 sed -i "" "1s%.*%#!/use/bin/env python3%" ${code_dir}/prebuilts/python/${target_os}-x86/3.10.2/bin/pip3.10 31fi 32 33# llvm_ndk is merged form llvm and libcxx-ndk for compiling the native of hap 34llvm_dir="${code_dir}/prebuilts/clang/ohos/linux-x86_64" 35llvm_dir_win="${code_dir}/prebuilts/clang/ohos/windows-x86_64" 36llvm_dir_mac_x86="${code_dir}/prebuilts/clang/ohos/darwin-x86_64" 37llvm_dir_mac_arm64="${code_dir}/prebuilts/clang/ohos/darwin-arm64" 38llvm_dir_list=($llvm_dir $llvm_dir_win $llvm_dir_mac_x86 $llvm_dir_mac_arm64) 39 40# copy libcxx-ndk library outside c++ 41function copy_inside_cxx(){ 42for i in ${llvm_dir_list[@]} 43do 44 libcxx_dir="${i}/libcxx-ndk/lib" 45 if [[ -d "${i}/libcxx-ndk" ]]; then 46 for file in $(ls ${libcxx_dir}) 47 do 48 if [ ! -d "${libcxx_dir}/${file}/c++" ];then 49 $(mkdir -p ${libcxx_dir}/c++) 50 $(cp -r ${libcxx_dir}/${file}/* ${libcxx_dir}/c++) 51 $(mv ${libcxx_dir}/c++ ${libcxx_dir}/${file}/c++) 52 fi 53 done 54 fi 55done 56} 57 58function update_llvm_ndk(){ 59if [[ -e "${llvm_dir}/llvm_ndk" ]];then 60 rm -rf "${llvm_dir}/llvm_ndk" 61fi 62mkdir -p "${llvm_dir}/llvm_ndk" 63cp -af "${llvm_dir}/llvm/include" "${llvm_dir}/llvm_ndk" 64cp -rfp "${llvm_dir}/libcxx-ndk/include" "${llvm_dir}/llvm_ndk" 65} 66 67function change_rustlib_name(){ 68rust_dir="${code_dir}/prebuilts/rustc/linux-x86_64/current/lib/rustlib/" 69for file in $(find "$rust_dir" -path "$rust_dir/x86_64-unknown-linux-gnu" -prune -o -name "lib*.*") 70do 71 dir_name=${file%/*} 72 file_name=${file##*/} 73 file_prefix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[1]}') 74 file_prefix=$(echo "$file_prefix" | awk '{split($1, arr, "-"); print arr[1]}') 75 file_suffix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[2]}') 76 if [[ "$file_suffix" != "rlib" && "$file_suffix" != "so" || "$file_prefix" == "librustc_demangle" || "$file_prefix" == "libcfg_if" || "$file_prefix" == "libunwind" ]] 77 then 78 continue 79 fi 80 if [[ "$file_suffix" == "rlib" ]] 81 then 82 if [[ "$file_prefix" == "libstd" || "$file_prefix" == "libtest" ]] 83 then 84 newfile_name="$file_prefix.dylib.rlib" 85 else 86 newfile_name="$file_prefix.rlib" 87 fi 88 fi 89 90 if [[ "$file_suffix" == "so" ]] 91 then 92 newfile_name="$file_prefix.dylib.so" 93 fi 94 if [[ "$file_name" == "$newfile_name" ]] 95 then 96 continue 97 fi 98 mv $file "$dir_name/$newfile_name" 99done 100} 101 102copy_inside_cxx 103echo "======copy inside cxx finished!======" 104