6
6
#include < tuple>
7
7
#include < iomanip>
8
8
#ifdef __APPLE__
9
- #include < sys/time.h>
9
+ # include < sys/time.h>
10
10
#endif
11
11
12
12
#include " nix/store/machines.hh"
26
26
using namespace nix ;
27
27
using std::cin;
28
28
29
- static void handleAlarm (int sig) {
30
- }
29
+ static void handleAlarm (int sig) {}
31
30
32
31
std::string escapeUri (std::string uri)
33
32
{
@@ -42,13 +41,15 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
42
41
return openLockFile (fmt (" %s/%s-%d" , currentLoad, escapeUri (m.storeUri .render ()), slot), true );
43
42
}
44
43
45
- static bool allSupportedLocally (Store & store, const StringSet& requiredFeatures) {
44
+ static bool allSupportedLocally (Store & store, const StringSet & requiredFeatures)
45
+ {
46
46
for (auto & feature : requiredFeatures)
47
- if (!store.config .systemFeatures .get ().count (feature)) return false ;
47
+ if (!store.config .systemFeatures .get ().count (feature))
48
+ return false ;
48
49
return true ;
49
50
}
50
51
51
- static int main_build_remote (int argc, char * * argv)
52
+ static int main_build_remote (int argc, char ** argv)
52
53
{
53
54
{
54
55
logger = makeJSONLogger (getStandardError ());
@@ -85,7 +86,7 @@ static int main_build_remote(int argc, char * * argv)
85
86
that gets cleared on reboot, but it wouldn't work on macOS. */
86
87
auto currentLoadName = " /current-load" ;
87
88
if (auto localStore = store.dynamic_pointer_cast <LocalFSStore>())
88
- currentLoad = std::string { localStore->config .stateDir } + currentLoadName;
89
+ currentLoad = std::string{ localStore->config .stateDir } + currentLoadName;
89
90
else
90
91
currentLoad = settings.nixStateDir + currentLoadName;
91
92
@@ -107,8 +108,11 @@ static int main_build_remote(int argc, char * * argv)
107
108
108
109
try {
109
110
auto s = readString (source);
110
- if (s != " try" ) return 0 ;
111
- } catch (EndOfFile &) { return 0 ; }
111
+ if (s != " try" )
112
+ return 0 ;
113
+ } catch (EndOfFile &) {
114
+ return 0 ;
115
+ }
112
116
113
117
auto amWilling = readInt (source);
114
118
auto neededSystem = readString (source);
@@ -117,10 +121,10 @@ static int main_build_remote(int argc, char * * argv)
117
121
118
122
/* It would be possible to build locally after some builds clear out,
119
123
so don't show the warning now: */
120
- bool couldBuildLocally = maxBuildJobs > 0
121
- && ( neededSystem == settings. thisSystem
122
- || settings.extraPlatforms .get ().count (neededSystem) > 0 )
123
- && allSupportedLocally (*store, requiredFeatures);
124
+ bool couldBuildLocally =
125
+ maxBuildJobs > 0
126
+ && (neededSystem == settings. thisSystem || settings.extraPlatforms .get ().count (neededSystem) > 0 )
127
+ && allSupportedLocally (*store, requiredFeatures);
124
128
/* It's possible to build this locally right now: */
125
129
bool canBuildLocally = amWilling && couldBuildLocally;
126
130
@@ -139,11 +143,8 @@ static int main_build_remote(int argc, char * * argv)
139
143
for (auto & m : machines) {
140
144
debug (" considering building on remote machine '%s'" , m.storeUri .render ());
141
145
142
- if (m.enabled &&
143
- m.systemSupported (neededSystem) &&
144
- m.allSupported (requiredFeatures) &&
145
- m.mandatoryMet (requiredFeatures))
146
- {
146
+ if (m.enabled && m.systemSupported (neededSystem) && m.allSupported (requiredFeatures)
147
+ && m.mandatoryMet (requiredFeatures)) {
147
148
rightType = true ;
148
149
AutoCloseFD free;
149
150
uint64_t load = 0 ;
@@ -185,8 +186,7 @@ static int main_build_remote(int argc, char * * argv)
185
186
if (!bestSlotLock) {
186
187
if (rightType && !canBuildLocally)
187
188
std::cerr << " # postpone\n " ;
188
- else
189
- {
189
+ else {
190
190
// build the hint template.
191
191
std::string errorText =
192
192
" Failed to find a machine for remote build!\n "
@@ -205,16 +205,11 @@ static int main_build_remote(int argc, char * * argv)
205
205
drvstr = " <unknown>" ;
206
206
207
207
auto error = HintFmt::fromFormatString (errorText);
208
- error
209
- % drvstr
210
- % neededSystem
211
- % concatStringsSep<StringSet>(" , " , requiredFeatures)
208
+ error % drvstr % neededSystem % concatStringsSep<StringSet>(" , " , requiredFeatures)
212
209
% machines.size ();
213
210
214
211
for (auto & m : machines)
215
- error
216
- % concatStringsSep<StringSet>(" , " , m.systemTypes )
217
- % m.maxJobs
212
+ error % concatStringsSep<StringSet>(" , " , m.systemTypes ) % m.maxJobs
218
213
% concatStringsSep<StringSet>(" , " , m.supportedFeatures )
219
214
% concatStringsSep<StringSet>(" , " , m.mandatoryFeatures );
220
215
@@ -242,9 +237,7 @@ static int main_build_remote(int argc, char * * argv)
242
237
sshStore->connect ();
243
238
} catch (std::exception & e) {
244
239
auto msg = chomp (drainFD (5 , false ));
245
- printError (" cannot build on '%s': %s%s" ,
246
- storeUri, e.what (),
247
- msg.empty () ? " " : " : " + msg);
240
+ printError (" cannot build on '%s': %s%s" , storeUri, e.what (), msg.empty () ? " " : " : " + msg);
248
241
bestMachine->enabled = false ;
249
242
continue ;
250
243
}
@@ -253,7 +246,7 @@ static int main_build_remote(int argc, char * * argv)
253
246
}
254
247
}
255
248
256
- connected:
249
+ connected:
257
250
close (5 );
258
251
259
252
assert (sshStore);
@@ -265,13 +258,14 @@ static int main_build_remote(int argc, char * * argv)
265
258
266
259
AutoCloseFD uploadLock;
267
260
{
268
- auto setUpdateLock = [&](auto && fileName){
261
+ auto setUpdateLock = [&](auto && fileName) {
269
262
uploadLock = openLockFile (currentLoad + " /" + escapeUri (fileName) + " .upload-lock" , true );
270
263
};
271
264
try {
272
265
setUpdateLock (storeUri);
273
266
} catch (SysError & e) {
274
- if (e.errNo != ENAMETOOLONG) throw ;
267
+ if (e.errNo != ENAMETOOLONG)
268
+ throw ;
275
269
// Try again hashing the store URL so we have a shorter path
276
270
auto h = hashString (HashAlgorithm::MD5, storeUri);
277
271
setUpdateLock (h.to_string (HashFormat::Base64, false ));
@@ -315,7 +309,7 @@ static int main_build_remote(int argc, char * * argv)
315
309
//
316
310
// This condition mirrors that: that code enforces the "rules" outlined there;
317
311
// we do the best we can given those "rules".
318
- if (trustedOrLegacy || drv.type ().isCA ()) {
312
+ if (trustedOrLegacy || drv.type ().isCA ()) {
319
313
// Hijack the inputs paths of the derivation to include all
320
314
// the paths that come from the `inputDrvs` set. We don’t do
321
315
// that for the derivations whose `inputDrvs` is empty
@@ -330,28 +324,26 @@ static int main_build_remote(int argc, char * * argv)
330
324
optResult = sshStore->buildDerivation (*drvPath, (const BasicDerivation &) drv);
331
325
auto & result = *optResult;
332
326
if (!result.success ())
333
- throw Error (" build of '%s' on '%s' failed: %s" , store->printStorePath (*drvPath), storeUri, result.errorMsg );
327
+ throw Error (
328
+ " build of '%s' on '%s' failed: %s" , store->printStorePath (*drvPath), storeUri, result.errorMsg );
334
329
} else {
335
- copyClosure (*store, *sshStore, StorePathSet {*drvPath}, NoRepair, NoCheckSigs, substitute);
336
- auto res = sshStore->buildPathsWithResults ({
337
- DerivedPath::Built {
338
- .drvPath = makeConstantStorePathRef (*drvPath),
339
- .outputs = OutputsSpec::All {},
340
- }
341
- });
330
+ copyClosure (*store, *sshStore, StorePathSet{*drvPath}, NoRepair, NoCheckSigs, substitute);
331
+ auto res = sshStore->buildPathsWithResults ({DerivedPath::Built{
332
+ .drvPath = makeConstantStorePathRef (*drvPath),
333
+ .outputs = OutputsSpec::All{},
334
+ }});
342
335
// One path to build should produce exactly one build result
343
336
assert (res.size () == 1 );
344
337
optResult = std::move (res[0 ]);
345
338
}
346
339
347
-
348
340
auto outputHashes = staticOutputHashes (*store, drv);
349
341
std::set<Realisation> missingRealisations;
350
342
StorePathSet missingPaths;
351
343
if (experimentalFeatureSettings.isEnabled (Xp::CaDerivations) && !drv.type ().hasKnownOutputPaths ()) {
352
344
for (auto & outputName : wantedOutputs) {
353
345
auto thisOutputHash = outputHashes.at (outputName);
354
- auto thisOutputId = DrvOutput{ thisOutputHash, outputName };
346
+ auto thisOutputId = DrvOutput{thisOutputHash, outputName};
355
347
if (!store->queryRealisation (thisOutputId)) {
356
348
debug (" missing output %s" , outputName);
357
349
assert (optResult);
0 commit comments