summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/build.cc15
-rw-r--r--nix/libstore/globals.cc4
-rw-r--r--nix/libstore/globals.hh7
-rw-r--r--nix/local.mk10
-rw-r--r--nix/nix-daemon/guix-daemon.cc2
5 files changed, 33 insertions, 5 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 5bf3e3aacb..275d6a5f7c 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -32,7 +32,10 @@
#include <grp.h>
#include <zlib.h>
-#include <bzlib.h>
+
+#if HAVE_BZLIB_H
+# include <bzlib.h>
+#endif
/* Includes required for chroot support. */
#if HAVE_SYS_PARAM_H
@@ -746,7 +749,9 @@ private:
/* File descriptor for the log file. */
FILE * fLogFile;
gzFile gzLogFile;
+#if HAVE_BZLIB_H
BZFILE * bzLogFile;
+#endif
AutoCloseFD fdLogFile;
/* Number of bytes received from the builder's stdout/stderr. */
@@ -895,7 +900,9 @@ DerivationGoal::DerivationGoal(const Path & drvPath, const StringSet & wantedOut
, retrySubstitution(false)
, fLogFile(0)
, gzLogFile(0)
+#if HAVE_BZLIB_H
, bzLogFile(0)
+#endif
, useChroot(false)
, buildMode(buildMode)
{
@@ -2620,6 +2627,7 @@ Path DerivationGoal::openLogFile()
return logFileName;
}
+#if HAVE_BZLIB_H
case COMPRESSION_BZIP2: {
Path logFileName = (format("%1%/%2%.bz2") % dir % string(baseName, 2)).str();
AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
@@ -2635,6 +2643,7 @@ Path DerivationGoal::openLogFile()
return logFileName;
}
+#endif
case COMPRESSION_NONE: {
Path logFileName = (format("%1%/%2%") % dir % string(baseName, 2)).str();
@@ -2657,12 +2666,14 @@ void DerivationGoal::closeLogFile()
gzLogFile = NULL;
if (err != Z_OK) throw Error(format("cannot close compressed log file (gzip error = %1%)") % err);
}
+#if HAVE_BZLIB_H
else if (bzLogFile) {
int err;
BZ2_bzWriteClose(&err, bzLogFile, 0, 0, 0);
bzLogFile = 0;
if (err != BZ_OK) throw Error(format("cannot close compressed log file (BZip2 error = %1%)") % err);
}
+#endif
if (fLogFile) {
fclose(fLogFile);
@@ -2732,10 +2743,12 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
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 HAVE_BZLIB_H
} else if (bzLogFile) {
int err;
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);
+#endif
} else if (fdLogFile != -1)
writeFull(fdLogFile, data);
}
diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc
index 82d528dc98..4ab6c3a0f9 100644
--- a/nix/libstore/globals.cc
+++ b/nix/libstore/globals.cc
@@ -45,7 +45,11 @@ Settings::Settings()
useSshSubstituter = false;
impersonateLinux26 = false;
keepLog = true;
+#if HAVE_BZLIB_H
logCompression = COMPRESSION_BZIP2;
+#else
+ logCompression = COMPRESSION_GZIP;
+#endif
maxLogSize = 0;
cacheFailure = false;
pollInterval = 5;
diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh
index 81cf2f52d4..2439936959 100644
--- a/nix/libstore/globals.hh
+++ b/nix/libstore/globals.hh
@@ -1,5 +1,6 @@
#pragma once
+#include "config.h"
#include "types.hh"
#include <map>
@@ -11,8 +12,10 @@ namespace nix {
enum CompressionType
{
COMPRESSION_NONE = 0,
- COMPRESSION_GZIP = 1,
- COMPRESSION_BZIP2 = 2
+ COMPRESSION_GZIP = 1
+#if HAVE_BZLIB_H
+ , COMPRESSION_BZIP2 = 2
+#endif
};
struct Settings {
diff --git a/nix/local.mk b/nix/local.mk
index d802da6170..4452301c63 100644
--- a/nix/local.mk
+++ b/nix/local.mk
@@ -132,7 +132,7 @@ guix_daemon_CPPFLAGS = \
-I$(top_srcdir)/%D%/libstore
guix_daemon_LDADD = \
- libstore.a libutil.a libformat.a -lz -lbz2 \
+ libstore.a libutil.a libformat.a -lz \
$(SQLITE3_LIBS) $(LIBGCRYPT_LIBS)
guix_daemon_headers = \
@@ -149,9 +149,15 @@ guix_register_CPPFLAGS = \
# XXX: Should we start using shared libs?
guix_register_LDADD = \
- libstore.a libutil.a libformat.a -lz -lbz2 \
+ libstore.a libutil.a libformat.a -lz \
$(SQLITE3_LIBS) $(LIBGCRYPT_LIBS)
+if HAVE_LIBBZ2
+
+guix_daemon_LDADD += -lbz2
+guix_register_LDADD += -lbz2
+
+endif HAVE_LIBBZ2
noinst_HEADERS = \
$(libformat_headers) $(libutil_headers) $(libstore_headers) \
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index a1ef90dfdc..b71b100f6c 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -206,8 +206,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
settings.logCompression = COMPRESSION_NONE;
else if (strcmp (arg, "gzip") == 0)
settings.logCompression = COMPRESSION_GZIP;
+#if HAVE_BZLIB_H
else if (strcmp (arg, "bzip2") == 0)
settings.logCompression = COMPRESSION_BZIP2;
+#endif
else
{
fprintf (stderr, _("error: %s: unknown compression type\n"), arg);