-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild.cs
More file actions
65 lines (55 loc) · 2.02 KB
/
Build.cs
File metadata and controls
65 lines (55 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Build.cs — task runner for ArcNET
// Usage: dotnet run --project Build.cs -- <command>
// Commands: build | test | format | format-check | bench | publish
//
// Requires .NET 10 SDK. Run from the repo root.
using System;
using System.Diagnostics;
using System.IO;
var command = args.Length > 0 ? args[0].ToLowerInvariant() : "build";
var root = Path.GetDirectoryName(Path.GetFullPath("Build.cs"))!;
var slnx = Path.Combine(root, "ArcNET.Build.slnx");
switch (command)
{
case "build":
Run("dotnet", $"build {slnx} -c Release");
break;
case "test":
foreach (var testProj in Directory.GetFiles(root, "*.Tests.csproj", SearchOption.AllDirectories))
Run("dotnet", $"run --project {testProj}");
break;
case "format":
Run("dotnet", "csharpier format .");
Run("dotnet", $"format style {slnx}");
Run("dotnet", $"format analyzers {slnx}");
break;
case "format-check":
Run("dotnet", "csharpier check .");
Run("dotnet", $"format style {slnx} --verify-no-changes");
Run("dotnet", $"format analyzers {slnx} --verify-no-changes");
break;
case "bench":
var benchProj = Path.Combine(root, "src", "Benchmarks", "ArcNET.Benchmarks");
Run("dotnet", $"run --project {benchProj} -c Release");
break;
case "publish":
Run("dotnet", $"pack {slnx} -c Release -o artifacts/nuget");
break;
default:
Console.Error.WriteLine($"Unknown command: {command}");
Console.Error.WriteLine("Usage: dotnet run --project Build.cs -- build|test|format|format-check|bench|publish");
Environment.Exit(1);
break;
}
static void Run(string cmd, string args)
{
Console.WriteLine($"\n> {cmd} {args}");
var psi = new ProcessStartInfo(cmd, args) { UseShellExecute = false };
var p = Process.Start(psi)!;
p.WaitForExit();
if (p.ExitCode != 0)
{
Console.Error.WriteLine($"Command failed with exit code {p.ExitCode}");
Environment.Exit(p.ExitCode);
}
}