Skip to content

Commit bdf7104

Browse files
edolstraRossComputerGuy
authored andcommitted
Don't use DerivedPath::toJSON()
It doesn't work on unrealized paths.
1 parent 7e7faaf commit bdf7104

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

src/libstore/build-result.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ void to_json(nlohmann::json & json, const BuildResult & buildResult)
2323
json["stopTime"] = buildResult.stopTime;
2424
}
2525

26-
nlohmann::json KeyedBuildResult::toJSON(Store & store) const
26+
void to_json(nlohmann::json & json, const KeyedBuildResult & buildResult)
2727
{
28-
auto json = nlohmann::json((const BuildResult &) *this);
29-
json["path"] = path.toJSON(store);
30-
return json;
28+
to_json(json, (const BuildResult &) buildResult);
29+
auto path = nlohmann::json::object();
30+
std::visit(
31+
overloaded{
32+
[&](const DerivedPathOpaque & opaque) { path["opaque"] = opaque.path.to_string(); },
33+
[&](const DerivedPathBuilt & drv) {
34+
path["drvPath"] = drv.drvPath->getBaseStorePath().to_string();
35+
path["outputs"] = drv.outputs.to_string();
36+
},
37+
},
38+
buildResult.path.raw());
39+
json["path"] = std::move(path);
3140
}
3241

3342
} // namespace nix

src/libstore/build/derivation-goal.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,6 @@ Goal::Done DerivationGoal::doneFailure(BuildError ex)
377377
fs << worker.store.printStorePath(drvPath) << "\t" << buildResult.toString() << std::endl;
378378
}
379379

380-
logger->result(
381-
act ? act->id : getCurActivity(),
382-
resBuildResult,
383-
KeyedBuildResult(
384-
buildResult,
385-
DerivedPath::Built{.drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs}).toJSON(worker.store));
386-
387380
return amDone(buildResult.success() ? ecSuccess : ecFailed, std::move(ex));
388381
}
389382

src/libstore/build/substitution-goal.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ Goal::Done PathSubstitutionGoal::done(ExitCode result, BuildResult::Status statu
3737
buildResult.errorMsg = *errorMsg;
3838
}
3939

40-
logger->result(
41-
getCurActivity(),
42-
resBuildResult,
43-
KeyedBuildResult(
44-
buildResult,
45-
DerivedPath::Opaque{storePath}).toJSON(worker.store));
46-
4740
return amDone(result);
4841
}
4942

src/libstore/include/nix/store/build-result.hh

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,46 @@ struct BuildResult
5555
static std::string_view statusToString(Status status)
5656
{
5757
switch (status) {
58-
case Built: return "Built";
59-
case Substituted: return "Substituted";
60-
case AlreadyValid: return "AlreadyValid";
61-
case PermanentFailure: return "PermanentFailure";
62-
case InputRejected: return "InputRejected";
63-
case OutputRejected: return "OutputRejected";
64-
case TransientFailure: return "TransientFailure";
65-
case CachedFailure: return "CachedFailure";
66-
case TimedOut: return "TimedOut";
67-
case MiscFailure: return "MiscFailure";
68-
case DependencyFailed: return "DependencyFailed";
69-
case LogLimitExceeded: return "LogLimitExceeded";
70-
case NotDeterministic: return "NotDeterministic";
71-
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
72-
case NoSubstituters: return "NoSubstituters";
73-
default: return "Unknown";
58+
case Built:
59+
return "Built";
60+
case Substituted:
61+
return "Substituted";
62+
case AlreadyValid:
63+
return "AlreadyValid";
64+
case PermanentFailure:
65+
return "PermanentFailure";
66+
case InputRejected:
67+
return "InputRejected";
68+
case OutputRejected:
69+
return "OutputRejected";
70+
case TransientFailure:
71+
return "TransientFailure";
72+
case CachedFailure:
73+
return "CachedFailure";
74+
case TimedOut:
75+
return "TimedOut";
76+
case MiscFailure:
77+
return "MiscFailure";
78+
case DependencyFailed:
79+
return "DependencyFailed";
80+
case LogLimitExceeded:
81+
return "LogLimitExceeded";
82+
case NotDeterministic:
83+
return "NotDeterministic";
84+
case ResolvesToAlreadyValid:
85+
return "ResolvesToAlreadyValid";
86+
case NoSubstituters:
87+
return "NoSubstituters";
88+
case HashMismatch:
89+
return "HashMismatch";
90+
default:
91+
return "Unknown";
7492
};
7593
}
7694

77-
std::string toString() const {
78-
return
79-
std::string(statusToString(status))
80-
+ ((errorMsg == "") ? "" : " : " + errorMsg);
95+
std::string toString() const
96+
{
97+
return std::string(statusToString(status)) + ((errorMsg == "") ? "" : " : " + errorMsg);
8198
}
8299

83100
/**
@@ -165,7 +182,6 @@ struct KeyedBuildResult : BuildResult
165182
};
166183

167184
void to_json(nlohmann::json & json, const BuildResult & buildResult);
168-
169-
}
185+
void to_json(nlohmann::json & json, const KeyedBuildResult & buildResult);
170186

171187
} // namespace nix

0 commit comments

Comments
 (0)