From 8c52f23b831949deb708de4c463fd1f6251e6728 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 22 Feb 2018 05:02:03 +0100 Subject: build-game: Properly find sourceRoot So far we only checked for the source root by checking only one level of directories, so for example if the source code is unpacked into something like "a/b/c" and only "c" contains files, the previous implementation would set the source root to be "a". In addition we didn't do a check on the type of the contents, so for example if the archive contains only *one* file, that *file* itself would be set as the source root and the chdir to that will fail later. What we do now is recursively search through directories in order to find the last directory that does not contain *only* a subdirectory. Signed-off-by: aszlig --- pkgs/games/build-support/build-game.nix | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkgs/games/build-support/build-game.nix b/pkgs/games/build-support/build-game.nix index ea97d72a..b06537c5 100644 --- a/pkgs/games/build-support/build-game.nix +++ b/pkgs/games/build-support/build-game.nix @@ -30,12 +30,11 @@ buildSandbox (stdenv.mkDerivation ({ setSourceRoot = '' popd &> /dev/null '' + lib.optionalString (setSourceRoot == "") '' - unpackedFiles="$(find "$name" -mindepth 1 -maxdepth 1 -print)" - if [ $(echo "$unpackedFiles" | wc -l) -gt 1 ]; then - sourceRoot="$name" - else - sourceRoot="$name/''${unpackedFiles##*/}" - fi + sourceRoot="$(find "$name" -type d -exec sh -c ' + ndirs="$(find "$1" -mindepth 1 -maxdepth 1 -type d -printf x | wc -m)" + nelse="$(find "$1" -mindepth 1 -maxdepth 1 ! -type d -printf x | wc -m)" + ! [ "$ndirs" -eq 1 -a "$nelse" -eq 0 ] + ' -- {} \; -print -quit)" ''; runtimeDependencies = let -- cgit 1.4.1