1# Copyright (c) 2021-2022 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.
13import("//base/startup/appspawn/appspawn.gni")
14import("//build/ohos.gni")
15import("//build/ohos/native_stub/native_stub.gni")
16
17config("appspawn_server_config") {
18  visibility = [ ":*" ]
19  include_dirs = [
20    "${appspawn_path}/common",
21    "${appspawn_path}/standard",
22    "${appspawn_path}/modules/common",
23    "${appspawn_path}/modules/modulemgr",
24    "${appspawn_path}/modules/sysevent",
25  ]
26
27  cflags = []
28  if (build_selinux) {
29    cflags += [ "-DWITH_SELINUX" ]
30  }
31
32  if (build_seccomp) {
33    cflags += [ "-DWITH_SECCOMP" ]
34    if (appspawn_seccomp_privilege) {
35      cflags += [ "-DSECCOMP_PRIVILEGE" ]
36    }
37  }
38  configs = [ "${appspawn_path}:appspawn_config" ]
39}
40
41ohos_executable("appspawn") {
42  sources = [
43    "${appspawn_path}/common/appspawn_server.c",
44    "${appspawn_path}/common/appspawn_trace.cpp",
45    "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp",
46    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
47    "${appspawn_path}/standard/appspawn_appmgr.c",
48    "${appspawn_path}/standard/appspawn_kickdog.c",
49    "${appspawn_path}/standard/appspawn_main.c",
50    "${appspawn_path}/standard/appspawn_msgmgr.c",
51    "${appspawn_path}/standard/appspawn_service.c",
52    "${appspawn_path}/standard/nwebspawn_launcher.c",
53  ]
54
55  defines = []
56  configs = [
57    ":appspawn_server_config",
58    "${appspawn_path}:appspawn_config",
59  ]
60  deps = [
61    "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
62    "${appspawn_path}/util:libappspawn_util",
63  ]
64  if (asan_detector || is_asan) {
65    defines += [ "ASAN_DETECTOR" ]
66  }
67  if (is_debug || build_variant == "root") {
68    defines += [ "DEBUG_BEGETCTL_BOOT" ]
69  }
70  if (appspawn_support_prefork) {
71    defines += [ "APPSPAWN_SUPPORT_PREFORK" ]
72  }
73
74  external_deps = [
75    "cJSON:cjson",
76    "c_utils:utils",
77    "config_policy:configpolicy_util",
78    "hilog:libhilog",
79    "hitrace:hitrace_meter",
80    "init:libbegetutil",
81  ]
82  if (enable_appspawn_dump_catcher) {
83    external_deps += [ "faultloggerd:libdfx_dumpcatcher" ]
84  }
85  if (appspawn_use_encaps) {
86    defines += [ "USE_ENCAPS" ]
87  }
88  if (appspawn_report_event) {
89    defines += [ "APPSPAWN_HISYSEVENT" ]
90    external_deps += [ "hisysevent:libhisysevent" ]
91    sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ]
92  }
93  if (build_selinux) {
94    defines += [ "WITH_SELINUX" ]
95    external_deps += [
96      "selinux:libselinux",
97      "selinux_adapter:libhap_restorecon",
98    ]
99  }
100  cflags = []
101
102  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
103    defines += [ "APPSPAWN_SANDBOX_NEW" ]
104  }
105
106  #ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64z" ]
107  if (!defined(global_parts_info) ||
108      defined(global_parts_info.security_code_signature)) {
109    defines += [ "CODE_SIGNATURE_ENABLE" ]
110    external_deps += [ "code_signature:libcode_sign_attr_utils" ]
111  }
112
113  version_script = get_label_info(
114                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
115                       "target_gen_dir") + "/" + get_label_info(
116                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
117                       "name") + stub_version_script_suffix
118
119  install_enable = true
120  subsystem_name = "${subsystem_name}"
121  part_name = "${part_name}"
122}
123
124ohos_shared_library("appspawn_helper") {
125  sources = [ "${appspawn_path}/common/appspawn_server.c" ]
126  defines = [ "APPSPAWN_HELPER" ]
127  configs = [
128    ":appspawn_server_config",
129    "${appspawn_path}:appspawn_config",
130  ]
131  cflags = [
132    "-fvisibility=hidden",
133    "-fstack-protector-all",
134  ]
135  external_deps = [
136    "hilog:libhilog",
137    "init:libbegetutil",
138  ]
139
140  install_enable = true
141  subsystem_name = "${subsystem_name}"
142  part_name = "${part_name}"
143}
144
145ohos_prebuilt_etc("appspawn.rc") {
146  source = "appspawn.cfg"
147  relative_install_dir = "init"
148  subsystem_name = "${subsystem_name}"
149  part_name = "${part_name}"
150}
151
152ohos_executable("pid_ns_init") {
153  sources = [ "${appspawn_path}/standard/pid_ns_init.c" ]
154  install_enable = true
155  subsystem_name = "${subsystem_name}"
156  part_name = "${part_name}"
157}
158
159# to support cjappspawn
160ohos_executable("cjappspawn") {
161  sources = [
162    "${appspawn_path}/common/appspawn_server.c",
163    "${appspawn_path}/common/appspawn_trace.cpp",
164    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
165    "${appspawn_path}/standard/appspawn_appmgr.c",
166    "${appspawn_path}/standard/appspawn_kickdog.c",
167    "${appspawn_path}/standard/appspawn_main.c",
168    "${appspawn_path}/standard/appspawn_msgmgr.c",
169    "${appspawn_path}/standard/appspawn_service.c",
170    "${appspawn_path}/standard/nwebspawn_launcher.c",
171  ]
172
173  defines = [ "CJAPP_SPAWN" ]
174  configs = [
175    ":appspawn_server_config",
176    "${appspawn_path}:appspawn_config",
177  ]
178  deps = [
179    "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
180    "${appspawn_path}/util:libappspawn_util",
181  ]
182  if (asan_detector || is_asan) {
183    defines += [ "ASAN_DETECTOR" ]
184  }
185
186  external_deps = [
187    "cJSON:cjson",
188    "c_utils:utils",
189    "config_policy:configpolicy_util",
190    "hilog:libhilog",
191    "hitrace:hitrace_meter",
192    "init:libbegetutil",
193  ]
194  if (appspawn_report_event) {
195    defines += [ "APPSPAWN_HISYSEVENT" ]
196    external_deps += [ "hisysevent:libhisysevent" ]
197    sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ]
198  }
199  if (build_selinux) {
200    defines += [ "WITH_SELINUX" ]
201    external_deps += [
202      "selinux:libselinux",
203      "selinux_adapter:libhap_restorecon",
204    ]
205  }
206  cflags = []
207
208  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
209    defines += [ "APPSPAWN_SANDBOX_NEW" ]
210  }
211
212  #ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64z" ]
213  if (!defined(global_parts_info) ||
214      defined(global_parts_info.security_code_signature)) {
215    defines += [ "CODE_SIGNATURE_ENABLE" ]
216    external_deps += [ "code_signature:libcode_sign_attr_utils" ]
217  }
218
219  version_script = get_label_info(
220                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
221                       "target_gen_dir") + "/" + get_label_info(
222                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
223                       "name") + stub_version_script_suffix
224
225  install_enable = true
226  subsystem_name = "${subsystem_name}"
227  part_name = "${part_name}"
228}
229
230# to support nativespawn
231ohos_executable("nativespawn") {
232  sources = [
233    "${appspawn_path}/common/appspawn_server.c",
234    "${appspawn_path}/common/appspawn_trace.cpp",
235    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
236    "${appspawn_path}/standard/appspawn_appmgr.c",
237    "${appspawn_path}/standard/appspawn_kickdog.c",
238    "${appspawn_path}/standard/appspawn_main.c",
239    "${appspawn_path}/standard/appspawn_msgmgr.c",
240    "${appspawn_path}/standard/appspawn_service.c",
241    "${appspawn_path}/standard/nwebspawn_launcher.c",
242  ]
243
244  defines = [ "NATIVE_SPAWN" ]
245  configs = [
246    ":appspawn_server_config",
247    "${appspawn_path}:appspawn_config",
248  ]
249  deps = [
250    "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
251    "${appspawn_path}/util:libappspawn_util",
252  ]
253  if (asan_detector || is_asan) {
254    defines += [ "ASAN_DETECTOR" ]
255  }
256
257  external_deps = [
258    "cJSON:cjson",
259    "c_utils:utils",
260    "config_policy:configpolicy_util",
261    "hilog:libhilog",
262    "hitrace:hitrace_meter",
263    "init:libbegetutil",
264  ]
265  if (appspawn_report_event) {
266    defines += [ "APPSPAWN_HISYSEVENT" ]
267    external_deps += [ "hisysevent:libhisysevent" ]
268    sources += [ "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp" ]
269  }
270  if (build_selinux) {
271    defines += [ "WITH_SELINUX" ]
272    external_deps += [
273      "selinux:libselinux",
274      "selinux_adapter:libhap_restorecon",
275    ]
276  }
277  cflags = []
278
279  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
280    defines += [ "APPSPAWN_SANDBOX_NEW" ]
281  }
282
283  #ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64z" ]
284  if (!defined(global_parts_info) ||
285      defined(global_parts_info.security_code_signature)) {
286    defines += [ "CODE_SIGNATURE_ENABLE" ]
287    external_deps += [ "code_signature:libcode_sign_attr_utils" ]
288  }
289
290  version_script = get_label_info(
291                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
292                       "target_gen_dir") + "/" + get_label_info(
293                       "${appspawn_path}/modules/module_engine:libappspawn_stub_versionscript",
294                       "name") + stub_version_script_suffix
295
296  install_enable = true
297  subsystem_name = "${subsystem_name}"
298  part_name = "${part_name}"
299}
300
301ohos_prebuilt_etc("cjappspawn.rc") {
302  source = "cjappspawn.cfg"
303  relative_install_dir = "init"
304  subsystem_name = "${subsystem_name}"
305  part_name = "${part_name}"
306}
307
308ohos_prebuilt_etc("nativespawn.rc") {
309  source = "nativespawn.cfg"
310  relative_install_dir = "init"
311  subsystem_name = "${subsystem_name}"
312  part_name = "${part_name}"
313}
314