summaryrefslogtreecommitdiff
path: root/nix/libstore/build.cc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-01-05 17:48:23 +0100
committerLudovic Courtès <ludo@gnu.org>2018-01-07 23:47:22 +0100
commitf997137d0e2eba27bb1e2b282ee19ea474c41e12 (patch)
tree3a188ef54d7157cabc5c0b432e92b3bcabad03fd /nix/libstore/build.cc
parent29a686688674dc875775305312513405fa396a06 (diff)
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.
Diffstat (limited to 'nix/libstore/build.cc')
-rw-r--r--nix/libstore/build.cc15
1 files changed, 14 insertions, 1 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);
}