• 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'
19root_dir=$(pwd)
20echo "build root dir is $root_dir"
21
22git config --global core.longpaths true
23case "$OSTYPE" in
24  darwin*)  sed="gsed" ;;
25esac
26if [ ! -d "third_party" ];then
27    mkdir third_party
28fi
29cd third_party
30
31if [ ! -f "sqlite/BUILD.gn" ];then
32    rm -rf sqlite
33    git clone --depth=1 git@gitee.com:openharmony/third_party_sqlite.git
34    if [ -d "third_party_sqlite" ];then
35        mv third_party_sqlite sqlite
36        $cp ../prebuilts/patch_sqlite/sqlite3build.gn ../third_party/sqlite/BUILD.gn
37    fi
38fi
39if [ ! -f "protobuf/BUILD.gn" ];then
40    rm -rf protobuf
41    git clone --depth=1 git@gitee.com:openharmony/third_party_protobuf.git
42    if [ -d "third_party_protobuf" ];then
43        mv third_party_protobuf protobuf
44        $cp ../prebuilts/patch_protobuf/protobufbuild.gn ../third_party/protobuf/BUILD.gn
45    fi
46fi
47
48if [ ! -f "zlib/BUILD.gn" ];then
49    rm -rf zlib
50    git clone --depth=1 git@gitee.com:openharmony/third_party_zlib.git
51    if [ -d "third_party_zlib" ];then
52        mv third_party_zlib zlib
53        $cp ../prebuilts/patch_zlib/zlibbuild.gn zlib/BUILD.gn
54    fi
55fi
56
57if [ ! -f "bzip2/BUILD.gn" ];then
58    rm -rf bzip2
59    git clone --depth=1 git@gitee.com:openharmony/third_party_bzip2.git
60    if [ -d "third_party_bzip2" ];then
61        mv third_party_bzip2 bzip2
62        $cp ../prebuilts/patch_bzip2/bzip2build.gn bzip2/BUILD.gn
63        cd bzip2
64        ./install.sh $(pwd)
65        cd ..
66    fi
67fi
68
69if [ ! -f "googletest/BUILD.gn" ];then
70    rm -rf googletest
71    git clone --depth=1 git@gitee.com:openharmony/third_party_googletest.git
72    if [ -d "third_party_googletest" ];then
73        mv third_party_googletest googletest
74        $cp ../prebuilts/patch_googletest/googletestbuild.gn ../third_party/googletest/BUILD.gn
75        $patch -p1 < ../prebuilts/patch_googletest/gtest.patch
76    fi
77fi
78
79if [ ! -f "json/BUILD.gn" ];then
80    rm -rf json
81    git clone --depth=1 git@gitee.com:openharmony/third_party_json.git
82    if [ -d "third_party_json" ];then
83        mv third_party_json json
84    fi
85fi
86
87if [ ! -f "libunwind/BUILD.gn" ];then
88    rm -rf libunwind
89    git clone  git@gitee.com:openharmony/third_party_libunwind.git
90    if [ -d "third_party_libunwind" ];then
91        mv third_party_libunwind libunwind
92        cd libunwind
93        git reset --hard 2c16627236d5e62c8fe78e088d21eca3c362c71c
94        cd ..
95        $cp ../prebuilts/patch_libunwind/libunwindbuild.gn libunwind/BUILD.gn
96    fi
97fi
98
99if [ ! -f "perf_include/libbpf/linux/perf_event.h" ];then
100   mkdir -p perf_include/libbpf/linux
101   rm -rf perf_event.h
102   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
103   mv perf_event.h perf_include/libbpf/linux/perf_event.h
104   $patch -p0 perf_include/libbpf/linux/perf_event.h ../prebuilts/patch_perf_event/perf_event.h.patch
105fi
106
107if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then
108   rm -rf hiviewdfx_faultloggerd perf_include/hiviewdfx/faultloggerd
109   mkdir -p perf_include/hiviewdfx/faultloggerd/interfaces/innerkits
110   git clone git@gitee.com:openharmony/hiviewdfx_faultloggerd.git
111   cd hiviewdfx_faultloggerd
112   git reset --hard 7296f69c0d418cd9353638f3117296e4b494e4e5
113   cd ..
114   mv hiviewdfx_faultloggerd/common/ perf_include/hiviewdfx/faultloggerd
115   mv hiviewdfx_faultloggerd/interfaces/common/ perf_include/hiviewdfx/faultloggerd/interfaces
116   mv hiviewdfx_faultloggerd/interfaces/nonlinux/ perf_include/hiviewdfx/faultloggerd/interfaces
117   mv hiviewdfx_faultloggerd/interfaces/innerkits/unwinder/ perf_include/hiviewdfx/faultloggerd/interfaces/innerkits
118   find  perf_include/hiviewdfx/faultloggerd -type f -name "*.gn" -delete
119    $cp ../prebuilts/patch_hiperf/hiviewdfx_BUILD.gn ../third_party/perf_include/hiviewdfx/BUILD.gn
120   rm -rf hiviewdfx_faultloggerd
121   rm -rf perf_include/hiviewdfx/common/build
122   rm -rf perf_include/hiviewdfx/common/cutil
123   rm perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_regs_x86_64.cpp
124    $sed -i '/TRAP_BRANCH/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp
125    $sed -i '/TRAP_HWBKPT/s/^/\/\/ /' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_signal.cpp
126    $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp
127    $sed -i '/is_ohos/s/is_ohos/true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_regs.h
128    $sed -i '/#include <vector>/a #include "debug_logger.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/unwinder.h
129    $sed -i '/getpid() == gettid()/s/getpid() == gettid()/false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/unwinder.cpp
130    $sed -i '/!realpath(path, realPath)/s/!realpath(path, realPath)/false/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.cpp
131    $sed -i '/#include "dfx_util.h"/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp
132    $sed -i '/#include <string>/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_mmap.h
133    $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
134    $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
135    $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h
136    $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
137    $sed -i '/#ifndef is_ohos_lite/s/#ifndef is_ohos_lite/#if false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
138    $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp
139    $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
140    $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
141    $sed -i '/#define DFX_NONLINUX_DEFINE_H/a #ifndef is_linux' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h
142    $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/common/byte_order.h
143    $sed -i '$a #endif' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h
144    $cp ../prebuilts/patch_hiperf/string_view_util.h ../third_party/perf_include/hiviewdfx/faultloggerd/common/dfxutil/string_view_util.h
145fi
146if [ ! -f "hiperf/BUILD.gn" ];then
147    rm -rf hiperf developtools_hiperf
148    git clone git@gitee.com:openharmony/developtools_hiperf.git
149    cd developtools_hiperf
150    git reset --hard 9d189f41d76c1ae6e8e12238aef5ef5b8cdbc09f
151    cd ..
152    if [ -d "developtools_hiperf" ];then
153        mv developtools_hiperf hiperf
154        $cp ../prebuilts/patch_hiperf/BUILD.gn ../third_party/hiperf/BUILD.gn
155        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h
156        # $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h
157        $sed -i "/#include \"report_json_file.h\"/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h
158        $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/debug_logger.h
159        $sed -i "/#include <gtest\/gtest_prod.h>/s/^\(.*\)$/\/\/\1/g" hiperf/include/utilities.h
160        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_thread.h
161        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/callstack.h
162        # $sed -i '/unwinder.h/s/^/\/\/ /' hiperf/include/callstack.h
163        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/symbols_file.h
164        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/virtual_runtime.h
165        $sed -i "/FRIEND_TEST/s/^\(.*\)$/\/\/\1/g" hiperf/include/report.h
166        $sed -i "s/HIPERF_DEBUG/ALWAYSTRUE/g" hiperf/include/virtual_thread.h
167        # $sed -i "/using __s8 = char;/a #define unw_word_t uint64_t" hiperf/include/nonlinux/linux/types.h
168        # $sed -i '/^void Report::PrepareConsole(/,/^}/ s/^.*$/\/\/&/; /^void Report::PrepareConsole(/,/return;/ s/^[[:blank:]]*/    /' hiperf/src/report.cpp
169        # $sed -i '/namespace HiPerf {/avoid Report::PrepareConsole(){ return;}' hiperf/src/report.cpp
170        # $sed -i '/HITRACE_METER_NAME/s/^/\/\/ /' hiperf/src/callstack.cpp
171        # $sed -i '/hitrace_meter.h/s/^/\/\/ /' hiperf/src/callstack.cpp
172        # $sed -i '/dlfcn.h/s/^/\/\/ /' hiperf/src/callstack.cpp
173        # $sed -i '/dfx_ark.h/s/^/\/\/ /' hiperf/src/callstack.cpp
174        # $sed -i '/dfx_regs.h/s/^/\/\/ /' hiperf/src/callstack.cpp
175        $sed -i '/return DoUnwind2/s/^/\/\/ /' hiperf/src/callstack.cpp
176        # $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/src/virtual_runtime.cpp
177        # $sed -i '/#if defined(is_ohos) && is_ohos/s/defined(is_ohos) && is_ohos/true/g' hiperf/include/virtual_runtime.h
178        # $sed -i '/symbolsTable, elfFile_, elfPath/s/symbolsTable, elfFile_, elfPath/symbolsTable, elfFile_, filePath_/g' hiperf/src/symbols_file.cpp
179        $sed -i '/spe_decoder.h/s/^/\/\/ /' hiperf/src/virtual_runtime.cpp
180        $sed -i '/spe_decoder.h/s/^/\/\/ /' hiperf/src/perf_event_record.cpp
181    fi
182fi
183
184if [ ! -f "bounds_checking_function/BUILD.gn" ];then
185    rm -rf bounds_checking_function
186    git clone --depth=1 git@gitee.com:openharmony/third_party_bounds_checking_function.git bounds_checking_function
187    $cp ../prebuilts/patch_bounds_checking_function/bounds_checking_functionbuild.gn bounds_checking_function/BUILD.gn
188fi
189
190if [ ! -d "commonlibrary" ];then
191    rm -rf commonlibrary
192    git clone --depth=1 git@gitee.com:openharmony/commonlibrary_c_utils.git
193    if [ -d "commonlibrary_c_utils" ];then
194        mv commonlibrary_c_utils commonlibrary
195        rm -rf commonlibrary_c_utils
196    fi
197fi
198
199if [ ! -f "profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h" ];then
200    rm -rf profiler
201    git clone --depth=1 git@gitee.com:openharmony/developtools_profiler.git
202    if [ -d "developtools_profiler" ];then
203        mkdir -p profiler/device/plugins/ftrace_plugin/include
204        $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_common_type.h profiler/device/plugins/ftrace_plugin/include
205        $cp developtools_profiler/device/plugins/ftrace_plugin/include/ftrace_namespace.h profiler/device/plugins/ftrace_plugin/include
206        rm -rf developtools_profiler
207    fi
208fi
209
210if [ ! -d "llvm-project" ];then
211    rm -rf llvm-project
212    git clone --depth=1 git@gitee.com:openharmony/third_party_llvm-project.git
213    if [ -d "third_party_llvm-project" ];then
214        mv third_party_llvm-project llvm-project
215        cd llvm-project
216        $patch -p1 < ../../prebuilts/patch_llvm/llvm.patch
217        cd $root_dir
218        # Symbolic link llvm sub folder of llvm-project source code to build root.
219        # REF: https://gitee.com/openharmony/third_party_llvm-project/blob/master/llvm/utils/gn/.gn
220        ln -s $root_dir/third_party/llvm-project/llvm llvm
221    fi
222fi
223