1# Copyright (c) 2021 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/python.gni") 15import("//build/ohos/build_var.gni") 16import("//build/ohos/notice/notice.gni") 17import("//build/version.gni") 18 19sdk_base_build_gn = "//build/ohos/sdk/BUILD.gn" 20generated_files_dir = get_path_info(sdk_base_build_gn, "gen_dir") 21generated_sdk_module_install_paths = 22 "${generated_files_dir}/ohos_sdk_install_paths.json" 23 24sdk_system_windows = "windows" 25sdk_system_linux = "linux" 26sdk_system_darwin = "darwin" 27 28ohos_sdk_out_dir = "$product_output_dir/${product_name}" 29ohos_sdk_copy_dir = "$root_build_dir/${product_name}" 30 31declare_args() { 32 sdk_check_flag = true 33 sdk_for_hap_build = false 34} 35 36declare_args() { 37 enable_sign = false 38} 39 40sdk_toolchains = { 41 linux = "//build/toolchain/linux:clang_x64" 42 windows = "//build/toolchain/mingw:mingw_x86_64" 43 if (host_cpu == "arm64") { 44 darwin = "//build/toolchain/mac:clang_arm64" 45 } else { 46 darwin = "//build/toolchain/mac:clang_x64" 47 } 48} 49 50if (host_cpu == "arm64") { 51 arch = "arm64" 52} else if (host_cpu == "riscv64") { 53 arch = "riscv64" 54} else { 55 arch = "x64" 56} 57 58if (sdk_platform == "default") { 59 if (host_os == "mac") { 60 sdk_systems = [ sdk_system_darwin ] 61 } else { 62 sdk_systems = [ 63 sdk_system_windows, 64 sdk_system_linux, 65 ] 66 } 67} else if (sdk_platform == "mac") { 68 sdk_systems = [ sdk_system_darwin ] 69} else if (sdk_platform == "win") { 70 sdk_systems = [ sdk_system_windows ] 71} else if (sdk_platform == "linux") { 72 sdk_systems = [ sdk_system_linux ] 73} 74 75template("copy_and_archive") { 76 assert(defined(invoker.dest_dir)) 77 assert(defined(invoker.sdk_system)) 78 assert(defined(invoker.sdk_type)) 79 assert(defined(invoker.sdk_modules_desc_file)) 80 forward_variables_from(invoker, [ "testonly" ]) 81 82 action_with_pydeps(target_name) { 83 deps = [] 84 if (defined(invoker.deps)) { 85 deps += invoker.deps 86 } 87 88 script = "//build/ohos/sdk/copy_sdk_modules.py" 89 depfile = "$target_gen_dir/$target_name.d" 90 91 _sdk_output_archive = 92 "$ohos_sdk_out_dir/${invoker.sdk_system}/${invoker.zipfile_name}" 93 _notice_output_archive = "${sdk_notice_archive_dir}/${invoker.sdk_system}-${invoker.sdk_type}.zip" 94 outputs = [ 95 _sdk_output_archive, 96 _notice_output_archive, 97 ] 98 99 args = [ 100 "--sdk-modules-desc-file", 101 rebase_path(invoker.sdk_modules_desc_file, root_build_dir), 102 "--sdk-archive-paths-file", 103 rebase_path(generated_sdk_module_install_paths, root_build_dir), 104 "--dest-dir", 105 rebase_path(invoker.dest_dir, root_build_dir), 106 "--sdk-output-archive", 107 rebase_path(_sdk_output_archive, root_build_dir), 108 "--notice-output-archive", 109 rebase_path(_notice_output_archive, root_build_dir), 110 "--depfile", 111 rebase_path(depfile, root_build_dir), 112 "--archive-dir", 113 rebase_path("${invoker.dest_dir}/${invoker.sdk_type}", root_build_dir), 114 ] 115 116 if (defined(invoker.zip_prefix_path)) { 117 args += [ 118 "--zip-prefix-path", 119 invoker.zip_prefix_path, 120 ] 121 } 122 } 123} 124 125template("make_sdk_modules") { 126 assert(defined(invoker.zipfile_name)) 127 assert(defined(invoker.sdk_modules)) 128 assert(defined(invoker.sdk_toolchain)) 129 assert(defined(invoker.sdk_type)) 130 assert(defined(invoker.sdk_system)) 131 132 if (invoker.sdk_modules == []) { 133 not_needed(invoker, [ "sdk_toolchain" ]) 134 } 135 copy_and_archive(target_name) { 136 forward_variables_from(invoker, 137 [ 138 "testonly", 139 "sdk_system", 140 "sdk_type", 141 "zipfile_name", 142 ]) 143 _sdk_modules = [] 144 _sdk_module_infos = [] 145 146 foreach(_label, invoker.sdk_modules) { 147 _target_label = get_label_info(_label, "label_no_toolchain") 148 sources = [ _target_label ] 149 if (sources == []) { 150 _sdk_modules += [ _target_label ] 151 } else { 152 _sdk_modules += [ "${_target_label}(${invoker.sdk_toolchain})" ] 153 } 154 sources = [] 155 } 156 not_needed(invoker, [ "sdk_toolchain" ]) 157 158 foreach(_label, _sdk_modules) { 159 _module_info_file = get_label_info(_label, "target_out_dir") + "/" + 160 get_label_info(_label, "name") + "_module_info.json" 161 _sdk_module_infos += [ 162 { 163 label = get_label_info(_label, "label_no_toolchain") 164 module_info_file = rebase_path(_module_info_file, root_build_dir) 165 }, 166 ] 167 } 168 sdk_modules_desc_file = "${target_gen_dir}/${target_name}_sdk_modules.json" 169 write_file(sdk_modules_desc_file, _sdk_module_infos, "json") 170 171 deps = _sdk_modules 172 if (defined(invoker.deps)) { 173 deps += invoker.deps 174 } 175 dest_dir = "${ohos_sdk_copy_dir}/${sdk_system}" 176 zip_prefix_path = "${invoker.sdk_type}" 177 } 178} 179 180template("make_linux_sdk_modules") { 181 make_sdk_modules(target_name) { 182 forward_variables_from(invoker, 183 [ 184 "testonly", 185 "zipfile_name", 186 "sdk_modules", 187 "sdk_type", 188 "deps", 189 ]) 190 sdk_toolchain = sdk_toolchains.linux 191 sdk_system = sdk_system_linux 192 } 193} 194 195template("make_windows_sdk_modules") { 196 make_sdk_modules(target_name) { 197 forward_variables_from(invoker, 198 [ 199 "testonly", 200 "zipfile_name", 201 "sdk_modules", 202 "sdk_type", 203 "deps", 204 ]) 205 sdk_toolchain = sdk_toolchains.windows 206 sdk_system = sdk_system_windows 207 } 208} 209 210template("make_darwin_sdk_modules") { 211 make_sdk_modules(target_name) { 212 forward_variables_from(invoker, 213 [ 214 "testonly", 215 "zipfile_name", 216 "sdk_modules", 217 "sdk_type", 218 "deps", 219 ]) 220 sdk_toolchain = sdk_toolchains.darwin 221 sdk_system = sdk_system_darwin 222 } 223} 224