1#!/bin/bash 2# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14set -e 15patch='patch' 16sed='sed' 17cp='cp' 18rm='rm' 19case "$OSTYPE" in 20 darwin*) sed="gsed" ;; 21esac 22if [ ! -d "third_party" ];then 23 mkdir third_party 24fi 25cd third_party 26 27if [ ! -f "sqlite/BUILD.gn" ];then 28 rm -rf sqlite 29 git clone --depth=1 git@gitee.com:openharmony/third_party_sqlite.git 30 if [ -d "third_party_sqlite" ];then 31 mv third_party_sqlite sqlite 32 $cp ../prebuilts/patch_sqlite/sqlite3build.gn ../third_party/sqlite/BUILD.gn 33 fi 34fi 35if [ ! -f "protobuf/BUILD.gn" ];then 36 rm -rf protobuf 37 git clone --depth=1 git@gitee.com:openharmony/third_party_protobuf.git 38 if [ -d "third_party_protobuf" ];then 39 mv third_party_protobuf protobuf 40 $cp ../prebuilts/patch_protobuf/protobufbuild.gn ../third_party/protobuf/BUILD.gn 41 fi 42fi 43 44if [ ! -f "zlib/BUILD.gn" ];then 45 rm -rf zlib 46 git clone --depth=1 git@gitee.com:openharmony/third_party_zlib.git 47 if [ -d "third_party_zlib" ];then 48 mv third_party_zlib zlib 49 $cp ../prebuilts/patch_zlib/zlibbuild.gn zlib/BUILD.gn 50 fi 51fi 52 53if [ ! -f "bzip2/BUILD.gn" ];then 54 rm -rf bzip2 55 git clone --depth=1 git@gitee.com:openharmony/third_party_bzip2.git 56 if [ -d "third_party_bzip2" ];then 57 mv third_party_bzip2 bzip2 58 $cp ../prebuilts/patch_bzip2/bzip2build.gn bzip2/BUILD.gn 59 cd bzip2 60 ./install.sh `pwd` 61 cd .. 62 fi 63fi 64 65if [ ! -f "googletest/BUILD.gn" ];then 66 rm -rf googletest 67 git clone --depth=1 git@gitee.com:openharmony/third_party_googletest.git 68 if [ -d "third_party_googletest" ];then 69 mv third_party_googletest googletest 70 $cp ../prebuilts/patch_googletest/googletestbuild.gn ../third_party/googletest/BUILD.gn 71 $patch -p1 < ../prebuilts/patch_googletest/gtest.patch 72 fi 73fi 74 75if [ ! -f "json/BUILD.gn" ];then 76 rm -rf json 77 git clone --depth=1 git@gitee.com:openharmony/third_party_json.git 78 if [ -d "third_party_json" ];then 79 mv third_party_json json 80 fi 81fi 82 83if [ ! -f "libunwind/BUILD.gn" ];then 84 rm -rf libunwind 85 git clone --depth=1 git@gitee.com:openharmony/third_party_libunwind.git 86 if [ -d "third_party_libunwind" ];then 87 mv third_party_libunwind libunwind 88 $cp ../prebuilts/patch_libunwind/libunwindbuild.gn libunwind/BUILD.gn 89 fi 90fi 91 92if [ ! -f "perf_include/libbpf/linux/perf_event.h" ];then 93 mkdir -p perf_include/libbpf/linux 94 rm -rf perf_event.h 95 curl https://gitee.com/openharmony/third_party_libbpf/raw/20221117/github.com/libbpf/libbpf/refs/tags/v0.7.0/include/uapi/linux/perf_event.h > perf_event.h 96 mv perf_event.h perf_include/libbpf/linux/perf_event.h 97 $patch -p0 perf_include/libbpf/linux/perf_event.h ../prebuilts/patch_perf_event/perf_event.h.patch 98fi 99 100if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then 101 rm -rf hiviewdfx_faultloggerd perf_include/hiviewdfx/faultloggerd 102 mkdir -p perf_include/hiviewdfx/faultloggerd/interfaces/innerkits 103 git clone git@gitee.com:openharmony/hiviewdfx_faultloggerd.git 104 cd hiviewdfx_faultloggerd 105 git reset --hard 7bd128c8fa91b79606c1bb21f20123879b351a4f 106 cd .. 107 mv hiviewdfx_faultloggerd/common/ perf_include/hiviewdfx/faultloggerd 108 mv hiviewdfx_faultloggerd/interfaces/common/ perf_include/hiviewdfx/faultloggerd/interfaces 109 mv hiviewdfx_faultloggerd/interfaces/nonlinux/ perf_include/hiviewdfx/faultloggerd/interfaces 110 mv hiviewdfx_faultloggerd/interfaces/innerkits/unwinder/ perf_include/hiviewdfx/faultloggerd/interfaces/innerkits 111 find perf_include/hiviewdfx/faultloggerd -type f -name "*.gn" -delete 112 $cp ../prebuilts/patch_hiperf/hiviewdfx_BUILD.gn ../third_party/perf_include/hiviewdfx/BUILD.gn 113 rm -rf hiviewdfx_faultloggerd 114 rm -rf perf_include/hiviewdfx/common/build 115 rm -rf perf_include/hiviewdfx/common/cutil 116 rm perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_regs_x86_64.cpp 117 $sed -i '/TRAP_BRANCH/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp 118 $sed -i '/TRAP_HWBKPT/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp 119 $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp 120 $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_regs.h 121 $sed -i '/#include <vector>/a #include "debug_logger.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/unwinder.h 122 $sed -i '/getpid() == gettid()/s/getpid() == gettid()/false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/unwinder.cpp 123 $sed -i '/!realpath(path, realPath)/s/!realpath(path, realPath)/false/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.cpp 124 $sed -i '/#include "dfx_util.h"/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp 125 $sed -i '/#include <string>/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_mmap.h 126 $sed -i '/#if is_ohos && !is_mingw/s/#if is_ohos && !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h 127 $sed -i '/#if is_ohos && !is_mingw/s/#if is_ohos && !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp 128 $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h 129 $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp 130 $sed -i '/#ifndef is_ohos_lite/s/#ifndef is_ohos_lite/#if false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp 131 $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp 132 $sed -i '/#if !is_mingw/s/#if !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf_define.h 133 $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf_parser.h 134 $sed -i '/#define DFX_NONLINUX_DEFINE_H/a #ifndef is_linux' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h 135 $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/common/byte_order.h 136 $sed -i '$a #endif' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h 137 $cp ../prebuilts/patch_hiperf/string_view_util.h ../third_party/perf_include/hiviewdfx/faultloggerd/common/dfxutil/string_view_util.h 138fi 139if [ ! -f "hiperf/BUILD.gn" ];then 140 rm -rf hiperf developtools_hiperf 141 git clone git@gitee.com:openharmony/developtools_hiperf.git 142 cd developtools_hiperf 143 git reset --hard 59eecf523796401740d02894f64b4d23f7d370a9 144 cd .. 145 if [ -d "developtools_hiperf" ];then 146 mv developtools_hiperf hiperf 147 $cp ../prebuilts/patch_hiperf/BUILD.gn ../third_party/hiperf/BUILD.gn 148 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h 149 $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h 150 $sed -i "/#include \"report_json_file.h\"/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h 151 $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/debug_logger.h 152 $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/utilities.h 153 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h 154 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/callstack.h 155 $sed -i '/unwinder.h/s/^/\/\/ /' hiperf/include/callstack.h 156 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/symbols_file.h 157 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_runtime.h 158 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h 159 $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h 160 $sed -i "/using __s8 = char;/a #define unw_word_t uint64_t" hiperf/include/nonlinux/linux/types.h 161 $sed -i '/^void Report::PrepareConsole(/,/^}/ s/^.*$/\/\/&/; /^void Report::PrepareConsole(/,/return;/ s/^[[:blank:]]*/ /' hiperf/src/report.cpp 162 $sed -i '/namespace HiPerf {/avoid Report::PrepareConsole(){ return;}' hiperf/src/report.cpp 163 $sed -i '/HITRACE_METER_NAME/s/^/\/\/ /' hiperf/src/callstack.cpp 164 $sed -i '/hitrace_meter.h/s/^/\/\/ /' hiperf/src/callstack.cpp 165 $sed -i '/dlfcn.h/s/^/\/\/ /' hiperf/src/callstack.cpp 166 $sed -i '/dfx_ark.h/s/^/\/\/ /' hiperf/src/callstack.cpp 167 $sed -i '/dfx_regs.h/s/^/\/\/ /' hiperf/src/callstack.cpp 168 $sed -i '/return DoUnwind2/s/^/\/\/ /' hiperf/src/callstack.cpp 169 $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/src/virtual_runtime.cpp 170 $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/include/virtual_runtime.h 171 $sed -i '/symbolsTable, elfFile_, elfPath/s/symbolsTable, elfFile_, elfPath/symbolsTable, elfFile_, filePath_/g' hiperf/src/symbols_file.cpp 172 fi 173fi 174 175if [ ! -f "bounds_checking_function/BUILD.gn" ];then 176 rm -rf bounds_checking_function 177 git clone --depth=1 git@gitee.com:openharmony/third_party_bounds_checking_function.git bounds_checking_function 178 $cp ../prebuilts/patch_bounds_checking_function/bounds_checking_functionbuild.gn bounds_checking_function/BUILD.gn 179fi 180 181if [ ! -d "commonlibrary" ];then 182 rm -rf commonlibrary 183 git clone --depth=1 git@gitee.com:openharmony/commonlibrary_c_utils.git 184 if [ -d "commonlibrary_c_utils" ];then 185 mv commonlibrary_c_utils commonlibrary 186 rm -rf commonlibrary_c_utils 187 fi 188fi 189 190if [ ! -f "profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h" ];then 191 rm -rf profiler 192 git clone --depth=1 git@gitee.com:openharmony/developtools_profiler.git 193 if [ -d "developtools_profiler" ];then 194 mkdir -p profiler/device/plugins/ftrace_plugin/include 195 $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h profiler/device/plugins/ftrace_plugin/include 196 $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_namespace.h profiler/device/plugins/ftrace_plugin/include 197 rm -rf developtools_profiler 198 fi 199fi 200