Skip to content

Commit 1d6c7e7

Browse files
grahamcmergify[bot]
authored andcommitted
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. (cherry picked from commit e4f62e4) # Conflicts: # src/build-remote/build-remote.cc # src/libcmd/common-eval-args.cc # src/libcmd/repl.cc # src/libexpr-tests/error_traces.cc # src/libexpr-tests/primops.cc # src/libexpr-tests/trivial.cc # src/libexpr/eval-cache.cc # src/libexpr/eval-profiler-settings.cc # src/libexpr/eval-profiler.cc # src/libexpr/eval.cc # src/libexpr/get-drvs.cc # src/libexpr/include/nix/expr/eval-inline.hh # src/libexpr/include/nix/expr/eval-profiler-settings.hh # src/libexpr/include/nix/expr/eval-profiler.hh # src/libexpr/include/nix/expr/eval-settings.hh # src/libexpr/include/nix/expr/eval.hh # src/libexpr/include/nix/expr/function-trace.hh # src/libexpr/include/nix/expr/symbol-table.hh # src/libexpr/include/nix/expr/value.hh # src/libexpr/nixexpr.cc # src/libexpr/primops.cc # src/libexpr/primops/context.cc # src/libexpr/primops/fetchTree.cc # src/libexpr/value-to-json.cc # src/libexpr/value-to-xml.cc # src/libfetchers/fetch-to-store.cc # src/libfetchers/fetchers.cc # src/libfetchers/git-utils.cc # src/libfetchers/git.cc # src/libfetchers/github.cc # src/libfetchers/include/nix/fetchers/cache.hh # src/libfetchers/include/nix/fetchers/fetch-settings.hh # src/libfetchers/include/nix/fetchers/git-utils.hh # src/libfetchers/tarball.cc # src/libflake/flake.cc # src/libflake/flakeref.cc # src/libmain/include/nix/main/shared.hh # src/libmain/shared.cc # src/libstore-tests/machines.cc # src/libstore-tests/outputs-spec.cc # src/libstore/build/derivation-building-goal.cc # src/libstore/build/derivation-goal.cc # src/libstore/build/derivation-trampoline-goal.cc # src/libstore/build/drv-output-substitution-goal.cc # src/libstore/build/entry-points.cc # src/libstore/build/goal.cc # src/libstore/build/substitution-goal.cc # src/libstore/build/worker.cc # src/libstore/derived-path-map.cc # src/libstore/filetransfer.cc # src/libstore/gc.cc # src/libstore/include/nix/store/build/derivation-building-goal.hh # src/libstore/include/nix/store/build/derivation-goal.hh # src/libstore/include/nix/store/build/derivation-trampoline-goal.hh # src/libstore/include/nix/store/build/goal.hh # src/libstore/include/nix/store/build/worker.hh # src/libstore/include/nix/store/filetransfer.hh # src/libstore/include/nix/store/globals.hh # src/libstore/include/nix/store/local-store.hh # src/libstore/local-binary-cache-store.cc # src/libstore/local-store.cc # src/libstore/misc.cc # src/libstore/remote-store.cc # src/libstore/s3-binary-cache-store.cc # src/libstore/sqlite.cc # src/libstore/store-api.cc # src/libstore/unix/build/darwin-derivation-builder.cc # src/libstore/unix/build/derivation-builder.cc # src/libstore/unix/build/linux-derivation-builder.cc # src/libstore/unix/user-lock.cc # src/libutil-tests/url.cc # src/libutil/current-process.cc # src/libutil/error.cc # src/libutil/file-system.cc # src/libutil/freebsd/freebsd-jail.cc # src/libutil/freebsd/include/nix/util/freebsd-jail.hh # src/libutil/include/nix/util/error.hh # src/libutil/include/nix/util/file-system.hh # src/libutil/include/nix/util/logging.hh # src/libutil/include/nix/util/position.hh # src/libutil/include/nix/util/sort.hh # src/libutil/include/nix/util/sync.hh # src/libutil/include/nix/util/xml-writer.hh # src/libutil/logging.cc # src/libutil/serialise.cc # src/libutil/tee-logger.cc # src/libutil/windows/file-descriptor.cc # src/libutil/windows/windows-error.cc # src/nix-channel/nix-channel.cc # src/nix-env/nix-env.cc # src/nix-store/nix-store.cc # src/nix/flake-command.hh # src/nix/flake.cc # src/nix/main.cc # src/nix/prefetch.cc # src/nix/profile.cc # src/nix/run.cc # src/nix/unix/daemon.cc
1 parent bcd5e7f commit 1d6c7e7

