2020-05-07 10:21:39 +00:00
|
|
|
# This is the Android Asset Packaging Tool(AAPT2).
|
|
|
|
# It is used by Gradle to package Android app resources.
|
|
|
|
# See: https://developer.android.com/studio/command-line/aapt2
|
|
|
|
|
2022-05-26 09:11:34 +00:00
|
|
|
{ lib, stdenv, pkgs, fetchurl }:
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
let
|
2020-05-07 10:21:39 +00:00
|
|
|
inherit (lib) getAttr optionals;
|
|
|
|
inherit (stdenv) isLinux isDarwin;
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
pname = "aapt2";
|
|
|
|
# Warning: This must be the same as gradlePluginVersion android/gradle.properties
|
2021-09-02 12:24:09 +00:00
|
|
|
version = "3.5.4-6197926";
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
pkgPath = "com/android/tools/build/aapt2";
|
|
|
|
repoUrl = "https://dl.google.com/dl/android/maven2";
|
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
platform =
|
|
|
|
if isLinux then "linux" else
|
|
|
|
if isDarwin then "osx" else
|
|
|
|
throw "Unknown platform!";
|
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
filenames = {
|
2020-05-07 10:21:39 +00:00
|
|
|
jar = "${pname}-${version}-${platform}.jar";
|
2020-05-07 10:21:39 +00:00
|
|
|
pom = "${pname}-${version}.pom";
|
|
|
|
};
|
|
|
|
|
|
|
|
urls = {
|
|
|
|
jar = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.jar}";
|
2020-05-07 10:21:39 +00:00
|
|
|
sha256 = getAttr platform {
|
2021-09-02 12:24:09 +00:00
|
|
|
linux = "0hrlbxdn6bkl6qr9y599mjs0dy72q0352j30vpkza4lbq5b7rj9v";
|
|
|
|
osx = "0hhvxyr0jxci01qqkcrn80h4qs3b43lqxpbss0xvrkd1nwdilmnb";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
sha = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.jar}.sha1";
|
2020-05-07 10:21:39 +00:00
|
|
|
sha256 = getAttr platform {
|
2021-09-02 12:24:09 +00:00
|
|
|
linux = "0ipmkl911hf17g2pb39jjkwrbb07p0cd1qd10p2fl8d1icxf63sz";
|
|
|
|
osx = "156jbw4xm43902c0cqrag9l1s3fg6i1irsdz8m8659i9530ywwpx";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
pom = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.pom}";
|
2021-09-02 12:24:09 +00:00
|
|
|
sha256 = "00ra1xz4x1sfcf0z6x9in3b1flpyvxjbhpvhacc32r8b58nfvqzp";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit pname version;
|
|
|
|
|
|
|
|
srcs = with urls; [ jar sha pom ];
|
2020-05-07 10:21:39 +00:00
|
|
|
phases = [ "unpackPhase" ]
|
|
|
|
++ optionals isLinux [ "patchPhase" ]; # OSX binaries don't need patchelf
|
2022-05-26 09:11:34 +00:00
|
|
|
buildInputs = with pkgs; [ zip unzip patchelf ];
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
for src in $srcs; do
|
2020-05-07 10:21:39 +00:00
|
|
|
filename=$(stripHash $src)
|
|
|
|
cp $src $out/$filename
|
2020-05-07 10:21:39 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
# On Linux, we need to patch the interpreter in Java packages
|
|
|
|
# that contain native executables to use Nix's interpreter instead.
|
|
|
|
patchPhase = ''
|
|
|
|
# We need an stdenv with a compiler
|
|
|
|
[[ -n "$NIX_CC" ]] || exit 1
|
|
|
|
|
|
|
|
# Patch executables from maven dependency to use Nix's interpreter
|
|
|
|
tmpDir=$(mktemp -d)
|
2022-05-26 09:11:34 +00:00
|
|
|
unzip $out/${filenames.jar} -d $tmpDir
|
2020-05-07 10:21:39 +00:00
|
|
|
for exe in `find $tmpDir/ -type f -executable`; do
|
2022-05-26 09:11:34 +00:00
|
|
|
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $exe
|
2020-05-07 10:21:39 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Rebuild the .jar file with patched binaries
|
|
|
|
pushd $tmpDir > /dev/null
|
|
|
|
chmod u+w $out/${filenames.jar}
|
2022-05-26 09:11:34 +00:00
|
|
|
zip -fr $out/${filenames.jar}
|
2020-05-07 10:21:39 +00:00
|
|
|
chmod $out/${filenames.jar} --reference=$out/${filenames.jar}.sha1
|
|
|
|
popd > /dev/null
|
|
|
|
rm -rf $tmpDir
|
|
|
|
'';
|
|
|
|
}
|