Skip to content

Commit 5493097

Browse files
committed
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
1 parent 7f2e78c commit 5493097

File tree

441 files changed

+22795
-22881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

441 files changed

+22795
-22881
lines changed

precompiled-headers.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
#include <unistd.h>
5050

5151
#ifndef _WIN32
52-
# include <grp.h>
53-
# include <netdb.h>
54-
# include <pwd.h>
55-
# include <sys/resource.h>
56-
# include <sys/select.h>
57-
# include <sys/socket.h>
58-
# include <sys/utsname.h>
59-
# include <sys/wait.h>
60-
# include <termios.h>
52+
# include <grp.h>
53+
# include <netdb.h>
54+
# include <pwd.h>
55+
# include <sys/resource.h>
56+
# include <sys/select.h>
57+
# include <sys/socket.h>
58+
# include <sys/utsname.h>
59+
# include <sys/wait.h>
60+
# include <termios.h>
6161
#endif
6262

6363
#include <nlohmann/json.hpp>

src/build-remote/build-remote.cc

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <tuple>
77
#include <iomanip>
88
#ifdef __APPLE__
9-
#include <sys/time.h>
9+
# include <sys/time.h>
1010
#endif
1111

1212
#include "nix/store/machines.hh"
@@ -26,8 +26,7 @@
2626
using namespace nix;
2727
using std::cin;
2828

29-
static void handleAlarm(int sig) {
30-
}
29+
static void handleAlarm(int sig) {}
3130

3231
std::string escapeUri(std::string uri)
3332
{
@@ -42,13 +41,15 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
4241
return openLockFile(fmt("%s/%s-%d", currentLoad, escapeUri(m.storeUri.render()), slot), true);
4342
}
4443

