Skip to content

Commit

Permalink
nix: re-add maven-inputs2nix.sh script
Browse files Browse the repository at this point in the history
Was mistakenly removed in: d5ef218
#10217

Signed-off-by: Jakub Sokołowski <jakub@status.im>
  • Loading branch information
jakubgs committed May 1, 2020
1 parent 7a05859 commit e5add7b
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
current_dir=$(cd "${BASH_SOURCE%/*}" && pwd)
inputs_file_path="${current_dir}/maven-inputs.txt"
output_nix_file_path="${current_dir}/maven-sources.nix"
inputs2nix=$(realpath --relative-to="${current_dir}" "${GIT_ROOT}/nix/tools/maven/maven-inputs2nix.sh")
inputs2nix="${GIT_ROOT}/nix/mobile/android/maven-and-npm-deps/maven/maven-inputs2nix.sh"

echo "Regenerating Nix files, this process should take about 90 minutes"
nix-shell --run "set -Eeuo pipefail; LC_ALL=C ${current_dir}/fetch-maven-deps.sh | sort -u -o ${inputs_file_path}" \
Expand Down
157 changes: 157 additions & 0 deletions nix/mobile/android/maven-and-npm-deps/maven/maven-inputs2nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/env bash

#
# This script takes a maven-inputs.txt file and builds a Nix expression that can be used by maven-repo-builder.nix to produce a path to a local Maven repository
#

function getSHA() {
nix-prefetch-url --type sha256 "$1" 2> /dev/null
}

_tmp=$(mktemp)
sort $1 | uniq > $_tmp
trap "rm $_tmp" EXIT INT

apacheUrl='https://repo.maven.apache.org/maven2'
clojarsUrl='https://repo.clojars.org'
fabricUrl='https://maven.fabric.io/public'
googleUrl='https://dl.google.com/dl/android/maven2'
gradleUrl='http://repo.gradle.org/gradle/libs-releases-local'
gradlePluginsUrl='https://plugins.gradle.org/m2'
javaUrl='https://maven.java.net/content/repositories/releases'
jcenterUrl='https://jcenter.bintray.com'
jitpackUrl='https://jitpack.io'
mavenUrl='https://repo1.maven.org/maven2'
sonatypeSnapshotsUrl='https://oss.sonatype.org/content/repositories/snapshots'
sonatypePublicGridUrl='https://repository.sonatype.org/content/groups/sonatype-public-grid'

# Writes Nix attribute set describing a package (represented by its URL)
function writeEntry() {
local depurl=$1
if [[ "$depurl" = "$apacheUrl"* ]]; then
host='apache'
prefix=$apacheUrl
elif [[ "$depurl" = "$clojarsUrl"* ]]; then
host='clojars'
prefix=$clojarsUrl
elif [[ "$depurl" = "$fabricUrl"* ]]; then
host='fabric-io'
prefix=$fabricUrl
elif [[ "$depurl" = "$googleUrl"* ]]; then
host='google'
prefix=$googleUrl
elif [[ "$depurl" = "$gradleUrl"* ]]; then
host='gradle'
prefix=$gradleUrl
elif [[ "$depurl" = "$gradlePluginsUrl"* ]]; then
host='gradlePlugins'
prefix=$gradlePluginsUrl
elif [[ "$depurl" = "$jcenterUrl"* ]]; then
host='jcenter'
prefix=$jcenterUrl
elif [[ "$depurl" = "$jitpackUrl"* ]]; then
host='jitpack'
prefix=$jitpackUrl
elif [[ "$depurl" = "$javaUrl"* ]]; then
host='java'
prefix=$javaUrl
elif [[ "$depurl" = "$mavenUrl"* ]]; then
host='maven'
prefix=$mavenUrl
elif [[ "$depurl" = "$sonatypeSnapshotsUrl"* ]]; then
host='sonatypeSnapshots'
prefix=$sonatypeSnapshotsUrl
elif [[ "$depurl" = "$sonatypePublicGridUrl"* ]]; then
host='sonatypePublicGrid'
prefix=$sonatypePublicGridUrl
else
echo "Unknown host in $depurl, exiting."
exit 1
fi
deppath="${depurl/$prefix\//}"
pom_sha256=$(getSHA "$depurl.pom")
[ -n "$pom_sha256" ] && pom_sha1=$(curl -s --location "$depurl.pom.sha1") || unset pom_sha1
jar_sha256=$(getSHA "$depurl.jar")
type='jar'
if [ -z "$jar_sha256" ]; then
jar_sha256=$(getSHA "$depurl.aar")
[ -n "$jar_sha256" ] && type='aar'
fi
[ -n "$jar_sha256" ] && jar_sha1=$(curl -s --location "$depurl.${type}.sha1") || unset jar_sha1

if [ -z "$pom_sha256" ] && [ -z "$jar_sha256" ] && [ -z "$aar_sha256" ]; then
echo "Warning: failed to download $depurl" > /dev/stderr
echo "Exiting." > /dev/stderr
exit 1
fi

echo -n " \"$depurl\" =
{
host = repositories.$host;
path =
\"$deppath\";
type = \"$type\";"
if [ -n "$pom_sha256" ]; then
echo -n "
pom = {
sha1 = \"$pom_sha1\";
sha256 = \"$pom_sha256\";
};"
fi
if [ -n "$jar_sha256" ]; then
echo -n "
jar = {
sha1 = \"$jar_sha1\";
sha256 = \"$jar_sha256\";
};"
fi
echo "
};"
}

lineCount=$(wc -l $1 | cut -f 1 -d ' ')
currentLine=0
pstr="[=======================================================================]"

echo "# Auto-generated by $(realpath --relative-to="$(dirname $1)" ${BASH_SOURCE})
{ }:
let
repositories = {
apache = \"$mavenUrl\";
clojars = \"$clojarsUrl\";
fabric-io = \"$fabricUrl\";
google = \"$googleUrl\";
gradle = \"$gradleUrl\";
gradlePlugins = \"$gradlePluginsUrl\";
java = \"$javaUrl\";
jcenter = \"$jcenterUrl\";
jitpack = \"$jitpackUrl\";
maven = \"$mavenUrl\";
sonatypeSnapshots =
\"$sonatypeSnapshotsUrl\";
sonatypePublicGrid =
\"$sonatypePublicGridUrl\";
};
in {"
echo "Generating Nix file from $1..." > /dev/stderr
while read depurl
do
currentLine=$(( $currentLine + 1 ))
pd=$(( $currentLine * 73 / $lineCount ))
printf "\r%3d.%1d%% %.${pd}s" $(( $currentLine * 100 / $lineCount )) $(( ($currentLine * 1000 / $lineCount) % 10 )) $pstr > /dev/stderr

if [ -z "$depurl" ]; then
continue
fi
writeEntry $depurl

# com.android.tools.build:aapt2 package also includes a platform-specific package, so we should add that too
if [[ "$depurl" = *'com/android/tools/build/aapt2/'* ]]; then
writeEntry "$depurl-linux"
writeEntry "$depurl-osx"
fi
done < $_tmp

echo "}"

0 comments on commit e5add7b

Please sign in to comment.