Skip to content

Commit d895bc0

Browse files
committed
jadx: convert to gradle setup hook
1 parent 6d513fb commit d895bc0

File tree

2 files changed

+704
-80
lines changed

2 files changed

+704
-80
lines changed

pkgs/tools/security/jadx/default.nix

Lines changed: 9 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,108 +5,37 @@
55
, jdk
66
, quark-engine
77
, makeWrapper
8-
, perl
98
, imagemagick
109
, makeDesktopItem
1110
, copyDesktopItems
1211
, desktopToDarwinBundle
1312
}:
1413

15-
let
14+
stdenv.mkDerivation (finalAttrs: {
1615
pname = "jadx";
1716
version = "1.4.7";
1817

1918
src = fetchFromGitHub {
2019
owner = "skylot";
21-
repo = pname;
22-
rev = "v${version}";
20+
repo = finalAttrs.pname;
21+
rev = "v${finalAttrs.version}";
2322
hash = "sha256-3t2e3WfH/ohkdGWlfV3t9oHJ1Q6YM6nSLOgmzgJEkls=";
2423
};
2524

26-
deps = stdenv.mkDerivation {
27-
name = "${pname}-deps";
28-
inherit src;
29-
30-
nativeBuildInputs = [ gradle jdk perl ];
31-
32-
buildPhase = ''
33-
export GRADLE_USER_HOME=$(mktemp -d)
34-
export JADX_VERSION=${version}
35-
gradle --no-daemon jar
36-
37-
# Apparently, Gradle won't cache the `compileOnlyApi` dependency
38-
# `org.jetbrains:annotations:22.0.0` which is defined in
39-
# `io.github.skylot:raung-common`. To make it available in the
40-
# output, we patch `build.gradle` and run Gradle again.
41-
substituteInPlace build.gradle \
42-
--replace 'org.jetbrains:annotations:23.0.0' 'org.jetbrains:annotations:22.0.0'
43-
gradle --no-daemon jar
44-
'';
45-
46-
# Mavenize dependency paths
47-
# e.g. org.codehaus.groovy/groovy/2.4.0/{hash}/groovy-2.4.0.jar -> org/codehaus/groovy/groovy/2.4.0/groovy-2.4.0.jar
48-
installPhase = ''
49-
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
50-
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
51-
| sh
52-
53-
# Work around okio-2.10.0 bug, fixed in 3.0. Remove "-jvm" from filename.
54-
# https://github.com/square/okio/issues/954
55-
mv $out/com/squareup/okio/okio/2.10.0/okio{-jvm,}-2.10.0.jar
56-
'';
57-
58-
outputHashMode = "recursive";
59-
outputHash = "sha256-QebPRmfLtXy4ZlyKeGC5XNzhMTsYI0X36My+nTFvQpM=";
60-
};
61-
in stdenv.mkDerivation (finalAttrs: {
62-
inherit pname version src;
63-
6425
nativeBuildInputs = [ gradle jdk imagemagick makeWrapper copyDesktopItems ]
6526
++ lib.optionals stdenv.hostPlatform.isDarwin [ desktopToDarwinBundle ];
6627

6728
# Otherwise, Gradle fails with `java.net.SocketException: Operation not permitted`
6829
__darwinAllowLocalNetworking = true;
6930

70-
buildPhase = ''
71-
# The installDist Gradle build phase tries to copy some dependency .jar
72-
# files multiple times into the build directory. This ends up failing when
73-
# the dependencies are read directly from the Nix store since they are not
74-
# marked as chmod +w. To work around this, get a local copy of the
75-
# dependency store, and give write permissions.
76-
depsDir=$(mktemp -d)
77-
cp -R ${deps}/* $depsDir
78-
chmod -R u+w $depsDir
79-
80-
gradleInit=$(mktemp)
81-
cat >$gradleInit <<EOF
82-
gradle.projectsLoaded {
83-
rootProject.allprojects {
84-
buildscript {
85-
repositories {
86-
clear()
87-
maven { url '$depsDir' }
88-
}
89-
}
90-
repositories {
91-
clear()
92-
maven { url '$depsDir' }
93-
}
94-
}
95-
}
31+
mitmCache = gradle.fetchDeps {
32+
inherit (finalAttrs) pname;
33+
data = ./deps.json;
34+
};
9635

97-
settingsEvaluated { settings ->
98-
settings.pluginManagement {
99-
repositories {
100-
maven { url '$depsDir' }
101-
}
102-
}
103-
}
104-
EOF
36+
preBuild = "export JADX_VERSION=${finalAttrs.version}";
10537

106-
export GRADLE_USER_HOME=$(mktemp -d)
107-
export JADX_VERSION=${version}
108-
gradle --offline --no-daemon --info --init-script $gradleInit pack
109-
'';
38+
gradleBuildTask = "pack";
11039

11140
installPhase = ''
11241
runHook preInstall

0 commit comments

Comments
 (0)