<commit_before>{ stdenv, stdenv_32bit, fetchurl, fetchzip, unzip, makeWrapper
, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons, sources
, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, libGLU_combined, alsaLib
, freetype, fontconfig, glib, gtk2, atk, file, jdk, coreutils, libpulseaudio, dbus
, zlib, glxinfo, xkeyboardconfig
, includeSources
, licenseAccepted
}:
{ platformVersions, abiVersions, useGoogleAPIs, buildToolsVersions ? [], useExtraSupportLibs ? false
, useGooglePlayServices ? false, useInstantApps ? false }:

if !licenseAccepted then throw ''
    You must accept the Android Software Development Kit License Agreement at
    https://developer.android.com/studio/terms
    by setting nixpkgs config option 'android_sdk.accept_license = true;'
  ''
else assert licenseAccepted;

let inherit (stdenv.lib) makeLibraryPath;

    googleRepository = let version = "gms_v9_rc41_wear_2_0_rc6";
      in fetchzip rec {
        url = "https://dl-ssl.google.com/android/repository/google_m2repository_${version}.zip";
        sha256 = "0k99xmynv0k62d301zx5jnjkddflr51i5lb02l9incg7m5cn8kzx";
      };

in

stdenv.mkDerivation rec {
  name = "android-sdk-${version}";
  version = "26.1.1";

  src = if (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
    then fetchurl {
      url = "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip";
      sha256 = "1yfy0qqxz1ixpsci1pizls1nrncmi8p16wcb9rimdn4q3mdfxzwj";
    }
    else if stdenv.hostPlatform.system == "x86_64-darwin" then fetchurl {
      url = "https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip";
      sha256 = "0gl5c30m40kx0vvrpbaa8cw8wq2vb89r14hgzb1df4qgpic97cpc";
    }
    else throw "platform not ${stdenv.hostPlatform.system} supported!";

  buildCommand = ''
    mkdir -p $out/libexec
    cd $out/libexec
    unpackFile $src
    cd tools

    for f in monitor bin/monkeyrunner bin/uiautomatorviewer
    do
        sed -i -e "s|/bin/ls|${coreutils}/bin/ls|" "$f"
    done

    ${stdenv.lib.optionalString (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
    ''
      # There are a number of native binaries. We must patch them to let them find the interpreter and libstdc++

      for i in mksdcard
      do
          patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
          patchelf --set-rpath ${stdenv_32bit.cc.cc.lib}/lib $i
      done

      # The following scripts used SWT and wants to dynamically load some GTK+ stuff.
      # Creating these wrappers ensure that they can be found:

      wrapProgram `pwd`/android \
        --prefix PATH : ${jdk}/bin \
        --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ glib gtk2 libXtst ]}

      wrapProgram `pwd`/bin/uiautomatorviewer \
        --prefix PATH : ${jdk}/bin \
        --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ glib gtk2 libXtst ]}

      # The emulators need additional libraries, which are dynamically loaded => let's wrap them

      ${stdenv.lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") ''
        for i in emulator emulator-check
        do
            wrapProgram `pwd`/$i \
              --prefix PATH : ${stdenv.lib.makeBinPath [ file glxinfo ]} \
              --suffix LD_LIBRARY_PATH : `pwd`/lib:${makeLibraryPath [ stdenv.cc.cc libX11 libxcb libXau libXdmcp libXext libGLU_combined alsaLib zlib libpulseaudio dbus.lib ]} \
              --suffix QT_XKB_CONFIG_ROOT : ${xkeyboardconfig}/share/X11/xkb
        done
      ''}
    ''}

    patchShebangs .

    ${if stdenv.hostPlatform.system == "i686-linux" then
      ''
        # The monitor requires some more patching

        cd lib/monitor-x86
        patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 monitor
        patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so

        wrapProgram `pwd`/monitor \
          --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk2 atk stdenv.cc.cc libXtst ]}

        cd ../..
      ''
      else if stdenv.hostPlatform.system == "x86_64-linux" then
      ''
        # The monitor requires some more patching