45-
static bool allSupportedLocally(Store & store, const StringSet& requiredFeatures) {
44+
static bool allSupportedLocally(Store & store, const StringSet & requiredFeatures)
45+
{
4646
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;
4849
return true;
4950
}
5051

51-
static int main_build_remote(int argc, char * * argv)
52+
static int main_build_remote(int argc, char ** argv)
5253
{
5354
{
5455
logger = makeJSONLogger(getStandardError());
@@ -85,7 +86,7 @@ static int main_build_remote(int argc, char * * argv)
8586
that gets cleared on reboot, but it wouldn't work on macOS. */
8687
auto currentLoadName = "/current-load";
8788
if (auto localStore = store.dynamic_pointer_cast<LocalFSStore>())
88-
currentLoad = std::string { localStore->config.stateDir } + currentLoadName;
89+
currentLoad = std::string{localStore->config.stateDir} + currentLoadName;
8990
else
9091
currentLoad = settings.nixStateDir + currentLoadName;
9192

@@ -107,8 +108,11 @@ static int main_build_remote(int argc, char * * argv)
107108

108109
try {
109110
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+
}
112116

113117
auto amWilling = readInt(source);
114118
auto neededSystem = readString(source);
@@ -117,10 +121,10 @@ static int main_build_remote(int argc, char * * argv)
117121

118122
/* It would be possible to build locally after some builds clear out,
119123
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);
124128
/* It's possible to build this locally right now: */
125129
bool canBuildLocally = amWilling && couldBuildLocally;
126130

@@ -139,11 +143,8 @@ static int main_build_remote(int argc, char * * argv)
139143
for (auto & m : machines) {
140144
debug("considering building on remote machine '%s'", m.storeUri.render());
141145

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)) {
147148
rightType = true;
148149
AutoCloseFD free;
149150
uint64_t load = 0;
@@ -185,8 +186,7 @@ static int main_build_remote(int argc, char * * argv)
185186
if (!bestSlotLock) {
186187
if (rightType && !canBuildLocally)
187188
std::cerr << "# postpone\n";
188-
else
189-
{
189+
else {
190190
// build the hint template.
191191
std::string errorText =
192192
"Failed to find a machine for remote build!\n"
@@ -205,16 +205,11 @@ static int main_build_remote(int argc, char * * argv)
205205
drvstr = "<unknown>";
206206

207207
auto error = HintFmt::fromFormatString(errorText);
208-
error
209-
% drvstr
210-
% neededSystem
211-
% concatStringsSep<StringSet>(", ", requiredFeatures)
208+
error % drvstr % neededSystem % concatStringsSep<StringSet>(", ", requiredFeatures)
212209
% machines.size();
213210

214211
for (auto & m : machines)
215-
error
216-
% concatStringsSep<StringSet>(", ", m.systemTypes)
217-
% m.maxJobs
212+
error % concatStringsSep<StringSet>(", ", m.systemTypes) % m.maxJobs
218213
% concatStringsSep<StringSet>(", ", m.supportedFeatures)
219214
% concatStringsSep<StringSet>(", ", m.mandatoryFeatures);
220215

@@ -242,9 +237,7 @@ static int main_build_remote(int argc, char * * argv)
242237
sshStore->connect();
243238
} catch (std::exception & e) {
244239
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);
248241
bestMachine->enabled = false;
249242
continue;
250243
}
@@ -253,7 +246,7 @@ static int main_build_remote(int argc, char * * argv)
253246
}
254247
}
255248

256-
connected:
249+
connected:
257250
close(5);
258251

259252
assert(sshStore);
@@ -265,13 +258,14 @@ static int main_build_remote(int argc, char * * argv)
265258

266259
AutoCloseFD uploadLock;
267260
{
268-
auto setUpdateLock = [&](auto && fileName){
261+
auto setUpdateLock = [&](auto && fileName) {
269262
uploadLock = openLockFile(currentLoad + "/" + escapeUri(fileName) + ".upload-lock", true);
270263
};
271264
try {
272265
setUpdateLock(storeUri);
273266
} catch (SysError & e) {
274-
if (e.errNo != ENAMETOOLONG) throw;
267+
if (e.errNo != ENAMETOOLONG)
268+
throw;
275269
// Try again hashing the store URL so we have a shorter path
276270
auto h = hashString(HashAlgorithm::MD5, storeUri);
277271
setUpdateLock(h.to_string(HashFormat::Base64, false));
@@ -315,7 +309,7 @@ static int main_build_remote(int argc, char * * argv)
315309
//
316310
// This condition mirrors that: that code enforces the "rules" outlined there;
317311
// we do the best we can given those "rules".
318-
if (trustedOrLegacy || drv.type().isCA()) {
312+
if (trustedOrLegacy || drv.type().isCA()) {
319313
// Hijack the inputs paths of the derivation to include all
320314
// the paths that come from the `inputDrvs` set. We don’t do
321315
// that for the derivations whose `inputDrvs` is empty
@@ -330,28 +324,26 @@ static int main_build_remote(int argc, char * * argv)
330324
optResult = sshStore->buildDerivation(*drvPath, (const BasicDerivation &) drv);
331325
auto & result = *optResult;
332326
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);
334329
} 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+
}});
342335
// One path to build should produce exactly one build result
343336
assert(res.size() == 1);
344337
optResult = std::move(res[0]);
345338
}
346339

347-
348340
auto outputHashes = staticOutputHashes(*store, drv);
349341
std::set<Realisation> missingRealisations;
350342
StorePathSet missingPaths;
351343
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations) && !drv.type().hasKnownOutputPaths()) {
352344
for (auto & outputName : wantedOutputs) {
353345
auto thisOutputHash = outputHashes.at(outputName);
354-
auto thisOutputId = DrvOutput{ thisOutputHash, outputName };
346+
auto thisOutputId = DrvOutput{thisOutputHash, outputName};
355347
if (!store->queryRealisation(thisOutputId)) {
356348
debug("missing output %s", outputName);
357349
assert(optResult);

src/libcmd/built-path.cc

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,22 @@
1010
namespace nix {
1111

1212
// Custom implementation to avoid `ref` ptr equality
13-
GENERATE_CMP_EXT(
14-
,
15-
std::strong_ordering,
16-
SingleBuiltPathBuilt,
17-
*me->drvPath,
18-
me->output);
13+
GENERATE_CMP_EXT(, std::strong_ordering, SingleBuiltPathBuilt, *me->drvPath, me->output);
1914

2015
// Custom implementation to avoid `ref` ptr equality
2116

2217
// TODO no `GENERATE_CMP_EXT` because no `std::set::operator<=>` on
2318
// Darwin, per header.
24-
GENERATE_EQUAL(
25-
,
26-
BuiltPathBuilt ::,
27-
BuiltPathBuilt,
28-
*me->drvPath,
29-
me->outputs);
19+
GENERATE_EQUAL(, BuiltPathBuilt ::, BuiltPathBuilt, *me->drvPath, me->outputs);
3020

3121
StorePath SingleBuiltPath::outPath() const
3222
{
3323
return std::visit(
3424
overloaded{
3525
[](const SingleBuiltPath::Opaque & p) { return p.path; },
3626
[](const SingleBuiltPath::Built & b) { return b.output.second; },
37-
}, raw()
38-
);
27+
},
28+
raw());
3929
}
4030

4131
StorePathSet BuiltPath::outPaths() const
@@ -49,13 +39,13 @@ StorePathSet BuiltPath::outPaths() const
4939
res.insert(path);
5040
return res;
5141
},
52-
}, raw()
53-
);
42+
},
43+
raw());
5444
}
5545

