Unverified Commit d36bbaca authored by Emily's avatar Emily Committed by GitHub
Browse files

dpkg: fix build on case-insensitive filesystems; add install check (#445168)

parents 45019987 b15eb848
Loading
Loading
Loading
Loading
+41 −19
Original line number Diff line number Diff line
@@ -14,17 +14,30 @@
  autoreconfHook,
  pkg-config,
  diffutils,
  versionCheckHook,
  glibc ? !stdenv.hostPlatform.isDarwin,
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "dpkg";
  version = "1.22.21";

  src = fetchgit {
    url = "https://git.launchpad.net/ubuntu/+source/dpkg";
    rev = "applied/${version}";
    hash = "sha256-UiXZfwvgsgyXR6olNzKelt/3Fgtp7KU8UbTRRkDl8wY=";
    tag = "applied/${finalAttrs.version}";
    leaveDotGit = true;
    # Fix filename conflict on case-insensitive filesystems
    postFetch = ''
      pushd $out
      git checkout HEAD -- scripts/t/Dpkg_BuildTree.t
      mv scripts/t/Dpkg_BuildTree.t scripts/t/Dpkg_BuildTreeC.t
      substituteInPlace scripts/Makefile.am --replace-fail t/Dpkg_BuildTree.t t/Dpkg_BuildTreeC.t
      substituteInPlace scripts/Makefile.in --replace-fail t/Dpkg_BuildTree.t t/Dpkg_BuildTreeC.t
      git checkout HEAD -- scripts/t/dpkg_buildtree.t
      rm -rf .git
      popd
    '';
    hash = "sha256-LK6nOPewjRyKyHdwJgmLILoZ6sEfJzRtC7pIeWz01lA=";
  };

  configureFlags = [
@@ -48,7 +61,7 @@ stdenv.mkDerivation rec {
    PATH=$TMPDIR:$PATH

    for i in $(find . -name Makefile.in); do
      substituteInPlace $i --replace "install-data-local:" "disabled:" ;
      substituteInPlace $i --replace-quiet "install-data-local:" "disabled:" ;
    done

    # Skip check broken when cross-compiling.
@@ -61,21 +74,26 @@ stdenv.mkDerivation rec {

    # Dpkg commands sometimes calls out to shell commands
    substituteInPlace lib/dpkg/dpkg.h \
       --replace '"dpkg-deb"' \"$out/bin/dpkg-deb\" \
       --replace '"dpkg-split"' \"$out/bin/dpkg-split\" \
       --replace '"dpkg-query"' \"$out/bin/dpkg-query\" \
       --replace '"dpkg-divert"' \"$out/bin/dpkg-divert\" \
       --replace '"dpkg-statoverride"' \"$out/bin/dpkg-statoverride\" \
       --replace '"dpkg-trigger"' \"$out/bin/dpkg-trigger\" \
       --replace '"dpkg"' \"$out/bin/dpkg\" \
       --replace '"debsig-verify"' \"$out/bin/debsig-verify\" \
       --replace '"rm"' \"${coreutils}/bin/rm\" \
       --replace '"cat"' \"${coreutils}/bin/cat\" \
       --replace '"diff"' \"${diffutils}/bin/diff\"
       --replace-fail '"dpkg-deb"' \"$out/bin/dpkg-deb\" \
       --replace-fail '"dpkg-split"' \"$out/bin/dpkg-split\" \
       --replace-fail '"dpkg-query"' \"$out/bin/dpkg-query\" \
       --replace-fail '"dpkg-divert"' \"$out/bin/dpkg-divert\" \
       --replace-fail '"dpkg-statoverride"' \"$out/bin/dpkg-statoverride\" \
       --replace-fail '"dpkg-trigger"' \"$out/bin/dpkg-trigger\" \
       --replace-fail '"dpkg"' \"$out/bin/dpkg\" \
       --replace-fail '"debsig-verify"' \"$out/bin/debsig-verify\" \
       --replace-fail '"rm"' \"${coreutils}/bin/rm\" \
       --replace-fail '"cat"' \"${coreutils}/bin/cat\" \
       --replace-fail '"diff"' \"${diffutils}/bin/diff\"
  ''
  + lib.optionalString stdenv.hostPlatform.isDarwin ''
    # realpath("/var/lib/dpkg", NULL) gives EPERM on sandboxed darwin instead of the expected ENOENT,
    # which makes some tests fail.
    sed -i '/opts normalize/a AT_SKIP_IF([true])' src/at/chdir.at
  ''
  + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
    substituteInPlace src/main/help.c \
       --replace '"ldconfig"' \"${glibc.bin}/bin/ldconfig\"
       --replace-fail '"ldconfig"' \"${glibc.bin}/bin/ldconfig\"
  '';

  buildInputs = [
@@ -96,7 +114,7 @@ stdenv.mkDerivation rec {
  postInstall = ''
    for i in $out/bin/*; do
      if head -n 1 $i | grep -q perl; then
        substituteInPlace $i --replace \
        substituteInPlace $i --replace-fail \
          "${perl}/bin/perl" "${perl}/bin/perl -I $out/${perl.libPrefix}"
      fi
    done
@@ -105,6 +123,10 @@ stdenv.mkDerivation rec {
    cp -r scripts/t/origins $out/etc/dpkg
  '';

  doInstallCheck = true;
  nativeInstallCheckInputs = [ versionCheckHook ];
  versionCheckProgramArg = "--version";

  setupHook = ./setup-hook.sh;

  meta = with lib; {
@@ -112,7 +134,7 @@ stdenv.mkDerivation rec {
    homepage = "https://wiki.debian.org/Teams/Dpkg";
    license = licenses.gpl2Plus;
    platforms = platforms.unix;
    broken = stdenv.hostPlatform.isDarwin;
    maintainers = with maintainers; [ siriobalmelli ];
    mainProgram = "dpkg";
  };
}
})