• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2025 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
15set -ex
16
17function about() {
18    cat <<-ENDHELP
19    Script to dowload and prepare the ArkUI environment
20    where
21        --help            Show this help and exit
22        --nexus-repo      Nexus repo, like nexus.example.com:1234
23        --openlab-token   Token to access to openlab
24        (you can ask this information from Titova Tatiana)
25    Please use this file to set up your .npmrc
26        https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/npmrc
27    Use these instructions to manually prepare ArkUI Hello app
28        https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/How%20to%20Build%20the%20Shopping%20Application%20(for%20host)
29        https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/How%20to%20Build%20the%20Shopping%20Application%20(for%20Board%20and%20Mobile%20Devices)
30    Use these instructions to install custom compiler
31        https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/Setup%20custom%20SDK%20to%20run%20apps
32        https://gitee.com/openharmony-sig/arkcompiler_ets_frontend/wikis/How%20to%20build%20es2panda
33ENDHELP
34}
35
36while [ -n "$1" ]; do
37    case "$1" in
38        -h | --help)
39            about
40            exit 0
41            ;;
42        --nexus-repo)
43            NEXUS_REPO="${2}"
44            shift 2
45            ;;
46        --openlab-token)
47            KOALA_TOKEN="${2}"
48            shift 2
49            ;;
50        *)
51            echo "Unknown option" "${1}"
52            exit 1
53            ;;
54    esac
55done
56
57if [ -z "${NEXUS_REPO}" ]; then
58    echo "Please set NEXUS_REPO"
59    echo "export NEXUS_REPO=nexus.example.com:1234"
60    exit 1
61fi
62
63if [ -z "${NPROC_PER_JOB}" ]; then
64    NPROC_PER_JOB=16
65fi
66
67HUAWEI_MIRROR="${HUAWEI_MIRROR:-https://repo.huaweicloud.com/repository/npm/}"
68KOALA_REGISTRY="${KOALA_REGISTRY:-https://$NEXUS_REPO/repository/koala-npm/}"
69NINJA_OPTIONS="-j ${NPROC_PER_JOB}"
70
71retry() {
72  local -r -i max_attempts="$1"; shift
73  local -r cmd="$@"
74  local -i attempt_num=1
75  local -i delay=5
76
77  until $cmd
78    do
79      if (( attempt_num == max_attempts ))
80      then
81        echo "Attempt $attempt_num failed and there are no more attempts left!"
82         return 1
83      else
84        echo "Attempt $((attempt_num++)) failed! Trying again in $((delay *= attempt_num)) seconds..."
85        sleep ${delay}
86      fi
87    done
88}
89
90function do_checkout() {
91    local repo=$1
92    local rev=$2
93    local dest=$3
94    local patch=$4
95    [ -n "${repo}" ] || exit 1
96    [ -n "${rev}" ] || exit 1
97    [ -n "${dest}" ] || exit 1
98    mkdir -p "${dest}"
99    CMD_TIMEOUT=10m
100    pushd "${dest}" || exit 1
101        git init && git remote add origin "${repo}"
102        retry 5 timeout ${CMD_TIMEOUT} git fetch --depth 1 origin "${rev}" || {
103            echo "(Some error occurred while fetching rev: ${rev}"
104            exit 1
105        } && {
106            git checkout FETCH_HEAD || exit 1
107            [ -n "${patch}" ] && git apply "${patch}"
108        }
109        git log -1
110    popd >/dev/null 2>&1 || exit 1
111}
112
113SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
114source "${SCRIPT_DIR}"/arkui.properties
115
116ARKUI_DEV_REPO="${ARKUI_DEV_REPO:-https://gitee.com/rri_opensource/koala_projects.git}"
117ARKUI_DEV_BRANCH="${ARKUI_DEV_BRANCH:-master}"
118ARKUI_DEST="${ARKUI_DEST:-koala-sig}"
119
120do_checkout "${ARKUI_DEV_REPO}" "${ARKUI_DEV_BRANCH}" "${ARKUI_DEST}"
121
122cd "${ARKUI_DEST}" || exit 1
123
124npm config set package-lock false
125npm config set strict-ssl false
126npm config set registry "${HUAWEI_MIRROR}"
127npm config set @koalaui:registry "${KOALA_REGISTRY}"
128npm config set @panda:registry "https://$NEXUS_REPO/repository/koala-npm/"
129npm config set @ohos:registry "https://repo.harmonyos.com/npm/"
130if [ -z "${KOALA_REPO}" ] ; then
131    npm config set "//$NEXUS_REPO/repository/koala-npm/:_auth=$KOALA_TOKEN"
132fi
133
134npm install -d
135
136pushd incremental/tools/panda/ || exit 1
137if [ -z "${PANDA_SDK_TARBALL}" ] ; then
138npm run panda:sdk:install
139else
140npm install "${PANDA_SDK_TARBALL}"
141fi
142popd >/dev/null 2>&1 || exit 1
143
144pushd arkoala-arkts || exit 1
145npm install -d
146popd >/dev/null 2>&1 || exit 1
147
148return 0
149