Skip to content

Commit

Permalink
xar: 1.6.1 -> 498
Browse files Browse the repository at this point in the history
This change switches the xar package from unmaintained fork of the
original project to the Apple Open Source tarball (with patch set from
Gentoo to make the package compatible with non-Darwin platforms).
  • Loading branch information
tie committed Jul 27, 2024
1 parent 02cbd68 commit aecc53b
Show file tree
Hide file tree
Showing 16 changed files with 2,006 additions and 74 deletions.
201 changes: 168 additions & 33 deletions pkgs/tools/compression/xar/default.nix
Original file line number Diff line number Diff line change
@@ -1,49 +1,184 @@
{ lib, stdenv, fetchurl, pkg-config, libxml2, xz, openssl, zlib, bzip2, fts, autoreconfHook }:
{
lib,
stdenv,
fetchurl,
applyPatches,

stdenv.mkDerivation rec {
version = "1.6.1";
autoreconfHook,

# Required dependencies.
zlib,
libxml2,

# Optional dependencies.
withExt2 ? lib.meta.availableOn stdenv.hostPlatform e2fsprogs,
e2fsprogs,
withAcl ? lib.meta.availableOn stdenv.hostPlatform acl,
acl,
withBzip2 ? true,
bzip2,
withLzma ? true,
xz, # lzma

# Platform-specific dependencies.
musl-fts,
openssl,
darwin, # CommonCrypto

gitUpdater,

# for tests
xar,
testers,
python3,
libxslt, # xsltproc
runCommand,
makeWrapper,
buildPackages,
}:
let
pname = "xar";
version = "498";

src = fetchurl {
url = "https://github.com/downloads/mackyle/xar/${pname}-${version}.tar.gz";
sha256 = "0ghmsbs6xwg1092v7pjcibmk5wkyifwxw6ygp08gfz25d2chhipf";
# Extended POSIX ACLs are not supported in Nix sandbox. For some reason, xar
# prints that it ignored the error if it can’t set ACLs, but then exits with
# non-zero code. As a workaround, use xar without ACL support for tests. For
# manual tests, we expose script via xar.passthru.manualTest attribute.
xarForTests = buildPackages.xar.override { withAcl = false; };

pythonForTests = py: py.withPackages (p: [ p.xattr ]);

src = applyPatches {
name = "source";
src = fetchurl {
url = "https://opensource.apple.com/tarballs/xar/xar-${version}.tar.gz";
hash = "sha256-nO5PgLls9ZLMxUWk/dUeTaSlvTtHNJAWN9Z7BD7/PHU=";
};
patches = map (f: ./patches/${f}) (builtins.attrNames (builtins.readDir ./patches));
};
in
stdenv.mkDerivation {
inherit pname version src;

nativeBuildInputs = [ autoreconfHook pkg-config ];
buildInputs = [ libxml2 xz openssl zlib bzip2 fts ];
sourceRoot = "source/xar";

patches = [
./0001-Add-useless-descriptions-to-AC_DEFINE.patch
./0002-Use-pkg-config-for-libxml2.patch
outputs = [
"out"
"lib"
"dev"
];

postPatch = ''
substituteInPlace configure.ac \
--replace 'OpenSSL_add_all_ciphers' 'OPENSSL_init_crypto' \
--replace 'openssl/evp.h' 'openssl/crypto.h'
'';
separateDebugInfo = true;

configureFlags = lib.optional (fts != null) "LDFLAGS=-lfts";
strictDeps = true;

meta = {
homepage = "https://mackyle.github.io/xar/";
description = "Extensible Archiver";

longDescription =
'' The XAR project aims to provide an easily extensible archive format.
Important design decisions include an easily extensible XML table of
contents for random access to archived files, storing the toc at the
beginning of the archive to allow for efficient handling of streamed
archives, the ability to handle files of arbitrarily large sizes, the
ability to choose independent encodings for individual files in the
archive, the ability to store checksums for individual files in both
compressed and uncompressed form, and the ability to query the table
of content's rich meta-data.
nativeBuildInputs = [ autoreconfHook ];

# For some reason libxml2 package headers are in subdirectory and thus aren’t
# picked up by stdenv’s C compiler wrapper (see ccWrapper_addCVars). This
# doesn’t really belong here and either should be part of libxml2 package or
# libxml2 in Nixpkgs can just fix their header paths.
env.NIX_CFLAGS_COMPILE = "-isystem ${libxml2.dev}/include/libxml2";

buildInputs =
let
crypto = if stdenv.hostPlatform.isDarwin then darwin.CommonCrypto else openssl;
in
[
crypto
zlib
libxml2
]
++ lib.optionals withExt2 [ e2fsprogs ]
++ lib.optionals withAcl [ acl ]
++ lib.optionals withBzip2 [ bzip2 ]
++ lib.optionals withLzma [ xz ]
++ lib.optionals stdenv.hostPlatform.isMusl [ musl-fts ];

passthru.tests = {
version = testers.testVersion {
package = xar;
version = "1.8dev";
};

# Check that xar builds without optional dependencies.
minimal = xar.override {
withExt2 = false;
withAcl = false;
withBzip2 = false;
withLzma = false;
};

integrationTest =
let
python = pythonForTests python3.pythonOnBuildForHost;
in
runCommand "xar-tests-integration-test"
{
inherit src;
python = python.executable;
nativeBuildInputs = [
xarForTests
python
libxslt
];
}
''
"$python" -- "$src"/xar/test/run-all.py
touch -- "$out"
'';

smokeTest =
runCommand "xar-tests-smoke-test"
{
inherit src;
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ xarForTests ];
}
''
cp -- "$src"/xar/test/buffer.c buffer.c
"$CC_FOR_BUILD" -lxar -o buffer buffer.c
./buffer buffer.c
xar -x -f test.xar
diff buffer.c mydir/secondfile
touch -- "$out"
'';
};

# The difference between manualTest and tests.integrationTests is that the
# latter uses a trimmed-down xar version that runs in Nix sandbox. For
# convenience, we expose manualTest to allow testing xar manually. In addition
# to that, unlike passthru.tests, manualTest runs on the host platform.
#
# Run with
# $ manualTest=$(nix build --no-link --print-out-paths --file . xar.manualTest) && "$manualTest"
# Ensure that all tests are PASSED and none are FAILED or SKIPPED.
passthru.manualTest =
let
python = pythonForTests python3;
in
runCommand "xar-manual-test"
{
inherit src xar libxslt;
python = python.interpreter;
nativeBuildInputs = [ makeWrapper ];
}
''
makeWrapper "$python" "$out" \
--prefix PATH : "$xar/bin" \
--suffix PATH : "$libxslt/bin" \
--add-flags -- \
--add-flags "$src/xar/test/run-all.py"
'';

license = lib.licenses.bsd3;
passthru.updateScript = gitUpdater { };

meta = {
homepage = "https://github.com/apple-oss-distributions/xar";
description = "An easily extensible archive format";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ copumpkin ];
platforms = lib.platforms.all;
platforms = lib.platforms.all;
mainProgram = "xar";
};
}
Loading

0 comments on commit aecc53b

Please sign in to comment.