From c1d18cb6a74dd34411b6e948f3fb76be4275a939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=89=8D=E6=9D=B0?= Date: Wed, 7 May 2025 09:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=9E=84=E5=BB=BA=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E4=BF=AE=E6=94=B9=E6=BA=90=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=BA=90=E7=A0=81=E6=95=B4=E6=94=B9=E7=94=9F=E6=88=90=E5=9C=A8?= =?UTF-8?q?out=E7=9B=AE=E5=BD=95=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周才杰 --- BUILD.gn | 153 +++++++++++------------------------------- bundle.json | 6 ++ copy_generic_files.sh | 31 +++++++++ 3 files changed, 76 insertions(+), 114 deletions(-) create mode 100755 copy_generic_files.sh diff --git a/BUILD.gn b/BUILD.gn index 6ff9dd6..46a0c18 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -16,8 +16,43 @@ import("//build/ohos.gni") PCRE2_LIB_DIR = "//third_party/pcre2/pcre2" +# use action replace exec_script +action("copy_generic_files") { + script = rebase_path("//third_party/pcre2/copy_generic_files.sh") + inputs = [ + "$PCRE2_LIB_DIR/src/config.h.generic", + "$PCRE2_LIB_DIR/src/pcre2.h.generic", + "$PCRE2_LIB_DIR/src/pcre2_chartables.c", + ] + outputs = [ + "${target_gen_dir}/src/pcre2_chartables.c", + ] + args = [ + rebase_path("$PCRE2_LIB_DIR"), + rebase_path("${target_gen_dir}"), + ] +} + +# srcs depended by glib +ohos_shared_headers("pcre2_generated_headers") { + include_dirs = [get_label_info(":copy_generic_files", "target_gen_dir") + "/src"] + deps = [":copy_generic_files"] + part_name = "pcre2" + subsystem_name = "thirdparty" +} + +# include dir depended by glib +ohos_prebuilt_etc("publish_generic_file") { + source = get_label_info(":copy_generic_files", "target_gen_dir") + "/src/pcre2_chartables.c" + output = "pcre2_chartables.c" + part_name = "pcre2" + subsystem_name = "thirdparty" + deps = [":copy_generic_files"] +} + config("third_party_pcre2_config") { include_dirs = [ "$PCRE2_LIB_DIR/src" ] + include_dirs += [ "${target_gen_dir}/src" ] } pcre2_sources = [ @@ -51,63 +86,11 @@ pcre2_sources = [ ] ohos_shared_library("libpcre2") { + deps = [ ":publish_generic_file" ] branch_protector_ret = "pac_ret" - - md5_check_script = rebase_path("$PCRE2_LIB_DIR/check_md5.sh") - _arguments_config = [ - rebase_path("$PCRE2_LIB_DIR/src/config.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src/config.h"), - ] - - check_config_result = - exec_script(md5_check_script, _arguments_config, "string") - if (check_config_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/config.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src/config.h"), - ]) - } - - _arguments_pcre2 = [ - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h"), - ] - - check_pcre2_result = exec_script(md5_check_script, _arguments_pcre2, "string") - if (check_pcre2_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h"), - ]) - } - - _arguments_pcre2_chartables = [ - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c.dist"), - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c"), - ] - - check_pcre2_chartables_result = - exec_script(md5_check_script, _arguments_pcre2_chartables, "string") - if (check_pcre2_chartables_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c.dist"), - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c"), - ]) - } - output_name = "libpcre2" sources = pcre2_sources - sources += [ "$PCRE2_LIB_DIR/src/pcre2_chartables.c" ] - include_dirs = [ "$PCRE2_LIB_DIR/src" ] + sources += get_target_outputs(":publish_generic_file") public_configs = [ ":third_party_pcre2_config" ] cflags = [ "-D_GNU_SOURCE", @@ -132,68 +115,10 @@ ohos_shared_library("libpcre2") { } ohos_static_library("libpcre2_static") { - exec_script("/usr/bin/env", - [ - "mkdir", - "-p", - rebase_path("$PCRE2_LIB_DIR/src_static"), - ]) - md5_check_script = rebase_path("$PCRE2_LIB_DIR/check_md5.sh") - _arguments_config = [ - rebase_path("$PCRE2_LIB_DIR/src/config.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src_static/config.h"), - ] - - check_config_result = - exec_script(md5_check_script, _arguments_config, "string") - if (check_config_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/config.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src_static/config.h"), - ]) - } - - _arguments_pcre2 = [ - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src_static/pcre2.h"), - ] - - check_pcre2_result = exec_script(md5_check_script, _arguments_pcre2, "string") - if (check_pcre2_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/pcre2.h.generic"), - rebase_path("$PCRE2_LIB_DIR/src_static/pcre2.h"), - ]) - } - - _arguments_pcre2_chartables = [ - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c.dist"), - rebase_path("$PCRE2_LIB_DIR/src_static/pcre2_chartables.c"), - ] - - check_pcre2_chartables_result = - exec_script(md5_check_script, _arguments_pcre2_chartables, "string") - if (check_pcre2_chartables_result == "") { - exec_script("/usr/bin/env", - [ - "cp", - "-f", - rebase_path("$PCRE2_LIB_DIR/src/pcre2_chartables.c.dist"), - rebase_path("$PCRE2_LIB_DIR/src_static/pcre2_chartables.c"), - ]) - } - + deps = [ ":publish_generic_file" ] output_name = "libpcre2_static" sources = pcre2_sources - sources += [ "$PCRE2_LIB_DIR/src_static/pcre2_chartables.c" ] - include_dirs = [ "$PCRE2_LIB_DIR/src" ] - include_dirs += [ "$PCRE2_LIB_DIR/src_static" ] + sources += get_target_outputs(":publish_generic_file") public_configs = [ ":third_party_pcre2_config" ] cflags = [ "-D_GNU_SOURCE", diff --git a/bundle.json b/bundle.json index 4e91562..941c297 100644 --- a/bundle.json +++ b/bundle.json @@ -38,6 +38,12 @@ "header_files": [], "header_base": "//third_party/pcre2/pcre2/src" } + }, + { + "name": "//third_party/pcre2:publish_generic_file" + }, + { + "name": "//third_party/pcre2:pcre2_generated_headers" } ], "test": [] diff --git a/copy_generic_files.sh b/copy_generic_files.sh new file mode 100755 index 0000000..87fb8b8 --- /dev/null +++ b/copy_generic_files.sh @@ -0,0 +1,31 @@ +#! /bin/bash + +# Copyright (c) 2025 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. + +pcre2_lib_dir=$1 +pcre2_gen_dir=$2 + +function check_md5_and_copy() { + echo "check_md5_and_copy $1 $2" + check_config_result=$(bash $pcre2_lib_dir/check_md5.sh $1 $2) + echo "${check_config_result}x" + if [[ "${check_config_result}x" == "x" ]];then + cp -f $1 $2 + fi +} + +mkdir -P $pcre2_lib_dir/src +check_md5_and_copy $pcre2_lib_dir/src/config.h.generic $pcre2_gen_dir/src/config.h +check_md5_and_copy $pcre2_lib_dir/src/pcre2.h.generic $pcre2_gen_dir/src/pcre2.h +check_md5_and_copy $pcre2_lib_dir/src/pcre2_chartables.c.dist $pcre2_gen_dir/src/pcre2_chartables.c -- Gitee