• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
14
15# use ./build.sh -nosym to build content_shell without symbol.
16set -e
17basedir=$(dirname "$0")
18CUR_DIR=$PWD
19ROOT_DIR="${CUR_DIR%/src*}""/src"
20# Global variables.
21BUILD_TARGET_WEBVIEW="ohos_nweb_hap"
22BUILD_TARGET_BROWSERSHELL="ohos_browser_shell"
23BUILD_TARGET_NATIVE="libweb_engine web_render libnweb_render"
24BUILD_TARGET_BROWSER_SERVICE="ohos_nweb_ex/browser_service"
25BUILD_TARGET_BROWSER_SERVICE_HAR="browser_service_har"
26TEXT_BOLD="\033[1m"
27TEXT_NORMAL="\033[0m"
28
29#Add build args begin
30buildargs="
31  target_os=\"ohos\"
32  is_debug=false
33  use_allocator=\"none\"
34  is_official_build=true
35  is_component_build=false
36  is_chrome_branded=false
37  use_official_google_api_keys=false
38  use_ozone=true
39  use_aura=true
40  ozone_auto_platforms=false
41  ozone_platform=\"headless\"
42  ozone_platform_headless=true
43  enable_extensions=true
44  ffmpeg_branding=\"Chrome\"
45  use_kerberos=false
46  use_bundled_fontconfig=true
47  enable_resource_allowlist_generation=false
48  clang_use_chrome_plugins=false
49  enable_message_center=true
50  safe_browsing_mode=0
51  use_custom_libcxx=false
52  use_sysroot=false
53  gpu_switch=\"on\"
54  proprietary_codecs=true
55  media_use_ffmpeg=true"
56#Add build args end
57
58buildgn=1
59buildcount=0
60buildccache=0
61buildsymbol=0
62buildproduct=""
63buildarg_cpu="target_cpu=\"arm\""
64buildarg_musl="use_musl=true"
65build_dir="out/rk3568/"
66build_product_name="product_name=\"rk3568\""
67build_target="${BUILD_TARGET_NATIVE}"
68build_output=""
69artifact_mode=0
70without_nweb_ex=0
71build_sysroot="use_ohos_sdk_sysroot=false"
72
73usage() {
74  echo -ne "USAGE: $0 [OPTIONS] [PRODUCT]
75
76${TEXT_BOLD}OPTIONS${TEXT_NORMAL}:
77  -j N              force number of build jobs
78  -ccache           Enable CCache.
79  -t <target>       Build target, supports:
80                      n Build native files.
81                      b Build BrowserShell.
82                      w Build NWeb WebView.
83                      m Build NWebEx napi module.
84                      M Build NWebEx napi npm package.
85  -o <output_dir>   Output directory, for example: Default.
86  -A, -artifact     Artifact mode, using pre-built NDK rather than building
87                    them locally.
88
89${TEXT_BOLD}PRODUCT${TEXT_NORMAL}:
90  rk3568 rk3568_64
91  Default is: rk3568
92"
93}
94
95while [ "$1" != "" ]; do
96  case $1 in
97    "rk3568")
98      buildarg_cpu="target_cpu=\"arm\""
99      buildarg_musl="use_musl=true"
100      build_dir="out/rk3568/"
101      build_product_name="product_name=\"rk3568\""
102    ;;
103    "rk3568_64")
104      buildarg_cpu="target_cpu=\"arm64\""
105      buildarg_musl="use_musl=true"
106      build_dir="out/rk3568_64/"
107      build_product_name="product_name=\"rk3568\""
108    ;;
109    "-j")
110      shift
111      buildcount=$1
112    ;;
113    "-ccache")
114      buildccache=1
115    ;;
116    "-sym")
117      buildsymbol=1
118    ;;
119    "-t")
120      shift
121      build_target=$1
122      ;;
123    "-o")
124      shift
125      build_output=$1
126      ;;
127    "-artifact"|"-A")
128      artifact_mode=1
129      ;;
130    "-without-nweb-ex")
131      without_nweb_ex=1
132      ;;
133    "-h")
134      usage
135      exit 0
136      ;;
137    *)
138      echo " -> $1 <- is not a valid option, please follow the usage below: "
139      usage
140      exit 1
141    ;;
142  esac
143  shift
144done
145
146if [ "-${build_output}" != "-" ]; then
147  build_dir="out/${build_output}/"
148fi
149
150case "${build_target}" in
151  "w"|"${BUILD_TARGET_WEBVIEW}")
152    build_target="${BUILD_TARGET_WEBVIEW}"
153    ;;
154  "b"|"${BUILD_TARGET_BROWSERSHELL}")
155    build_target="${BUILD_TARGET_BROWSERSHELL}"
156    [[ "-$buildarg_musl" == "-use_musl=true" ]] && build_sysroot="use_ohos_sdk_sysroot=true"
157    ;;
158  "n"|"${BUILD_TARGET_NATIVE}")
159    build_target="${BUILD_TARGET_NATIVE}"
160    ;;
161  "m"|"${BUILD_TARGET_BROWSER_SERVICE}")
162    build_target="${BUILD_TARGET_BROWSER_SERVICE}"
163    build_sysroot="use_ohos_sdk_sysroot=true"
164    [[ "-${build_product_name}" != "-product_name=\"rk3568\"" ]] && echo \
165      "Use -t M instead of -t m to build ${build_target} for current platform."\
166      && exit 1
167    ;;
168  "M"|"${BUILD_TARGET_BROWSER_SERVICE_HAR}")
169    build_target="${BUILD_TARGET_BROWSER_SERVICE_HAR}"
170    [[ "-$buildarg_musl" == "-use_musl=true" ]] && build_sysroot="use_ohos_sdk_sysroot=true"
171    ;;
172  *)
173    echo "Invalid build_target: ${build_target}"
174    exit 2
175    ;;
176esac
177
178SYMBOL_LEVEL=1
179if [ $buildsymbol = 1 ]; then
180  SYMBOL_LEVEL=2
181fi
182
183if [ $buildcount = 0 ]; then
184  #buildcount=$(grep processor /proc/cpuinfo | wc -l)
185  buildcount=40
186fi
187
188if [ $buildccache = 1 ]; then
189  if [ $buildcount = 0 ]; then
190    buildcount=64
191  fi
192  GN_ARGS="cc_wrapper=\"ccache\" clang_use_chrome_plugins=false linux_use_bundled_binutils=false"
193  export CCACHE_CPP2=yes
194fi
195
196if [ ${artifact_mode} -eq 1 ]; then
197  GN_ARGS="${GN_ARGS} build_chromium_with_ohos_src=false"
198else
199  GN_ARGS="${GN_ARGS} build_chromium_with_ohos_src=true"
200fi
201
202# Extract ohos-sdk.
203if [ -f "src/ohos_sdk/.install" ]; then
204  bash "src/ohos_sdk/.install"
205  if [ $? -ne 0 ]; then
206    echo "ERROR: Failed to install ohos-sdk, abort!"
207    exit 1
208  fi
209fi
210
211if [ -f "${ROOT_DIR}/ohos_nweb_hap/BUILD.gn" ]; then
212  buildargs="${buildargs}
213  enable_ohos_nweb_hap=true"
214fi
215
216if [ ${without_nweb_ex} -ne 1 -a ${artifact_mode} -eq 1 ]; then
217  if ! [ -d "${ROOT_DIR}"/"${build_dir}" ]; then
218    mkdir -p "${ROOT_DIR}"/"${build_dir}"
219  fi
220
221  BUILD_CONFIG_NAME="ohos_nweb_ex_config.gn"
222  CONFIG_AUTO_GEN_DIR="build/config_gn_java"
223  config_override=build/config/default.json
224  config_to_gn_args=""
225
226  if [ -f "${ROOT_DIR}"/"${build_dir}""${BUILD_CONFIG_NAME}" ]; then
227    rm "${ROOT_DIR}"/"${build_dir}""${BUILD_CONFIG_NAME}"
228  fi
229  # Generate build_config.gn
230  if ! [ -d "${CONFIG_AUTO_GEN_DIR}" ];then
231      mkdir "${CONFIG_AUTO_GEN_DIR}"
232  fi
233
234  result=python build/config_to_gn.py \
235     -o "${ROOT_DIR}"/"${build_dir}""${BUILD_CONFIG_NAME}" \
236     -d ${CONFIG_AUTO_GEN_DIR} \
237     -i ${config_override} ${config_to_gn_args}
238  if [ $? -ne 0 ]; then
239    echo -e "Failed to execute build/config_to_gn.py, see errors above."
240    exit 1
241  fi
242  buildargs="${buildargs}
243    ohos_nweb_ex_config_name=\"//${build_dir}${BUILD_CONFIG_NAME}\"
244    "
245fi
246
247cd src
248
249time_start_for_build=$(date +%s)
250time_start_for_gn=$time_start_for_build
251
252if [ $buildgn = 1 ]; then
253  echo "generating args list: $buildargs $GN_ARGS"
254  third_party/depot_tools/gn gen $build_dir --args="$buildargs $buildarg_cpu $buildarg_musl $build_sysroot $build_product_name $GN_ARGS symbol_level=$SYMBOL_LEVEL"
255fi
256time_end_for_gn=$(date +%s)
257
258third_party/depot_tools/ninja -C $build_dir -j$buildcount ${build_target}
259time_end_for_build=$(date +%s)
260
261time_format() {
262  hours=$((($1 - $2) / 3600))
263  minutes=$((($1 - $2) % 3600 / 60))
264  seconds=$((($1 - $2) % 60))
265}
266
267time_format $time_end_for_gn $time_start_for_gn
268printf "\n\e[32mTime for gn  : %dH:%dM:%dS \e[0m\n" $hours $minutes $seconds
269time_format $time_end_for_build $time_end_for_gn
270printf "\e[32mTime for build : %dH:%dM:%dS \e[0m\n" $hours $minutes $seconds
271time_format $time_end_for_build $time_start_for_build
272printf "\e[32mTime for Total : %dH:%dM:%dS \e[0m\n\n" $hours $minutes $seconds
273
274echo "build done"
275