1#!/usr/bin/env bash 2# Copyright (c) 2024-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 -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 GEN_STDINTEROP_PATH="${1:-${GENPATH}}/std/interop/js" 23readonly ARR="${GEN_ESCOMPAT_PATH}/Array.ets" 24readonly BLT_ARR="${GEN_STDCORE_PATH}/BuiltinArray.ets" 25readonly BLT_ARR_SORT="${GEN_STDCORE_PATH}/BuiltinArraySort.ets" 26readonly BLT_ARR_ARG="${GEN_STDCORE_PATH}/BuiltinArrayAlgorithms.ets" 27readonly DATAVIEW="${GEN_ESCOMPAT_PATH}/DataView.ets" 28readonly TYPED_ARR="${GEN_ESCOMPAT_PATH}/TypedArrays.ets" 29readonly TYPED_UARR="${GEN_ESCOMPAT_PATH}/TypedUArrays.ets" 30readonly FUNC="${GEN_STDCORE_PATH}/Function.ets" 31readonly TUP="${GEN_STDCORE_PATH}/Tuple.ets" 32readonly INTEROP_TRANSFER_HELPER="${GEN_STDINTEROP_PATH}/InteropTransferHelper.ets" 33 34cd "$SCRIPT_DIR" 35 36JINJA_PATH="${VENV_DIR}/bin/jinja2" 37if ! [[ -f "${JINJA_PATH}" ]]; then 38 JINJA_PATH="jinja2" 39fi 40 41function format_file() { 42 sed -e 's/\b \s\+\b/ /g' | sed -e 's/\s\+$//g' | sed -e 's+/\*\s*\*/\s*++g' | cat -s 43} 44 45mkdir -p "${GEN_ESCOMPAT_PATH}" 46mkdir -p "${GEN_STDCORE_PATH}" 47mkdir -p "${GEN_STDINTEROP_PATH}" 48 49# Generate Array 50echo "Generating ${ARR}" 51erb Array_escompat.erb | format_file > "${ARR}" 52 53echo "Generating ${BLT_ARR}" 54erb Array_builtin.erb | format_file > "${BLT_ARR}" 55 56echo "Generating ${BLT_ARR_SORT}" 57"${JINJA_PATH}" Array_builtin_sort.ets.j2 | format_file > "${BLT_ARR_SORT}" 58 59echo "Generating ${BLT_ARR_ARG}" 60"${JINJA_PATH}" Array_builtin_algorithms.ets.j2 | format_file > "${BLT_ARR_ARG}" 61 62# Generate TypedArrays 63echo "Generating ${DATAVIEW}" 64"${JINJA_PATH}" "${SCRIPT_DIR}/DataView.ets.j2" -o "${DATAVIEW}" 65 66echo "Generating ${TYPED_ARR}" 67"${JINJA_PATH}" "${SCRIPT_DIR}/typedArray.ets.j2" -o "${TYPED_ARR}" 68 69echo "Generating ${TYPED_UARR}" 70"${JINJA_PATH}" "${SCRIPT_DIR}/typedUArray.ets.j2" -o "${TYPED_UARR}" 71 72# Generate Functions 73echo "Generating ${FUNC}" 74"${JINJA_PATH}" "${SCRIPT_DIR}/Function.ets.j2" -o "${FUNC}" 75 76# Generate Tuples 77echo "Generating ${TUP}" 78"${JINJA_PATH}" "${SCRIPT_DIR}/Tuple.ets.j2" -o "${TUP}" 79 80# Generate InteropTransferHelper 81echo "Generating ${INTEROP_TRANSFER_HELPER}" 82"${JINJA_PATH}" "${SCRIPT_DIR}/InteropTransferHelper.ets.j2" -o "${INTEROP_TRANSFER_HELPER}" 83 84exit 0 85