2020-05-07 10:21:39 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-02-28 17:22:17 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
set -Eeo 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
|
|
|
|
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
|
|
|
|
2022-06-07 11:21:15 +00:00
|
|
|
CUR_DIR=$(cd "${BASH_SOURCE%/*}" && pwd)
|
2020-05-07 10:21:39 +00:00
|
|
|
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
|
|
|
|
|
2020-11-27 11:35:21 +00:00
|
|
|
# Generate list of Gradle sub-projects.
|
|
|
|
function gen_proj_list() {
|
2023-02-28 17:22:17 +00:00
|
|
|
"${CUR_DIR}/get_projects.sh" | sort -u -o "${PROJ_LIST}"
|
|
|
|
echo -e "Found ${GRN}$(wc -l < "${PROJ_LIST}")${RST} sub-projects..."
|
2020-11-27 11:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check each sub-project in parallel, the ":" is for local deps.
|
|
|
|
function gen_deps_list() {
|
2023-02-28 17:22:17 +00:00
|
|
|
PROJECTS=$(cat "${PROJ_LIST}")
|
|
|
|
# WARNING: The ${PROJECTS[@]} needs to remain unquoted to expand correctly.
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
"${CUR_DIR}/get_deps.sh" ":" ${PROJECTS[@]} | sort -uV -o "${DEPS_LIST}"
|
|
|
|
echo -e "${CLR}Found ${GRN}$(wc -l < "${DEPS_LIST}")${RST} direct dependencies..."
|
2020-11-27 11:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Find download URLs for each dependency.
|
|
|
|
function gen_deps_urls() {
|
2023-02-28 17:22:17 +00:00
|
|
|
go-maven-resolver < "${DEPS_LIST}" | sort -uV -o "${DEPS_URLS}"
|
|
|
|
echo -e "${CLR}Found ${GRN}$(wc -l < "${DEPS_URLS}")${RST} dependency URLs..."
|
2020-11-27 11:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate the JSON that Nix will consume.
|
|
|
|
function gen_deps_json() {
|
|
|
|
# Open the Nix attribute set.
|
2023-02-28 17:22:17 +00:00
|
|
|
echo -n "[" > "${DEPS_JSON}"
|
2020-11-27 11:35:21 +00:00
|
|
|
|
|
|
|
# Format URLs into a Nix consumable file.
|
2023-02-28 17:22:17 +00:00
|
|
|
URLS=$(cat "${DEPS_URLS}")
|
2022-05-18 08:12:22 +00:00
|
|
|
# Avoid rate limiting by using 4 of the available threads.
|
|
|
|
parallel --will-cite --keep-order --jobs 4 \
|
2020-11-27 11:35:21 +00:00
|
|
|
"${CUR_DIR}/url2json.sh" \
|
2023-02-28 17:22:17 +00:00
|
|
|
::: "${URLS}" \
|
|
|
|
>> "${DEPS_JSON}"
|
2020-11-27 11:35:21 +00:00
|
|
|
|
|
|
|
# Drop tailing comma on last object, stupid JSON
|
2023-02-28 17:22:17 +00:00
|
|
|
sed -i '$ s/},/}/' "${DEPS_JSON}"
|
2020-11-27 11:35:21 +00:00
|
|
|
|
|
|
|
# Close the Nix attribute set
|
2023-02-28 17:22:17 +00:00
|
|
|
echo "]" >> "${DEPS_JSON}"
|
2020-11-27 11:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2020-05-07 10:21:39 +00:00
|
|
|
echo "Regenerating Nix files..."
|
|
|
|
|
|
|
|
# Gradle needs to be run in 'android' subfolder
|
2022-07-25 20:38:41 +00:00
|
|
|
cd "${GIT_ROOT}/android"
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Stop gradle daemons to avoid locking
|
|
|
|
./gradlew --stop >/dev/null
|
|
|
|
|
2020-11-27 11:35:21 +00:00
|
|
|
# A way to run a specific stage of generation
|
2023-02-28 17:22:17 +00:00
|
|
|
if [[ -n "${1}" ]] && type "${1}" > /dev/null; then
|
2020-11-27 11:35:21 +00:00
|
|
|
${1}; exit 0
|
|
|
|
elif [[ -n "${1}" ]]; then
|
|
|
|
echo "No such function: ${1}"; exit 1
|
|
|
|
fi
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2020-11-27 11:35:21 +00:00
|
|
|
# Run each stage in order
|
|
|
|
gen_proj_list
|
|
|
|
gen_deps_list
|
2023-06-14 01:47:41 +00:00
|
|
|
# FIXME: Temporary fix for missing package.
|
|
|
|
echo 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.6.10' >> "${DEPS_LIST}"
|
|
|
|
echo 'com.android.tools.lint:lint-gradle:30.2.2' >> "${DEPS_LIST}"
|
|
|
|
echo 'com.android.tools.build:gradle:7.0.4' >> "${DEPS_LIST}"
|
2020-11-27 11:35:21 +00:00
|
|
|
gen_deps_urls
|
|
|
|
gen_deps_json
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2023-02-28 17:22:17 +00:00
|
|
|
REL_DEPS_JSON=$(realpath --relative-to="${PWD}" "${DEPS_JSON}")
|
2020-05-24 13:44:15 +00:00
|
|
|
echo -e "${CLR}Generated Nix deps file: ${REL_DEPS_JSON#../}"
|
2020-05-07 10:21:39 +00:00
|
|
|
echo -e "${GRN}Done${RST}"
|