17c804472Sopenharmony_ci#!/bin/bash
27c804472Sopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd.
37c804472Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
47c804472Sopenharmony_ci# you may not use this file except in compliance with the License.
57c804472Sopenharmony_ci# You may obtain a copy of the License at
67c804472Sopenharmony_ci#
77c804472Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
87c804472Sopenharmony_ci#
97c804472Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
107c804472Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
117c804472Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127c804472Sopenharmony_ci# See the License for the specific language governing permissions and
137c804472Sopenharmony_ci# limitations under the License.
147c804472Sopenharmony_ci
157c804472Sopenharmony_ciset -e
167c804472Sopenharmony_ciecho "copy source code..."
177c804472Sopenharmony_ciprebuilts_path=${9}
187c804472Sopenharmony_ci# copy dependency file to generate dir of gn
197c804472Sopenharmony_ci# the params come from .gn
207c804472Sopenharmony_ci
217c804472Sopenharmony_ci# copy runtime to target out, and runtime/css-what is solt link, copy it always follow symbolic links in SOURCE
227c804472Sopenharmony_ciif [ "${8}" == 'true' ];then
237c804472Sopenharmony_ci  #cp -R -L $3 $8
247c804472Sopenharmony_ci  if [ "${12}" == 'true' ];then
257c804472Sopenharmony_ci    cp -R ${11} $7
267c804472Sopenharmony_ci  fi
277c804472Sopenharmony_cielse
287c804472Sopenharmony_ci  #cp -r -L $3 $8
297c804472Sopenharmony_ci  if [ "${12}" == 'true' ];then
307c804472Sopenharmony_ci    cp -r ${11} $7
317c804472Sopenharmony_ci  fi
327c804472Sopenharmony_cifi
337c804472Sopenharmony_ci
347c804472Sopenharmony_ci# $2 => node $3 => node_modules
357c804472Sopenharmony_cicp -f $4 $7
367c804472Sopenharmony_ci
377c804472Sopenharmony_ciif [ -d "$prebuilts_path" ]; then
387c804472Sopenharmony_ci  echo "copy node_modules..."
397c804472Sopenharmony_ci  if [ "${9}" == 'true' ];then
407c804472Sopenharmony_ci    cp -R $3 $7
417c804472Sopenharmony_ci  else
427c804472Sopenharmony_ci    cp -r $3 $7
437c804472Sopenharmony_ci  fi
447c804472Sopenharmony_cielse
457c804472Sopenharmony_ci  echo "download node_modules..."
467c804472Sopenharmony_ci  npm install
477c804472Sopenharmony_ci  cp -r ./node_modules ../../tools_previewer/automock/mock-generate
487c804472Sopenharmony_cifi
497c804472Sopenharmony_ci
507c804472Sopenharmony_cicp -f $5 $7
517c804472Sopenharmony_cicp -f $6 $7
527c804472Sopenharmony_cicp -f $1 $7
537c804472Sopenharmony_cicp -f ${13} $7
547c804472Sopenharmony_ciif [ -d "$prebuilts_path" ]; then
557c804472Sopenharmony_ci  echo "prebuilts exists"
567c804472Sopenharmony_ci  # address problme of parallzing compile
577c804472Sopenharmony_ci  rm -rf "$7/current"
587c804472Sopenharmony_ci  link_path=$(realpath $2)
597c804472Sopenharmony_ci  ln -s $link_path "$7/current"
607c804472Sopenharmony_ci  cd $7
617c804472Sopenharmony_ci  if [ "${8}" == 'true' ];then
627c804472Sopenharmony_ci    if [ "${12}" == 'true' ];then
637c804472Sopenharmony_ci      ./current/bin/node ./mock-generate/build.js ${10}
647c804472Sopenharmony_ci    fi
657c804472Sopenharmony_ci    ./current/bin/node build_jsmock_system_plugin.js || exit 1 &
667c804472Sopenharmony_ci    wait
677c804472Sopenharmony_ci  else
687c804472Sopenharmony_ci    if [ "${12}" == 'true' ];then
697c804472Sopenharmony_ci      ./current/bin/node ./mock-generate/build.js ${10}
707c804472Sopenharmony_ci    fi
717c804472Sopenharmony_ci    ./current/bin/node build_jsmock_system_plugin.js || exit 1 &
727c804472Sopenharmony_ci    wait
737c804472Sopenharmony_ci  fi
747c804472Sopenharmony_cielse
757c804472Sopenharmony_ci  npm run build
767c804472Sopenharmony_cifi
777c804472Sopenharmony_ci
787c804472Sopenharmony_ci# after running, remove dependency file
797c804472Sopenharmony_cirm -rf ./node_modules
807c804472Sopenharmony_ciif [ "${8}" == 'true' ];then
817c804472Sopenharmony_ci  rm -rf ./current
827c804472Sopenharmony_cielse
837c804472Sopenharmony_ci  rm -rf ./current
847c804472Sopenharmony_cifi
857c804472Sopenharmony_cirm -rf ./runtime
867c804472Sopenharmony_cirm -rf ./tsconfig.json
877c804472Sopenharmony_cirm -rf build_jsmock_system_plugin.js
887c804472Sopenharmony_cirm -rf ./.eslintrc
897c804472Sopenharmony_cirm -rf ./.babelrc
907c804472Sopenharmony_cirm -rf ./package.json
917c804472Sopenharmony_ciif [ "${12}" == 'true' ];then
927c804472Sopenharmony_ci  rm -rf ./mock-generate
937c804472Sopenharmony_cifi
94