1#!/bin/bash 2# Copyright (c) 2021 Huawei Device Co., Ltd. 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 "googletest/BUILD.gn" ];then 45 rm -rf googletest 46 git clone --depth=1 git@gitee.com:openharmony/third_party_googletest.git 47 if [ -d "third_party_googletest" ];then 48 mv third_party_googletest googletest 49 $cp ../prebuilts/patch_googletest/googletestbuild.gn ../third_party/googletest/BUILD.gn 50 $patch -p0 ../third_party/googletest/googletest/include/gtest/internal/gtest-internal.h ../prebuilts/patch_googletest/gtest_internal.h.patch 51 $patch -p0 ../third_party/googletest/googletest/include/gtest/internal/gtest-port.h ../prebuilts/patch_googletest/gtest_port.h.patch 52 $patch -p0 ../third_party/googletest/googletest/include/gtest/gtest-message.h ../prebuilts/patch_googletest/gtest-message.h.patch 53 $sed -i "/using ::std::string/s/^\(.*\)$/\/\/\1/g" ../third_party/googletest/googletest/include/gtest/hwext/gtest-tag.h 54 fi 55fi 56 57if [ ! -f "json/BUILD.gn" ];then 58 rm -rf json 59 git clone --depth=1 git@gitee.com:openharmony/third_party_json.git 60 if [ -d "third_party_json" ];then 61 mv third_party_json json 62 fi 63fi 64 65if [ ! -f "libunwind/BUILD.gn" ];then 66 rm -rf libunwind 67 git clone --depth=1 git@gitee.com:openharmony/third_party_libunwind.git 68 if [ -d "third_party_libunwind" ];then 69 mv third_party_libunwind libunwind 70 $cp ../prebuilts/patch_libunwind/libunwindbuild.gn libunwind/BUILD.gn 71 fi 72fi 73 74if [ ! -f "perf_include/libbpf/linux/perf_event.h" ];then 75 mkdir -p perf_include/libbpf/linux 76 rm -rf perf_event.h 77 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 78 mv perf_event.h perf_include/libbpf/linux/perf_event.h 79 $patch -p0 perf_include/libbpf/linux/perf_event.h ../prebuilts/patch_perf_event/perf_event.h.patch 80fi 81 82if [ ! -f "perf_include/musl/elf.h" ];then 83 mkdir -p perf_include/musl 84 rm -rf elf.h 85 curl https://gitee.com/openharmony/third_party_musl/raw/master/include/elf.h > elf.h 86 mv elf.h perf_include/musl/elf.h 87fi 88 89if [ ! -d "perf_include/hiviewdfx/hilog" ];then 90 rm -rf hiviewdfx_hilog perf_include/hiviewdfx/hilog 91 mkdir -p perf_include/hiviewdfx/hilog 92 git clone --depth=1 https://gitee.com/openharmony/hiviewdfx_hilog.git 93 mv hiviewdfx_hilog/interfaces/native/innerkits/include/ perf_include/hiviewdfx/hilog 94 rm -rf hiviewdfx_hilog 95fi 96 97if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then 98 rm -rf hiviewdfx_faultloggerd perf_include/hiviewdfx/faultloggerd 99 mkdir -p perf_include/hiviewdfx/faultloggerd/interfaces/innerkits 100 git clone git@gitee.com:openharmony/hiviewdfx_faultloggerd.git 101 cd hiviewdfx_faultloggerd 102 git reset --hard b7e7ae4340a39db64d2cdf5f8fdb96cdb368f6a7 103 cd .. 104 mv hiviewdfx_faultloggerd/common/ perf_include/hiviewdfx/faultloggerd 105 mv hiviewdfx_faultloggerd/interfaces/common/ perf_include/hiviewdfx/faultloggerd/interfaces 106 mv hiviewdfx_faultloggerd/interfaces/nonlinux/ perf_include/hiviewdfx/faultloggerd/interfaces 107 mv hiviewdfx_faultloggerd/interfaces/innerkits/unwinder/ perf_include/hiviewdfx/faultloggerd/interfaces/innerkits 108 find perf_include/hiviewdfx/faultloggerd -type f -name "*.gn" -delete 109 $cp ../prebuilts/patch_hiperf/hiviewdfx_BUILD.gn ../third_party/perf_include/hiviewdfx/BUILD.gn 110 rm -rf hiviewdfx_faultloggerd 111 rm -rf perf_include/hiviewdfx/common/build 112 rm -rf perf_include/hiviewdfx/common/cutil 113 rm perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_regs_x86_64.cpp 114 $sed -i '/HiLogPrint/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/common/dfxlog/dfx_log.cpp 115 $sed -i '/TRAP_BRANCH/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp 116 $sed -i '/TRAP_HWBKPT/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp 117 $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp 118 $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_regs.h 119 $sed -i '/#include <vector>/a #include "debug_logger.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/unwinder.h 120 $sed -i '/VerifyFilePath/s/const std::vector<const std::string>/std::vector\<std::string\>/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.h 121 $sed -i '/VerifyFilePath/s/const std::vector<const std::string>/std::vector\<std::string\>/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.cpp 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 137fi 138if [ ! -f "hiperf/BUILD.gn" ];then 139 rm -rf hiperf developtools_hiperf 140 git clone git@gitee.com:openharmony/developtools_hiperf.git 141 cd developtools_hiperf 142 git reset --hard 9d9322fcd0a83ab409f26b3c6dfaea2bb8d42628 143 cd .. 144 if [ -d "developtools_hiperf" ];then 145 mv developtools_hiperf hiperf 146 $cp ../prebuilts/patch_hiperf/BUILD.gn ../third_party/hiperf/BUILD.gn 147 $cp ../prebuilts/patch_hiperf/file_ex.h hiperf/include/nonlinux/linux 148 $cp ../prebuilts/patch_hiperf/unique_fd.h hiperf/include/nonlinux/linux 149 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h 150 $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h 151 $sed -i "/#include \"report_json_file.h\"/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h 152 $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/debug_logger.h 153 $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/utilities.h 154 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h 155 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/callstack.h 156 $sed -i '/unwinder.h/s/^/\/\/ /' hiperf/include/callstack.h 157 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/symbols_file.h 158 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_runtime.h 159 $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h 160 161 $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h 162 $sed -i "/using __s8 = char;/a #define unw_word_t uint64_t" hiperf/include/nonlinux/linux/types.h 163 $sed -i '/^void Report::PrepareConsole(/,/^}/ s/^.*$/\/\/&/; /^void Report::PrepareConsole(/,/return;/ s/^[[:blank:]]*/ /' hiperf/src/report.cpp 164 $sed -i '/namespace HiPerf {/avoid Report::PrepareConsole(){ return;}' hiperf/src/report.cpp 165 $sed -i '/HITRACE_METER_NAME/s/^/\/\/ /' hiperf/src/callstack.cpp 166 $sed -i '/hitrace_meter.h/s/^/\/\/ /' hiperf/src/callstack.cpp 167 $sed -i '/dlfcn.h/s/^/\/\/ /' hiperf/src/callstack.cpp 168 $sed -i '/dfx_ark.h/s/^/\/\/ /' hiperf/src/callstack.cpp 169 $sed -i '/dfx_regs.h/s/^/\/\/ /' hiperf/src/callstack.cpp 170 $sed -i '/return DoUnwind2/s/^/\/\/ /' hiperf/src/callstack.cpp 171 $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/src/virtual_runtime.cpp 172 $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/include/virtual_runtime.h 173 $sed -i '/symbolsTable, elfFile_, elfPath/s/symbolsTable, elfFile_, elfPath/symbolsTable, elfFile_, filePath_/g' hiperf/src/symbols_file.cpp 174 fi 175fi 176 177if [ ! -f "bounds_checking_function/BUILD.gn" ];then 178 rm -rf bounds_checking_function 179 git clone --depth=1 git@gitee.com:openharmony/third_party_bounds_checking_function.git bounds_checking_function 180 $cp ../prebuilts/patch_bounds_checking_function/bounds_checking_functionbuild.gn bounds_checking_function/BUILD.gn 181fi 182 183if [ ! -f "commonlibrary/c_utils/base/include/nocopyable.h" ];then 184 rm -rf commonlibrary 185 git clone --depth=1 git@gitee.com:openharmony/commonlibrary_c_utils.git 186 if [ -d "commonlibrary_c_utils" ];then 187 mkdir -p commonlibrary/c_utils/base/include 188 $cp commonlibrary_c_utils/base/include/nocopyable.h commonlibrary/c_utils/base/include 189 rm -rf commonlibrary_c_utils 190 fi 191fi 192 193if [ ! -f "profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h" ];then 194 rm -rf profiler 195 git clone --depth=1 git@gitee.com:openharmony/developtools_profiler.git 196 if [ -d "developtools_profiler" ];then 197 mkdir -p profiler/device/plugins/ftrace_plugin/include 198 $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h profiler/device/plugins/ftrace_plugin/include 199 $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_namespace.h profiler/device/plugins/ftrace_plugin/include 200 rm -rf developtools_profiler 201 fi 202fi 203