|
1 | 1 | { stdenv, lib, pkgs, fetchurl, writeShellScriptBin }:
|
2 | 2 |
|
3 | 3 | let
|
4 |
| - inherit (lib) |
5 |
| - removeSuffix optionalString splitString concatMapStrings |
6 |
| - attrByPath attrValues last makeOverridable importJSON; |
| 4 | + inherit (lib) concatStrings concatMapStrings mapAttrsToList makeOverridable; |
7 | 5 |
|
8 |
| - inherit (pkgs) aapt2; |
9 |
| - |
10 |
| - deps = importJSON ./deps.json; |
11 |
| - |
12 |
| - # some .jar files have an `-aot` suffix that doesn't work for .pom files |
13 |
| - getPOM = jarUrl: "${removeSuffix "-aot" jarUrl}.pom"; |
| 6 | + deps = lib.importJSON ./deps.json; |
14 | 7 |
|
15 | 8 | script = writeShellScriptBin "create-local-maven-repo" (''
|
16 | 9 | mkdir -p $out
|
17 | 10 | cd $out
|
18 | 11 | '' +
|
19 |
| - # TODO: Generalize this section to not repeat the same code. |
20 |
| - (concatMapStrings (dep: |
21 |
| - let |
22 |
| - url = "${dep.host}/${dep.path}"; |
23 |
| - pom = { |
24 |
| - sha1 = attrByPath [ "pom" "sha1" ] "" dep; |
25 |
| - sha256 = attrByPath [ "pom" "sha256" ] "" dep; |
26 |
| - }; |
27 |
| - pom-download = optionalString (pom.sha256 != "") ( |
28 |
| - fetchurl { url = getPOM url; inherit (pom) sha256; } |
29 |
| - ); |
30 |
| - jar = { |
31 |
| - sha1 = attrByPath [ "jar" "sha1" ] "" dep; |
32 |
| - sha256 = attrByPath [ "jar" "sha256" ] "" dep; |
33 |
| - }; |
34 |
| - jar-download = optionalString (jar.sha256 != "") ( |
35 |
| - fetchurl { url = "${url}.${dep.type}"; inherit (jar) sha256; } |
36 |
| - ); |
37 |
| - nodeps = { |
38 |
| - sha1 = attrByPath [ "nodeps" "sha1" ] "" dep; |
39 |
| - sha256 = attrByPath [ "nodeps" "sha256" ] "" dep; |
40 |
| - }; |
41 |
| - nodeps-download = optionalString (nodeps.sha256 != "") ( |
42 |
| - fetchurl { url = "${url}-nodeps.jar"; inherit (nodeps) sha256; } |
43 |
| - ); |
44 |
| - fileName = last (splitString "/" dep.path); |
45 |
| - directory = removeSuffix fileName dep.path; |
46 |
| - in |
47 |
| - '' |
48 |
| - mkdir -p ${directory} |
49 |
| -
|
50 |
| - ${optionalString (pom-download != "") '' |
51 |
| - ln -s "${pom-download}" "${getPOM dep.path}" |
52 |
| - ''} |
53 |
| - ${optionalString (pom.sha1 != "") '' |
54 |
| - echo "${pom.sha1}" > "${getPOM dep.path}.sha1" |
55 |
| - ''} |
56 |
| - ${optionalString (jar-download != "") '' |
57 |
| - ln -s "${jar-download}" "${dep.path}.${dep.type}" |
58 |
| - ''} |
59 |
| - ${optionalString (jar.sha1 != "") '' |
60 |
| - echo "${jar.sha1}" > "${dep.path}.${dep.type}.sha1" |
61 |
| - ''} |
62 |
| - ${optionalString (nodeps-download != "") '' |
63 |
| - ln -s "${nodeps-download}" "${dep.path}-nodeps.jar" |
64 |
| - ''} |
65 |
| - ${optionalString (nodeps.sha1 != "") '' |
66 |
| - echo "${nodeps.sha1}" > "${dep.path}.${dep.type}.sha1" |
67 |
| - ''} |
| 12 | + # For each dependency in deps.json. |
| 13 | + (concatMapStrings (dep: concatStrings |
| 14 | + # And for each file in the 'files' dict of given dependency. |
| 15 | + (mapAttrsToList (filename: hashes: let |
| 16 | + # Download given file(POM, JAR, nodeps JAR, or AAR). |
| 17 | + download = fetchurl { |
| 18 | + url = "${dep.repo}/${dep.path}/${filename}"; |
| 19 | + inherit (hashes) sha256; |
| 20 | + }; |
| 21 | + # And symlink it in the correct folder along with SHA1. |
| 22 | + in '' |
| 23 | + mkdir -p "${dep.path}" |
| 24 | + ln -s "${download}" "${dep.path}/${filename}" |
| 25 | + echo "${hashes.sha1}" > "${dep.path}/${filename}.sha1" |
68 | 26 | '')
|
69 |
| - deps)); |
| 27 | + dep.files) |
| 28 | + ) deps) |
| 29 | + ); |
70 | 30 |
|
71 | 31 | in makeOverridable stdenv.mkDerivation {
|
72 | 32 | name = "status-mobile-maven-deps";
|
73 |
| - buildInputs = [ aapt2 ]; |
| 33 | + |
| 34 | + buildInputs = [ pkgs.aapt2 ]; |
| 35 | + |
74 | 36 | phases = [ "buildPhase" "patchPhase" ];
|
75 | 37 | buildPhase = "${script}/bin/create-local-maven-repo";
|
76 |
| - # Patched AAPT2 |
| 38 | + # Replace AAPT2 package only with our patched version from overlay. |
77 | 39 | patchPhase = ''
|
78 |
| - aapt2_dir=$out/com/android/tools/build/aapt2/${aapt2.version} |
| 40 | + aapt2_dir=$out/com/android/tools/build/aapt2/${pkgs.aapt2.version} |
79 | 41 | mkdir -p $aapt2_dir
|
80 |
| - ln -sf ${aapt2}/* $aapt2_dir |
| 42 | + ln -sf ${pkgs.aapt2}/* $aapt2_dir |
81 | 43 | '';
|
82 | 44 | }
|
0 commit comments