diff options
-rw-r--r-- | src/libexpr/print.cc | 1 | ||||
-rw-r--r-- | src/libstore/build/derivation-goal.cc | 1 | ||||
-rw-r--r-- | src/libstore/derivations.cc | 1 | ||||
-rw-r--r-- | src/libutil/abstract-setting-to-json.hh | 2 | ||||
-rw-r--r-- | src/libutil/args.cc | 1 | ||||
-rw-r--r-- | src/libutil/experimental-features-json.hh | 29 | ||||
-rw-r--r-- | src/libutil/experimental-features.cc | 2 | ||||
-rw-r--r-- | src/libutil/experimental-features.hh | 22 | ||||
-rw-r--r-- | src/libutil/logging-json.hh | 23 | ||||
-rw-r--r-- | src/libutil/logging.hh | 12 | ||||
-rw-r--r-- | src/libutil/meson.build | 2 | ||||
-rw-r--r-- | src/nix/main.cc | 1 | ||||
-rw-r--r-- | tests/unit/libutil-support/tests/cli-literate-parser.cc | 1 |
13 files changed, 64 insertions, 34 deletions
diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc index 71ab1edbf..19ef6f8aa 100644 --- a/src/libexpr/print.cc +++ b/src/libexpr/print.cc @@ -1,4 +1,5 @@ #include <limits> +#include <span> #include <unordered_set> #include "print.hh" diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 481cb76e8..5e0795115 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -13,6 +13,7 @@ #include "topo-sort.hh" #include "callback.hh" #include "local-store.hh" // TODO remove, along with remaining downcasts +#include "logging-json.hh" #include <regex> #include <queue> diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index ab84255d3..fef680421 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -8,6 +8,7 @@ #include "common-protocol.hh" #include "common-protocol-impl.hh" #include "fs-accessor.hh" +#include "json-utils.hh" #include <boost/container/small_vector.hpp> #include <nlohmann/json.hpp> diff --git a/src/libutil/abstract-setting-to-json.hh b/src/libutil/abstract-setting-to-json.hh index eea687d8a..60807412a 100644 --- a/src/libutil/abstract-setting-to-json.hh +++ b/src/libutil/abstract-setting-to-json.hh @@ -4,6 +4,8 @@ #include <nlohmann/json.hpp> #include "config.hh" #include "json-utils.hh" +// Required for instances of to_json and from_json for ExperimentalFeature +#include "experimental-features-json.hh" namespace nix { template<typename T> diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 3e39b4d7c..520f50c30 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -2,6 +2,7 @@ #include "args/root.hh" #include "hash.hh" #include "json-utils.hh" +#include "experimental-features-json.hh" #include <glob.h> diff --git a/src/libutil/experimental-features-json.hh b/src/libutil/experimental-features-json.hh new file mode 100644 index 000000000..a4f999a93 --- /dev/null +++ b/src/libutil/experimental-features-json.hh @@ -0,0 +1,29 @@ +#pragma once +///@file + +#include "experimental-features.hh" +#include "json-utils.hh" + +namespace nix { + +/** + * Compute the documentation of all experimental features. + * + * See `doc/manual` for how this information is used. + */ +nlohmann::json documentExperimentalFeatures(); + +/** + * Semi-magic conversion to and from json. + * See the nlohmann/json readme for more details. + */ +void to_json(nlohmann::json &, const ExperimentalFeature &); +void from_json(const nlohmann::json &, ExperimentalFeature &); + +/** + * It is always rendered as a string + */ +template<> +struct json_avoids_null<ExperimentalFeature> : std::true_type {}; + +}; diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc index d1e1d7423..25beba467 100644 --- a/src/libutil/experimental-features.cc +++ b/src/libutil/experimental-features.cc @@ -1,4 +1,6 @@ #include "experimental-features.hh" +// Required for instances of to_json and from_json for ExperimentalFeature +#include "experimental-features-json.hh" #include "util.hh" #include "nlohmann/json.hpp" diff --git a/src/libutil/experimental-features.hh b/src/libutil/experimental-features.hh index cc841c0a6..38889e7bc 100644 --- a/src/libutil/experimental-features.hh +++ b/src/libutil/experimental-features.hh @@ -1,9 +1,7 @@ #pragma once ///@file -#include "comparator.hh" #include "error.hh" -#include "json-utils.hh" #include "types.hh" namespace nix { @@ -53,13 +51,6 @@ const std::optional<ExperimentalFeature> parseExperimentalFeature( std::string_view showExperimentalFeature(const ExperimentalFeature); /** - * Compute the documentation of all experimental features. - * - * See `doc/manual` for how this information is used. - */ -nlohmann::json documentExperimentalFeatures(); - -/** * Shorthand for `str << showExperimentalFeature(feature)`. */ std::ostream & operator<<( @@ -87,17 +78,4 @@ public: MissingExperimentalFeature(ExperimentalFeature missingFeature); }; -/** - * Semi-magic conversion to and from json. - * See the nlohmann/json readme for more details. - */ -void to_json(nlohmann::json &, const ExperimentalFeature &); -void from_json(const nlohmann::json &, ExperimentalFeature &); - -/** - * It is always rendered as a string - */ -template<> -struct json_avoids_null<ExperimentalFeature> : std::true_type {}; - } diff --git a/src/libutil/logging-json.hh b/src/libutil/logging-json.hh new file mode 100644 index 000000000..8263ad707 --- /dev/null +++ b/src/libutil/logging-json.hh @@ -0,0 +1,23 @@ +#pragma once +///@file logging-json.hh +/// +///@brief Logging functions for json specifically, split due to the cost of +///including nlohmann. + +#include "logging.hh" + +#include <nlohmann/json_fwd.hpp> + +namespace nix { + +std::optional<nlohmann::json> parseJSONMessage(const std::string & msg); + +bool handleJSONLogMessage(nlohmann::json & json, + const Activity & act, std::map<ActivityId, Activity> & activities, + bool trusted); + +bool handleJSONLogMessage(const std::string & msg, + const Activity & act, std::map<ActivityId, Activity> & activities, + bool trusted); + +}; diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 7a6341d70..dc6f53d77 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -5,8 +5,6 @@ #include "error.hh" #include "config.hh" -#include <nlohmann/json_fwd.hpp> - namespace nix { typedef enum { @@ -184,16 +182,6 @@ Logger * makeSimpleLogger(bool printBuildLogs = true); Logger * makeJSONLogger(Logger & prevLogger); -std::optional<nlohmann::json> parseJSONMessage(const std::string & msg); - -bool handleJSONLogMessage(nlohmann::json & json, - const Activity & act, std::map<ActivityId, Activity> & activities, - bool trusted); - -bool handleJSONLogMessage(const std::string & msg, - const Activity & act, std::map<ActivityId, Activity> & activities, - bool trusted); - /** * suppress msgs > this */ diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 084d7ed11..66eba9d85 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -50,6 +50,7 @@ libutil_headers = files( 'error.hh', 'exit.hh', 'experimental-features.hh', + 'experimental-features-json.hh', 'finally.hh', 'fmt.hh', 'git.hh', @@ -59,6 +60,7 @@ libutil_headers = files( 'json-impls.hh', 'json-utils.hh', 'logging.hh', + 'logging-json.hh', 'lru-cache.hh', 'monitor-fd.hh', 'namespaces.hh', diff --git a/src/nix/main.cc b/src/nix/main.cc index e033a5f5a..6bc46eba3 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -13,6 +13,7 @@ #include "finally.hh" #include "loggers.hh" #include "markdown.hh" +#include "experimental-features-json.hh" #include <sys/types.h> #include <sys/socket.h> diff --git a/tests/unit/libutil-support/tests/cli-literate-parser.cc b/tests/unit/libutil-support/tests/cli-literate-parser.cc index c943a813e..b3830e32c 100644 --- a/tests/unit/libutil-support/tests/cli-literate-parser.cc +++ b/tests/unit/libutil-support/tests/cli-literate-parser.cc @@ -3,6 +3,7 @@ #include "debug-char.hh" #include "types.hh" #include "util.hh" +#include <ranges> #include <iostream> #include <memory> #include <boost/algorithm/string/trim.hpp> |