5646
SingleDerivedPath::Built SingleBuiltPath::Built::discardOutputPath() const
5747
{
58-
return SingleDerivedPath::Built {
48+
return SingleDerivedPath::Built{
5949
.drvPath = make_ref<SingleDerivedPath>(drvPath->discardOutputPath()),
6050
.output = output.first,
6151
};
@@ -65,14 +55,10 @@ SingleDerivedPath SingleBuiltPath::discardOutputPath() const
6555
{
6656
return std::visit(
6757
overloaded{
68-
[](const SingleBuiltPath::Opaque & p) -> SingleDerivedPath {
69-
return p;
70-
},
71-
[](const SingleBuiltPath::Built & b) -> SingleDerivedPath {
72-
return b.discardOutputPath();
73-
},
74-
}, raw()
75-
);
58+
[](const SingleBuiltPath::Opaque & p) -> SingleDerivedPath { return p; },
59+
[](const SingleBuiltPath::Built & b) -> SingleDerivedPath { return b.discardOutputPath(); },
60+
},
61+
raw());
7662
}
7763

7864
nlohmann::json BuiltPath::Built::toJSON(const StoreDirConfig & store) const
@@ -97,16 +83,12 @@ nlohmann::json SingleBuiltPath::Built::toJSON(const StoreDirConfig & store) cons
9783

9884
nlohmann::json SingleBuiltPath::toJSON(const StoreDirConfig & store) const
9985
{
100-
return std::visit([&](const auto & buildable) {
101-
return buildable.toJSON(store);
102-
}, raw());
86+
return std::visit([&](const auto & buildable) { return buildable.toJSON(store); }, raw());
10387
}
10488

10589
nlohmann::json BuiltPath::toJSON(const StoreDirConfig & store) const
10690
{
107-
return std::visit([&](const auto & buildable) {
108-
return buildable.toJSON(store);
109-
}, raw());
91+
return std::visit([&](const auto & buildable) { return buildable.toJSON(store); }, raw());
11092
}
11193

11294
RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
@@ -116,20 +98,18 @@ RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
11698
overloaded{
11799
[&](const BuiltPath::Opaque & p) { res.insert(p.path); },
118100
[&](const BuiltPath::Built & p) {
119-
auto drvHashes =
120-
staticOutputHashes(store, store.readDerivation(p.drvPath->outPath()));
121-
for (auto& [outputName, outputPath] : p.outputs) {
122-
if (experimentalFeatureSettings.isEnabled(
123-
Xp::CaDerivations)) {
101+
auto drvHashes = staticOutputHashes(store, store.readDerivation(p.drvPath->outPath()));
102+
for (auto & [outputName, outputPath] : p.outputs) {
103+
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
124104
auto drvOutput = get(drvHashes, outputName);
125105
if (!drvOutput)
126106
throw Error(
127107
"the derivation '%s' has unrealised output '%s' (derived-path.cc/toRealisedPaths)",
128-
store.printStorePath(p.drvPath->outPath()), outputName);
129-
auto thisRealisation = store.queryRealisation(
130-
DrvOutput{*drvOutput, outputName});
131-
assert(thisRealisation); // We’ve built it, so we must
132-
// have the realisation
108+
store.printStorePath(p.drvPath->outPath()),
109+
outputName);
110+
auto thisRealisation = store.queryRealisation(DrvOutput{*drvOutput, outputName});
111+
assert(thisRealisation); // We’ve built it, so we must
112+
// have the realisation
133113
res.insert(*thisRealisation);
134114
} else {
135115
res.insert(outputPath);

0 commit comments

Comments
 (0)