• 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.
14set -e
15while [ $# -gt 0 ]; do
16  case "$1" in
17    -skip-ssl|--skip-ssl) # wget、npm skip ssl check, which will allow
18                          # hacker to get and modify data stream between server and client!
19    SKIP_SSL=YES
20    ;;
21    -h|--help)
22    HELP=YES
23    ;;
24    --disable-rich)       # disable the rich module of python
25    DISABLE_RICH=YES
26    ;;
27    --enable-symlink)     # enable symlink while copying node_modules
28    ENABLE_SYMLINK=YES
29    ;;
30    --tool-repo)
31    TOOL_REPO="$2"
32    shift
33    ;;
34    --tool-repo=*)
35    TOOL_REPO="${1#--tool-repo=}"
36    ;;
37    --npm-registry)
38    NPM_REGISTRY="$2"
39    shift
40    ;;
41    --npm-registry=*)
42    NPM_REGISTRY="${1#--npm-registry=}"
43    ;;
44    --trusted-host)
45    TRUSTED_HOST="$2"
46    shift
47    ;;
48    --trusted-host=*)
49    TRUSTED_HOST="${1#--trusted-host=}"
50    ;;
51    --pypi-url)           # python package index url
52    PYPI_URL="$2"
53    shift
54    ;;
55    --pypi-url=*)
56    PYPI_URL="${1#--pypi-url=}"
57    ;;
58    *)
59    echo "$0: Warning: unsupported parameter: $1" >&2
60    ;;
61  esac
62  shift
63done
64
65case $(uname -s) in
66    Linux)
67
68        host_platform=linux
69        ;;
70    Darwin)
71        host_platform=darwin
72        ;;
73    *)
74        echo "Unsupported host platform: $(uname -s)"
75        exit 1
76esac
77
78case $(uname -m) in
79    arm64)
80
81        host_cpu=arm64
82        ;;
83    *)
84        host_cpu=x86_64
85esac
86
87if [ "X${SKIP_SSL}" == "XYES" ];then
88    wget_ssl_check="--skip-ssl"
89else
90    wget_ssl_check=''
91fi
92
93if [ "X${HELP}" == "XYES" ];then
94    help="-h"
95else
96    help=''
97fi
98
99if [ "X${ENABLE_SYMLINK}" == "XYES" ];then
100    enable_symlink="--enable-symlink"
101else
102    enable_symlink=''
103fi
104
105if [ ! -z "$TOOL_REPO" ];then
106    tool_repo="--tool-repo $TOOL_REPO"
107else
108    tool_repo=''
109fi
110
111if [ ! -z "$NPM_REGISTRY" ];then
112    npm_registry="--npm-registry $NPM_REGISTRY"
113else
114    npm_registry=''
115fi
116
117if [ ! -z "$TRUSTED_HOST" ];then
118    trusted_host=$TRUSTED_HOST
119elif [ ! -z "$PYPI_URL" ];then
120    trusted_host=${PYPI_URL/#*:\/\//}       # remove prefix part such as http:// https:// etc.
121    trusted_host=${trusted_host/%[:\/]*/}   # remove suffix part including the port number
122else
123    trusted_host='repo.huaweicloud.com'
124fi
125
126if [ ! -z "$PYPI_URL" ];then
127    pypi_url=$PYPI_URL
128else
129    pypi_url='http://repo.huaweicloud.com/repository/pypi/simple'
130fi
131
132if [ $UID -ne 0 ]; then
133    npm_para=''
134else
135    npm_para='--unsafe-perm'
136fi
137
138if [ "X${DISABLE_RICH}" == "XYES" ];then
139  disable_rich='--disable-rich'
140else
141  set +e
142  pip3 install --trusted-host $trusted_host -i $pypi_url rich;
143  if [ $? -eq 0 ];then
144      echo "rich installed successfully"
145  else
146      disable_rich='--disable-rich'
147  fi
148  set -e
149fi
150
151cpu="--host-cpu $host_cpu"
152platform="--host-platform $host_platform"
153script_path=$(cd $(dirname $0);pwd)
154code_dir=$(dirname ${script_path})
155echo "prebuilts_download start"
156python3 "${code_dir}/build/prebuilts_download.py" $wget_ssl_check $tool_repo $npm_registry $help $cpu $platform $npm_para $disable_rich $enable_symlink
157echo "prebuilts_download end"
158
159# llvm_ndk is merged form llvm and libcxx-ndk for compiling the native of hap
160llvm_dir="${code_dir}/prebuilts/clang/ohos/linux-x86_64"
161if [[ -e "${llvm_dir}/llvm_ndk" ]];then
162  rm -rf "${llvm_dir}/llvm_ndk"
163fi
164mkdir -p "${llvm_dir}/llvm_ndk"
165cp -af "${llvm_dir}/llvm/include" "${llvm_dir}/llvm_ndk"
166cp -rfp "${llvm_dir}/libcxx-ndk/include/libcxx-ohos/include" "${llvm_dir}/llvm_ndk"
167
168if [[ "${host_platform}" == "linux" ]]; then
169    sed -i "1s%.*%#!/usr/bin/env python3%" ${code_dir}/prebuilts/python/${host_platform}-x86/3.9.2/bin/pip3.9
170elif [[ "${host_platform}" == "darwin" ]]; then
171    sed -i "" "1s%.*%#!/use/bin/env python3%" ${code_dir}/prebuilts/python/${host_platform}-x86/3.9.2/bin/pip3.9
172fi
173prebuild_python3_path="$code_dir/prebuilts/python/${host_platform}-x86/3.9.2/bin/python3.9"
174prebuild_pip3_path="${code_dir}/prebuilts/python/${host_platform}-x86/3.9.2/bin/pip3.9"
175$prebuild_python3_path $prebuild_pip3_path install --trusted-host $trusted_host -i $pypi_url pyyaml requests prompt_toolkit\=\=1.0.14 kconfiglib\>\=14.1.0
176echo -e "\n"
177