daemon: Make libbz2 an optional dependency.

* config-daemon.ac: Don't bail out when libbz2 is missing.  Define
'HAVE_LIBBZ2' Automake conditional.
* nix/libstore/build.cc: Wrap relevant bits in '#if HAVE_BZLIB_H'.
* nix/libstore/globals.cc (Settings::Settings): 'logCompression'
defaults to COMPRESSION_GZIP when HAVE_BZLIB_H is false.
* nix/libstore/globals.hh (CompressionType): Make 'COMPRESSION_BZIP2'
conditional on HAVE_BZLIB_H.
* nix/local.mk (guix_register_LDADD, guix_daemon_LDADD): Add -lbz2 only
when HAVE_LIBBZ2.
* nix/nix-daemon/guix-daemon.cc (parse_opt): Ignore "bzip2" when not
HAVE_BZLIB_H.
This commit is contained in:
Ludovic Courtès 2018-01-05 17:48:23 +01:00
parent 29a6866886
commit f997137d0e
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
6 changed files with 40 additions and 10 deletions

View File

@ -24,11 +24,12 @@ if test "x$guix_build_daemon" = "xyes"; then
AC_CHECK_HEADERS([zlib.h], [true], AC_CHECK_HEADERS([zlib.h], [true],
[AC_MSG_ERROR([Guix requires zlib. See http://www.zlib.net/.])]) [AC_MSG_ERROR([Guix requires zlib. See http://www.zlib.net/.])])
dnl Look for libbz2, a required dependency. dnl Look for libbz2, an optional dependency.
AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [true], AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [HAVE_LIBBZ2=yes], [HAVE_LIBBZ2=no])
[AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) if test "x$HAVE_LIBBZ2" = xyes; then
AC_CHECK_HEADERS([bzlib.h], [true], AC_CHECK_HEADERS([bzlib.h])
[AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) HAVE_LIBBZ2="$ac_cv_header_bzlib_h"
fi
dnl Look for SQLite, a required dependency. dnl Look for SQLite, a required dependency.
PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19]) PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19])
@ -169,6 +170,7 @@ if test "x$guix_build_daemon" = "xyes"; then
[chmod +x nix/scripts/offload]) [chmod +x nix/scripts/offload])
fi fi
AM_CONDITIONAL([HAVE_LIBBZ2], [test "x$HAVE_LIBBZ2" = "xyes"])
AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"]) AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"])
AM_CONDITIONAL([BUILD_DAEMON_OFFLOAD], \ AM_CONDITIONAL([BUILD_DAEMON_OFFLOAD], \
[test "x$guix_build_daemon" = "xyes" \ [test "x$guix_build_daemon" = "xyes" \

View File

@ -32,7 +32,10 @@
#include <grp.h> #include <grp.h>
#include <zlib.h> #include <zlib.h>
#include <bzlib.h>
#if HAVE_BZLIB_H
# include <bzlib.h>
#endif
/* Includes required for chroot support. */ /* Includes required for chroot support. */
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
@ -746,7 +749,9 @@ private:
/* File descriptor for the log file. */ /* File descriptor for the log file. */
FILE * fLogFile; FILE * fLogFile;
gzFile gzLogFile; gzFile gzLogFile;
#if HAVE_BZLIB_H
BZFILE * bzLogFile; BZFILE * bzLogFile;
#endif
AutoCloseFD fdLogFile; AutoCloseFD fdLogFile;
/* Number of bytes received from the builder's stdout/stderr. */ /* Number of bytes received from the builder's stdout/stderr. */
@ -895,7 +900,9 @@ DerivationGoal::DerivationGoal(const Path & drvPath, const StringSet & wantedOut
, retrySubstitution(false) , retrySubstitution(false)
, fLogFile(0) , fLogFile(0)
, gzLogFile(0) , gzLogFile(0)
#if HAVE_BZLIB_H
, bzLogFile(0) , bzLogFile(0)
#endif
, useChroot(false) , useChroot(false)
, buildMode(buildMode) , buildMode(buildMode)
{ {
@ -2620,6 +2627,7 @@ Path DerivationGoal::openLogFile()
return logFileName; return logFileName;
} }
#if HAVE_BZLIB_H
case COMPRESSION_BZIP2: { case COMPRESSION_BZIP2: {
Path logFileName = (format("%1%/%2%.bz2") % dir % string(baseName, 2)).str(); Path logFileName = (format("%1%/%2%.bz2") % dir % string(baseName, 2)).str();
AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
@ -2635,6 +2643,7 @@ Path DerivationGoal::openLogFile()
return logFileName; return logFileName;
} }
#endif
case COMPRESSION_NONE: { case COMPRESSION_NONE: {
Path logFileName = (format("%1%/%2%") % dir % string(baseName, 2)).str(); Path logFileName = (format("%1%/%2%") % dir % string(baseName, 2)).str();
@ -2657,12 +2666,14 @@ void DerivationGoal::closeLogFile()
gzLogFile = NULL; gzLogFile = NULL;
if (err != Z_OK) throw Error(format("cannot close compressed log file (gzip error = %1%)") % err); if (err != Z_OK) throw Error(format("cannot close compressed log file (gzip error = %1%)") % err);
} }
#if HAVE_BZLIB_H
else if (bzLogFile) { else if (bzLogFile) {
int err; int err;
BZ2_bzWriteClose(&err, bzLogFile, 0, 0, 0); BZ2_bzWriteClose(&err, bzLogFile, 0, 0, 0);
bzLogFile = 0; bzLogFile = 0;
if (err != BZ_OK) throw Error(format("cannot close compressed log file (BZip2 error = %1%)") % err); if (err != BZ_OK) throw Error(format("cannot close compressed log file (BZip2 error = %1%)") % err);
} }
#endif
if (fLogFile) { if (fLogFile) {
fclose(fLogFile); fclose(fLogFile);
@ -2732,10 +2743,12 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
count = gzwrite(gzLogFile, data.data(), data.size()); count = gzwrite(gzLogFile, data.data(), data.size());
if (count == 0) throw Error(format("cannot write to compressed log file (gzip error = %1%)") % gzerror(gzLogFile, &err)); if (count == 0) throw Error(format("cannot write to compressed log file (gzip error = %1%)") % gzerror(gzLogFile, &err));
} }
#if HAVE_BZLIB_H
} else if (bzLogFile) { } else if (bzLogFile) {
int err; int err;
BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size()); BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size());
if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err); if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err);
#endif
} else if (fdLogFile != -1) } else if (fdLogFile != -1)
writeFull(fdLogFile, data); writeFull(fdLogFile, data);
} }

