From d8fc7f954654560a545ad25d17143efc8fd883e9 Mon Sep 17 00:00:00 2001 From: hupeixi Date: Wed, 29 Nov 2023 10:41:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8C=85=E6=89=AB=E6=8F=8F=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hupeixi --- BUILD.gn | 9 +++ META-INF/check_tool/MANIFEST.MF | 4 ++ OAT.xml | 1 + build.py | 12 ++++ checkTool.sh | 118 ++++++++++++++++++++++++++++++++ packingtool.gni | 2 + 6 files changed, 146 insertions(+) create mode 100644 META-INF/check_tool/MANIFEST.MF create mode 100644 checkTool.sh diff --git a/BUILD.gn b/BUILD.gn index 8cca83a6..bc69cc23 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -20,12 +20,14 @@ packing_tool("packing_tool") { "//developtools/packing_tool/haptobin.sh", "//developtools/packing_tool/packingTool.sh", "//developtools/packing_tool/unpackingTool.sh", + "//developtools/packing_tool/checkTool.sh", ] outputs = [ "${target_out_dir}/jar/haptobin_tool.jar", "${target_out_dir}/jar/app_unpacking_tool.jar", "${target_out_dir}/jar/app_packing_tool.jar", "${target_out_dir}/jar", + "${target_out_dir}/jar/app_check_tool.jar", ] } @@ -50,6 +52,13 @@ ohos_prebuilt_etc("app_packing_tool") { install_enable = false } +ohos_prebuilt_etc("app_check_tool") { + list = get_target_outputs(":packing_tool") + source = list[3] + deps = [ ":packing_tool" ] + install_enable = false +} + ohos_prebuilt_etc("fastjson-1.2.83") { source = "jar/fastjson-1.2.83.jar" install_enable = false diff --git a/META-INF/check_tool/MANIFEST.MF b/META-INF/check_tool/MANIFEST.MF new file mode 100644 index 00000000..83a23b98 --- /dev/null +++ b/META-INF/check_tool/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Class-Path: fastjson-1.2.83.jar +Created-By: javac.py +Main-Class: ohos.ScanEntrance diff --git a/OAT.xml b/OAT.xml index 33fe5d8c..85281534 100644 --- a/OAT.xml +++ b/OAT.xml @@ -61,6 +61,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/build.py b/build.py index 5a776bc8..d56ba64c 100755 --- a/build.py +++ b/build.py @@ -30,6 +30,7 @@ def main(): parser.add_argument('--haptobinOutput', required=True) parser.add_argument('--unpackOutput', required=True) parser.add_argument('--packOutput', required=True) + parser.add_argument('--checkOutput', required=True) parser.add_argument('--outpath', required=True) parser.add_argument('--toolchain', required=True) parser.add_argument('--compileTarget', required=True) @@ -37,6 +38,7 @@ def main(): print(args.haptobinOutput) print(args.unpackOutput) print(args.packOutput) + print(args.checkOutput) print(args.outpath) print(args.compileTarget) root_dir = os.path.dirname(os.path.realpath(__file__)) @@ -85,6 +87,16 @@ def main(): print(pack_out.decode('utf-8')) print(pack_err.decode('utf-8')) raise Exception("compile packing tool java class failed!") + + #compile app_check_tool.jar + check_tool_shell_path = os.path.join(root_dir, "checkTool.sh") + command_check = ['bash', check_tool_shell_path, root_dir, args.checkOutput, args.outpath, toolchain] + child_check = subprocess.Popen(command_check, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + check_out, check_err = child_check.communicate(timeout=time_out) + if child_check.returncode != 0: + print(check_out.decode('utf-8')) + print(check_err.decode('utf-8')) + raise Exception("compile check tool java class failed!") if __name__ == '__main__': sys.exit(main()) diff --git a/checkTool.sh b/checkTool.sh new file mode 100644 index 00000000..b2479446 --- /dev/null +++ b/checkTool.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +# 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. +set -e +root_path=$1 +pack_build_out_jar_path=$2 +pack_build_out_path=$3 +toolchain=$4 +final_path=$(pwd) + +jar_dir="jar" +pack_jar_file="app_check_tool.jar" +fastjson_jar_file="fastjson-1.2.83.jar" +jar_directory="${root_path}/jar" +pack_jar_path="${root_path}/${jar_dir}/${pack_jar_file}" +manifest_path="${root_path}/META-INF/check_tool/MANIFEST.MF" +css_path="${root_path}/adapter/ohos/scan_template.css" +html_path="${root_path}/adapter/ohos/scan_template.html" + +out_dir="${root_path}/out/${toolchain}/check_tool" +if [ -d "${out_dir}/ohos" ] + then + echo "${out_dir}/ohos exist" + else + mkdir -p "${out_dir}/ohos" +fi + +jar_path="${root_path}/jar" +fastjson_jar_path="${root_path}/jar/fastjson-1.2.83.jar" +java_suffix=".java" +java_collection="" +declare -a compile_class=( + "BundleException" + "CommandParser" + "ScanEntrance" + "Scan" + "ScanVerify" + "ScanStatDuplicate" + "ScanStatFileSize" + "ScanStatSuffix" + "Log" + "PackFormatter" + "ShowHelp" + "Utility" + "FileUtils" + ) +compile_class_length=${#compile_class[@]} +for ((i=0; i<${compile_class_length};++i)) +do + java_collection="${java_collection} ${root_path}/adapter/ohos/${compile_class[$i]}${java_suffix}" +done +compile_command="javac -source 1.8 -target 1.8 -cp ${fastjson_jar_path} -d ${out_dir} ${java_collection}" +eval ${compile_command} + +temp_dir="$root_path/jar/temp_${toolchain}" +if [ -d "${temp_dir}" ] + then + echo "${temp_dir} exit" + else + mkdir ${temp_dir} +fi + +cd ${out_dir} +product_pack_jar_command="jar -cvfm ${temp_dir}/${pack_jar_file} ${manifest_path} ./ohos ${css_path} ${html_path}" +eval ${product_pack_jar_command} + +# merge app_packing_tool.jar and fastjson +cp ${fastjson_jar_path} "${temp_dir}/${fastjson_jar_file}" +detach_pack_jar_command="jar -xvf ${pack_jar_file}" +detach_fastjson_jar_command="jar -xvf ${fastjson_jar_file}" +cd ${temp_dir} +eval ${detach_pack_jar_command} +eval ${detach_fastjson_jar_command} +rm ${pack_jar_file} +rm ${fastjson_jar_file} + +cd ${jar_directory} +temp_pack_jar_dir="${root_path}/jar/packtool_${toolchain}" +temp_pack_jar_path="${root_path}/jar/packtool_${toolchain}/${pack_jar_file}" +merge_pack_fast_jar_command="jar -cvfm ${temp_pack_jar_path} ${manifest_path} -C ${temp_dir} ." +if [ -d "${temp_pack_jar_dir}" ] + then + echo "${temp_pack_jar_dir} exist" + else + mkdir -p ${temp_pack_jar_dir} +fi +eval ${merge_pack_fast_jar_command} + +# make out dir +final_pack_out_path="${final_path}/${pack_build_out_path}" +final_pack_jar_path="${final_path}/${pack_build_out_jar_path}" +if [ -d "$final_pack_out_path" ] + then + echo "${final_pack_out_path} exist" + else + mkdir -p ${final_pack_out_path} +fi +copy_command="cp ${temp_pack_jar_path} ${final_pack_jar_path}" +eval ${copy_command} +if [ -f "${pack_jar_file}"] + then + echo "${pack_jar_file} exist" + else + cp ${temp_pack_jar_path} ${pack_jar_file} +fi +rm -rf ${temp_pack_jar_dir} +rm -rf ${temp_dir} +rm -rf "${root_path}/out" diff --git a/packingtool.gni b/packingtool.gni index 9a9b38d3..bd21b05e 100755 --- a/packingtool.gni +++ b/packingtool.gni @@ -33,6 +33,8 @@ template("packing_tool") { rebase_path(outputs[2], root_build_dir), "--outpath", rebase_path(outputs[3], root_build_dir), + "--checkOutput", + rebase_path(outputs[4], root_build_dir), "--toolchain", current_toolchain, ] -- Gitee From 3cae72062d89b9d751f2c4cf10d2837c5b1ae37c Mon Sep 17 00:00:00 2001 From: hupeixi Date: Wed, 29 Nov 2023 16:23:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hupeixi --- checkTool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkTool.sh b/checkTool.sh index b2479446..6228a1ed 100644 --- a/checkTool.sh +++ b/checkTool.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 -- Gitee