• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ohos.gni")
15HDC_PATH = "."
16import("//developtools/hdc/hdc.gni")
17
18py_out_dir = "$root_out_dir/gen/" + rebase_path(".", "//")
19
20declare_args() {
21  # suggestion: uv threads number from 16 - 256
22  hdcd_uv_thread_size = 4
23  hdc_uv_thread_size = 128
24}
25
26hdc_common_sources = [
27  "src/common/async_cmd.cpp",
28  "src/common/auth.cpp",
29  "src/common/base.cpp",
30  "src/common/channel.cpp",
31  "src/common/circle_buffer.cpp",
32  "src/common/debug.cpp",
33  "src/common/file.cpp",
34  "src/common/file_descriptor.cpp",
35  "src/common/forward.cpp",
36  "src/common/session.cpp",
37  "src/common/task.cpp",
38  "src/common/tcp.cpp",
39  "src/common/transfer.cpp",
40  "src/common/usb.cpp",
41]
42
43hash_sources = [
44  "scripts/hdc_hash_gen.py",
45  "src/common/base.cpp",
46  "src/common/channel.h",
47  "src/common/session.h",
48  "src/common/transfer.h",
49]
50
51if (hdc_support_uart) {
52  hdc_common_sources += [ "src/common/uart.cpp" ]
53}
54config("hdc_config") {
55  include_dirs = [
56    "src/common",
57    "${py_out_dir}",
58  ]
59  cflags_cc = [ "-std=c++17" ]
60  if (is_mingw) {
61    cflags_cc += [ "-Wno-inconsistent-dllimport" ]  # in mingw some sec api will
62                                                    # overwrite by utilsecurec
63  }
64}
65
66template("hdcd_source_set") {
67  forward_variables_from(invoker, "*")
68
69  ohos_source_set(target_name) {
70    use_exceptions = true
71    sources = [
72      "src/daemon/daemon.cpp",
73      "src/daemon/daemon_app.cpp",
74      "src/daemon/daemon_bridge.cpp",
75      "src/daemon/daemon_forward.cpp",
76      "src/daemon/daemon_tcp.cpp",
77      "src/daemon/daemon_unity.cpp",
78      "src/daemon/daemon_usb.cpp",
79      "src/daemon/jdwp.cpp",
80      "src/daemon/main.cpp",
81      "src/daemon/shell.cpp",
82      "src/daemon/system_depend.cpp",
83    ]
84    sources += hdc_common_sources
85
86    defines = [
87      "HARMONY_PROJECT",
88      "USE_CONFIG_UV_THREADS",
89      "SIZE_THREAD_POOL=$hdcd_uv_thread_size",
90      "HDC_HILOG",
91      "OPENSSL_SUPPRESS_DEPRECATED",
92    ]
93
94    if (hdc_debug) {
95      defines += [ "HDC_DEBUG" ]
96    }
97    if (hdc_support_uart) {
98      defines += [ "HDC_SUPPORT_UART" ]
99      sources += [ "src/daemon/daemon_uart.cpp" ]
100    }
101    if (js_jdwp_connect) {
102      defines += [ "JS_JDWP_CONNECT" ]
103    }
104    if (build_variant == "user") {
105      defines += [ "HDC_BUILD_VARIANT_USER" ]
106    }
107    if (use_musl) {
108      if (use_jemalloc && use_jemalloc_dfx_intf) {
109        defines += [ "CONFIG_USE_JEMALLOC_DFX_INIF" ]
110      }
111    }
112    if (is_emulator) {
113      defines += [ "HDC_EMULATOR" ]
114    }
115    configs = [ ":hdc_config" ]
116
117    deps = []
118
119    deps += [
120      ":hdc_hash_gen",
121      "src/daemon/etc:daemon_etc",
122    ]
123
124    if (hdc_jdwp_test) {
125      defines += [ "SIMULATE_JDWP" ]
126      deps += [ "src/test/jdwp:jdwp_test" ]
127    }
128
129    external_deps = [
130      "bounds_checking_function:libsec_shared",
131      "c_utils:utilsbase",
132      "hilog:libhilog",
133      "init:libbegetutil",
134      "libuv:uv",
135      "lz4:liblz4_static",
136      "openssl:libcrypto_shared",
137    ]
138
139    if (build_selinux) {
140      external_deps += [ "selinux:libselinux" ]
141      defines += [ "SURPPORT_SELINUX" ]
142      if (image_name == "updater") {
143        defines += [ "UPDATER_MODE" ]
144      }
145      if (image_name == "system") {
146        defines += [ "HDC_TRACE" ]
147        external_deps += [ "hitrace:hitrace_meter" ]
148      }
149    }
150
151    if (hdc_version_check) {
152      defines += [ "HDC_VERSION_CHECK" ]
153    }
154
155    ldflags = [ "-rdynamic" ]
156
157    subsystem_name = "developtools"
158    part_name = "hdc"
159  }
160}
161
162if (product_name != "ohos-sdk") {
163  ohos_static_library("serialize_structs") {
164    sources = [
165      "hdc_rust/src/cffi/bridge.cpp",
166      "hdc_rust/src/cffi/cmd.cpp",
167      "hdc_rust/src/cffi/getparameter.cpp",
168      "hdc_rust/src/cffi/log.cpp",
169      "hdc_rust/src/cffi/mount.cpp",
170      "hdc_rust/src/cffi/mount_wrapper.cpp",
171      "hdc_rust/src/cffi/oh_usb.cpp",
172      "hdc_rust/src/cffi/sendmsg.cpp",
173      "hdc_rust/src/cffi/serial_struct.cpp",
174      "hdc_rust/src/cffi/sys_para.cpp",
175      "hdc_rust/src/cffi/transfer.cpp",
176      "hdc_rust/src/cffi/uart.cpp",
177      "hdc_rust/src/cffi/uart_wrapper.cpp",
178      "hdc_rust/src/cffi/usb_util.cpp",
179      "hdc_rust/src/cffi/usb_wrapper.cpp",
180      "hdc_rust/src/cffi/utils.cpp",
181    ]
182    output_extension = "so"
183
184    external_deps = [
185      "bounds_checking_function:libsec_static",
186      "hilog:libhilog",
187      "init:libbegetutil",
188      "lz4:liblz4_static",
189    ]
190
191    defines = [ "HDC_HILOG" ]
192
193    if (is_mac) {
194      defines = [ "HOST_MAC" ]
195    }
196
197    if (build_selinux) {
198      external_deps += [ "selinux:libselinux" ]
199      defines += [ "SURPPORT_SELINUX" ]
200    }
201
202    subsystem_name = "developtools"
203    part_name = "hdc"
204  }
205
206  ohos_rust_shared_library("lib") {
207    crate_name = "hdc"
208    crate_type = "dylib"
209    crate_root = "hdc_rust/src/lib.rs"
210    sources = [ "hdc_rust/src/lib.rs" ]
211
212    deps = [
213      ":serialize_structs",
214      "//third_party/rust/crates/humantime:lib",
215      "//third_party/rust/crates/libc:lib",
216      "//third_party/rust/crates/log:lib",
217      "//third_party/rust/crates/rust-openssl/openssl:lib",
218    ]
219    if (is_emulator && product_name != "ohos-sdk") {
220      features = [ "emulator" ]
221    }
222    external_deps = [
223      "hilog:hilog_rust",
224      "ylong_runtime:ylong_runtime",
225    ]
226    subsystem_name = "developtools"
227    part_name = "hdc"
228  }
229}
230
231template("build_hdc") {
232  forward_variables_from(invoker, "*")
233  image_name = target_name
234  hdcd_source_set("hdcd_${image_name}_source") {
235    if (build_selinux) {
236      image_name = image_name
237    }
238
239    subsystem_name = "developtools"
240    part_name = "hdc"
241  }
242
243  if (image_name == "system") {
244    if (is_emulator || use_clang_coverage) {
245      ohos_executable("hdcd_${image_name}_exe") {
246        deps = [ ":hdcd_${image_name}_source" ]
247        output_name = "hdcd_${image_name}"
248        install_enable = false
249        subsystem_name = "developtools"
250        part_name = "hdc"
251      }
252    } else {
253      ohos_rust_executable("hdcd_${image_name}_exe") {
254        sources = [ "hdc_rust/src/daemon/main.rs" ]
255        deps = [
256          ":lib",
257          ":serialize_structs",
258          "//third_party/rust/crates/env_logger:lib",
259          "//third_party/rust/crates/humantime:lib",
260          "//third_party/rust/crates/libc:lib",
261          "//third_party/rust/crates/log:lib",
262          "//third_party/rust/crates/nix:lib",
263          "//third_party/rust/crates/rust-openssl/openssl:lib",
264        ]
265        external_deps = [ "hilog:hilog_rust" ]
266
267        if (product_name != "ohos_sdk") {
268          external_deps += [ "ylong_runtime:ylong_runtime" ]
269        }
270        if (!defined(ohos_lite)) {
271          external_deps += [ "faultloggerd:panic_handler" ]
272        }
273
274        output_name = "hdcd_${image_name}"
275        install_enable = false
276        features = [ "daemon" ]
277        if (is_emulator) {
278          features += [ "emulator" ]
279        }
280        subsystem_name = "developtools"
281        part_name = "hdc"
282      }
283    }
284  } else {
285    ohos_executable("hdcd_${image_name}_exe") {
286      deps = [ ":hdcd_${image_name}_source" ]
287      output_name = "hdcd_${image_name}"
288      install_enable = false
289      subsystem_name = "developtools"
290      part_name = "hdc"
291    }
292  }
293
294  ohos_prebuilt_executable("hdcd_${image_name}") {
295    deps = [ ":hdcd_${image_name}_exe" ]
296    output = "${image_name}/hdcd"
297    install_enable = true
298    subsystem_name = "developtools"
299    part_name = "hdc"
300    source = "${root_out_dir}/${subsystem_name}/${part_name}/hdcd_${image_name}"
301    module_install_dir = "bin"
302    install_images = []
303    if (image_name == "updater") {
304      install_images = [ "updater" ]
305    } else {
306      install_images = [ "system" ]
307    }
308  }
309}
310
311build_hdc("system") {
312}
313
314build_hdc("updater") {
315}
316
317ohos_executable("hdc") {
318  use_exceptions = true
319  ldflags = []
320  libs = []
321  configs = [ ":hdc_config" ]
322  defines = [
323    "HDC_HOST",
324    "HARMONY_PROJECT",
325    "USE_CONFIG_UV_THREADS",
326    "SIZE_THREAD_POOL=$hdc_uv_thread_size",
327    "OPENSSL_SUPPRESS_DEPRECATED",
328  ]
329  if (is_mac) {
330    defines += [ "HOST_MAC" ]
331  }
332  if (hdc_debug) {
333    defines += [ "HDC_DEBUG" ]
334  }
335  sources = [
336    "src/host/client.cpp",
337    "src/host/ext_client.cpp",
338    "src/host/host_app.cpp",
339    "src/host/host_forward.cpp",
340    "src/host/host_tcp.cpp",
341    "src/host/host_unity.cpp",
342    "src/host/host_updater.cpp",
343    "src/host/host_usb.cpp",
344    "src/host/main.cpp",
345    "src/host/server.cpp",
346    "src/host/server_for_client.cpp",
347    "src/host/translate.cpp",
348  ]
349  sources += hdc_common_sources
350  if (hdc_support_uart) {
351    defines += [ "HDC_SUPPORT_UART" ]
352    sources += [ "src/host/host_uart.cpp" ]
353  }
354
355  deps = []
356
357  external_deps = [
358    "bounds_checking_function:libsec_static",
359    "libusb:libusb",
360    "libuv:uv_static",
361    "lz4:liblz4_static",
362    "openssl:libcrypto_static",
363  ]
364
365  deps += [ ":hdc_hash_gen" ]
366
367  if (!(is_mingw || is_mac) && build_selinux) {
368    external_deps += [ "selinux:libselinux" ]
369    defines += [ "SURPPORT_SELINUX" ]
370  }
371
372  if (hdc_version_check) {
373    defines += [ "HDC_VERSION_CHECK" ]
374  }
375
376  if (is_mingw) {
377    static_link = false
378
379    # we should use something we define , not just _WIN32 (this will defined in some windows header)
380    defines += [ "HOST_MINGW" ]  # we define this for mingw
381    defines += [ "WIN32_LEAN_AND_MEAN" ]
382    libs += [ "setupapi" ]
383    ldflags += [
384      "-Wl,--whole-archive",
385      "-lpthread",
386      "-Wl,--no-whole-archive",
387    ]
388  }
389
390  if (is_linux) {
391    static_link = false
392    defines += [ "HOST_LINUX" ]
393    ldflags += [
394      "-Wl,--whole-archive",
395      "-lpthread",
396      "-latomic",
397      "-ldl",
398      "-lrt",
399      "-Wl,--no-whole-archive",
400    ]
401  }
402
403  subsystem_name = "developtools"
404  part_name = "hdc"
405}
406
407group("hdc_target") {
408  deps = [
409    ":hdc",
410    ":hdc_register",
411    ":hdcd_system",
412    ":hdcd_updater",
413  ]
414}
415
416group("hdc_target_all") {
417  deps = [ ":hdc_target" ]
418}
419
420group("hdc_all") {
421  testonly = true
422  deps = [ ":hdc_target_all" ]
423}
424
425group("hdc_test_target") {
426  testonly = true
427  deps = [ "test:hdc_fuzztest" ]
428}
429
430action("hdc_hash_gen") {
431  script = "scripts/hdc_hash_gen.py"
432  sources = hash_sources
433  outputs = [ "$py_out_dir" ]
434  args = [
435    "-f",
436    "hdc_hash_gen.h",
437    "-i",
438    rebase_path(".", root_build_dir),
439    "-o",
440    rebase_path("$py_out_dir" + "/", root_build_dir),
441  ]
442  public_configs = [ ":hdc_config" ]
443}
444
445config("hdc_register_config") {
446  include_dirs = [
447    "src/common",
448    "src/daemon",
449  ]
450
451  cflags_cc = [
452    "-fexceptions",
453    "-fno-complete-member-pointers",
454    "-Wno-implicit-fallthrough",
455    "-fvisibility=default",
456    "-frtti",
457    "-std=c++17",
458  ]
459}
460
461ohos_shared_library("hdc_register") {
462  deps = []
463  defines = [
464    "JS_JDWP_CONNECT",
465    "HDC_HILOG",
466  ]
467
468  external_deps = [
469    "bounds_checking_function:libsec_shared",
470    "c_utils:utilsbase",
471    "hilog:libhilog",
472    "libuv:uv",
473  ]
474
475  sources = [
476    "src/register/hdc_connect.cpp",
477    "src/register/hdc_jdwp.cpp",
478  ]
479
480  public_configs = [ ":hdc_register_config" ]
481
482  innerapi_tags = [ "platformsdk" ]
483  subsystem_name = "developtools"
484  part_name = "hdc"
485  install_images = [ "updater" ]
486}
487