View File

@ -45,7 +45,11 @@ Settings::Settings()
useSshSubstituter = false; useSshSubstituter = false;
impersonateLinux26 = false; impersonateLinux26 = false;
keepLog = true; keepLog = true;
#if HAVE_BZLIB_H
logCompression = COMPRESSION_BZIP2; logCompression = COMPRESSION_BZIP2;
#else
logCompression = COMPRESSION_GZIP;
#endif
maxLogSize = 0; maxLogSize = 0;
cacheFailure = false; cacheFailure = false;
pollInterval = 5; pollInterval = 5;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "config.h"
#include "types.hh" #include "types.hh"
#include <map> #include <map>
@ -11,8 +12,10 @@ namespace nix {
enum CompressionType enum CompressionType
{ {
COMPRESSION_NONE = 0, COMPRESSION_NONE = 0,
COMPRESSION_GZIP = 1, COMPRESSION_GZIP = 1
COMPRESSION_BZIP2 = 2 #if HAVE_BZLIB_H
, COMPRESSION_BZIP2 = 2
#endif
}; };
struct Settings { struct Settings {

View File

@ -132,7 +132,7 @@ guix_daemon_CPPFLAGS = \
-I$(top_srcdir)/%D%/libstore -I$(top_srcdir)/%D%/libstore
guix_daemon_LDADD = \ guix_daemon_LDADD = \
libstore.a libutil.a libformat.a -lz -lbz2 \ libstore.a libutil.a libformat.a -lz \
$(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS)
guix_daemon_headers = \ guix_daemon_headers = \
@ -149,9 +149,15 @@ guix_register_CPPFLAGS = \
# XXX: Should we start using shared libs? # XXX: Should we start using shared libs?
guix_register_LDADD = \ guix_register_LDADD = \
libstore.a libutil.a libformat.a -lz -lbz2 \ libstore.a libutil.a libformat.a -lz \
$(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS)
if HAVE_LIBBZ2
guix_daemon_LDADD += -lbz2
guix_register_LDADD += -lbz2
endif HAVE_LIBBZ2
noinst_HEADERS = \ noinst_HEADERS = \
$(libformat_headers) $(libutil_headers) $(libstore_headers) \ $(libformat_headers) $(libutil_headers) $(libstore_headers) \

View File

@ -206,8 +206,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
settings.logCompression = COMPRESSION_NONE; settings.logCompression = COMPRESSION_NONE;
else if (strcmp (arg, "gzip") == 0) else if (strcmp (arg, "gzip") == 0)
settings.logCompression = COMPRESSION_GZIP; settings.logCompression = COMPRESSION_GZIP;
#if HAVE_BZLIB_H
else if (strcmp (arg, "bzip2") == 0) else if (strcmp (arg, "bzip2") == 0)
settings.logCompression = COMPRESSION_BZIP2; settings.logCompression = COMPRESSION_BZIP2;
#endif
else else
{ {
fprintf (stderr, _("error: %s: unknown compression type\n"), arg); fprintf (stderr, _("error: %s: unknown compression type\n"), arg);