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