2020-10-10 03:26:24 +02:00
|
|
|
#!/bin/bash -e
|
2020-12-28 19:52:17 +01:00
|
|
|
# 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
|
|
|
|
|
2021-09-11 12:27:22 +02:00
|
|
|
source ./setup-variables.sh
|
|
|
|
|
2020-12-28 19:52:17 +01:00
|
|
|
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}"
|
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
|
|
|
|
2020-10-11 10:21:29 +02:00
|
|
|
# Setup constants
|
2020-12-27 14:05:47 +01:00
|
|
|
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
|
2020-10-11 10:21:29 +02:00
|
|
|
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/
|
2021-04-07 20:41:23 +02:00
|
|
|
[ -f ./generated/src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java ] && rm ./generated/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-04-07 20:41:23 +02:00
|
|
|
[ -d "./generated/src/main/java/${JAVA_API_PACKAGE_PATH}/" ] || mkdir -p "./generated/src/main/java/${JAVA_API_PACKAGE_PATH}/"
|
|
|
|
[ -d "./generated/src/main/java/${JAVA_LIB_PACKAGE_PATH}/" ] || mkdir -p "./generated/src/main/java/${JAVA_LIB_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..."
|
2020-12-29 19:33:21 +01:00
|
|
|
export TD_GENERATED_BINARIES_DIR;
|
2020-12-27 14:05:47 +01:00
|
|
|
if [[ "$OPERATING_SYSTEM_NAME" == "windows" ]]; then
|
2020-12-29 19:33:21 +01:00
|
|
|
TD_GENERATED_BINARIES_DIR="$(realpath -m ./generated/td_tools/td/generate/Release)"
|
2020-10-10 23:53:21 +02:00
|
|
|
else
|
2020-12-29 19:33:21 +01:00
|
|
|
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..."
|
2020-12-29 19:33:21 +01:00
|
|
|
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-04-07 20:41:23 +02:00
|
|
|
./td_tools/td/generate/td_generate_java_api TdApi "./implementation/td/generate/scheme/td_api.tlo" "./src/main/java" "$JAVA_API_PACKAGE_PATH"
|
|
|
|
php ./implementation/td/generate/JavadocTlDocumentationGenerator.php "./implementation/td/generate/scheme/td_api.tl" "./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java"
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
echo "Patching TdApi.java..."
|
2021-04-07 20:41:23 +02:00
|
|
|
${PYTHON_EXECUTABLE} ../scripts/core/tdlib-serializer "$(realpath -m ./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java)" "$(realpath -m ./src/main/java/${JAVA_API_PACKAGE_PATH}/new_TdApi.java)" "$(realpath -m ../scripts/core/tdlib-serializer/headers.txt)"
|
|
|
|
rm ./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
|
2020-12-27 14:05:47 +01:00
|
|
|
if [[ "$OPERATING_SYSTEM_NAME" == "osx" ]]; then
|
2021-04-07 20:41:23 +02:00
|
|
|
unexpand --tabs=2 ./src/main/java/${JAVA_API_PACKAGE_PATH}/new_TdApi.java > ./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
|
2020-10-11 13:26:12 +02:00
|
|
|
else
|
2021-04-07 20:41:23 +02:00
|
|
|
unexpand -t 2 ./src/main/java/${JAVA_API_PACKAGE_PATH}/new_TdApi.java > ./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java
|
2020-10-11 13:26:12 +02:00
|
|
|
fi
|
2021-04-07 20:41:23 +02:00
|
|
|
rm ./src/main/java/${JAVA_API_PACKAGE_PATH}/new_TdApi.java
|
2020-10-10 03:26:24 +02:00
|
|
|
|
2021-04-07 20:41:23 +02:00
|
|
|
echo "Generated '$(realpath -m ./src/main/java/${JAVA_API_PACKAGE_PATH}/TdApi.java)'"
|
2020-10-10 03:26:24 +02:00
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
exit 0
|