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 if (use_musl) { 107 if (use_jemalloc && use_jemalloc_dfx_intf) { 108 defines += [ "CONFIG_USE_JEMALLOC_DFX_INIF" ] 109 } 110 } 111 if (is_emulator) { 112 defines += [ "HDC_EMULATOR" ] 113 } 114 configs = [ ":hdc_config" ] 115 116 deps = [ 117 "//third_party/libuv:uv", 118 "//third_party/lz4:liblz4_static", 119 "//third_party/openssl:libcrypto_shared", 120 ] 121 122 deps += [ 123 ":hdc_hash_gen", 124 "src/daemon/etc:daemon_etc", 125 ] 126 127 if (hdc_jdwp_test) { 128 defines += [ "SIMULATE_JDWP" ] 129 deps += [ "src/test/jdwp:jdwp_test" ] 130 } 131 132 external_deps = [ 133 "c_utils:utilsbase", 134 "hilog:libhilog", 135 "init:libbegetutil", 136 ] 137 138 include_dirs = [ 139 "//third_party/bounds_checking_function/include", 140 "//third_party/lz4/lib", 141 "//third_party/openssl/include", 142 "//third_party/libuv", 143 ] 144 145 if (build_selinux) { 146 deps += [ "//third_party/selinux:libselinux" ] 147 include_dirs += [ "//third_party/selinux/libselinux/include" ] 148 defines += [ "SURPPORT_SELINUX" ] 149 if (image_name == "updater") { 150 defines += [ "UPDATER_MODE" ] 151 } 152 if (image_name == "system") { 153 defines += [ "HDC_TRACE" ] 154 external_deps += [ "hitrace:hitrace_meter" ] 155 } 156 } 157 158 if (hdc_version_check) { 159 defines += [ "HDC_VERSION_CHECK" ] 160 } 161 162 ldflags = [ "-rdynamic" ] 163 164 subsystem_name = "developtools" 165 part_name = "hdc" 166 } 167} 168 169template("build_hdc") { 170 forward_variables_from(invoker, "*") 171 image_name = target_name 172 hdcd_source_set("hdcd_${image_name}_source") { 173 if (build_selinux) { 174 image_name = image_name 175 } 176 177 subsystem_name = "developtools" 178 part_name = "hdc" 179 } 180 181 ohos_executable("hdcd_${image_name}_exe") { 182 deps = [ ":hdcd_${image_name}_source" ] 183 output_name = "hdcd_${image_name}" 184 install_enable = false 185 subsystem_name = "developtools" 186 part_name = "hdc" 187 } 188 189 ohos_prebuilt_executable("hdcd_${image_name}") { 190 deps = [ ":hdcd_${image_name}_exe" ] 191 output = "${image_name}/hdcd" 192 install_enable = true 193 subsystem_name = "developtools" 194 part_name = "hdc" 195 source = "${root_out_dir}/${subsystem_name}/${part_name}/hdcd_${image_name}" 196 module_install_dir = "bin" 197 install_images = [] 198 if (image_name == "updater") { 199 install_images = [ "updater" ] 200 } else { 201 install_images = [ "system" ] 202 } 203 } 204} 205 206build_hdc("system") { 207} 208 209build_hdc("updater") { 210} 211 212ohos_executable("hdc") { 213 use_exceptions = true 214 ldflags = [] 215 libs = [] 216 configs = [ ":hdc_config" ] 217 defines = [ 218 "HDC_HOST", 219 "HARMONY_PROJECT", 220 "USE_CONFIG_UV_THREADS", 221 "SIZE_THREAD_POOL=$hdc_uv_thread_size", 222 "OPENSSL_SUPPRESS_DEPRECATED", 223 ] 224 if (is_mac) { 225 defines += [ "HOST_MAC" ] 226 } 227 if (hdc_debug) { 228 defines += [ "HDC_DEBUG" ] 229 } 230 sources = [ 231 "src/host/client.cpp", 232 "src/host/ext_client.cpp", 233 "src/host/host_app.cpp", 234 "src/host/host_forward.cpp", 235 "src/host/host_tcp.cpp", 236 "src/host/host_unity.cpp", 237 "src/host/host_updater.cpp", 238 "src/host/host_usb.cpp", 239 "src/host/main.cpp", 240 "src/host/server.cpp", 241 "src/host/server_for_client.cpp", 242 "src/host/translate.cpp", 243 ] 244 sources += hdc_common_sources 245 if (hdc_support_uart) { 246 defines += [ "HDC_SUPPORT_UART" ] 247 sources += [ "src/host/host_uart.cpp" ] 248 } 249 250 deps = [ 251 "//third_party/bounds_checking_function:libsec_static", 252 "//third_party/libusb:libusb", 253 "//third_party/libuv:uv_static", 254 "//third_party/lz4:liblz4_static", 255 "//third_party/openssl:libcrypto_static", 256 ] 257 258 deps += [ ":hdc_hash_gen" ] 259 260 include_dirs = [ 261 "//third_party/bounds_checking_function/include", 262 "//third_party/lz4/lib", 263 "//third_party/openssl/include", 264 "//third_party/libuv", 265 ] 266 267 if (!(is_mingw || is_mac) && build_selinux) { 268 deps += [ "//third_party/selinux:libselinux" ] 269 include_dirs += [ "//third_party/selinux/libselinux/include" ] 270 defines += [ "SURPPORT_SELINUX" ] 271 } 272 273 if (hdc_version_check) { 274 defines += [ "HDC_VERSION_CHECK" ] 275 } 276 277 if (is_mingw) { 278 static_link = false 279 280 # we should use something we define , not just _WIN32 (this will defined in some windows header) 281 defines += [ "HOST_MINGW" ] # we define this for mingw 282 defines += [ "WIN32_LEAN_AND_MEAN" ] 283 libs += [ "setupapi" ] 284 ldflags += [ 285 "-Wl,--whole-archive", 286 "-lpthread", 287 "-Wl,--no-whole-archive", 288 ] 289 } 290 291 if (is_linux) { 292 static_link = false 293 defines += [ "HOST_LINUX" ] 294 ldflags += [ 295 "-Wl,--whole-archive", 296 "-lpthread", 297 "-latomic", 298 "-ldl", 299 "-lrt", 300 "-Wl,--no-whole-archive", 301 ] 302 } 303 304 subsystem_name = "developtools" 305 part_name = "hdc" 306} 307 308group("hdc_target") { 309 deps = [ 310 ":hdc", 311 ":hdc_register", 312 ":hdcd_system", 313 ":hdcd_updater", 314 ] 315} 316 317group("hdc_target_all") { 318 deps = [ ":hdc_target" ] 319} 320 321group("hdc_all") { 322 testonly = true 323 deps = [ ":hdc_target_all" ] 324} 325 326group("hdc_test_target") { 327 testonly = true 328 deps = [ "test:hdc_fuzztest" ] 329} 330 331action("hdc_hash_gen") { 332 script = "scripts/hdc_hash_gen.py" 333 sources = hash_sources 334 outputs = [ "$py_out_dir" ] 335 args = [ 336 "-f", 337 "hdc_hash_gen.h", 338 "-i", 339 rebase_path(".", root_build_dir), 340 "-o", 341 rebase_path("$py_out_dir" + "/", root_build_dir), 342 ] 343 public_configs = [ ":hdc_config" ] 344} 345 346config("hdc_register_config") { 347 cflags_cc = [ 348 "-fexceptions", 349 "-fno-complete-member-pointers", 350 "-Wno-implicit-fallthrough", 351 "-fvisibility=default", 352 "-frtti", 353 "-std=c++17", 354 ] 355} 356 357ohos_shared_library("hdc_register") { 358 deps = [] 359 defines = [ 360 "JS_JDWP_CONNECT", 361 "HDC_HILOG", 362 ] 363 364 external_deps = [ 365 "c_utils:utilsbase", 366 "hilog:libhilog", 367 ] 368 369 deps += [ 370 "//third_party/bounds_checking_function:libsec_shared", 371 "//third_party/libuv:uv", 372 ] 373 374 sources = [ 375 "src/register/hdc_connect.cpp", 376 "src/register/hdc_jdwp.cpp", 377 ] 378 379 configs = [ ":hdc_register_config" ] 380 381 subsystem_name = "developtools" 382 part_name = "hdc" 383} 384