Skip to content

Commit 3776ab9

Browse files
committed
wip
1 parent 7c8ef82 commit 3776ab9

File tree

17 files changed

+911
-689
lines changed

17 files changed

+911
-689
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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ 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;
43-
44-
}
40+
info("Running ", __traits(identifier, cmd));
41+
cmd();
42+
info("Execution Succesfull");
43+
return 0;
44+
}
4545
}
4646
catch (Exception e)
4747
{
@@ -53,8 +53,9 @@ int main(string[] args)
5353
void setLogLevel(LogLevel l)
5454
{
5555
import std.logger : globalLogLevel, sharedLog;
56+
5657
globalLogLevel = l;
57-
(cast()sharedLog()).logLevel = l;
58+
(cast() sharedLog()).logLevel = l;
5859
}
5960

6061
int wrongUsage(string error)
Lines changed: 54 additions & 53 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;
6-
import std.algorithm : map;
4+
import std.json : parseJSON, JSONValue;
5+
import std.stdio : writeln, write;
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,58 +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-
string arch = "aarch64";
43-
}
44-
version (X86_64) {
45-
string arch = "x86_64";
46-
}
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";
4735

48-
version (linux) {
49-
string os = "linux";
50-
}
51-
version (OSX) {
52-
string os = "darwin";
53-
}
36+
version (linux)
37+
static immutable string os = "linux";
38+
else version (OSX)
39+
static immutable string os = "darwin";
5440

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

67-
foreach (line; res.stderr.byLine)
68-
{
69-
"\r".write;
70-
line.write;
71-
}
72-
"".writeln;
73-
auto json = parseJSON(res.stdout.byLine.join("\n").to!string);
74-
auto path = json.array[0]["outputs"]["out"].str;
75-
execute(["cachix", "push", params.cachixCache, path], false, true).writeln;
76-
}
77-
}
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";
55+
56+
auto matrix = nixEvalJobs(params, platform, cachixUrl, false);
57+
matrix.each!(handlePackage);
58+
}
7859

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;
7980
}
8081
}

0 commit comments

Comments
 (0)