1# Copyright (c) 2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/config/clang/clang.gni") 15import("//build/ohos.gni") 16 17ace_root = "//foundation/arkui/ace_engine" 18is_ohos_standard_system = is_standard_system && !is_arkui_x 19use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64" 20use_mac = "${current_os}_${current_cpu}" == "mac_x64" || 21 "${current_os}_${current_cpu}" == "mac_arm64" 22use_ios = "${current_os}_${current_cpu}" == "ios_x64" || 23 "${current_os}_${current_cpu}" == "ios_arm64" 24use_linux = "${current_os}_${current_cpu}" == "linux_x64" 25windows_buildtool = "//build/toolchain/mingw:mingw_x86_64" 26 27if (!defined(default_aosp_source_dir)) { 28 default_aosp_source_dir = "/" 29} 30objcopy_default = "${default_aosp_source_dir}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin/objcopy" 31objcopy_mingw = "${default_aosp_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy" 32objcopy_x86_64 = "${default_clang_base_path}/bin/llvm-objcopy" 33if ("${current_os}_${current_cpu}" == "mac_arm64") { 34 mac_buildtool = "//build/toolchain/mac:clang_arm64" 35} else if ("${current_os}_${current_cpu}" == "mac_x64") { 36 mac_buildtool = "//build/toolchain/mac:clang_x64" 37} 38objcopy_clang = "$clang_base_path/bin/llvm-objcopy" 39if (is_ohos_standard_system) { 40 objcopy_default = "//prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy" 41} else if (is_arkui_x) { 42 if (host_os == "mac") { 43 objcopy_default = objcopy_clang 44 } else if (defined(aosp_objcopy)) { 45 objcopy_default = aosp_objcopy 46 } 47} 48 49template("gen_obj") { 50 name = target_name 51 action("gen_obj_" + name) { 52 visibility = [ ":*" ] # Only targets in this file can depend on this. 53 54 if (use_mingw_win) { 55 objcopy_tool = objcopy_mingw 56 script = "$ace_root/build/tools/build_resource_to_bytecode.py" 57 } else if (use_mac || target_os == "ios") { 58 objcopy_tool = objcopy_clang 59 script = "$ace_root/build/tools/build_resource_to_bytecode.py" 60 } else if (use_linux) { 61 objcopy_tool = objcopy_x86_64 62 script = "$ace_root/build/tools/build_resource_to_bytecode.py" 63 } else if (target_cpu == "x86_64") { 64 objcopy_tool = objcopy_x86_64 65 script = "$ace_root/build/tools/run_objcopy.py" 66 } else { 67 objcopy_tool = objcopy_default 68 script = "$ace_root/build/tools/run_objcopy.py" 69 } 70 71 args = [ 72 "--objcopy", 73 rebase_path(objcopy_tool), 74 "--input", 75 rebase_path(invoker.input), 76 "--output", 77 rebase_path(invoker.output), 78 "--arch", 79 current_cpu, 80 ] 81 82 deps = [] 83 deps += invoker.snapshot_dep 84 85 inputs = [ invoker.input ] 86 outputs = [ invoker.output ] 87 } 88 89 source_set("gen_obj_src_" + name) { 90 sources = [ invoker.output ] 91 deps = [ ":gen_obj_" + name ] 92 } 93} 94