From 3d4e98e5906dde19f0cc905e33d37d291db9c017 Mon Sep 17 00:00:00 2001 From: handyohos Date: Wed, 28 Dec 2022 20:31:33 +0800 Subject: [PATCH] Feature: hide symbols for napi modules 1) add version_script for napi modules. 2) white list for napi modules depended by other modules right now. Signed-off-by: handyohos Change-Id: Idf4cb3de544e27c7ed57b9ef98afea2d05742ad9 #I67WFI --- config/BUILDCONFIG.gn | 4 ++++ templates/cxx/cxx.gni | 25 +++++++++++++++++++++++++ templates/cxx/napi.versionscript | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+) mode change 100644 => 100755 config/BUILDCONFIG.gn create mode 100755 templates/cxx/napi.versionscript diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn old mode 100644 new mode 100755 index f2c01dadeb..de4fb88ebb --- a/config/BUILDCONFIG.gn +++ b/config/BUILDCONFIG.gn @@ -82,6 +82,10 @@ product_build_config = global_parts_info = read_file("${preloader_output_dir}/parts_config.json", "json") +napi_white_list = read_file( + "//developtools/integration_verification/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json", + "json") + product_company = product_build_config.product_company device_company = product_build_config.device_company device_build_path = product_build_config.device_build_path diff --git a/templates/cxx/cxx.gni b/templates/cxx/cxx.gni index 2bdeee63c4..93abc65918 100755 --- a/templates/cxx/cxx.gni +++ b/templates/cxx/cxx.gni @@ -745,6 +745,31 @@ template("ohos_shared_library") { ldflags += [ "-Wl,--version-script=${_version_script}" ] } } + + module_type_napi = false + if (defined(invoker.relative_install_dir) && product_name != "ohos-sdk") { + relative_paths = string_split(invoker.relative_install_dir, "/") + foreach(p, relative_paths) { + if (p == "module") { + module_type_napi = true + } + } + if (module_type_napi) { + foreach(m, filter_include(napi_white_list, [ target_name ])) { + if (m == target_name) { + module_type_napi = false + } + } + } + } + if (module_type_napi) { + if (!defined(invoker.version_script)) { + _version_script = + rebase_path("//build/templates/cxx/napi.versionscript") + inputs += [ _version_script ] + ldflags += [ "-Wl,--version-script=${_version_script}" ] + } + } } } diff --git a/templates/cxx/napi.versionscript b/templates/cxx/napi.versionscript new file mode 100755 index 0000000000..016214a3c5 --- /dev/null +++ b/templates/cxx/napi.versionscript @@ -0,0 +1,23 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +1.0 { + global: + _init; + _fini; + NAPI_*_GetABCCode; + NAPI_*_GetJSCode; + + local: + *; +}; -- Gitee