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/templates/common/copy.gni") 16 17# Append something (files or lines) to a file and install it. 18# 19# Variables: 20# source: file to be appended (Required) 21# deps: some targets deps on (Optional) 22# output: the final install file name (Optional); 23# If not set, it will install with the source file name 24# files: files to be appended to the end of source file (Optional) 25# lines: lines of strings to be appended to the end of souce file (Optional) 26# 27# Example: 28# ohos_file_appender("cust_passwd") { 29# source = "//base/startup/init/services/etc/passwd" 30# deps = [ "//base/startup/init/services/etc:passwd" ] 31# files = [ "cust_passwd", "passwd2" ] 32# lines = [ "tses::1222:1222:/bin/false", "tses2::1223:1223:/bin/false" ] 33# output = "passwd" 34# } 35# It will append files and lines to source passwd file after deps targets 36# 37template("ohos_file_appender") { 38 assert(defined(invoker.source), "source full target name must be defined.") 39 40 _file_appender_target = "${target_name}_appended" 41 42 if (defined(invoker.output)) { 43 _final_install_name = get_path_info(invoker.output, "file") 44 } else { 45 _final_install_name = get_path_info(invoker.source, "file") 46 } 47 48 _appended_file = 49 target_gen_dir + "/${target_name}.appended/" + _final_install_name 50 51 action_with_pydeps(_file_appender_target) { 52 script = "//base/startup/init/services/etc/appender/file_appender.py" 53 depfile = "${target_gen_dir}/${target_name}.d" 54 if (defined(invoker.deps)) { 55 deps = invoker.deps 56 } else { 57 deps = [] 58 } 59 args = [ 60 "--output", 61 rebase_path(_appended_file, root_build_dir), 62 "--source-file", 63 rebase_path(invoker.source, root_build_dir), 64 "--depfile", 65 rebase_path(depfile, root_build_dir), 66 ] 67 if (defined(invoker.files)) { 68 foreach(file, invoker.files) { 69 args += [ 70 "--append-file", 71 rebase_path(file, root_build_dir), 72 ] 73 } 74 } 75 if (defined(invoker.lines)) { 76 foreach(line, invoker.lines) { 77 args += [ 78 "--append-line", 79 line, 80 ] 81 } 82 } 83 inputs = [ invoker.source ] 84 outputs = [ _appended_file ] 85 } 86 87 ohos_copy(target_name) { 88 forward_variables_from(invoker, 89 [ 90 "testonly", 91 "visibility", 92 93 "deps", 94 "public_configs", 95 "subsystem_name", 96 "part_name", 97 98 # For generate_module_info 99 "install_images", 100 "module_install_dir", 101 "relative_install_dir", 102 "symlink_target_name", 103 104 # Open source license related 105 "license_file", 106 "license_as_sources", 107 ]) 108 if (defined(deps)) { 109 deps += [ ":$_file_appender_target" ] 110 } else { 111 deps = [ ":$_file_appender_target" ] 112 } 113 set_sources_assignment_filter([]) 114 sources = [ _appended_file ] 115 outputs = [ "${target_out_dir}/${target_name}/${_final_install_name}" ] 116 module_type = "etc" 117 install_enable = true 118 module_source_dir = "${target_out_dir}/${target_name}" 119 module_install_name = _final_install_name 120 if (defined(invoker.install_enable)) { 121 install_enable = invoker.install_enable 122 } 123 } 124} 125