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("//base/update/updater/updater_default_cfg.gni")
15import("//build/ohos.gni")
16
17HDC_PATH = "//developtools/hdc/src"
18updater_path = rebase_path("${updater_absolutely_path}", ".")
19
20hash_sources = [
21  "${hdc_base}/scripts/hdc_hash_gen.py",
22  "${hdc_base}/src/common/base.cpp",
23  "${hdc_base}/src/common/channel.h",
24  "${hdc_base}/src/common/session.h",
25  "${hdc_base}/src/common/transfer.h",
26]
27
28py_out_dir = "$root_build_dir/gen/" + rebase_path(".", "//")
29
30config("hdc_config") {
31  include_dirs = [ "${py_out_dir}" ]
32  cflags_cc = [ "-std=c++17" ]
33  if (is_mingw) {
34    cflags_cc += [ "-Wno-inconsistent-dllimport" ]  # in mingw some sec api will
35                                                    # overwrite by utilsecurec
36  }
37}
38
39action("hdc_hash_gen") {
40  script = "${hdc_base}/scripts/hdc_hash_gen.py"
41  sources = hash_sources
42  outputs = [ "$py_out_dir" ]
43  args = [
44    "-f",
45    "hdc_hash_gen.h",
46    "-i",
47    rebase_path("${hdc_base}", root_build_dir),
48    "-o",
49    rebase_path("$py_out_dir" + "/", root_build_dir),
50  ]
51  public_configs = [ ":hdc_config" ]
52}
53
54common_sources = [
55  "${HDC_PATH}/common/async_cmd.cpp",
56  "${HDC_PATH}/common/auth.cpp",
57  "${HDC_PATH}/common/base.cpp",
58  "${HDC_PATH}/common/channel.cpp",
59  "${HDC_PATH}/common/circle_buffer.cpp",
60  "${HDC_PATH}/common/compress.cpp",
61  "${HDC_PATH}/common/debug.cpp",
62  "${HDC_PATH}/common/decompress.cpp",
63  "${HDC_PATH}/common/entry.cpp",
64  "${HDC_PATH}/common/file.cpp",
65  "${HDC_PATH}/common/file_descriptor.cpp",
66  "${HDC_PATH}/common/forward.cpp",
67  "${HDC_PATH}/common/header.cpp",
68  "${HDC_PATH}/common/session.cpp",
69  "${HDC_PATH}/common/task.cpp",
70  "${HDC_PATH}/common/tcp.cpp",
71  "${HDC_PATH}/common/transfer.cpp",
72  "${HDC_PATH}/common/usb.cpp",
73]
74
75config("flashd_hdc_config") {
76  include_dirs = [ "./common" ]
77  cflags_cc = [ "-std=c++17" ]
78}
79
80ohos_static_library("flashd_deamon") {
81  sources = [
82    "${HDC_PATH}/daemon/daemon_app.cpp",
83    "${HDC_PATH}/daemon/daemon_forward.cpp",
84    "${HDC_PATH}/daemon/daemon_tcp.cpp",
85    "${HDC_PATH}/daemon/daemon_unity.cpp",
86    "${HDC_PATH}/daemon/daemon_usb.cpp",
87    "${HDC_PATH}/daemon/jdwp.cpp",
88    "${HDC_PATH}/daemon/shell.cpp",
89    "daemon/daemon.cpp",
90    "daemon/system_depend.cpp",
91  ]
92
93  sources += common_sources
94
95  defines = [
96    "HARMONY_PROJECT",
97    "OPENSSL_SUPPRESS_DEPRECATED",
98  ]
99
100  configs = [ ":flashd_hdc_config" ]
101
102  external_deps = [
103    "bounds_checking_function:libsec_static",
104    "c_utils:utils",
105    "libuv:uv",
106    "lz4:liblz4_static",
107    "openssl:libcrypto_shared",
108  ]
109
110  deps = [ "${updater_path}/services/flashd:hdc_hash_gen" ]
111
112  if (updater_hdc_depend) {
113    external_deps += [ "hdc:hdc_updater" ]
114  }
115
116  if (use_musl) {
117    external_deps += [ "init:libbegetutil_static" ]
118  }
119
120  include_dirs = [
121    "${updater_path}/services/common",
122    "${updater_path}/services/flashd",
123    "${updater_path}/services/flashd/daemon",
124    "${updater_path}/services/flashd/common",
125    "${updater_path}/services/flashd/host",
126    "${updater_path}/services/include",
127    "${updater_path}/services/include/fs_manager",
128    "${updater_path}/services/include/package",
129    "${updater_path}/services/include/applypatch",
130    "${updater_path}/services/include/script",
131    "${updater_path}/services/include/log",
132    "${updater_path}/interfaces/kits/include",
133    "${updater_path}/utils/include",
134  ]
135
136  if (build_selinux) {
137    external_deps += [ "selinux:libselinux_static" ]
138    defines += [
139      "SURPPORT_SELINUX",
140      "UPDATER_MODE",
141    ]
142  }
143
144  if (build_variant == "user") {
145    defines += [ "UPDATER_BUILD_VARIANT_USER" ]
146  }
147
148  subsystem_name = "updater"
149  part_name = "updater"
150}
151
152ohos_static_library("libflashd") {
153  sources = [
154    "${updater_path}/services/flashd/daemon/commander.cpp",
155    "${updater_path}/services/flashd/daemon/commander_factory.cpp",
156    "${updater_path}/services/flashd/daemon/daemon_updater.cpp",
157    "${updater_path}/services/flashd/daemon/erase_commander.cpp",
158    "${updater_path}/services/flashd/daemon/flash_commander.cpp",
159    "${updater_path}/services/flashd/daemon/flashd_main.cpp",
160    "${updater_path}/services/flashd/daemon/flashd_utils.cpp",
161    "${updater_path}/services/flashd/daemon/format_commander.cpp",
162    "${updater_path}/services/flashd/daemon/update_commander.cpp",
163    "${updater_path}/services/flashd/image_writer/image_writer.cpp",
164    "${updater_path}/services/flashd/partition.cpp",
165    "${updater_path}/services/hdi/client/update_hdi_client.cpp",
166    "${updater_path}/services/updater_binary/update_image_block.cpp",
167    "${updater_path}/services/updater_binary/update_image_patch.cpp",
168    "${updater_path}/services/updater_binary/update_partitions.cpp",
169    "${updater_path}/services/updater_binary/update_processor.cpp",
170  ]
171
172  defines = [
173    "HARMONY_PROJECT",
174    "OPENSSL_SUPPRESS_DEPRECATED",
175  ]
176
177  deps = [
178    ":flashd_deamon",
179    "${updater_path}/interfaces/kits/misc_info:libmiscinfo",
180    "${updater_path}/interfaces/kits/slot_info:libslotinfo",
181    "${updater_path}/interfaces/kits/updaterkits:libupdaterkits",
182    "${updater_path}/services/applypatch:libapplypatch",
183    "${updater_path}/services/common/ring_buffer:libringbuffer",
184    "${updater_path}/services/diffpatch/patch:libpatch",
185    "${updater_path}/services/flashd:hdc_hash_gen",
186    "${updater_path}/services/flow_update/update_bin:libBinFlowUpdate",
187    "${updater_path}/services/fs_manager:libfsmanager",
188    "${updater_path}/services/hdi/server:libupdate_hdi_impl",
189    "${updater_path}/services/log:libupdaterlog",
190    "${updater_path}/services/package:libupdaterpackage",
191    "${updater_path}/services/script:libupdaterscript",
192    "${updater_path}/utils:libutils",
193  ]
194
195  include_dirs = [
196    "${updater_path}/services",
197    "${updater_path}/services/common",
198    "${updater_path}/services/flashd",
199    "${updater_path}/services/flashd/daemon",
200    "${updater_path}/services/flashd/common",
201    "${updater_path}/services/flow_update",
202    "${updater_path}/interfaces/kits/include",
203    "${updater_path}/services/include/package",
204    "${updater_path}/services/include/ptable_parse",
205    "${updater_path}/services/include/script",
206    "${updater_path}/services/include/log",
207    "${updater_path}/services/include",
208    "${updater_path}/services/ptable_parse",
209    "${updater_path}/utils/include",
210    "${updater_path}/utils/json",
211  ]
212
213  if (defined(use_ptable)) {
214    include_dirs += [ "${updater_path}/services/ptable_parse" ]
215    deps += [ "${updater_path}/services/ptable_parse:libptableparse" ]
216    defines += [ "UPDATER_USE_PTABLE" ]
217  }
218
219  external_deps = [
220    "bounds_checking_function:libsec_static",
221    "bzip2:libbz2",
222    "cJSON:cjson",
223    "c_utils:utils",
224    "init:libbegetutil_static",
225    "libuv:uv",
226    "lz4:liblz4_static",
227    "openssl:libcrypto_shared",
228    "zlib:libz",
229  ]
230
231  if (updater_hdc_depend) {
232    external_deps += [ "hdc:hdc_updater" ]
233  }
234
235  if (build_selinux) {
236    external_deps += [ "selinux:libselinux_static" ]
237    defines += [ "SURPPORT_SELINUX" ]
238  }
239
240  if (defined(binary_custom_external_deps)) {
241    external_deps += binary_custom_external_deps
242  }
243
244  part_name = "updater"
245  subsystem_name = "updater"
246}
247
248group("updater_flashd") {
249  deps = [ ":libflashd" ]
250}
251