diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2018-01-05 17:48:23 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2018-01-07 23:47:22 +0100 |
| commit | f997137d0e2eba27bb1e2b282ee19ea474c41e12 (patch) | |
| tree | 3a188ef54d7157cabc5c0b432e92b3bcabad03fd | |
| parent | 29a686688674dc875775305312513405fa396a06 (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.
| -rw-r--r-- | config-daemon.ac | 12 | ||||
| -rw-r--r-- | nix/libstore/build.cc | 15 | ||||
| -rw-r--r-- | nix/libstore/globals.cc | 4 | ||||
| -rw-r--r-- | nix/libstore/globals.hh | 7 | ||||
| -rw-r--r-- | nix/local.mk | 10 | ||||
| -rw-r--r-- | nix/nix-daemon/guix-daemon.cc | 2 |
6 files changed, 40 insertions, 10 deletions
diff --git a/config-daemon.ac b/config-daemon.ac index 59f6f2713ff..80d84cbdbcc 100644 --- a/config-daemon.ac +++ b/config-daemon.ac | |||
| @@ -24,11 +24,12 @@ if test "x$guix_build_daemon" = "xyes"; then | |||
| 24 | AC_CHECK_HEADERS([zlib.h], [true], | 24 | AC_CHECK_HEADERS([zlib.h], [true], |
| 25 | [AC_MSG_ERROR([Guix requires zlib. See http://www.zlib.net/.])]) | 25 | [AC_MSG_ERROR([Guix requires zlib. See http://www.zlib.net/.])]) |
| 26 | 26 | ||
| 27 | dnl Look for libbz2, a required dependency. | 27 | dnl Look for libbz2, an optional dependency. |
| 28 | AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [true], | 28 | AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [HAVE_LIBBZ2=yes], [HAVE_LIBBZ2=no]) |
| 29 | [AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) | 29 | if test "x$HAVE_LIBBZ2" = xyes; then |
| 30 | AC_CHECK_HEADERS([bzlib.h], [true], | 30 | AC_CHECK_HEADERS([bzlib.h]) |
| 31 | [AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) | 31 | HAVE_LIBBZ2="$ac_cv_header_bzlib_h" |
| 32 | fi | ||
| 32 | 33 | ||
| 33 | dnl Look for SQLite, a required dependency. | 34 | dnl Look for SQLite, a required dependency. |
| 34 | PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19]) | 35 | PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19]) |
| @@ -169,6 +170,7 @@ if test "x$guix_build_daemon" = "xyes"; then | |||
| 169 | [chmod +x nix/scripts/offload]) | 170 | [chmod +x nix/scripts/offload]) |
| 170 | fi | 171 | fi |
| 171 | 172 | ||
| 173 | AM_CONDITIONAL([HAVE_LIBBZ2], [test "x$HAVE_LIBBZ2" = "xyes"]) | ||
| 172 | AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"]) | 174 | AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"]) |
| 173 | AM_CONDITIONAL([BUILD_DAEMON_OFFLOAD], \ | 175 | AM_CONDITIONAL([BUILD_DAEMON_OFFLOAD], \ |
| 174 | [test "x$guix_build_daemon" = "xyes" \ | 176 | [test "x$guix_build_daemon" = "xyes" \ |
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 5bf3e3aacb4..275d6a5f7c0 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -32,7 +32,10 @@ | |||
| 32 | #include <grp.h> | 32 | #include <grp.h> |
| 33 | 33 | ||
| 34 | #include <zlib.h> | 34 | #include <zlib.h> |
| 35 | #include <bzlib.h> | 35 | |
| 36 | #if HAVE_BZLIB_H | ||
| 37 | # include <bzlib.h> | ||
| 38 | #endif | ||
| 36 | 39 | ||
| 37 | /* Includes required for chroot support. */ | 40 | /* Includes required for chroot support. */ |
| 38 | #if HAVE_SYS_PARAM_H | 41 | #if HAVE_SYS_PARAM_H |
| @@ -746,7 +749,9 @@ private: | |||
| 746 | /* File descriptor for the log file. */ | 749 | /* File descriptor for the log file. */ |
| 747 | FILE * fLogFile; | 750 | FILE * fLogFile; |
| 748 | gzFile gzLogFile; | 751 | gzFile gzLogFile; |
| 752 | #if HAVE_BZLIB_H | ||
| 749 | BZFILE * bzLogFile; | 753 | BZFILE * bzLogFile; |
| 754 | #endif | ||
| 750 | AutoCloseFD fdLogFile; | 755 | AutoCloseFD fdLogFile; |
| 751 | 756 | ||
| 752 | /* Number of bytes received from the builder's stdout/stderr. */ | 757 | /* Number of bytes received from the builder's stdout/stderr. */ |
| @@ -895,7 +900,9 @@ DerivationGoal::DerivationGoal(const Path & drvPath, const StringSet & wantedOut | |||
| 895 | , retrySubstitution(false) | 900 | , retrySubstitution(false) |
| 896 | , fLogFile(0) | 901 | , fLogFile(0) |
| 897 | , gzLogFile(0) | 902 | , gzLogFile(0) |
| 903 | #if HAVE_BZLIB_H | ||
| 898 | , bzLogFile(0) | 904 | , bzLogFile(0) |
| 905 | #endif | ||
| 899 | , useChroot(false) | 906 | , useChroot(false) |
| 900 | , buildMode(buildMode) | 907 | , buildMode(buildMode) |
| 901 | { | 908 | { |
| @@ -2620,6 +2627,7 @@ Path DerivationGoal::openLogFile() | |||
| 2620 | return logFileName; | 2627 | return logFileName; |
| 2621 | } | 2628 | } |
| 2622 | 2629 | ||
| 2630 | #if HAVE_BZLIB_H | ||
| 2623 | case COMPRESSION_BZIP2: { | 2631 | case COMPRESSION_BZIP2: { |
| 2624 | Path logFileName = (format("%1%/%2%.bz2") % dir % string(baseName, 2)).str(); | 2632 | Path logFileName = (format("%1%/%2%.bz2") % dir % string(baseName, 2)).str(); |
| 2625 | AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); | 2633 | AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666); |
| @@ -2635,6 +2643,7 @@ Path DerivationGoal::openLogFile() | |||
| 2635 | 2643 | ||
| 2636 | return logFileName; | 2644 | return logFileName; |
| 2637 | } | 2645 | } |
| 2646 | #endif | ||
| 2638 | 2647 | ||
| 2639 | case COMPRESSION_NONE: { | 2648 | case COMPRESSION_NONE: { |
| 2640 | Path logFileName = (format("%1%/%2%") % dir % string(baseName, 2)).str(); | 2649 | Path logFileName = (format("%1%/%2%") % dir % string(baseName, 2)).str(); |
| @@ -2657,12 +2666,14 @@ void DerivationGoal::closeLogFile() | |||
| 2657 | gzLogFile = NULL; | 2666 | gzLogFile = NULL; |
| 2658 | if (err != Z_OK) throw Error(format("cannot close compressed log file (gzip error = %1%)") % err); | 2667 | if (err != Z_OK) throw Error(format("cannot close compressed log file (gzip error = %1%)") % err); |
| 2659 | } | 2668 | } |
| 2669 | #if HAVE_BZLIB_H | ||
| 2660 | else if (bzLogFile) { | 2670 | else if (bzLogFile) { |
| 2661 | int err; | 2671 | int err; |
| 2662 | BZ2_bzWriteClose(&err, bzLogFile, 0, 0, 0); | 2672 | BZ2_bzWriteClose(&err, bzLogFile, 0, 0, 0); |
| 2663 | bzLogFile = 0; | 2673 | bzLogFile = 0; |
| 2664 | if (err != BZ_OK) throw Error(format("cannot close compressed log file (BZip2 error = %1%)") % err); | 2674 | if (err != BZ_OK) throw Error(format("cannot close compressed log file (BZip2 error = %1%)") % err); |
| 2665 | } | 2675 | } |
| 2676 | #endif | ||
| 2666 | 2677 | ||
| 2667 | if (fLogFile) { | 2678 | if (fLogFile) { |
| 2668 | fclose(fLogFile); | 2679 | fclose(fLogFile); |
| @@ -2732,10 +2743,12 @@ void DerivationGoal::handleChildOutput(int fd, const string & data) | |||
| 2732 | count = gzwrite(gzLogFile, data.data(), data.size()); | 2743 | count = gzwrite(gzLogFile, data.data(), data.size()); |
| 2733 | if (count == 0) throw Error(format("cannot write to compressed log file (gzip error = %1%)") % gzerror(gzLogFile, &err)); | 2744 | if (count == 0) throw Error(format("cannot write to compressed log file (gzip error = %1%)") % gzerror(gzLogFile, &err)); |
| 2734 | } | 2745 | } |
| 2746 | #if HAVE_BZLIB_H | ||
| 2735 | } else if (bzLogFile) { | 2747 | } else if (bzLogFile) { |
| 2736 | int err; | 2748 | int err; |
| 2737 | BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size()); | 2749 | BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size()); |
| 2738 | if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err); | 2750 | if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err); |
| 2751 | #endif | ||
| 2739 | } else if (fdLogFile != -1) | 2752 | } else if (fdLogFile != -1) |
| 2740 | writeFull(fdLogFile, data); | 2753 | writeFull(fdLogFile, data); |
| 2741 | } | 2754 | } |
diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc index 82d528dc98c..4ab6c3a0f9c 100644 --- a/nix/libstore/globals.cc +++ b/nix/libstore/globals.cc | |||
| @@ -45,7 +45,11 @@ Settings::Settings() | |||
| 45 | useSshSubstituter = false; | 45 | useSshSubstituter = false; |
| 46 | impersonateLinux26 = false; | 46 | impersonateLinux26 = false; |
| 47 | keepLog = true; | 47 | keepLog = true; |
| 48 | #if HAVE_BZLIB_H | ||
| 48 | logCompression = COMPRESSION_BZIP2; | 49 | logCompression = COMPRESSION_BZIP2; |
| 50 | #else | ||
| 51 | logCompression = COMPRESSION_GZIP; | ||
| 52 | #endif | ||
| 49 | maxLogSize = 0; | 53 | maxLogSize = 0; |
| 50 | cacheFailure = false; | 54 | cacheFailure = false; |
| 51 | pollInterval = 5; | 55 | pollInterval = 5; |
diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh index 81cf2f52d42..24399369599 100644 --- a/nix/libstore/globals.hh +++ b/nix/libstore/globals.hh | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #include "config.h" | ||
| 3 | #include "types.hh" | 4 | #include "types.hh" |
| 4 | 5 | ||
| 5 | #include <map> | 6 | #include <map> |
| @@ -11,8 +12,10 @@ namespace nix { | |||
| 11 | enum CompressionType | 12 | enum CompressionType |
| 12 | { | 13 | { |
| 13 | COMPRESSION_NONE = 0, | 14 | COMPRESSION_NONE = 0, |
| 14 | COMPRESSION_GZIP = 1, | 15 | COMPRESSION_GZIP = 1 |
| 15 | COMPRESSION_BZIP2 = 2 | 16 | #if HAVE_BZLIB_H |
| 17 | , COMPRESSION_BZIP2 = 2 | ||
| 18 | #endif | ||
| 16 | }; | 19 | }; |
| 17 | 20 | ||
| 18 | struct Settings { | 21 | struct Settings { |
diff --git a/nix/local.mk b/nix/local.mk index d802da61705..4452301c63b 100644 --- a/nix/local.mk +++ b/nix/local.mk | |||
| @@ -132,7 +132,7 @@ guix_daemon_CPPFLAGS = \ | |||
| 132 | -I$(top_srcdir)/%D%/libstore | 132 | -I$(top_srcdir)/%D%/libstore |
| 133 | 133 | ||
| 134 | guix_daemon_LDADD = \ | 134 | guix_daemon_LDADD = \ |
| 135 | libstore.a libutil.a libformat.a -lz -lbz2 \ | 135 | libstore.a libutil.a libformat.a -lz \ |
| 136 | $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) | 136 | $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) |
| 137 | 137 | ||
| 138 | guix_daemon_headers = \ | 138 | guix_daemon_headers = \ |
| @@ -149,9 +149,15 @@ guix_register_CPPFLAGS = \ | |||
| 149 | 149 | ||
| 150 | # XXX: Should we start using shared libs? | 150 | # XXX: Should we start using shared libs? |
| 151 | guix_register_LDADD = \ | 151 | guix_register_LDADD = \ |
| 152 | libstore.a libutil.a libformat.a -lz -lbz2 \ | 152 | libstore.a libutil.a libformat.a -lz \ |
| 153 | $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) | 153 | $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) |
| 154 | 154 | ||
| 155 | if HAVE_LIBBZ2 | ||
| 156 | |||
| 157 | guix_daemon_LDADD += -lbz2 | ||
| 158 | guix_register_LDADD += -lbz2 | ||
| 159 | |||
| 160 | endif HAVE_LIBBZ2 | ||
| 155 | 161 | ||
| 156 | noinst_HEADERS = \ | 162 | noinst_HEADERS = \ |
| 157 | $(libformat_headers) $(libutil_headers) $(libstore_headers) \ | 163 | $(libformat_headers) $(libutil_headers) $(libstore_headers) \ |
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index a1ef90dfdce..b71b100f6c0 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) | |||
| 206 | settings.logCompression = COMPRESSION_NONE; | 206 | settings.logCompression = COMPRESSION_NONE; |
| 207 | else if (strcmp (arg, "gzip") == 0) | 207 | else if (strcmp (arg, "gzip") == 0) |
| 208 | settings.logCompression = COMPRESSION_GZIP; | 208 | settings.logCompression = COMPRESSION_GZIP; |
| 209 | #if HAVE_BZLIB_H | ||
| 209 | else if (strcmp (arg, "bzip2") == 0) | 210 | else if (strcmp (arg, "bzip2") == 0) |
| 210 | settings.logCompression = COMPRESSION_BZIP2; | 211 | settings.logCompression = COMPRESSION_BZIP2; |
| 212 | #endif | ||
| 211 | else | 213 | else |
| 212 | { | 214 | { |
| 213 | fprintf (stderr, _("error: %s: unknown compression type\n"), arg); | 215 | fprintf (stderr, _("error: %s: unknown compression type\n"), arg); |
