forked from exercism/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
96 lines (78 loc) · 3.02 KB
/
build.cake
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
var target = Argument("target", "Default");
var exercise = Argument<string>("exercise", null);
var sourceDir = "./exercises";
var buildDir = "./build";
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = System.Environment.ProcessorCount };
Task("Clean")
.Does(() => {
CleanDirectory(buildDir);
});
Task("BuildGenerators")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreBuild("./generators/Generators.fsproj");
});
// Copy everything to build so we make no changes in the actual files.
Task("CopyExercises")
.IsDependentOn("BuildGenerators")
.Does(() => {
CopyDirectory($"{sourceDir}/{exercise}", $"{buildDir}/{exercise}");
});
Task("EnableAllTests")
.IsDependentOn("CopyExercises")
.Does(() => {
var skipRegex = new Regex(@"Skip = ""Remove to run test""", RegexOptions.Compiled);
var testFiles = GetFiles(buildDir + "/*/*Test.fs");
foreach (var testFile in testFiles) {
var contents = System.IO.File.ReadAllText(testFile.FullPath);
if (skipRegex.IsMatch(contents)) {
var updatedContents = skipRegex.Replace(contents, "");
System.IO.File.WriteAllText(testFile.FullPath, updatedContents);
}
}
});
Task("TestRefactoringProjects")
.IsDependentOn("EnableAllTests")
.Does(() => {
var refactoringProjects =
GetFiles(buildDir + "/*/TreeBuilding.fsproj")
+ GetFiles(buildDir + "/*/Ledger.fsproj")
+ GetFiles(buildDir + "/*/Markdown.fsproj");
Parallel.ForEach(refactoringProjects, parallelOptions, (project) => DotNetCoreTest(project.FullPath));
});
Task("ReplaceStubWithExample")
.IsDependentOn("TestRefactoringProjects")
.Does(() => {
var projects = GetFiles(buildDir + "/*/*.fsproj");
foreach (var project in projects) {
var projectDir = project.GetDirectory();
var projectName = project.GetFilenameWithoutExtension();
var stub = projectDir.GetFilePath(projectName).AppendExtension("fs");
var example = projectDir.GetFilePath("Example.fs");
DeleteFile(stub);
MoveFile(example, stub);
}
});
Task("AddPackagesUsedInExampleImplementations")
.IsDependentOn("ReplaceStubWithExample")
.Does(() => {
var projects = GetFiles(buildDir + "/*/SgfParsing.fsproj");
Parallel.ForEach(projects, parallelOptions, (project) => DotNetCoreTool(project.FullPath, "add", "package FParsec"));
});
Task("TestUsingExampleImplementation")
.IsDependentOn("AddPackagesUsedInExampleImplementations")
.Does(() => {
if (string.IsNullOrEmpty(exercise)) {
DotNetCoreTest($"{buildDir}/Exercises.sln");
}
else {
DotNetCoreTest($"{buildDir}/{exercise}");
}
});
Task("Default")
.IsDependentOn("TestUsingExampleImplementation")
.Does(() => { });
RunTarget(target);