File tree

587 files changed

+29093
-20565
lines changed

Some content is hidden

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

587 files changed

+29093
-20565
lines changed

src/build-remote/build-remote.cc

Lines changed: 48 additions & 43 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
@@ -329,29 +323,40 @@ static int main_build_remote(int argc, char * * argv)
329323
drv.inputSrcs = store->parseStorePathSet(inputs);
330324
optResult = sshStore->buildDerivation(*drvPath, (const BasicDerivation &) drv);
331325
auto & result = *optResult;
326+
<<<<<<< HEAD
332327
if (!result.success())
333328
throw Error("build of '%s' on '%s' failed: %s", store->printStorePath(*drvPath), storeUri, result.errorMsg);
334-
} 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 {},
329+
=======
330+
if (!result.success()) {
331+
if (settings.keepFailed) {
332+
warn(
333+
"The failed build directory was kept on the remote builder due to `--keep-failed`.%s",
334+
(settings.thisSystem == drv.platform || settings.extraPlatforms.get().count(drv.platform) > 0)
335+
? " You can re-run the command with `--builders ''` to disable remote building for this invocation."
336+
: "");
340337
}
341-
});
338+
throw Error(
339+
"build of '%s' on '%s' failed: %s", store->printStorePath(*drvPath), storeUri, result.errorMsg);
340+
}
341+
>>>>>>> e4f62e460 (Apply clang-format universally.)
342+
} else {
343+
copyClosure(*store, *sshStore, StorePathSet{*drvPath}, NoRepair, NoCheckSigs, substitute);
344+
auto res = sshStore->buildPathsWithResults({DerivedPath::Built{
345+
.drvPath = makeConstantStorePathRef(*drvPath),
346+
.outputs = OutputsSpec::All{},
347+
}});
342348
// One path to build should produce exactly one build result
343349
assert(res.size() == 1);
344350
optResult = std::move(res[0]);
345351
}
346352

347-
348353
auto outputHashes = staticOutputHashes(*store, drv);
349354
std::set<Realisation> missingRealisations;
350355
StorePathSet missingPaths;
351356
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations) && !drv.type().hasKnownOutputPaths()) {
352357
for (auto & outputName : wantedOutputs) {
353358
auto thisOutputHash = outputHashes.at(outputName);
354-
auto thisOutputId = DrvOutput{ thisOutputHash, outputName };
359+
auto thisOutputId = DrvOutput{thisOutputHash, outputName};
355360
if (!store->queryRealisation(thisOutputId)) {
356361
debug("missing output %s", outputName);
357362
assert(optResult);

src/libcmd/built-path.cc

Lines changed: 22 additions & 42 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);
@@ -141,4 +121,4 @@ RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
141121
return res;
142122
}
143123

144-
}
124+
} // namespace nix

src/libcmd/command-installable-value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ void InstallableValueCommand::run(ref<Store> store, ref<Installable> installable
88
run(store, installableValue);
99
}
1010

11-
}
11+
} // namespace nix

src/libcmd/command.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,4 @@ void MixOutLinkBase::createOutLinksMaybe(const std::vector<BuiltPathWithResult>
402402
createOutLinks(outLink, toBuiltPaths(buildables), *store2);
403403
}
404404

405-
}
405+
} // namespace nix

0 commit comments

Comments
 (0)