tdlight-java-natives/scripts/core/generate_tdapi_java_file.sh

121 lines
5.1 KiB
Bash
Raw Normal View History

2020-10-10 03:26:24 +02:00
#!/bin/bash -e
# MAIN REQUIRED ENVIRONMENT VARIABLES:
# OPERATING_SYSTEM_NAME = <windows | linux | osx>
# CPU_ARCHITECTURE_NAME = <amd64 | aarch64 | 386 | s390x | armhf | ppc64le>
# IMPLEMENTATION_NAME = <tdlib | tdlight>
2021-12-08 00:00:21 +01:00
# API_TYPE = <legacy | sealed>
# CPU_CORES = "-- -j<cores>" or "-m" on Windows
# OTHER REQUIRED ENVIRONMENT VARIABLES:
# CMAKE_EXTRA_ARGUMENTS = <args>
2020-10-10 03:26:24 +02:00
# Check variables correctness
if [ -z "${OPERATING_SYSTEM_NAME}" ]; then
echo "Missing parameter: OPERATING_SYSTEM_NAME"
exit 1
fi
if [ -z "${CPU_ARCHITECTURE_NAME}" ]; then
echo "Missing parameter: CPU_ARCHITECTURE_NAME"
exit 1
fi
if [ -z "${IMPLEMENTATION_NAME}" ]; then
echo "Missing parameter: IMPLEMENTATION_NAME"
exit 1
fi
2021-12-08 00:00:21 +01:00
if [ -z "${API_TYPE}" ]; then
echo "Missing parameter: API_TYPE"
exit 1
fi
2020-10-10 03:26:24 +02:00
if [ -z "${CPU_CORES}" ]; then
echo "Missing parameter: CPU_CORES"
exit 1
fi
2021-09-11 12:27:22 +02:00
source ./setup-variables.sh
2021-12-08 00:00:21 +01:00
if [[ "$API_TYPE" == "sealed" ]]; then
MIN_JDK_VERSION="17"
SEALED="true"
else
MIN_JDK_VERSION="8"
SEALED="false"
fi
cd ../../
2021-04-07 20:41:23 +02:00
JAVA_API_PACKAGE_PATH="it/tdlight/jni"
JAVA_LIB_PACKAGE_PATH="it/tdlight/tdnative"
2020-10-10 03:26:24 +02:00
# Print details
echo "Generating TdApi.java..."
echo "Current directory: $(pwd)"
echo "Operating system: ${OPERATING_SYSTEM_NAME}"
echo "Architecture: ${CPU_ARCHITECTURE_NAME}"
echo "Td implementation: ${IMPLEMENTATION_NAME}"
2021-12-08 00:00:21 +01:00
echo "API type: ${API_TYPE}"
echo "Min jdk version: ${MIN_JDK_VERSION}"
echo "Sealed: ${SEALED}"
2020-10-10 15:08:26 +02:00
echo "CPU cores count: ${CPU_CORES}"
echo "CMake extra arguments: '${CMAKE_EXTRA_ARGUMENTS}'"
2021-04-07 20:41:23 +02:00
echo "JAVA_API_PACKAGE_PATH: '${JAVA_API_PACKAGE_PATH}'"
echo "JAVA_LIB_PACKAGE_PATH: '${JAVA_LIB_PACKAGE_PATH}'"
2020-10-10 03:26:24 +02:00
# Setup constants
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
export PYTHON_EXECUTABLE="python"
else
export PYTHON_EXECUTABLE="python3"
fi
2020-10-10 03:26:24 +02:00
# Delete old data
echo "Deleting old data..."
2021-12-08 00:48:27 +01:00
[ -d ./generated-"$API_TYPE"/tdjni_build/ ] && rm -r ./generated-"$API_TYPE"/tdjni_build/
[ -d ./generated-"$API_TYPE"/tdjni_bin/ ] && rm -r ./generated-"$API_TYPE"/tdjni_bin/
[ -d ./generated-"$API_TYPE"/tdjni_docs/ ] && rm -r ./generated-"$API_TYPE"/tdjni_docs/
[ -f ./generated-"$API_TYPE"/src/main/java17/${JAVA_API_PACKAGE_PATH}/TdApi.java ] && rm ./generated-"$API_TYPE"/src/main/java17/${JAVA_API_PACKAGE_PATH}/TdApi.java
[ -f ./generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java ] && rm ./generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
2020-10-10 03:26:24 +02:00
# Create missing folders
echo "Creating missing folders..."
2021-12-08 00:48:27 +01:00
[ -d "./generated-$API_TYPE/src/main/java/${JAVA_API_PACKAGE_PATH}/" ] || mkdir -p "./generated-$API_TYPE/src/main/java/${JAVA_API_PACKAGE_PATH}/"
[ -d "./generated-$API_TYPE/src/main/java/${JAVA_LIB_PACKAGE_PATH}/" ] || mkdir -p "./generated-$API_TYPE/src/main/java/${JAVA_LIB_PACKAGE_PATH}/"
[ -d ./generated-"$API_TYPE"/tdjni_build/ ] || mkdir ./generated-"$API_TYPE"/tdjni_build/
[ -d ./generated-"$API_TYPE"/tdjni_bin/ ] || mkdir ./generated-"$API_TYPE"/tdjni_bin/
[ -d ./generated-"$API_TYPE"/tdjni_docs/ ] || mkdir ./generated-"$API_TYPE"/tdjni_docs/
2020-10-10 03:26:24 +02:00
2020-10-10 23:53:21 +02:00
# Copy executables
echo "Copying executables..."
2021-09-14 02:58:39 +02:00
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
TD_GENERATED_BINARIES_DIR="$(realpath -m ./generated/td_tools/td/generate/Release)"
2020-10-10 23:53:21 +02:00
else
TD_GENERATED_BINARIES_DIR="$(realpath -m ./generated/td_tools/td/generate)"
2020-10-10 23:53:21 +02:00
fi
2021-09-14 02:58:39 +02:00
export TD_GENERATED_BINARIES_DIR
2020-10-10 03:26:24 +02:00
# Configure cmake
echo "Configuring CMake..."
cd ./generated/
echo "Telegram source path: '$(realpath -m ./implementation/)'"
2020-10-10 03:26:24 +02:00
# Run cmake to generate TdApi.java
echo "Generating TdApi.java..."
2021-12-08 00:48:27 +01:00
./td_tools/td/generate/td_generate_java_api TdApi "./implementation/td/generate/scheme/td_api.tlo" "../generated-$API_TYPE/src/main/java" "$JAVA_API_PACKAGE_PATH"
php ./implementation/td/generate/JavadocTlDocumentationGenerator.php "./implementation/td/generate/scheme/td_api.tl" "../generated-$API_TYPE/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java"
mv "../generated-$API_TYPE/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java" "../generated-$API_TYPE/src/main/java/${JAVA_API_PACKAGE_PATH}/php_TdApi.java"
2020-10-10 03:26:24 +02:00
2021-12-08 00:00:21 +01:00
echo "Patching TdApi.java for Java ${MIN_JDK_VERSION}..."
2021-12-08 00:48:27 +01:00
${PYTHON_EXECUTABLE} ../scripts/core/tdlib-serializer "$(realpath -m ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/php_TdApi.java)" "$(realpath -m ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/unexpanded_TdApi.java)" "$(realpath -m ../scripts/core/tdlib-serializer/headers.txt)" "$SEALED"
2021-10-23 19:13:08 +02:00
if [[ "$OPERATING_SYSTEM_NAME" == "osx" ]]; then
2021-12-08 00:48:27 +01:00
unexpand --tabs=2 ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/unexpanded_TdApi.java > ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
2021-10-23 19:13:08 +02:00
else
2021-12-08 00:48:27 +01:00
unexpand -t 2 ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/unexpanded_TdApi.java > ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
2021-10-23 19:13:08 +02:00
fi
2021-12-08 00:48:27 +01:00
rm ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/unexpanded_TdApi.java
2021-10-23 19:13:08 +02:00
2021-12-08 00:48:27 +01:00
echo "Generated '$(realpath -m ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java)'"
2021-10-23 19:13:08 +02:00
2021-12-08 00:48:27 +01:00
rm ../generated-"$API_TYPE"/src/main/java/${JAVA_API_PACKAGE_PATH}/php_TdApi.java
2020-10-10 03:26:24 +02:00
echo "Done."
exit 0