1# Copyright (C) 2025 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. 13import("//build/test.gni") 14 15adlt_llvm_bin = "$musl_adlt_llvm/bin" 16adlt_llvm_ld = "$adlt_llvm_bin/ld.lld" 17adlt_llvm_readelf = "$adlt_llvm_bin/llvm-readelf" 18 19adlt_abs_runtime_clang_path = rebase_path(default_runtime_clang_path, "") 20 21adlt_unstripped_lib_dir = "${root_build_dir}/lib.unstripped/musl/libc-test-lib" 22adlt_bin_dir = "${root_build_dir}/musl/libc-test" 23adlt_lib_dir = "${root_build_dir}/musl/libc-test-lib" 24adlt_moved_lib_dir = "$adlt_lib_dir/adlt_orig_libs" 25 26adlt_target_bin_dir = "/data/local/tmp/libc-test" 27adlt_target_lib_dir = "/data/local/tmp/libc-test-lib" 28 29template("adlt_shared_library") { 30 foreach(cfg, invoker.lib_configs) { 31 ohos_shared_library(cfg.name) { 32 output_name = "libadlt_${cfg.name}" 33 output_extension = "so" 34 35 subsystem_name = "musl" 36 part_name = "libc-test-lib" 37 testonly = true 38 39 forward_variables_from(cfg, "*", [ "name", "configs", "include_dirs", "asmflags", "cflags", "ldflags" ]) 40 41 if (defined(deps)) { 42 deps += [ 43 "//third_party/musl/libc-test/src/functionalext/adlt:adlt_build_syms", 44 "//third_party/musl/libc-test/src/functionalext/adlt:adlt_common", 45 ] 46 } 47 48 configs = [] 49 if (defined(invoker.configs)) { 50 configs += invoker.configs 51 } 52 53 if (defined(cfg.configs)) { 54 configs += cfg.configs 55 } 56 57 include_dirs = [] 58 if (defined(invoker.include_dirs)) { 59 include_dirs += invoker.include_dirs 60 } 61 62 if (defined(cfg.include_dirs)) { 63 include_dirs += cfg.include_dirs 64 } 65 66 asmflags = [] 67 if (defined(invoker.asmflags)) { 68 asmflags += invoker.asmflags 69 } 70 71 if (defined(cfg.asmflags)) { 72 asmflags += cfg.asmflags 73 } 74 75 cflags = [] 76 if (defined(invoker.cflags)) { 77 cflags += invoker.cflags 78 } 79 80 if (defined(cfg.cflags)) { 81 cflags += cfg.cflags 82 } 83 84 ldflags = [ "-Wl,--emit-relocs", "-Wl,--no-relax" ] 85 if (defined(invoker.ldflags)) { 86 ldflags += invoker.ldflags 87 } 88 89 if (defined(cfg.ldflags)) { 90 ldflags += cfg.ldflags 91 } 92 } 93 } 94 95 action(target_name) { 96 testonly = true 97 deps = [] 98 sources = [] 99 foreach(cfg, invoker.lib_configs) { 100 deps += [ ":${cfg.name}" ] 101 sources += [ "$adlt_unstripped_lib_dir/libadlt_${cfg.name}.so" ] 102 } 103 104 script = adlt_llvm_ld 105 outputs = [ "$adlt_lib_dir/libadlt_$target_name.so" ] 106 args = [ "--adlt", "-o" ] + rebase_path(outputs, "") + rebase_path(sources, "") 107 } 108} 109 110template("adlt_executable") { 111 adlt_shared_library(invoker.lib_name) { 112 lib_configs = invoker.lib_configs 113 114 if (defined(invoker.lib_include_dirs)) { 115 include_dirs = invoker.lib_include_dirs 116 } 117 118 if (defined(invoker.lib_common_configs)) { 119 configs = invoker.lib_common_configs 120 } 121 122 if (defined(invoker.lib_asmflags)) { 123 asmflags = invoker.lib_asmflags 124 } 125 126 if (defined(invoker.lib_cflags)) { 127 cflags = invoker.lib_cflags 128 } 129 130 if (defined(invoker.lib_ldflags)) { 131 ldflags = invoker.lib_ldflags 132 } 133 134 if (defined(invoker.lib_external_deps)) { 135 external_deps = invoker.lib_external_deps 136 } 137 } 138 139 ohos_executable("execute_$target_name") { 140 testonly = true 141 subsystem_name = "musl" 142 part_name = "libc-test" 143 configs = [ "//third_party/musl/libc-test/src/common:config_runtest" ] 144 145 output_name = string_replace(target_name, "execute_", "") 146 sources = invoker.sources 147 include_dirs = [ 148 "//third_party/musl/libc-test/src/functionalext/adlt/common", 149 "//third_party/musl/libc-test/src/functionalext/common", 150 "//third_party/musl/porting/linux/user/include", 151 "//third_party/musl/libc-test/src/common", 152 ] 153 154 if (defined(invoker.configs)) { 155 configs += invoker.configs 156 } 157 158 if (defined(invoker.include_dirs)) { 159 include_dirs += invoker.include_dirs 160 } 161 162 if (defined(invoker.asmflags)) { 163 asmflags = invoker.asmflags 164 } 165 166 if (defined(invoker.cflags)) { 167 cflags = invoker.cflags 168 } 169 170 ldflags = [ "-Wl,-rpath=./:/data/local/tmp/libc-test-lib/" ] 171 if (defined(invoker.ldflags)) { 172 ldflags += invoker.ldflags 173 } 174 175 if (defined(invoker.external_deps)) { 176 external_deps = invoker.external_deps 177 } 178 179 deps = [ "//third_party/musl/libc-test/src/functionalext/adlt:adlt_common" ] 180 if (defined(invoker.custom_deps)) { 181 deps += invoker.custom_deps 182 } else { 183 deps += [ ":${invoker.lib_name}" ] 184 foreach(cfg, invoker.lib_configs) { 185 deps += [ ":${cfg.name}" ] 186 } 187 } 188 189 if (defined(invoker.deps)) { 190 deps += invoker.deps 191 } 192 193 if (defined(invoker.data_deps)) { 194 data_deps = invoker.data_deps 195 } 196 } 197 198 action(target_name) { 199 testonly = true 200 deps = [ ":execute_$target_name" ] 201 script = "//third_party/musl/libc-test/src/functionalext/adlt/adlt_tools.py" 202 args = [ "build_sym_links", 203 "--lib-dir", rebase_path(adlt_lib_dir, ""), 204 "--target-lib-dir", adlt_target_lib_dir, 205 "--adlt-lib", "libadlt_${invoker.lib_name}.so", 206 "--orig-lib-list" ] 207 208 outputs = [] 209 foreach(cfg, invoker.lib_configs) { 210 args += [ "libadlt_${cfg.name}.so" ] 211 outputs += [ "$adlt_lib_dir/adlt_orig_libs/libadlt_${cfg.name}.so" ] 212 } 213 } 214}