From e862833ec662c1bffbe31b9a229147de391e801a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 1 Mar 2022 19:43:07 +0000 Subject: Move `BuildResult` defintion to its own header Just like we did for `ValidPathInfo` in d92d4f85a5c8a2a2385c084500a8b6bd54b54e6c. --- src/libstore/build-result.hh | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/libstore/build-result.hh (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh new file mode 100644 index 000000000..018ba31b3 --- /dev/null +++ b/src/libstore/build-result.hh @@ -0,0 +1,77 @@ +#pragma once + +#include "realisation.hh" + +#include +#include + + +namespace nix { + +struct BuildResult +{ + /* Note: don't remove status codes, and only add new status codes + at the end of the list, to prevent client/server + incompatibilities in the nix-store --serve protocol. */ + enum Status { + Built = 0, + Substituted, + AlreadyValid, + PermanentFailure, + InputRejected, + OutputRejected, + TransientFailure, // possibly transient + CachedFailure, // no longer used + TimedOut, + MiscFailure, + DependencyFailed, + LogLimitExceeded, + NotDeterministic, + ResolvesToAlreadyValid, + } status = MiscFailure; + std::string errorMsg; + + std::string toString() const { + auto strStatus = [&]() { + switch (status) { + case Built: return "Built"; + case Substituted: return "Substituted"; + case AlreadyValid: return "AlreadyValid"; + case PermanentFailure: return "PermanentFailure"; + case InputRejected: return "InputRejected"; + case OutputRejected: return "OutputRejected"; + case TransientFailure: return "TransientFailure"; + case CachedFailure: return "CachedFailure"; + case TimedOut: return "TimedOut"; + case MiscFailure: return "MiscFailure"; + case DependencyFailed: return "DependencyFailed"; + case LogLimitExceeded: return "LogLimitExceeded"; + case NotDeterministic: return "NotDeterministic"; + case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid"; + default: return "Unknown"; + }; + }(); + return strStatus + ((errorMsg == "") ? "" : " : " + errorMsg); + } + + /* How many times this build was performed. */ + unsigned int timesBuilt = 0; + + /* If timesBuilt > 1, whether some builds did not produce the same + result. (Note that 'isNonDeterministic = false' does not mean + the build is deterministic, just that we don't have evidence of + non-determinism.) */ + bool isNonDeterministic = false; + + DrvOutputs builtOutputs; + + /* The start/stop times of the build (or one of the rounds, if it + was repeated). */ + time_t startTime = 0, stopTime = 0; + + bool success() { + return status == Built || status == Substituted || status == AlreadyValid || status == ResolvesToAlreadyValid; + } +}; + +} -- cgit v1.2.3 From a4604f19284254ac98f19a13ff7c2216de7fe176 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Mar 2022 19:50:46 +0100 Subject: Add Store::buildPathsWithResults() This function is like buildPaths(), except that it returns a vector of BuildResults containing the exact statuses and output paths of each derivation / substitution. This is convenient for functions like Installable::build(), because they then don't need to do another series of calls to get the outputs of CA derivations. It's also a precondition to impure derivations, where we *can't* query the output of those derivations since they're not stored in the Nix database. Note that PathSubstitutionGoal can now also return a BuildStatus. --- src/libstore/build-result.hh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index 018ba31b3..c16027808 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -28,6 +28,7 @@ struct BuildResult LogLimitExceeded, NotDeterministic, ResolvesToAlreadyValid, + NoSubstituters, } status = MiscFailure; std::string errorMsg; @@ -63,15 +64,26 @@ struct BuildResult non-determinism.) */ bool isNonDeterministic = false; + /* For derivations, the derivation path and the wanted outputs. */ + std::optional drvPath; DrvOutputs builtOutputs; + /* For substitutions, the substituted path. */ + std::optional outPath; + /* The start/stop times of the build (or one of the rounds, if it was repeated). */ time_t startTime = 0, stopTime = 0; - bool success() { + bool success() + { return status == Built || status == Substituted || status == AlreadyValid || status == ResolvesToAlreadyValid; } + + void rethrow() + { + throw Error("%s", errorMsg); + } }; } -- cgit v1.2.3 From 761242afa08d5c9280ba6bd63a310b4334b83bb2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 9 Mar 2022 12:25:35 +0100 Subject: BuildResult: Use DerivedPath --- src/libstore/build-result.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index c16027808..d39d23a76 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -64,13 +64,13 @@ struct BuildResult non-determinism.) */ bool isNonDeterministic = false; + /* The derivation we built or the store path we substituted. */ + DerivedPath path; + /* For derivations, the derivation path and the wanted outputs. */ std::optional drvPath; DrvOutputs builtOutputs; - /* For substitutions, the substituted path. */ - std::optional outPath; - /* The start/stop times of the build (or one of the rounds, if it was repeated). */ time_t startTime = 0, stopTime = 0; -- cgit v1.2.3 From 4d98143914120d0163f5c50f30ce8a5289433f8f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 9 Mar 2022 20:31:50 +0100 Subject: BuildResult: Remove unused drvPath field --- src/libstore/build-result.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index d39d23a76..cb6d19b8e 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -67,8 +67,8 @@ struct BuildResult /* The derivation we built or the store path we substituted. */ DerivedPath path; - /* For derivations, the derivation path and the wanted outputs. */ - std::optional drvPath; + /* For derivations, a mapping from the names of the wanted outputs + to actual paths. */ DrvOutputs builtOutputs; /* The start/stop times of the build (or one of the rounds, if it -- cgit v1.2.3 From a4a1de69dcc3c6e0c40a093d67b5f20568a5f31e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Apr 2022 16:49:39 +0200 Subject: Add missing #include --- src/libstore/build-result.hh | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index cb6d19b8e..7f9bcce6d 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -1,6 +1,7 @@ #pragma once #include "realisation.hh" +#include "derived-path.hh" #include #include -- cgit v1.2.3 From c68963eaea7005b5bfb954e50fefb36c36084414 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 8 Apr 2022 11:48:30 +0200 Subject: Remove duplicate "error:" --- src/libstore/build-result.hh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libstore/build-result.hh') diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index 7f9bcce6d..24fb1f763 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -31,6 +31,8 @@ struct BuildResult ResolvesToAlreadyValid, NoSubstituters, } status = MiscFailure; + + // FIXME: include entire ErrorInfo object. std::string errorMsg; std::string toString() const { -- cgit v1.2.3