<commit_msg>androidsdk: fix monitor interpreter path<commit_after>{ stdenv, stdenv_32bit, fetchurl, fetchzip, unzip, makeWrapper
, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons, sources
, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, libGLU_combined, alsaLib
, freetype, fontconfig, glib, gtk2, atk, file, jdk, coreutils, libpulseaudio, dbus
, zlib, glxinfo, xkeyboardconfig
, includeSources
, licenseAccepted
}:
{ platformVersions, abiVersions, useGoogleAPIs, buildToolsVersions ? [], useExtraSupportLibs ? false
, useGooglePlayServices ? false, useInstantApps ? false }:

if !licenseAccepted then throw ''
    You must accept the Android Software Development Kit License Agreement at
    https://developer.android.com/studio/terms
    by setting nixpkgs config option 'android_sdk.accept_license = true;'
  ''
else assert licenseAccepted;

let inherit (stdenv.lib) makeLibraryPath;

    googleRepository = let version = "gms_v9_rc41_wear_2_0_rc6";
      in fetchzip rec {
        url = "https://dl-ssl.google.com/android/repository/google_m2repository_${version}.zip";
        sha256 = "0k99xmynv0k62d301zx5jnjkddflr51i5lb02l9incg7m5cn8kzx";
      };

in

stdenv.mkDerivation rec {
  name = "android-sdk-${version}";
  version = "26.1.1";

  src = if (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
    then fetchurl {
      url = "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip";
      sha256 = "1yfy0qqxz1ixpsci1pizls1nrncmi8p16wcb9rimdn4q3mdfxzwj";
    }
    else if stdenv.hostPlatform.system == "x86_64-darwin" then fetchurl {
      url = "https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip";
      sha256 = "0gl5c30m40kx0vvrpbaa8cw8wq2vb89r14hgzb1df4qgpic97cpc";
    }
    else throw "platform not ${stdenv.hostPlatform.system} supported!";

  buildCommand = ''
    mkdir -p $out/libexec
    cd $out/libexec
    unpackFile $src
    cd tools

    for f in monitor bin/monkeyrunner bin/uiautomatorviewer
    do
        sed -i -e "s|/bin/ls|${coreutils}/bin/ls|" "$f"
    done

    ${stdenv.lib.optionalString (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
    ''
      # There are a number of native binaries. We must patch them to let them find the interpreter and libstdc++

      for i in mksdcard
      do
          patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
          patchelf --set-rpath ${stdenv_32bit.cc.cc.lib}/lib $i
      done

      # The following scripts used SWT and wants to dynamically load some GTK+ stuff.
      # Creating these wrappers ensure that they can be found:

      wrapProgram `pwd`/android \
        --prefix PATH : ${jdk}/bin \
        --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ glib gtk2 libXtst ]}

      wrapProgram `pwd`/bin/uiautomatorviewer \
        --prefix PATH : ${jdk}/bin \
        --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ glib gtk2 libXtst ]}

      # The emulators need additional libraries, which are dynamically loaded => let's wrap them

      ${stdenv.lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") ''
        for i in emulator emulator-check
        do
            wrapProgram `pwd`/$i \
              --prefix PATH : ${stdenv.lib.makeBinPath [ file glxinfo ]} \
              --suffix LD_LIBRARY_PATH : `pwd`/lib:${makeLibraryPath [ stdenv.cc.cc libX11 libxcb libXau libXdmcp libXext libGLU_combined alsaLib zlib libpulseaudio dbus.lib ]} \
              --suffix QT_XKB_CONFIG_ROOT : ${xkeyboardconfig}/share/X11/xkb
        done
      ''}
    ''}

    patchShebangs .

    ${if stdenv.hostPlatform.system == "i686-linux" then
      ''
        # The monitor requires some more patching

        cd lib/monitor-x86
        patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 monitor
        patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so

        wrapProgram `pwd`/monitor \
          --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk2 atk stdenv.cc.cc libXtst ]}

        cd ../..
      ''
      else if stdenv.hostPlatform.system == "x86_64-linux" then
      ''
        # The monitor requires some more patching

{'fraction_non_alphanumeric': 0.11048885777622214, 'fraction_numerical': 0.031268230078170575, 'mean_word_length': 3.0760817879220164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3864381', 'n_tokens_mistral': 3151, 'n_tokens_neox': 2952, 'n_words': 650}