Skip to content

Commit 3aeb5c8

Browse files
committed
style(mcl/*.d): Format all .d files
1 parent 1c3349c commit 3aeb5c8

File tree

16 files changed

+656
-367
lines changed

16 files changed

+656
-367
lines changed

packages/mcl/src/main.d

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ int main(string[] args)
2727

2828
setLogLevel(logLevel);
2929

30-
try switch (args[1])
30+
try
31+
switch (args[1])
3132
{
32-
default:
33-
return wrongUsage("unknown command: `" ~ args[1] ~ "`");
33+
default:
34+
return wrongUsage("unknown command: `" ~ args[1] ~ "`");
3435

3536
static foreach (cmd; supportedCommands)
36-
case __traits(identifier, cmd):
37-
{
37+
case __traits(identifier, cmd):
38+
{
3839

39-
info("Running ", __traits(identifier, cmd));
40-
cmd();
41-
info("Execution Succesfull");
42-
return 0;
40+
info("Running ", __traits(identifier, cmd));
41+
cmd();
42+
info("Execution Succesfull");
43+
return 0;
4344

44-
}
45+
}
4546
}
4647
catch (Exception e)
4748
{
@@ -53,8 +54,9 @@ int main(string[] args)
5354
void setLogLevel(LogLevel l)
5455
{
5556
import std.logger : globalLogLevel, sharedLog;
57+
5658
globalLogLevel = l;
57-
(cast()sharedLog()).logLevel = l;
59+
(cast() sharedLog()).logLevel = l;
5860
}
5961

6062
int wrongUsage(string error)

packages/mcl/src/src/mcl/commands/ci.d

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module mcl.commands.ci;
22

33
import std.file : readText;
4-
import std.json : parseJSON,JSONValue;
5-
import std.stdio : writeln,write;
4+
import std.json : parseJSON, JSONValue;
5+
import std.stdio : writeln, write;
66
import std.algorithm : map;
77
import std.array : array, join;
88
import std.conv : to;
99
import std.process : ProcessPipes;
1010

1111
import mcl.utils.env : optional, parseEnv;
12-
import mcl.commands.ci_matrix: nixEvalJobs, SupportedSystem, Params;
13-
import mcl.commands.shard_matrix: generateShardMatrix;
12+
import mcl.commands.ci_matrix : nixEvalJobs, SupportedSystem, Params;
13+
import mcl.commands.shard_matrix : generateShardMatrix;
1414
import mcl.utils.path : rootDir, createResultDirs;
1515
import mcl.utils.process : execute;
1616
import mcl.utils.nix : nix;
@@ -38,17 +38,21 @@ export void ci()
3838
params.flakePost = "." ~ params.flakePost;
3939
}
4040
string cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";
41-
version (AArch64) {
41+
version (AArch64)
42+
{
4243
string arch = "aarch64";
4344
}
44-
version (X86_64) {
45+
version (X86_64)
46+
{
4547
string arch = "x86_64";
4648
}
4749

48-
version (linux) {
50+
version (linux)
51+
{
4952
string os = "linux";
5053
}
51-
version (OSX) {
54+
version (OSX)
55+
{
5256
string os = "darwin";
5357
}
5458

@@ -62,7 +66,9 @@ export void ci()
6266
else
6367
{
6468
writeln("Package ", pkg.name, " is not cached; building...");
65-
ProcessPipes res = execute!ProcessPipes(["nix", "build", "--json", ".#" ~ pkg.attrPath]);
69+
ProcessPipes res = execute!ProcessPipes([
70+
"nix", "build", "--json", ".#" ~ pkg.attrPath
71+
]);
6672

6773
foreach (line; res.stderr.byLine)
6874
{

packages/mcl/src/src/mcl/commands/ci_matrix.d

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,17 @@ Package[] checkCacheStatus(Package[] packages)
159159
foreach (ref pkg; packages.parallel)
160160
{
161161
pkg = checkPackage(pkg);
162-
struct Output { string isCached, name, storePath; }
162+
struct Output
163+
{
164+
string isCached, name, storePath;
165+
}
166+
163167
auto res = appender!string;
164168
writeRecordAsTable(
165169
Output(pkg.isCached ? "" : "", pkg.name, pkg.output),
166170
res
167171
);
168-
tracef("%s", res.data[0..$-1]);
172+
tracef("%s", res.data[0 .. $ - 1]);
169173
}
170174
return packages;
171175
}
@@ -265,12 +269,14 @@ Package[] nixEvalJobs(Params params, SupportedSystem system, string cachixUrl, b
265269
cacheUrl: cachixUrl ~ "/" ~ json["outputs"]["out"].str.matchFirst(
266270
"^/nix/store/(?P<hash>[^-]+)-")["hash"] ~ ".narinfo"
267271
};
268-
if (doCheck) {
272+
if (doCheck)
273+
{
269274
pkg = pkg.checkPackage();
270275
}
271276
result ~= pkg;
272277

273-
struct Output {
278+
struct Output
279+
{
274280
bool isCached;
275281
GitHubOS os;
276282
@MaxWidth(50) string attr;
@@ -377,10 +383,12 @@ unittest
377383

378384
void saveCachixDeploySpec(Package[] packages)
379385
{
380-
auto agents = packages.filter!(pkg => pkg.isCached == false).map!(pkg => JSONValue([
381-
"package": pkg.name,
382-
"out": pkg.output
383-
])).array;
386+
auto agents = packages.filter!(pkg => pkg.isCached == false)
387+
.map!(pkg => JSONValue([
388+
"package": pkg.name,
389+
"out": pkg.output
390+
]))
391+
.array;
384392
auto resPath = resultDir.buildPath("cachix-deploy-spec.json");
385393
resPath.write(JSONValue(agents).toString(JSONOptions.doNotEscapeSlashes));
386394
}
@@ -573,8 +581,9 @@ unittest
573581
const storePath = "/nix/store/" ~ storePathHash ~ "-hello-2.12.1";
574582

575583
auto testPackage = Package(
576-
output: storePath,
577-
cacheUrl: nixosCacheEndpoint ~ storePathHash ~ ".narinfo",
584+
output : storePath,
585+
cacheUrl:
586+
nixosCacheEndpoint ~ storePathHash ~ ".narinfo",
578587
);
579588

580589
assert(!testPackage.isCached);

packages/mcl/src/src/mcl/commands/deploy_spec.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export void deploy_spec()
2626
}
2727

2828
spawnProcessInline([
29-
"cachix", "deploy", "activate", deploySpecFile
30-
]);
29+
"cachix", "deploy", "activate", deploySpecFile
30+
]);
3131
}
3232

3333
void createMachineDeploySpec()
@@ -47,8 +47,8 @@ void createMachineDeploySpec()
4747

4848
auto result = [
4949
"agents": packages
50-
.map!(pkg => tuple(pkg.name, pkg.output))
51-
.assocArray
50+
.map!(pkg => tuple(pkg.name, pkg.output))
51+
.assocArray
5252
].JSONValue;
5353

5454
writeFile(deploySpecFile, result.toString());

packages/mcl/src/src/mcl/commands/host_info.d

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import std.file : exists, write, readText, readLink, dirEntries, SpanMode;
1414
import std.path : baseName;
1515
import std.json;
1616
import std.process : ProcessPipes, environment;
17-
import core.stdc.string: strlen;
17+
import core.stdc.string : strlen;
1818

1919
import mcl.utils.env : parseEnv, optional;
2020
import mcl.utils.json : toJSON;
@@ -47,7 +47,8 @@ string[string] getProcInfo(string fileOrData, bool file = true)
4747
{
4848
string[string] r;
4949
foreach (line; file ? fileOrData.readText().split(
50-
"\n").map!(strip).array : fileOrData.split("\n").map!(strip).array)
50+
"\n").map!(strip).array
51+
: fileOrData.split("\n").map!(strip).array)
5152
{
5253
if (line.indexOf(":") == -1 || line.strip == "edid-decode (hex):")
5354
{
@@ -205,7 +206,7 @@ ProcessorInfo getProcessorInfo()
205206
r.vendor = cpuid.x86_any.vendor;
206207
char[48] modelCharArr;
207208
cpuid.x86_any.brand(modelCharArr);
208-
r.model = modelCharArr.idup[0..(strlen(modelCharArr.ptr)-1)];
209+
r.model = modelCharArr.idup[0 .. (strlen(modelCharArr.ptr) - 1)];
209210
r.cpus = cpuid.unified.cpus();
210211
r.cores = [r.cpus * cpuid.unified.cores()];
211212
r.threads = [cpuid.unified.threads()];
@@ -384,8 +385,15 @@ MemoryInfo getMemoryInfo()
384385
r.count = dmi.getFromDmi("Type:").length;
385386
r.slots = dmi.getFromDmi("Memory Device")
386387
.filter!(a => a.indexOf("DMI type 17") != -1).array.length;
387-
r.totalGB = dmi.getFromDmi("Size:").map!(a => a.split(" ")[0]).array.filter!(isNumeric).array.map!(to!int).array.sum();
388-
r.total =r.totalGB.to!string ~ " GB (" ~ dmi.getFromDmi("Size:").map!(a => a.split(" ")[0]).join("/") ~ ")";
388+
r.totalGB = dmi.getFromDmi("Size:").map!(a => a.split(" ")[0])
389+
.array
390+
.filter!(isNumeric)
391+
.array
392+
.map!(to!int)
393+
.array
394+
.sum();
395+
r.total = r.totalGB.to!string ~ " GB (" ~ dmi.getFromDmi("Size:")
396+
.map!(a => a.split(" ")[0]).join("/") ~ ")";
389397
auto totalWidth = dmi.getFromDmi("Total Width");
390398
auto dataWidth = dmi.getFromDmi("Data Width");
391399
foreach (i, width; totalWidth)
@@ -570,7 +578,8 @@ DisplayInfo getDisplayInfo()
570578
d.model = ("Model" in edidData) ? edidData["Model"] : "Unknown";
571579
d.serial = ("Serial Number" in edidData) ? edidData["Serial Number"] : "Unknown";
572580
d.manufactureDate = ("Made in" in edidData) ? edidData["Made in"] : "Unknown";
573-
d.size = ("Maximum image size" in edidData) ? edidData["Maximum image size"] : "Unknown";
581+
d.size = ("Maximum image size" in edidData) ? edidData["Maximum image size"]
582+
: "Unknown";
574583
}
575584

576585
r.displays ~= d;
@@ -596,11 +605,14 @@ struct GraphicsProcessorInfo
596605
GraphicsProcessorInfo getGraphicsProcessorInfo()
597606
{
598607
GraphicsProcessorInfo r;
599-
if ("DISPLAY" !in environment) return r;
600-
try {
608+
if ("DISPLAY" !in environment)
609+
return r;
610+
try
611+
{
601612
auto glxinfo = getProcInfo(execute("glxinfo", false), false);
602613
r.vendor = ("OpenGL vendor string" in glxinfo) ? glxinfo["OpenGL vendor string"] : "Unknown";
603-
r.model = ("OpenGL renderer string" in glxinfo) ? glxinfo["OpenGL renderer string"] : "Unknown";
614+
r.model = ("OpenGL renderer string" in glxinfo) ? glxinfo["OpenGL renderer string"]
615+
: "Unknown";
604616
r.coreProfile = ("OpenGL core profile version string" in glxinfo) ? glxinfo["OpenGL core profile version string"] : "Unknown";
605617
r.vram = ("Video memory" in glxinfo) ? glxinfo["Video memory"] : "Unknown";
606618
}
@@ -641,7 +653,6 @@ MachineConfigInfo getMachineConfigInfo()
641653
{
642654
MachineConfigInfo r;
643655

644-
645656
// PCI devices
646657
foreach (path; dirEntries("/sys/bus/pci/devices", SpanMode.shallow).map!(a => a.name).array)
647658
{
@@ -751,31 +762,38 @@ MachineConfigInfo getMachineConfigInfo()
751762
}
752763

753764
if (_module != "" &&
754-
// Mass-storage controller. Definitely important.
755-
_class.startsWith("0x08") ||
756-
// Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
757-
(subClass.startsWith("0x03") || protocol.startsWith("0x01")))
765+
// Mass-storage controller. Definitely important.
766+
_class.startsWith("0x08") ||
767+
// Keyboard. Needed if we want to use the keyboard when things go wrong in the initrd.
768+
(subClass.startsWith("0x03") || protocol.startsWith("0x01")))
758769
{
759770
r.availableKernelModules ~= _module;
760771
}
761772
}
762773

763774
// Block and MMC devices
764775
foreach (path; (
765-
(exists("/sys/class/block") ? dirEntries("/sys/class/block", SpanMode.shallow).array : []) ~
766-
(exists("/sys/class/mmc_host") ? dirEntries("/sys/class/mmc_host", SpanMode.shallow).array : []))
776+
(exists("/sys/class/block") ? dirEntries("/sys/class/block", SpanMode.shallow)
777+
.array : []) ~
778+
(exists("/sys/class/mmc_host") ? dirEntries("/sys/class/mmc_host", SpanMode.shallow).array
779+
: []))
767780
.map!(a => a.name).array)
768781
{
769-
if (exists(path ~ "/device/driver/module")) {
782+
if (exists(path ~ "/device/driver/module"))
783+
{
770784
string _module = readLink(path ~ "/device/driver/module").baseName;
771785
r.availableKernelModules ~= _module;
772786
}
773787
}
774788
// Bcache
775-
auto bcacheDevices = dirEntries("/dev", SpanMode.shallow).map!(a => a.name).array.filter!(a => a.startsWith("bcache")).array;
789+
auto bcacheDevices = dirEntries("/dev", SpanMode.shallow).map!(a => a.name)
790+
.array
791+
.filter!(a => a.startsWith("bcache"))
792+
.array;
776793
bcacheDevices = bcacheDevices.filter!(device => device.indexOf("dev/bcachefs") == -1).array;
777794

778-
if (bcacheDevices.length > 0) {
795+
if (bcacheDevices.length > 0)
796+
{
779797
r.availableKernelModules ~= "bcache";
780798
}
781799
//Prevent unbootable systems if LVM snapshots are present at boot time.
@@ -785,27 +803,29 @@ MachineConfigInfo getMachineConfigInfo()
785803
}
786804
// Check if we're in a VirtualBox guest. If so, enable the guest additions.
787805
auto virt = execute!ProcessPipes("systemd-detect-virt", false).stdout.readln.strip;
788-
switch (virt) {
789-
case "oracle":
790-
r.literalAttrs ~= Literal("virtualisation.virtualbox.guest.enable = true;");
791-
break;
792-
case "parallels":
793-
r.literalAttrs ~= Literal("hardware.parallels.enable = true;");
794-
r.literalAttrs ~= Literal("nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \"prl-tools\" ];");
795-
break;
796-
case "qemu":
797-
case "kvm":
798-
case "bochs":
799-
r.imports ~= Literal("(modulesPath + \"/profiles/qemu-guest.nix\")");
800-
break;
801-
case "microsoft":
802-
r.literalAttrs ~= Literal("virtualization.hypervGuest.enable = true;");
803-
break;
804-
case "systemd-nspawn":
805-
r.literalAttrs ~= Literal("boot.isContainer;");
806-
break;
807-
default:
808-
break;
806+
switch (virt)
807+
{
808+
case "oracle":
809+
r.literalAttrs ~= Literal("virtualisation.virtualbox.guest.enable = true;");
810+
break;
811+
case "parallels":
812+
r.literalAttrs ~= Literal("hardware.parallels.enable = true;");
813+
r.literalAttrs ~= Literal(
814+
"nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ \"prl-tools\" ];");
815+
break;
816+
case "qemu":
817+
case "kvm":
818+
case "bochs":
819+
r.imports ~= Literal("(modulesPath + \"/profiles/qemu-guest.nix\")");
820+
break;
821+
case "microsoft":
822+
r.literalAttrs ~= Literal("virtualization.hypervGuest.enable = true;");
823+
break;
824+
case "systemd-nspawn":
825+
r.literalAttrs ~= Literal("boot.isContainer;");
826+
break;
827+
default:
828+
break;
809829
}
810830

811831
return r;

0 commit comments

Comments
 (0)