1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 20:16:03 +01:00

Write a destructor for DerivationBuilderImpl

This allows `DerivationBuildingGoal` to know less.
This commit is contained in:
John Ericson 2025-08-28 12:40:55 -04:00
parent 557bbe969e
commit 49da508f46
3 changed files with 33 additions and 31 deletions

View file

@ -59,18 +59,8 @@ DerivationBuildingGoal::~DerivationBuildingGoal()
ignoreExceptionInDestructor(); ignoreExceptionInDestructor();
} }
#ifndef _WIN32 // TODO enable `DerivationBuilder` on Windows #ifndef _WIN32 // TODO enable `DerivationBuilder` on Windows
if (builder) { if (builder)
try { builder.reset();
builder->stopDaemon();
} catch (...) {
ignoreExceptionInDestructor();
}
try {
builder->cleanupBuild(false);
} catch (...) {
ignoreExceptionInDestructor();
}
}
#endif #endif
try { try {
closeLogFile(); closeLogFile();

View file

@ -192,20 +192,6 @@ struct DerivationBuilder : RestrictionContext
*/ */
virtual SingleDrvOutputs unprepareBuild() = 0; virtual SingleDrvOutputs unprepareBuild() = 0;
/**
* Stop the in-process nix daemon thread.
* @see startDaemon
*/
virtual void stopDaemon() = 0;
/**
* Delete the temporary directory, if we have one.
*
* @param force We know the build suceeded, so don't attempt to
* preseve anything for debugging.
*/
virtual void cleanupBuild(bool force) = 0;
/** /**
* Kill any processes running under the build user UID or in the * Kill any processes running under the build user UID or in the
* cgroup of the build. * cgroup of the build.

View file

@ -85,6 +85,22 @@ public:
{ {
} }
~DerivationBuilderImpl()
{
/* Careful: we should never ever throw an exception from a
destructor. */
try {
stopDaemon();
} catch (...) {
ignoreExceptionInDestructor();
}
try {
cleanupBuild(false);
} catch (...) {
ignoreExceptionInDestructor();
}
}
protected: protected:
/** /**
@ -285,9 +301,11 @@ private:
*/ */
void startDaemon(); void startDaemon();
public: /**
* Stop the in-process nix daemon thread.
void stopDaemon() override; * @see startDaemon
*/
void stopDaemon();
protected: protected:
@ -342,9 +360,17 @@ private:
*/ */
SingleDrvOutputs registerOutputs(); SingleDrvOutputs registerOutputs();
public: protected:
void cleanupBuild(bool force) override; /**
* Delete the temporary directory, if we have one.
*
* @param force We know the build suceeded, so don't attempt to
* preseve anything for debugging.
*/
virtual void cleanupBuild(bool force);
public:
void killSandbox(bool getStats) override; void killSandbox(bool getStats) override;