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

94 lines
3.6 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 | armv6 | armv7 | ppc64le>
# IMPLEMENTATION_NAME = <tdlib | tdlight>
# 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
if [ -z "${CPU_CORES}" ]; then
echo "Missing parameter: CPU_CORES"
exit 1
fi
cd ../../
JAVA_PACKAGE_PATH="it/tdlight/jni"
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}"
2020-10-10 15:08:26 +02:00
echo "CPU cores count: ${CPU_CORES}"
echo "CMake extra arguments: '${CMAKE_EXTRA_ARGUMENTS}'"
echo "JAVA_PACKAGE_PATH: '${JAVA_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..."
[ -d ./generated/tdjni_build/ ] && rm -r ./generated/tdjni_build/
[ -d ./generated/tdjni_bin/ ] && rm -r ./generated/tdjni_bin/
[ -d ./generated/tdjni_docs/ ] && rm -r ./generated/tdjni_docs/
[ -f ./generated/src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java ] && rm ./generated/src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java
2020-10-10 03:26:24 +02:00
# Create missing folders
echo "Creating missing folders..."
[ -d "./generated/src/main/java/${JAVA_PACKAGE_PATH}/" ] || mkdir -p "./generated/src/main/java/${JAVA_PACKAGE_PATH}/"
2020-10-10 03:26:24 +02:00
[ -d ./generated/tdjni_build/ ] || mkdir ./generated/tdjni_build/
[ -d ./generated/tdjni_bin/ ] || mkdir ./generated/tdjni_bin/
[ -d ./generated/tdjni_docs/ ] || mkdir ./generated/tdjni_docs/
2020-10-10 23:53:21 +02:00
# Copy executables
echo "Copying executables..."
export TD_GENERATED_BINARIES_DIR;
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
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..."
./td_tools/td/generate/td_generate_java_api TdApi "./implementation/td/generate/scheme/td_api.tlo" "./src/main/java" "$JAVA_PACKAGE_PATH"
php ./implementation/td/generate/JavadocTlDocumentationGenerator.php "./implementation/td/generate/scheme/td_api.tl" "./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java"
2020-10-10 03:26:24 +02:00
echo "Patching TdApi.java..."
${PYTHON_EXECUTABLE} ../scripts/core/tdlib-serializer "$(realpath -m ./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java)" "$(realpath -m ./src/main/java/${JAVA_PACKAGE_PATH}/new_TdApi.java)" "$(realpath -m ../scripts/core/tdlib-serializer/headers.txt)"
rm ./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java
if [[ "$OPERATING_SYSTEM_NAME" == "osx" ]]; then
unexpand --tabs=2 ./src/main/java/${JAVA_PACKAGE_PATH}/new_TdApi.java > ./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java
2020-10-11 13:26:12 +02:00
else
unexpand -t 2 ./src/main/java/${JAVA_PACKAGE_PATH}/new_TdApi.java > ./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java
2020-10-11 13:26:12 +02:00
fi
rm ./src/main/java/${JAVA_PACKAGE_PATH}/new_TdApi.java
2020-10-10 03:26:24 +02:00
echo "Generated '$(realpath -m ./src/main/java/${JAVA_PACKAGE_PATH}/TdApi.java)'"
2020-10-10 03:26:24 +02:00
echo "Done."
exit 0