Skip to content

Commit 879078e

Browse files
committed
refactor(mcl/utils/json): Refactor and format
1 parent e578c45 commit 879078e

File tree

14 files changed

+630
-614
lines changed

14 files changed

+630
-614
lines changed

flake.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
};
198198

199199
dlang-nix = {
200-
url = "github:PetarKirov/dlang.nix?branch=feat/build-dub-package&rev=dab4c199ad644dc23b0b9481e2e5a063e9492b84";
200+
url = "github:PetarKirov/dlang.nix?branch=feat/build-dub-package&rev=21b1b3b18b3b635a43b319612aff529d26b1863b";
201201
inputs = {
202202
flake-compat.follows = "flake-compat";
203203
flake-parts.follows = "flake-parts";

packages/mcl/src/main.d

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ int main(string[] args)
4141
cmd();
4242
info("Execution Succesfull");
4343
return 0;
44-
4544
}
4645
}
4746
catch (Exception e)

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

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module mcl.commands.ci;
33
import std.file : readText;
44
import std.json : parseJSON, JSONValue;
55
import std.stdio : writeln, write;
6-
import std.algorithm : map;
6+
import std.algorithm : map, each;
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, Package;
13+
import mcl.commands.shard_matrix : generateShardMatrix, Shard;
1414
import mcl.utils.path : rootDir, createResultDirs;
1515
import mcl.utils.process : execute;
1616
import mcl.utils.nix : nix;
@@ -23,64 +23,59 @@ export void ci()
2323
params = parseEnv!Params;
2424

2525
auto shardMatrix = generateShardMatrix();
26-
foreach (shard; shardMatrix.include)
27-
{
28-
writeln("Shard ", shard.prefix ~ " ", shard.postfix ~ " ", shard.digit);
29-
params.flakePre = shard.prefix;
30-
params.flakePost = shard.postfix;
26+
shardMatrix.include.each!(handleShard);
27+
}
3128

32-
if (params.flakePre == "")
33-
{
34-
params.flakePre = "checks";
35-
}
36-
if (params.flakePost != "")
37-
{
38-
params.flakePost = "." ~ params.flakePost;
39-
}
40-
string cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";
41-
version (AArch64)
42-
{
43-
string arch = "aarch64";
44-
}
45-
version (X86_64)
46-
{
47-
string arch = "x86_64";
48-
}
29+
static immutable(SupportedSystem) platform()
30+
{
31+
version (AArch64)
32+
static immutable string arch = "aarch64";
33+
else version (X86_64)
34+
static immutable string arch = "x86_64";
4935

50-
version (linux)
51-
{
52-
string os = "linux";
53-
}
54-
version (OSX)
55-
{
56-
string os = "darwin";
57-
}
36+
version (linux)
37+
static immutable string os = "linux";
38+
else version (OSX)
39+
static immutable string os = "darwin";
5840

59-
auto matrix = nixEvalJobs(params, (arch ~ "_" ~ os).to!(SupportedSystem), cachixUrl, false);
60-
foreach (pkg; matrix)
61-
{
62-
if (pkg.isCached)
63-
{
64-
writeln("Package ", pkg.name, " is cached");
65-
}
66-
else
67-
{
68-
writeln("Package ", pkg.name, " is not cached; building...");
69-
ProcessPipes res = execute!ProcessPipes([
70-
"nix", "build", "--json", ".#" ~ pkg.attrPath
71-
]);
41+
return (arch ~ "_" ~ os).to!(SupportedSystem);
42+
}
7243

73-
foreach (line; res.stderr.byLine)
74-
{
75-
"\r".write;
76-
line.write;
77-
}
78-
"".writeln;
79-
auto json = parseJSON(res.stdout.byLine.join("\n").to!string);
80-
auto path = json.array[0]["outputs"]["out"].str;
81-
execute(["cachix", "push", params.cachixCache, path], false, true).writeln;
82-
}
83-
}
44+
void handleShard(Shard shard)
45+
{
46+
writeln("Shard ", shard.prefix ~ " ", shard.postfix ~ " ", shard.digit);
47+
params.flakePre = shard.prefix;
48+
params.flakePost = shard.postfix;
49+
50+
if (params.flakePre == "")
51+
params.flakePre = "checks";
52+
if (params.flakePost != "")
53+
params.flakePost = "." ~ params.flakePost;
54+
string cachixUrl = "https://" ~ params.cachixCache ~ ".cachix.org";
8455

56+
auto matrix = nixEvalJobs(params, platform, cachixUrl, false);
57+
matrix.each!(handlePackage);
58+
}
59+
60+
void handlePackage(Package pkg)
61+
{
62+
if (pkg.isCached)
63+
writeln("Package ", pkg.name, " is cached");
64+
else
65+
{
66+
writeln("Package ", pkg.name, " is not cached; building...");
67+
ProcessPipes res = execute!ProcessPipes([
68+
"nix", "build", "--json", ".#" ~ pkg.attrPath
69+
]);
70+
71+
foreach (line; res.stderr.byLine)
72+
{
73+
"\r".write;
74+
line.write;
75+
}
76+
"".writeln;
77+
auto json = parseJSON(res.stdout.byLine.join("\n").to!string);
78+
auto path = json.array[0]["outputs"]["out"].str;
79+
execute(["cachix", "push", params.cachixCache, path], false, true).writeln;
8580
}
8681
}

0 commit comments

Comments
 (0)