• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
52if [ ! -f "googletest/BUILD.gn" ];then
53    rm -rf googletest
54    git clone --depth=1 git@gitee.com:openharmony/third_party_googletest.git
55    if [ -d "third_party_googletest" ];then
56        mv third_party_googletest googletest
57        $cp ../prebuilts/patch_googletest/googletestbuild.gn ../third_party/googletest/BUILD.gn
58        $patch -p1 < ../prebuilts/patch_googletest/gtest.patch
59    fi
60fi
61
62if [ ! -f "json/BUILD.gn" ];then
63    rm -rf json
64    git clone --depth=1 git@gitee.com:openharmony/third_party_json.git
65    if [ -d "third_party_json" ];then
66        mv third_party_json json
67    fi
68fi
69
70if [ ! -f "libunwind/BUILD.gn" ];then
71    rm -rf libunwind
72    git clone --depth=1 git@gitee.com:openharmony/third_party_libunwind.git
73    if [ -d "third_party_libunwind" ];then
74        mv third_party_libunwind libunwind
75        $cp ../prebuilts/patch_libunwind/libunwindbuild.gn libunwind/BUILD.gn
76    fi
77fi
78
79if [ ! -f "perf_include/libbpf/linux/perf_event.h" ];then
80   mkdir -p perf_include/libbpf/linux
81   rm -rf perf_event.h
82   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
83   mv perf_event.h perf_include/libbpf/linux/perf_event.h
84   $patch -p0 perf_include/libbpf/linux/perf_event.h ../prebuilts/patch_perf_event/perf_event.h.patch
85fi
86
87if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then
88   rm -rf hiviewdfx_faultloggerd perf_include/hiviewdfx/faultloggerd
89   mkdir -p perf_include/hiviewdfx/faultloggerd/interfaces/innerkits
90   git clone git@gitee.com:openharmony/hiviewdfx_faultloggerd.git
91   cd hiviewdfx_faultloggerd
92   git reset --hard 7bd128c8fa91b79606c1bb21f20123879b351a4f
93   cd ..
94   mv hiviewdfx_faultloggerd/common/ perf_include/hiviewdfx/faultloggerd
95   mv hiviewdfx_faultloggerd/interfaces/common/ perf_include/hiviewdfx/faultloggerd/interfaces
96   mv hiviewdfx_faultloggerd/interfaces/nonlinux/ perf_include/hiviewdfx/faultloggerd/interfaces
97   mv hiviewdfx_faultloggerd/interfaces/innerkits/unwinder/ perf_include/hiviewdfx/faultloggerd/interfaces/innerkits
98   find  perf_include/hiviewdfx/faultloggerd -type f -name "*.gn" -delete
99    $cp ../prebuilts/patch_hiperf/hiviewdfx_BUILD.gn ../third_party/perf_include/hiviewdfx/BUILD.gn
100   rm -rf hiviewdfx_faultloggerd
101   rm -rf perf_include/hiviewdfx/common/build
102   rm -rf perf_include/hiviewdfx/common/cutil
103   rm perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_regs_x86_64.cpp
104    $sed -i '/TRAP_BRANCH/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp
105    $sed -i '/TRAP_HWBKPT/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp
106    $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp
107    $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_regs.h
108    $sed -i '/#include <vector>/a #include "debug_logger.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/unwinder.h
109    $sed -i '/getpid() == gettid()/s/getpid() == gettid()/false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/unwinder.cpp
110    $sed -i '/!realpath(path, realPath)/s/!realpath(path, realPath)/false/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.cpp
111    $sed -i '/#include "dfx_util.h"/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp
112    $sed -i '/#include <string>/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_mmap.h
113    $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
114    $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
115    $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h
116    $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
117    $sed -i '/#ifndef is_ohos_lite/s/#ifndef is_ohos_lite/#if false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
118    $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
119    $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
120    $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
121    $sed -i '/#define DFX_NONLINUX_DEFINE_H/a #ifndef is_linux' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h
122    $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/common/byte_order.h
123    $sed -i '$a #endif' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h
124    $cp ../prebuilts/patch_hiperf/string_view_util.h ../third_party/perf_include/hiviewdfx/faultloggerd/common/dfxutil/string_view_util.h
125fi
126if [ ! -f "hiperf/BUILD.gn" ];then
127    rm -rf hiperf developtools_hiperf
128    git clone git@gitee.com:openharmony/developtools_hiperf.git
129    cd developtools_hiperf
130    git reset --hard 59eecf523796401740d02894f64b4d23f7d370a9
131    cd ..
132    if [ -d "developtools_hiperf" ];then
133        mv developtools_hiperf hiperf
134        $cp ../prebuilts/patch_hiperf/BUILD.gn ../third_party/hiperf/BUILD.gn
135        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h
136        $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h
137        $sed -i "/#include \"report_json_file.h\"/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h
138        $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/debug_logger.h
139        $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/utilities.h
140        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h
141        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/callstack.h
142        $sed -i '/unwinder.h/s/^/\/\/ /' hiperf/include/callstack.h
143        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/symbols_file.h
144        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_runtime.h
145        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h
146
147        $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h
148        $sed -i "/using __s8 = char;/a #define unw_word_t uint64_t" hiperf/include/nonlinux/linux/types.h
149        $sed -i '/^void Report::PrepareConsole(/,/^}/ s/^.*$/\/\/&/; /^void Report::PrepareConsole(/,/return;/ s/^[[:blank:]]*/    /' hiperf/src/report.cpp
150        $sed -i '/namespace HiPerf {/avoid Report::PrepareConsole(){ return;}' hiperf/src/report.cpp
151        $sed -i '/HITRACE_METER_NAME/s/^/\/\/ /' hiperf/src/callstack.cpp
152        $sed -i '/hitrace_meter.h/s/^/\/\/ /' hiperf/src/callstack.cpp
153        $sed -i '/dlfcn.h/s/^/\/\/ /' hiperf/src/callstack.cpp
154        $sed -i '/dfx_ark.h/s/^/\/\/ /' hiperf/src/callstack.cpp
155        $sed -i '/dfx_regs.h/s/^/\/\/ /' hiperf/src/callstack.cpp
156        $sed -i '/return DoUnwind2/s/^/\/\/ /' hiperf/src/callstack.cpp
157        $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/src/virtual_runtime.cpp
158        $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/include/virtual_runtime.h
159        $sed -i '/symbolsTable, elfFile_, elfPath/s/symbolsTable, elfFile_, elfPath/symbolsTable, elfFile_, filePath_/g' hiperf/src/symbols_file.cpp
160    fi
161fi
162
163if [ ! -f "bounds_checking_function/BUILD.gn" ];then
164    rm -rf bounds_checking_function
165    git clone --depth=1 git@gitee.com:openharmony/third_party_bounds_checking_function.git bounds_checking_function
166    $cp ../prebuilts/patch_bounds_checking_function/bounds_checking_functionbuild.gn bounds_checking_function/BUILD.gn
167fi
168
169if [ ! -d "commonlibrary" ];then
170    rm -rf commonlibrary
171    git clone --depth=1 git@gitee.com:openharmony/commonlibrary_c_utils.git
172    if [ -d "commonlibrary_c_utils" ];then
173        mv commonlibrary_c_utils commonlibrary
174        rm -rf commonlibrary_c_utils
175    fi
176fi
177
178if [ ! -f "profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h" ];then
179    rm -rf profiler
180    git clone --depth=1 git@gitee.com:openharmony/developtools_profiler.git
181    if [ -d "developtools_profiler" ];then
182        mkdir -p profiler/device/plugins/ftrace_plugin/include
183        $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h profiler/device/plugins/ftrace_plugin/include
184        $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_namespace.h profiler/device/plugins/ftrace_plugin/include
185        rm -rf developtools_profiler
186    fi
187fi
188