diff --git a/BUILD.gn b/BUILD.gn index 6ff9dd6575e62fe6e4e955cef26124a3b5dcb8de..46a0c18c6c1da353c988c5b6ff723ead4eaf583b 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 4e9156250f215037328dcf848d710cb755f43fff..941c297f082f194d5ccc3a934f1d95b4cfd798e7 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 0000000000000000000000000000000000000000..87fb8b85976e625105c8f5a74f0afdff48cf1c79 --- /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