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 71# merge sa profile insall files and generate sa profile install info 72template("ohos_sa_install_info") { 73 assert(defined(invoker.system_install_info_file)) 74 assert(defined(invoker.sa_install_info_file)) 75 assert(defined(invoker.current_platform)) 76 assert(defined(invoker.current_platform_dir)) 77 78 forward_variables_from(invoker, 79 [ 80 "current_platform", 81 "current_platform_dir", 82 "system_install_info_file", 83 "sa_install_info_file", 84 "merged_sa_profile_dir", 85 "merged_sa_profile_zipfile", 86 ]) 87 88 _deps = [] 89 if (defined(invoker.deps)) { 90 _deps += invoker.deps 91 } 92 _sa_info_out_dir = "${current_platform_dir}/sa_profile" 93 binary_output_dir = "${_sa_info_out_dir}/binaries" 94 95 sa_profile_install_dir = "profile" 96 97 archive_info_file_name = "sa_modules_info.json" 98 sa_profile_archive_dir = "//${dist_dir_name}/sa_profiles" 99 sa_profile_archive_info_file = 100 "${sa_profile_archive_dir}/${archive_info_file_name}" 101 102 src_sa_install_info_file = "${_sa_info_out_dir}/src_sa_install_info.json" 103 104 action_with_pydeps("sa_profile_src_${current_platform}") { 105 deps = [ "//build/ohos/sa_profile:src_sa_infos_process" ] 106 deps += _deps 107 script = "//build/ohos/sa_profile/sa_profile_source.py" 108 src_sa_infos_file = "${product_output_dir}/src_sa_infos.json" 109 sources = [ 110 src_sa_infos_file, 111 system_install_info_file, 112 ] 113 outputs = [ src_sa_install_info_file ] 114 args = [ 115 "--src-sa-info-file", 116 rebase_path(src_sa_infos_file, root_build_dir), 117 "--system-install-info-file", 118 rebase_path(system_install_info_file, root_build_dir), 119 "--src-sa-install-info-file", 120 rebase_path(src_sa_install_info_file, root_build_dir), 121 ] 122 } 123 124 _sa_profile_binary_target = "sa_profile_binary_${current_platform}" 125 _binary_sa_output = "${_sa_info_out_dir}/${_sa_profile_binary_target}.zip" 126 action_with_pydeps(_sa_profile_binary_target) { 127 deps = _deps 128 deps += [ ":sa_profile_src_${current_platform}" ] 129 script = "//build/ohos/sa_profile/sa_profile_binary.py" 130 inputs = [ system_install_info_file ] 131 outputs = [ _binary_sa_output ] 132 depfile = "$target_gen_dir/$target_name.d" 133 args = [ 134 "--system-install-info-file", 135 rebase_path(system_install_info_file, root_build_dir), 136 "--sa-output-dir", 137 rebase_path(binary_output_dir, root_build_dir), 138 "--sa-output-zipfile", 139 rebase_path(_binary_sa_output, root_build_dir), 140 "--depfile", 141 rebase_path(depfile, root_build_dir), 142 ] 143 144 # Check if sa archive info file exists 145 _file_exists_script = "//build/ohos/file_exists.py" 146 _process_args = [ 147 "--filename", 148 rebase_path(sa_profile_archive_info_file, root_build_dir), 149 ] 150 _result = exec_script(_file_exists_script, _process_args, "string") 151 if (_result == "True") { 152 inputs += [ sa_profile_archive_info_file ] 153 args += [ 154 "--sa-profile-archive-info-file", 155 rebase_path(sa_profile_archive_info_file, root_build_dir), 156 ] 157 } 158 } 159 160 action_with_pydeps(target_name) { 161 deps = [ 162 ":sa_profile_binary_${current_platform}", 163 ":sa_profile_src_${current_platform}", 164 ] 165 script = "//build/ohos/sa_profile/sa_profile_merge.py" 166 sources = [ 167 _binary_sa_output, 168 src_sa_install_info_file, 169 ] 170 outputs = [ 171 sa_install_info_file, 172 merged_sa_profile_zipfile, 173 ] 174 depfile = "$target_gen_dir/$target_name.d" 175 args = [ 176 "--src-sa-install-info-file", 177 rebase_path(src_sa_install_info_file, root_build_dir), 178 "--no-src-sa-install-info-file", 179 rebase_path(_binary_sa_output, root_build_dir), 180 "--sa-output-dir", 181 rebase_path(merged_sa_profile_dir, root_build_dir), 182 "--merged-sa-profile", 183 rebase_path(merged_sa_profile_zipfile, root_build_dir), 184 "--sa-install-info-file", 185 rebase_path(sa_install_info_file, root_build_dir), 186 "--sa-info-install-dest-dir", 187 "${system_base_dir}/${sa_profile_install_dir}", 188 "--target-cpu", 189 target_cpu, 190 "--depfile", 191 rebase_path(depfile, root_build_dir), 192 ] 193 } 194} 195 196template("ohos_sa_info_archive") { 197 archive_info_file_name = "sa_modules_info.json" 198 _deps = [ "//build/ohos/sa_profile:src_sa_infos_process" ] 199 sa_profile_src_infos_file = "${product_output_dir}/src_sa_infos.json" 200 201 action_with_pydeps(target_name) { 202 deps = _deps 203 if (defined(invoker.deps)) { 204 deps += invoker.deps 205 } 206 inputs = [ sa_profile_src_infos_file ] 207 depfile = "$target_gen_dir/$target_name.d" 208 sa_archive_output_dir = "${dist_build_out_dir}/sa_profiles" 209 sa_archive_info_file = "${sa_archive_output_dir}/${archive_info_file_name}" 210 outputs = [ 211 sa_archive_info_file, 212 sa_archive_output_dir, 213 ] 214 script = "//build/ohos/sa_profile/sa_profile_archive.py" 215 args = [ 216 "--src-sa-install-info-file", 217 rebase_path(sa_profile_src_infos_file, root_build_dir), 218 "--sa-archive-output-dir", 219 rebase_path(sa_archive_output_dir, root_build_dir), 220 "--sa-archive-info-file", 221 rebase_path(sa_archive_info_file, root_build_dir), 222 "--depfile", 223 rebase_path(depfile, root_build_dir), 224 ] 225 } 226} 227