• 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_forward.cpp",
75      "src/daemon/daemon_tcp.cpp",
76      "src/daemon/daemon_unity.cpp",
77      "src/daemon/daemon_usb.cpp",
78      "src/daemon/jdwp.cpp",
79      "src/daemon/main.cpp",
80      "src/daemon/shell.cpp",
81      "src/daemon/system_depend.cpp",
82    ]
83    sources += hdc_common_sources
84
85    defines = [
86      "HARMONY_PROJECT",
87      "USE_CONFIG_UV_THREADS",
88      "SIZE_THREAD_POOL=$hdcd_uv_thread_size",
89      "HDC_HILOG",
90      "OPENSSL_SUPPRESS_DEPRECATED",
91    ]
92
93    if (hdc_debug) {
94      defines += [ "HDC_DEBUG" ]
95    }
96    if (hdc_support_uart) {
97      defines += [ "HDC_SUPPORT_UART" ]
98      sources += [ "src/daemon/daemon_uart.cpp" ]
99    }
100    if (js_jdwp_connect) {
101      defines += [ "JS_JDWP_CONNECT" ]
102    }
103    if (build_variant == "user") {
104      defines += [ "HDC_BUILD_VARIANT_USER" ]
105    }
106    configs = [ ":hdc_config" ]
107
108    deps = [
109      "//third_party/libuv:uv",
110      "//third_party/lz4:liblz4_static",
111      "//third_party/openssl:libcrypto_shared",
112    ]
113
114    deps += [
115      ":hdc_hash_gen",
116      "src/daemon/etc:daemon_etc",
117    ]
118
119    if (hdc_jdwp_test) {
120      defines += [ "SIMULATE_JDWP" ]
121      deps += [ "src/test/jdwp:jdwp_test" ]
122    }
123
124    external_deps = [
125      "c_utils:utilsbase",
126      "hilog:libhilog",
127      "init:libbegetutil",
128    ]
129
130    include_dirs = [
131      "//third_party/bounds_checking_function/include",
132      "//third_party/lz4/lib",
133      "//third_party/openssl/include",
134      "//third_party/libuv",
135    ]
136
137    if (build_selinux) {
138      deps += [ "//third_party/selinux:libselinux" ]
139      include_dirs += [ "//third_party/selinux/libselinux/include" ]
140      defines += [ "SURPPORT_SELINUX" ]
141      if (image_name == "updater") {
142        defines += [ "UPDATER_MODE" ]
143      }
144      if (image_name == "system") {
145        defines += [ "HDC_TRACE" ]
146        external_deps += [ "hitrace:hitrace_meter" ]
147      }
148    }
149
150    if (hdc_version_check) {
151      defines += [ "HDC_VERSION_CHECK" ]
152    }
153
154    ldflags = [ "-rdynamic" ]
155
156    subsystem_name = "developtools"
157    part_name = "hdc"
158  }
159}
160
161template("build_hdc") {
162  forward_variables_from(invoker, "*")
163  image_name = target_name
164  hdcd_source_set("hdcd_${image_name}_source") {
165    if (build_selinux) {
166      image_name = image_name
167    }
168
169    subsystem_name = "developtools"
170    part_name = "hdc"
171  }
172
173  ohos_executable("hdcd_${image_name}_exe") {
174    deps = [ ":hdcd_${image_name}_source" ]
175    output_name = "hdcd_${image_name}"
176    install_enable = false
177    subsystem_name = "developtools"
178    part_name = "hdc"
179  }
180
181  ohos_prebuilt_executable("hdcd_${image_name}") {
182    deps = [ ":hdcd_${image_name}_exe" ]
183    output = "${image_name}/hdcd"
184    install_enable = true
185    subsystem_name = "developtools"
186    part_name = "hdc"
187    source = "${root_out_dir}/${subsystem_name}/${part_name}/hdcd_${image_name}"
188    module_install_dir = "bin"
189    install_images = []
190    if (image_name == "updater") {
191      install_images = [ "updater" ]
192    } else {
193      install_images = [ "system" ]
194    }
195  }
196}
197
198build_hdc("system") {
199}
200
201build_hdc("updater") {
202}
203
204ohos_executable("hdc") {
205  use_exceptions = true
206  ldflags = []
207  libs = []
208  configs = [ ":hdc_config" ]
209  defines = [
210    "HDC_HOST",
211    "HARMONY_PROJECT",
212    "USE_CONFIG_UV_THREADS",
213    "SIZE_THREAD_POOL=$hdc_uv_thread_size",
214    "OPENSSL_SUPPRESS_DEPRECATED",
215  ]
216  if (is_mac) {
217    defines += [ "HOST_MAC" ]
218  }
219  if (hdc_debug) {
220    defines += [ "HDC_DEBUG" ]
221  }
222  sources = [
223    "src/host/client.cpp",
224    "src/host/ext_client.cpp",
225    "src/host/host_app.cpp",
226    "src/host/host_forward.cpp",
227    "src/host/host_tcp.cpp",
228    "src/host/host_unity.cpp",
229    "src/host/host_updater.cpp",
230    "src/host/host_usb.cpp",
231    "src/host/main.cpp",
232    "src/host/server.cpp",
233    "src/host/server_for_client.cpp",
234    "src/host/translate.cpp",
235  ]
236  sources += hdc_common_sources
237  if (hdc_support_uart) {
238    defines += [ "HDC_SUPPORT_UART" ]
239    sources += [ "src/host/host_uart.cpp" ]
240  }
241
242  deps = [
243    "//third_party/bounds_checking_function:libsec_static",
244    "//third_party/libusb:libusb",
245    "//third_party/libuv:uv_static",
246    "//third_party/lz4:liblz4_static",
247    "//third_party/openssl:libcrypto_static",
248  ]
249
250  deps += [ ":hdc_hash_gen" ]
251
252  include_dirs = [
253    "//third_party/bounds_checking_function/include",
254    "//third_party/lz4/lib",
255    "//third_party/openssl/include",
256    "//third_party/libuv",
257  ]
258
259  if (!(is_mingw || is_mac) && build_selinux) {
260    deps += [ "//third_party/selinux:libselinux" ]
261    include_dirs += [ "//third_party/selinux/libselinux/include" ]
262    defines += [ "SURPPORT_SELINUX" ]
263  }
264
265  if (hdc_version_check) {
266    defines += [ "HDC_VERSION_CHECK" ]
267  }
268
269  if (is_mingw) {
270    static_link = false
271
272    # we should use something we define , not just _WIN32 (this will defined in some windows header)
273    defines += [ "HOST_MINGW" ]  # we define this for mingw
274    defines += [ "WIN32_LEAN_AND_MEAN" ]
275    libs += [ "setupapi" ]
276    ldflags += [
277      "-Wl,--whole-archive",
278      "-lpthread",
279      "-Wl,--no-whole-archive",
280    ]
281  }
282
283  if (is_linux) {
284    static_link = false
285    defines += [ "HOST_LINUX" ]
286    ldflags += [
287      "-Wl,--whole-archive",
288      "-lpthread",
289      "-latomic",
290      "-ldl",
291      "-lrt",
292      "-Wl,--no-whole-archive",
293    ]
294  }
295
296  subsystem_name = "developtools"
297  part_name = "hdc"
298}
299
300group("hdc_target") {
301  deps = [
302    ":hdc",
303    ":hdcd_system",
304    ":hdcd_updater",
305  ]
306}
307
308group("hdc_target_all") {
309  deps = [ ":hdc_target" ]
310}
311
312group("hdc_all") {
313  testonly = true
314  deps = [ ":hdc_target_all" ]
315}
316
317group("hdc_test_target") {
318  testonly = true
319  deps = [ "test:hdc_fuzztest" ]
320}
321
322action("hdc_hash_gen") {
323  script = "scripts/hdc_hash_gen.py"
324  sources = hash_sources
325  outputs = [ "$py_out_dir" ]
326  args = [
327    "-f",
328    "hdc_hash_gen.h",
329    "-i",
330    rebase_path(".", root_build_dir),
331    "-o",
332    rebase_path("$py_out_dir" + "/", root_build_dir),
333  ]
334  public_configs = [ ":hdc_config" ]
335}
336