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_var.gni") 17 18# sa info config file template 19# support for configuring multiple files. 20template("ohos_sa_profile") { 21 assert(defined(invoker.sources)) 22 assert(defined(invoker.subsystem_name) || defined(invoker.part_name)) 23 24 if (defined(invoker.part_name)) { 25 part_name = invoker.part_name 26 } else { 27 part_name = invoker.subsystem_name 28 } 29 30 inputs_output_dir = "${root_out_dir}/sa_profile/inputs" 31 32 copy("${target_name}_copy") { 33 deps = [] 34 if (defined(invoker.deps)) { 35 deps += invoker.deps 36 } 37 sources = invoker.sources 38 outputs = [ "${target_out_dir}/profiles/{{source_file_part}}" ] 39 } 40 41 action_with_pydeps(target_name) { 42 deps = [ ":${target_name}_copy" ] 43 _output_dir = "${inputs_output_dir}/${part_name}" 44 _output_info_file = "${_output_dir}/${target_name}_info.json" 45 sources = get_target_outputs(":${target_name}_copy") 46 outputs = [ _output_info_file ] 47 script = "//build/ohos/sa_profile/sa_profile.py" 48 args = [ "--sa-input-files" ] 49 args += rebase_path(sources, root_build_dir) 50 args += [ 51 "--target-label", 52 get_label_info(":${target_name}", "label_with_toolchain"), 53 "--output-module-info-file", 54 rebase_path(_output_info_file, root_build_dir), 55 "--part-name", 56 part_name, 57 ] 58 sa_install_info = { 59 label = get_label_info(":$target_name", "label_with_toolchain") 60 install_info_file = rebase_path(_output_info_file, root_build_dir) 61 part_name = part_name 62 toolchain = current_toolchain 63 type = "sa" 64 } 65 metadata = { 66 sa_install_info = [ sa_install_info ] 67 } 68 } 69 70 sources_output = [] 71 foreach(source, invoker.sources) { 72 sources_output += 73 [ rebase_path("${target_out_dir}/profiles/${source}", root_build_dir) ] 74 } 75 module_label = get_label_info(":${target_name}", "label_with_toolchain") 76 target_deps_data = { 77 label = module_label 78 type = "etc" 79 prebuilt = true 80 output_path = sources_output 81 } 82 write_file("${target_out_dir}/${target_name}_deps_data.json", 83 target_deps_data, 84 "json") 85} 86 87# merge sa profile insall files and generate sa profile install info 88template("ohos_sa_install_info") { 89 assert(defined(invoker.system_install_info_file)) 90 assert(defined(invoker.sa_install_info_file)) 91 assert(defined(invoker.current_platform)) 92 assert(defined(invoker.current_platform_dir)) 93 94 forward_variables_from(invoker, 95 [ 96 "current_platform", 97 "current_platform_dir", 98 "system_install_info_file", 99 "sa_install_info_file", 100 "merged_sa_profile_dir", 101 "merged_sa_profile_zipfile", 102 ]) 103 104 _deps = [] 105 if (defined(invoker.deps)) { 106 _deps += invoker.deps 107 } 108 _sa_info_out_dir = "${current_platform_dir}/sa_profile" 109 binary_output_dir = "${_sa_info_out_dir}/binaries" 110 111 sa_profile_install_dir = "profile" 112 113 archive_info_file_name = "sa_modules_info.json" 114 sa_profile_archive_dir = "//${dist_dir_name}/sa_profiles" 115 sa_profile_archive_info_file = 116 "${sa_profile_archive_dir}/${archive_info_file_name}" 117 118 src_sa_install_info_file = "${_sa_info_out_dir}/src_sa_install_info.json" 119 120 action_with_pydeps("sa_profile_src_${current_platform}") { 121 deps = [ "//build/ohos/sa_profile:src_sa_infos_process" ] 122 deps += _deps 123 script = "//build/ohos/sa_profile/sa_profile_source.py" 124 src_sa_infos_file = "${product_output_dir}/src_sa_infos.json" 125 sources = [ 126 src_sa_infos_file, 127 system_install_info_file, 128 ] 129 outputs = [ src_sa_install_info_file ] 130 args = [ 131 "--src-sa-info-file", 132 rebase_path(src_sa_infos_file, root_build_dir), 133 "--system-install-info-file", 134 rebase_path(system_install_info_file, root_build_dir), 135 "--src-sa-install-info-file", 136 rebase_path(src_sa_install_info_file, root_build_dir), 137 ] 138 } 139 140 _sa_profile_binary_target = "sa_profile_binary_${current_platform}" 141 _binary_sa_output = "${_sa_info_out_dir}/${_sa_profile_binary_target}.zip" 142 action_with_pydeps(_sa_profile_binary_target) { 143 deps = _deps 144 deps += [ ":sa_profile_src_${current_platform}" ] 145 script = "//build/ohos/sa_profile/sa_profile_binary.py" 146 inputs = [ system_install_info_file ] 147 outputs = [ _binary_sa_output ] 148 depfile = "$target_gen_dir/$target_name.d" 149 args = [ 150 "--system-install-info-file", 151 rebase_path(system_install_info_file, root_build_dir), 152 "--sa-output-dir", 153 rebase_path(binary_output_dir, root_build_dir), 154 "--sa-output-zipfile", 155 rebase_path(_binary_sa_output, root_build_dir), 156 "--depfile", 157 rebase_path(depfile, root_build_dir), 158 ] 159 160 # Check if sa archive info file exists 161 _file_exists_script = "//build/ohos/file_exists.py" 162 _process_args = [ 163 "--filename", 164 rebase_path(sa_profile_archive_info_file, root_build_dir), 165 ] 166 _result = exec_script(_file_exists_script, _process_args, "string") 167 if (_result == "True") { 168 inputs += [ sa_profile_archive_info_file ] 169 args += [ 170 "--sa-profile-archive-info-file", 171 rebase_path(sa_profile_archive_info_file, root_build_dir), 172 ] 173 } 174 } 175 176 action_with_pydeps(target_name) { 177 deps = [ 178 ":sa_profile_binary_${current_platform}", 179 ":sa_profile_src_${current_platform}", 180 ] 181 script = "//build/ohos/sa_profile/sa_profile_merge.py" 182 sources = [ 183 _binary_sa_output, 184 src_sa_install_info_file, 185 ] 186 outputs = [ 187 sa_install_info_file, 188 merged_sa_profile_zipfile, 189 ] 190 depfile = "$target_gen_dir/$target_name.d" 191 args = [ 192 "--src-sa-install-info-file", 193 rebase_path(src_sa_install_info_file, root_build_dir), 194 "--no-src-sa-install-info-file", 195 rebase_path(_binary_sa_output, root_build_dir), 196 "--sa-output-dir", 197 rebase_path(merged_sa_profile_dir, root_build_dir), 198 "--merged-sa-profile", 199 rebase_path(merged_sa_profile_zipfile, root_build_dir), 200 "--sa-install-info-file", 201 rebase_path(sa_install_info_file, root_build_dir), 202 "--sa-info-install-dest-dir", 203 "${system_base_dir}/${sa_profile_install_dir}", 204 "--target-cpu", 205 target_cpu, 206 "--depfile", 207 rebase_path(depfile, root_build_dir), 208 ] 209 } 210} 211 212template("ohos_sa_info_archive") { 213 archive_info_file_name = "sa_modules_info.json" 214 _deps = [ "//build/ohos/sa_profile:src_sa_infos_process" ] 215 sa_profile_src_infos_file = "${product_output_dir}/src_sa_infos.json" 216 217 action_with_pydeps(target_name) { 218 deps = _deps 219 if (defined(invoker.deps)) { 220 deps += invoker.deps 221 } 222 inputs = [ sa_profile_src_infos_file ] 223 depfile = "$target_gen_dir/$target_name.d" 224 sa_archive_output_dir = "${dist_build_out_dir}/sa_profiles" 225 sa_archive_info_file = "${sa_archive_output_dir}/${archive_info_file_name}" 226 outputs = [ 227 sa_archive_info_file, 228 sa_archive_output_dir, 229 ] 230 script = "//build/ohos/sa_profile/sa_profile_archive.py" 231 args = [ 232 "--src-sa-install-info-file", 233 rebase_path(sa_profile_src_infos_file, root_build_dir), 234 "--sa-archive-output-dir", 235 rebase_path(sa_archive_output_dir, root_build_dir), 236 "--sa-archive-info-file", 237 rebase_path(sa_archive_info_file, root_build_dir), 238 "--depfile", 239 rebase_path(depfile, root_build_dir), 240 ] 241 } 242} 243