1# Copyright (c) 2023 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
17template("ohos_prebuilt_appdata_sandbox") {
18  assert(defined(invoker.source), "source must be defined for ${target_name}.")
19
20  _fixed_sandbox_target = "${target_name}_sandbox_fixed"
21  _fixed_sandbox_file = target_gen_dir + "/${target_name}.fixed/" +
22                        get_path_info(invoker.source, "file")
23  _output_para_file = get_path_info(invoker.source, "file")
24
25  action_with_pydeps(_fixed_sandbox_target) {
26    deps = []
27    script = "//base/startup/appspawn/etc/sandbox/appdata_sandbox_fixer.py"
28    depfile = "${target_gen_dir}/${target_name}.d"
29    args = [
30      "--output",
31      rebase_path(_fixed_sandbox_file, root_build_dir),
32      "--source-file",
33      rebase_path(invoker.source, root_build_dir),
34      "--depfile",
35      rebase_path(depfile, root_build_dir),
36    ]
37    if (defined(invoker.extra_sandbox_cfgs)) {
38      foreach(extra, invoker.extra_sandbox_cfgs) {
39        args += [
40          "--extra_sandbox_cfg",
41          rebase_path(extra, root_build_dir),
42        ]
43      }
44    }
45    if (defined(invoker.patterns)) {
46      foreach(pattern, invoker.patterns) {
47        args += [
48          "--patterns",
49          pattern,
50        ]
51      }
52    }
53    inputs = [ invoker.source ]
54    outputs = [ _fixed_sandbox_file ]
55  }
56
57  ohos_copy(target_name) {
58    deps = [ ":$_fixed_sandbox_target" ]
59    forward_variables_from(invoker,
60                           [
61                             "testonly",
62                             "visibility",
63
64                             "deps",
65                             "public_configs",
66                             "subsystem_name",
67                             "part_name",
68
69                             # For generate_module_info
70                             "install_images",
71                             "module_install_dir",
72                             "relative_install_dir",
73                             "symlink_target_name",
74
75                             # Open source license related
76                             "license_file",
77                             "license_as_sources",
78                           ])
79    sources = [ _fixed_sandbox_file ]
80    outputs = [ "${target_out_dir}/${target_name}/${_output_para_file}" ]
81    module_type = "etc"
82    install_enable = true
83    module_source_dir = "${target_out_dir}/${target_name}"
84    module_install_name = _output_para_file
85    if (defined(invoker.install_enable)) {
86      install_enable = invoker.install_enable
87    }
88  }
89}
90