about summary refs log tree commit diff
path: root/pkgs/games/build-support
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-02-22 05:02:03 +0100
committeraszlig <aszlig@nix.build>2018-02-22 05:02:03 +0100
commit8c52f23b831949deb708de4c463fd1f6251e6728 (patch)
tree8f4a5e97383ad5750971fb2ae6eb448493f12a89 /pkgs/games/build-support
parent77a0f47d06f3d21b78c7f34a129bc3f75d69fbf7 (diff)
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 <aszlig@nix.build>
Diffstat (limited to 'pkgs/games/build-support')
-rw-r--r--pkgs/games/build-support/build-game.nix11
1 files 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