Require libbrotli

This commit is contained in:
Eelco Dolstra 2018-08-06 11:48:35 +02:00
parent 4361a4331f
commit fa4def3d46
No known key found for this signature in database
GPG Key ID: 8170B4726D7198DE
5 changed files with 3 additions and 65 deletions

View File

@ -6,7 +6,6 @@ CXXFLAGS = @CXXFLAGS@
ENABLE_S3 = @ENABLE_S3@
HAVE_SODIUM = @HAVE_SODIUM@
HAVE_READLINE = @HAVE_READLINE@
HAVE_BROTLI = @HAVE_BROTLI@
HAVE_SECCOMP = @HAVE_SECCOMP@
LIBCURL_LIBS = @LIBCURL_LIBS@
OPENSSL_LIBS = @OPENSSL_LIBS@

View File

@ -179,12 +179,9 @@ AC_CHECK_LIB([lzma], [lzma_stream_encoder_mt],
[AC_DEFINE([HAVE_LZMA_MT], [1], [xz multithreaded compression support])])
# Look for libbrotli{enc,dec}, optional dependencies
PKG_CHECK_MODULES([LIBBROTLI], [libbrotlienc libbrotlidec],
[AC_DEFINE([HAVE_BROTLI], [1], [Whether to use libbrotli.])
CXXFLAGS="$LIBBROTLI_CFLAGS $CXXFLAGS"]
have_brotli=1], [have_brotli=])
AC_SUBST(HAVE_BROTLI, [$have_brotli])
# Look for libbrotli{enc,dec}.
PKG_CHECK_MODULES([LIBBROTLI], [libbrotlienc libbrotlidec], [CXXFLAGS="$LIBBROTLI_CFLAGS $CXXFLAGS"])
# Look for libseccomp, required for Linux sandboxing.
if test "$sys_name" = linux; then

View File

@ -8,10 +8,8 @@
#include <cstdio>
#include <cstring>
#if HAVE_BROTLI
#include <brotli/decode.h>
#include <brotli/encode.h>
#endif // HAVE_BROTLI
#include <iostream>
@ -132,12 +130,6 @@ static void decompressBzip2(Source & source, Sink & sink)
static void decompressBrotli(Source & source, Sink & sink)
{
#if !HAVE_BROTLI
RunOptions options(BROTLI, {"-d"});
options.standardIn = &source;
options.standardOut = &sink;
runProgram2(options);
#else
auto *s = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
if (!s)
throw CompressionError("unable to initialize brotli decoder");
@ -193,7 +185,6 @@ static void decompressBrotli(Source & source, Sink & sink)
if (ret == BROTLI_DECODER_RESULT_SUCCESS) return;
}
#endif // HAVE_BROTLI
}
ref<std::string> decompress(const std::string & method, const std::string & in)
@ -403,42 +394,6 @@ struct BzipSink : CompressionSink
}
};
struct LambdaCompressionSink : CompressionSink
{
Sink & nextSink;
std::string data;
using CompressFnTy = std::function<std::string(const std::string&)>;
CompressFnTy compressFn;
LambdaCompressionSink(Sink& nextSink, CompressFnTy compressFn)
: nextSink(nextSink)
, compressFn(std::move(compressFn))
{
};
void finish() override
{
flush();
nextSink(compressFn(data));
}
void write(const unsigned char * data, size_t len) override
{
checkInterrupt();
this->data.append((const char *) data, len);
}
};
struct BrotliCmdSink : LambdaCompressionSink
{
BrotliCmdSink(Sink& nextSink)
: LambdaCompressionSink(nextSink, [](const std::string& data) {
return runProgram(BROTLI, true, {}, data);
})
{
}
};
#if HAVE_BROTLI
struct BrotliSink : CompressionSink
{
Sink & nextSink;
@ -525,7 +480,6 @@ struct BrotliSink : CompressionSink
}
}
};
#endif // HAVE_BROTLI
ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & nextSink, const bool parallel)
{
@ -544,11 +498,7 @@ ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & next
else if (method == "bzip2")
return make_ref<BzipSink>(nextSink);
else if (method == "br")
#if HAVE_BROTLI
return make_ref<BrotliSink>(nextSink);
#else
return make_ref<BrotliCmdSink>(nextSink);
#endif
else
throw UnknownCompressionMethod(format("unknown compression method '%s'") % method);
}

View File

@ -1,10 +1,5 @@
source common.sh
# Only test if we found brotli libraries
# (CLI tool is likely unavailable if libraries are missing)
if [ -n "$HAVE_BROTLI" ]; then
clearStore
clearCache
@ -24,5 +19,3 @@ nix copy --from $cacheURI $outPath --no-check-sigs
HASH2=$(nix hash-path $outPath)
[[ $HASH = $HASH2 ]]
fi # HAVE_BROTLI

View File

@ -31,7 +31,6 @@ export xmllint="@xmllint@"
export SHELL="@bash@"
export PAGER=cat
export HAVE_SODIUM="@HAVE_SODIUM@"
export HAVE_BROTLI="@HAVE_BROTLI@"
export version=@PACKAGE_VERSION@
export system=@system@