Merge pull request #208380 from hadilq/androidenv/support-deplying-multiple-packages-in-one-derivation

androidenv: Support deploying multiple packages in one derivation
This commit is contained in:
Artturi 2023-01-11 05:57:24 +02:00 committed by GitHub
commit a6c9e51059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 49 deletions

View file

@ -112,8 +112,19 @@ let
] ++ extraLicenses);
in
rec {
deployAndroidPackage = callPackage ./deploy-androidpackage.nix {
deployAndroidPackages = callPackage ./deploy-androidpackages.nix {
inherit stdenv lib mkLicenses;
};
deployAndroidPackage = ({package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
let
extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ];
in
deployAndroidPackages ({
inherit os buildInputs meta;
packages = [ package ];
patchesInstructions = { "${package.name}" = patchInstructions; };
} // extraParams
));
platform-tools = callPackage ./platform-tools.nix {
inherit deployAndroidPackage;

View file

@ -1,46 +0,0 @@
{stdenv, unzip}:
{package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
let
extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ];
in
stdenv.mkDerivation ({
pname = package.name;
version = package.revision;
src = if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all;
buildInputs = [ unzip ] ++ buildInputs;
preferLocalBuild = true;
# Most Android Zip packages have a root folder, but some don't. We unpack
# the zip file in a folder and we try to discover whether it has a single root
# folder. If this is the case, we adjust the current working folder.
unpackPhase = ''
mkdir extractedzip
cd extractedzip
unpackFile "$src"
if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]
then
cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
fi
sourceRoot="$PWD"
'';
installPhase = ''
packageBaseDir=$out/libexec/android-sdk/${package.path}
mkdir -p $packageBaseDir
cd $packageBaseDir
cp -a $sourceRoot/* .
${patchInstructions}
'';
# We never attempt to strip. This is not required since we're doing binary
# deployments. Moreover, some executables that have been patched with patchelf
# may not work any longer after they have been stripped.
dontStrip = true;
dontPatchELF = true;
dontAutoPatchelf = true;
meta = {
description = package.displayName;
} // meta;
} // extraParams)

View file

@ -0,0 +1,57 @@
{stdenv, lib, unzip, mkLicenses}:
{packages, os ? null, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args:
let
extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ];
sortedPackages = builtins.sort (x: y: builtins.lessThan x.name y.name) packages;
in
stdenv.mkDerivation ({
inherit buildInputs;
pname = lib.concatMapStringsSep "-" (package: package.name) sortedPackages;
version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages;
src = map (package:
if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all
) packages;
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
preferLocalBuild = true;
unpackPhase = ''
buildDir=$PWD
i=0
for srcArchive in $src; do
extractedZip="extractedzip-$i"
i=$((i+1))
cd "$buildDir"
mkdir "$extractedZip"
cd "$extractedZip"
unpackFile "$srcArchive"
done
'';
installPhase = lib.concatStrings (lib.imap0 (i: package: ''
cd $buildDir/extractedzip-${toString i}
# Most Android Zip packages have a root folder, but some don't. We unpack
# the zip file in a folder and we try to discover whether it has a single root
# folder. If this is the case, we adjust the current working folder.
if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ]; then
cd "$(find . -mindepth 1 -maxdepth 1 -type d)"
fi
extractedZip="$PWD"
packageBaseDir=$out/libexec/android-sdk/${package.path}
mkdir -p $packageBaseDir
cd $packageBaseDir
cp -a $extractedZip/* .
${patchesInstructions.${package.name}}
'') packages);
# Some executables that have been patched with patchelf may not work any longer after they have been stripped.
dontStrip = true;
dontPatchELF = true;
dontAutoPatchelf = true;
meta = {
description = lib.concatMapStringsSep "\n" (package: package.displayName) packages;
} // meta;
} // extraParams)

View file

@ -7,13 +7,13 @@
sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy";
}),
pkgs ? import nixpkgsSource {
config.allowUnfree = true;
config.allowUnfree = true;
},
*/
# If you want to use the in-tree version of nixpkgs:
pkgs ? import ../../../../.. {
config.allowUnfree = true;
config.allowUnfree = true;
},
config ? pkgs.config