summaryrefslogtreecommitdiff
path: root/pkgs/development/mobile/androidenv/tools.nix
blob: efcbe8bdd6a1ae21397faf812095a26f4ef0d229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
  deployAndroidPackage,
  lib,
  stdenv,
  package,
  os,
  arch,
  autoPatchelfHook,
  makeWrapper,
  pkgs,
  pkgsi686Linux,
  postInstall,
  meta,
}:

deployAndroidPackage {
  name = "androidsdk-tools";
  inherit package os arch;
  nativeBuildInputs = [ makeWrapper ] ++ lib.optionals (os == "linux") [ autoPatchelfHook ];
  buildInputs = lib.optionals (os == "linux") (
    (with pkgs; [
      glibc
      freetype
      fontconfig
      fontconfig.lib
      stdenv.cc.cc.libgcc or null # fix for https://github.com/NixOS/nixpkgs/issues/226357
      libx11
      libxrender
      libxext
    ])
    ++ lib.optionals (os == "linux" && stdenv.hostPlatform.isx86_64) (
      with pkgsi686Linux;
      [
        glibc
        libx11
        libxrender
        libxext
        fontconfig.lib
        freetype
        zlib
      ]
    )
  );

  patchInstructions = ''
    ${lib.optionalString (os == "linux") ''
      # Auto patch all binaries
      autoPatchelf .
    ''}

    # Wrap all scripts that require JAVA_HOME
    for i in bin; do
      find $i -maxdepth 1 -type f -executable | while read program; do
        if grep -q "JAVA_HOME" $program; then
          wrapProgram $PWD/$program --prefix PATH : ${pkgs.jdk8}/bin
        fi
      done
    done

    # Wrap monitor script
    wrapProgram $PWD/monitor \
      --prefix PATH : ${pkgs.jdk8}/bin \
      --prefix LD_LIBRARY_PATH : ${
        lib.makeLibraryPath (
          with pkgs;
          [
            libx11
            libxtst
          ]
        )
      }

    # Patch all script shebangs
    patchShebangs .

    cd $out/libexec/android-sdk
    ${postInstall}
  '';

  inherit meta;
}