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/ohos-sdk" 29ohos_sdk_copy_dir = "$root_build_dir/ohos-sdk" 30 31sdk_toolchains = { 32 linux = "//build/toolchain/linux:clang_x64" 33 windows = "//build/toolchain/mingw:mingw_x86_64" 34 darwin = "//build/toolchain/mac:clang_x64" 35} 36 37if (host_os == "mac") { 38 sdk_systems = [ sdk_system_darwin ] 39} else { 40 sdk_systems = [ 41 sdk_system_windows, 42 sdk_system_linux, 43 ] 44} 45 46template("copy_and_archive") { 47 assert(defined(invoker.dest_dir)) 48 assert(defined(invoker.sdk_system)) 49 assert(defined(invoker.sdk_type)) 50 assert(defined(invoker.sdk_modules_desc_file)) 51 forward_variables_from(invoker, [ "testonly" ]) 52 53 action_with_pydeps(target_name) { 54 deps = [] 55 if (defined(invoker.deps)) { 56 deps += invoker.deps 57 } 58 59 script = "//build/ohos/sdk/copy_sdk_modules.py" 60 depfile = "$target_gen_dir/$target_name.d" 61 62 _sdk_output_archive = 63 "$ohos_sdk_out_dir/${invoker.sdk_system}/${invoker.zipfile_name}" 64 _notice_output_archive = "${sdk_notice_archive_dir}/${invoker.sdk_system}-${invoker.sdk_type}.zip" 65 outputs = [ 66 _sdk_output_archive, 67 _notice_output_archive, 68 ] 69 70 args = [ 71 "--sdk-modules-desc-file", 72 rebase_path(invoker.sdk_modules_desc_file, root_build_dir), 73 "--sdk-archive-paths-file", 74 rebase_path(generated_sdk_module_install_paths, root_build_dir), 75 "--dest-dir", 76 rebase_path(invoker.dest_dir, root_build_dir), 77 "--sdk-output-archive", 78 rebase_path(_sdk_output_archive, root_build_dir), 79 "--notice-output-archive", 80 rebase_path(_notice_output_archive, root_build_dir), 81 "--depfile", 82 rebase_path(depfile, root_build_dir), 83 "--archive-dir", 84 rebase_path("${invoker.dest_dir}/${invoker.sdk_type}", root_build_dir), 85 ] 86 87 if (defined(invoker.zip_prefix_path)) { 88 args += [ 89 "--zip-prefix-path", 90 invoker.zip_prefix_path, 91 ] 92 } 93 } 94} 95 96template("make_sdk_modules") { 97 assert(defined(invoker.zipfile_name)) 98 assert(defined(invoker.sdk_modules)) 99 assert(defined(invoker.sdk_toolchain)) 100 assert(defined(invoker.sdk_type)) 101 assert(defined(invoker.sdk_system)) 102 103 if (invoker.sdk_modules == []) { 104 not_needed(invoker, [ "sdk_toolchain" ]) 105 } 106 copy_and_archive(target_name) { 107 forward_variables_from(invoker, 108 [ 109 "testonly", 110 "sdk_system", 111 "sdk_type", 112 "zipfile_name", 113 ]) 114 _sdk_modules = [] 115 _sdk_module_infos = [] 116 117 foreach(_label, invoker.sdk_modules) { 118 _target_label = get_label_info(_label, "label_no_toolchain") 119 sources = [ _target_label ] 120 if (sources == []) { 121 _sdk_modules += [ _target_label ] 122 } else { 123 _sdk_modules += [ "${_target_label}(${invoker.sdk_toolchain})" ] 124 } 125 sources = [] 126 set_sources_assignment_filter([]) 127 } 128 not_needed(invoker, [ "sdk_toolchain" ]) 129 130 foreach(_label, _sdk_modules) { 131 _module_info_file = get_label_info(_label, "target_out_dir") + "/" + 132 get_label_info(_label, "name") + "_module_info.json" 133 _sdk_module_infos += [ 134 { 135 label = get_label_info(_label, "label_no_toolchain") 136 module_info_file = rebase_path(_module_info_file, root_build_dir) 137 }, 138 ] 139 } 140 sdk_modules_desc_file = "${target_gen_dir}/${target_name}_sdk_modules.json" 141 write_file(sdk_modules_desc_file, _sdk_module_infos, "json") 142 143 deps = _sdk_modules 144 if (defined(invoker.deps)) { 145 deps += invoker.deps 146 } 147 dest_dir = "${ohos_sdk_copy_dir}/${sdk_system}" 148 zip_prefix_path = "${invoker.sdk_type}" 149 } 150} 151 152template("make_linux_sdk_modules") { 153 make_sdk_modules(target_name) { 154 forward_variables_from(invoker, 155 [ 156 "testonly", 157 "zipfile_name", 158 "sdk_modules", 159 "sdk_type", 160 "deps", 161 ]) 162 sdk_toolchain = sdk_toolchains.linux 163 sdk_system = sdk_system_linux 164 } 165} 166 167template("make_windows_sdk_modules") { 168 make_sdk_modules(target_name) { 169 forward_variables_from(invoker, 170 [ 171 "testonly", 172 "zipfile_name", 173 "sdk_modules", 174 "sdk_type", 175 "deps", 176 ]) 177 sdk_toolchain = sdk_toolchains.windows 178 sdk_system = sdk_system_windows 179 } 180} 181 182template("make_darwin_sdk_modules") { 183 make_sdk_modules(target_name) { 184 forward_variables_from(invoker, 185 [ 186 "testonly", 187 "zipfile_name", 188 "sdk_modules", 189 "sdk_type", 190 "deps", 191 ]) 192 sdk_toolchain = sdk_toolchains.darwin 193 sdk_system = sdk_system_darwin 194 } 195} 196