2020-05-07 10:21:39 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-06-16 10:38:27 +00:00
|
|
|
# Stop on any failures, including in pipes
|
2020-05-24 13:44:15 +00:00
|
|
|
set -e
|
2020-06-16 10:38:27 +00:00
|
|
|
set -o pipefail
|
2020-05-24 13:44:15 +00:00
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
if [[ -z "${IN_NIX_SHELL}" ]]; then
|
|
|
|
echo "Remember to call 'make shell'!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# This script takes care of generating/updating the maven-sources.nix file
|
|
|
|
# representing the offline Maven repo containing the dependencies
|
|
|
|
# required to build the project
|
|
|
|
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
|
|
THIS_SCRIPT=$(realpath --relative-to="${GIT_ROOT}" ${BASH_SOURCE})
|
|
|
|
CUR_DIR=$(cd "${BASH_SOURCE%/*}" && pwd)
|
|
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
|
|
|
|
|
|
|
PROJ_LIST="${CUR_DIR}/proj.list"
|
|
|
|
DEPS_LIST="${CUR_DIR}/deps.list"
|
|
|
|
DEPS_URLS="${CUR_DIR}/deps.urls"
|
2020-05-14 09:13:06 +00:00
|
|
|
DEPS_JSON="${CUR_DIR}/deps.json"
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Raise limit of file descriptors
|
|
|
|
ulimit -n 16384
|
|
|
|
|
|
|
|
echo "Regenerating Nix files..."
|
|
|
|
|
|
|
|
# Gradle needs to be run in 'android' subfolder
|
|
|
|
cd $GIT_ROOT/android
|
|
|
|
|
|
|
|
# Stop gradle daemons to avoid locking
|
|
|
|
./gradlew --stop >/dev/null
|
|
|
|
|
|
|
|
# Generate list of Gradle sub-projects ----------------------------------------
|
|
|
|
${CUR_DIR}/get_projects.sh | sort -u -o ${PROJ_LIST}
|
|
|
|
|
|
|
|
echo -e "Found ${GRN}$(wc -l < ${PROJ_LIST})${RST} sub-projects..."
|
|
|
|
|
|
|
|
# Check each sub-project in parallel, the ":" is for local deps ---------------
|
|
|
|
PROJECTS=$(cat ${PROJ_LIST})
|
2020-05-24 13:44:15 +00:00
|
|
|
${CUR_DIR}/get_deps.sh ":" ${PROJECTS[@]} | sort -uV -o ${DEPS_LIST}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2020-05-24 13:44:15 +00:00
|
|
|
echo -e "${CLR}Found ${GRN}$(wc -l < ${DEPS_LIST})${RST} direct dependencies..."
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Find download URLs for each dependency --------------------------------------
|
2020-05-24 13:44:15 +00:00
|
|
|
cat ${DEPS_LIST} | go-maven-resolver | sort -uV -o ${DEPS_URLS}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2020-05-24 13:44:15 +00:00
|
|
|
echo -e "${CLR}Found ${GRN}$(wc -l < ${DEPS_URLS})${RST} dependency URLs..."
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Open the Nix attribute set --------------------------------------------------
|
2020-05-14 09:13:06 +00:00
|
|
|
echo -n "[" > ${DEPS_JSON}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Format URLs into a Nix consumable file.
|
|
|
|
URLS=$(cat ${DEPS_URLS})
|
|
|
|
parallel --will-cite --keep-order \
|
2020-05-14 09:13:06 +00:00
|
|
|
"${CUR_DIR}/url2json.sh" \
|
2020-05-07 10:21:39 +00:00
|
|
|
::: ${URLS} \
|
2020-05-14 09:13:06 +00:00
|
|
|
>> ${DEPS_JSON}
|
|
|
|
|
|
|
|
# Drop tailing comma on last object, stupid JSON
|
|
|
|
sed -i '$ s/},/}/' ${DEPS_JSON}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Close the Nix attribute set
|
2020-05-14 09:13:06 +00:00
|
|
|
echo "]" >> ${DEPS_JSON}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2020-05-24 13:44:15 +00:00
|
|
|
REL_DEPS_JSON=$(realpath --relative-to=${PWD} ${DEPS_JSON})
|
|
|
|
echo -e "${CLR}Generated Nix deps file: ${REL_DEPS_JSON#../}"
|
2020-05-07 10:21:39 +00:00
|
|
|
echo -e "${GRN}Done${RST}"
|