1#!/usr/bin/env bash 2# Copyright (c) 2024 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 -e -o pipefail 16 17readonly SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" 18readonly GENPATH="${SCRIPT_DIR}/../../stdlib" 19readonly GEN_ESCOMPAT_PATH="${1:-${GENPATH}}/escompat" 20readonly GEN_STDCORE_PATH="${1:-${GENPATH}}/std/core" 21readonly VENV_DIR=${VENV_DIR:-$(realpath ~/.venv-panda)} 22readonly ARR="${GEN_ESCOMPAT_PATH}/Array.sts" 23readonly BLT_ARR="${GEN_STDCORE_PATH}/BuiltinArray.sts" 24readonly BLT_ARR_SORT="${GEN_STDCORE_PATH}/BuiltinArraySort.sts" 25readonly BLT_ARR_ARG="${GEN_STDCORE_PATH}/BuiltinArrayAlgorithms.sts" 26readonly DATAVIEW="${GEN_ESCOMPAT_PATH}/DataView.sts" 27readonly TYPED_ARR="${GEN_ESCOMPAT_PATH}/TypedArrays.sts" 28readonly TYPED_UARR="${GEN_ESCOMPAT_PATH}/TypedUArrays.sts" 29readonly FUNC="${GEN_STDCORE_PATH}/Function.sts" 30 31cd "$SCRIPT_DIR" 32 33JINJA_PATH="${VENV_DIR}/bin/jinja2" 34if ! [[ -f "${JINJA_PATH}" ]]; then 35 JINJA_PATH="jinja2" 36fi 37 38function format_file() { 39 sed -e 's/\b \s\+\b/ /g' | sed -e 's/\s\+$//g' | sed -e 's+/\*\s*\*/\s*++g' | cat -s 40} 41 42mkdir -p "${GEN_ESCOMPAT_PATH}" 43mkdir -p "${GEN_STDCORE_PATH}" 44 45# Generate Array 46echo "Generating ${ARR}" 47erb Array_escompat.erb | format_file > "${ARR}" 48 49echo "Generating ${BLT_ARR}" 50erb Array_builtin.erb | format_file > "${BLT_ARR}" 51 52echo "Generating ${BLT_ARR_SORT}" 53"${JINJA_PATH}" Array_builtin_sort.sts.j2 | format_file > "${BLT_ARR_SORT}" 54 55echo "Generating ${BLT_ARR_ARG}" 56"${JINJA_PATH}" Array_builtin_algorithms.sts.j2 | format_file > "${BLT_ARR_ARG}" 57 58# Generate TypedArrays 59echo "Generating ${DATAVIEW}" 60"${JINJA_PATH}" "${SCRIPT_DIR}/DataView.sts.j2" -o "${DATAVIEW}" 61 62echo "Generating ${TYPED_ARR}" 63"${JINJA_PATH}" "${SCRIPT_DIR}/typedArray.sts.j2" -o "${TYPED_ARR}" 64 65echo "Generating ${TYPED_UARR}" 66"${JINJA_PATH}" "${SCRIPT_DIR}/typedUArray.sts.j2" -o "${TYPED_UARR}" 67 68# Generate Functions 69echo "Generating ${FUNC}" 70"${JINJA_PATH}" "${SCRIPT_DIR}/Function.sts.j2" -o "${FUNC}" 71 72exit 0 73