1#!/bin/bash 2# Copyright (c) 2025 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. 14 15set -e 16 17function prebuilt_sdk() { 18 local source_root_dir="$1" 19 local python_dir="$2" 20 local current_platform="$3" 21 local ccache_args="$4" 22 local xcache_args="$5" 23 local api_version="$6" 24 local generate_sbom="$7" 25 shift 7 26 local _sdk_gn_args=("$@") 27 28 local ROOT_PATH="${source_root_dir}" 29 local SDK_PREBUILTS_PATH="${ROOT_PATH}/prebuilts/ohos-sdk" 30 local SDK_BUILD_REQUIRED=false 31 32 sbom_gn_args=() 33 if [[ "${generate_sbom}" == "true" ]]; then 34 sbom_gn_args+=("--gn-flags=--ide=json") 35 sbom_gn_args+=("--gn-flags=--json-file-name=sbom/gn_gen.json") 36 fi 37 38 pushd "${ROOT_PATH}" > /dev/null || { 39 echo -e "\033[31m[OHOS ERROR] Failed to enter directory: ${ROOT_PATH}\033[0m" 40 exit 1 41 } 42 echo -e "[OHOS INFO] Building the latest ohos-sdk..." 43 ./build.py --product-name ohos-sdk \ 44 --python-dir ${python_dir} \ 45 ${ccache_args} \ 46 ${xcache_args} \ 47 --load-test-config=false \ 48 --get-warning-list=false \ 49 --stat-ccache=false \ 50 --compute-overlap-rate=false \ 51 --deps-guard=false \ 52 --generate-ninja-trace=false \ 53 --sbom=${generate_sbom} \ 54 ${sbom_gn_args[@]} \ 55 --gn-args "skip_generate_module_list_file=true sdk_platform=${current_platform} ndk_platform=${current_platform} use_cfi=false use_thin_lto=false enable_lto_O0=true sdk_check_flag=false enable_ndk_doxygen=false archive_ndk=false sdk_for_hap_build=true enable_archive_sdk=false enable_notice_collection=false enable_process_notice=false ${_sdk_gn_args[*]}" 56 if [[ "$?" -ne 0 ]]; then 57 echo -e "\033[31m[OHOS ERROR] ohos-sdk build failed! Try using '--no-prebuilts-sdk' to skip.\033[0m" 58 exit 1 59 fi 60 [[ -d "${ROOT_PATH}/prebuilts/ohos-sdk/linux" ]] && rm -rf "${ROOT_PATH}/prebuilts/ohos-sdk/linux" 61 mkdir -p "${SDK_PREBUILTS_PATH}" 62 mv "${ROOT_PATH}/out/sdk/ohos-sdk/linux" "${SDK_PREBUILTS_PATH}/" 63 mkdir -p "${SDK_PREBUILTS_PATH}/linux/native" 64 mv "${ROOT_PATH}/out/sdk/sdk-native/os-irrelevant/"* "${SDK_PREBUILTS_PATH}/linux/native/" 65 mv "${ROOT_PATH}/out/sdk/sdk-native/os-specific/linux/"* "${SDK_PREBUILTS_PATH}/linux/native/" 66 pushd "${SDK_PREBUILTS_PATH}/linux" > /dev/null 67 mkdir -p "${api_version}" 68 for dir in */; do 69 [[ -d "${dir}" && "${dir}" != "${api_version}/" ]] && mv "${dir}" "${api_version}/" 70 done 71 popd > /dev/null 72 popd > /dev/null 73 local target_dir="${source_root_dir}/prebuilts/ohos-sdk/linux/${api_version}/previewer" 74 [[ ! -d "${target_dir}" ]] && mkdir -p "${target_dir}" 75 cp -r "${source_root_dir}/prebuilts/ohos-sdk/linux/${api_version}/native/oh-uni-package.json" "${target_dir}/" 2>/dev/null 76 sed -i 's/Native/Previewer/g' "${target_dir}/oh-uni-package.json" 2>/dev/null 77 sed -i 's/native/previewer/g' "${target_dir}/oh-uni-package.json" 2>/dev/null 78 if [[ -d "${source_root_dir}/prebuilts/ohos-sdk-12/ohos-sdk/linux/12" ]]; then 79 mkdir -p "${source_root_dir}/prebuilts/ohos-sdk/linux/12" 80 mv "${source_root_dir}/prebuilts/ohos-sdk-12/ohos-sdk/linux/12/"* "${source_root_dir}/prebuilts/ohos-sdk/linux/12/" 81 fi 82 if [[ "$?" -ne 0 ]]; then 83 echo -e "\033[31m[OHOS ERROR] ohos-sdk post-processing failed!\033[0m" 84 exit 1 85 fi 86 87} 88 89function main() { 90 if [[ $# -lt 6 ]]; then 91 echo "Usage: $0 <source_root_dir> <ccache_args> <xcache_args> <api_version> <api_version> [prebuilt_sdk_gn_args...]" 92 exit 1 93 fi 94 95 local source_root_dir="$1" 96 local python_dir="$2" 97 local current_platform="$3" 98 local ccache_args="$4" 99 local xcache_args="$5" 100 local api_version="$6" 101 shift 6 102 103 local _sdk_gn_args=("$@") 104 105 prebuilt_sdk \ 106 "${source_root_dir}" \ 107 "${python_dir}" \ 108 "${current_platform}" \ 109 "${ccache_args}" \ 110 "${xcache_args}" \ 111 "${api_version}" \ 112 "${_sdk_gn_args[@]}" 113} 114 115if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then 116 main "$@" 117fi