-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbaufile.csx
115 lines (98 loc) · 3.65 KB
/
baufile.csx
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// parameters
var versionSuffix = Environment.GetEnvironmentVariable("VERSION_SUFFIX");
versionSuffix = string.IsNullOrWhiteSpace(versionSuffix) ? "-beta" : versionSuffix;
var msBuildFileVerbosity = (Verbosity)Enum.Parse(typeof(Verbosity), Environment.GetEnvironmentVariable("MSBUILD_FILE_VERBOSITY") ?? "detailed", true);
var nugetVerbosity = Environment.GetEnvironmentVariable("NUGET_VERBOSITY") ?? "quiet";
// solution specific variables
var version = File.ReadAllText("src/CommonAssemblyInfo.cs").Split(new[] { "AssemblyInformationalVersion(\"" }, 2, StringSplitOptions.None).ElementAt(1).Split(new[] { '"' }).First();
var nugetCommand = "scriptcs_packages/NuGet.CommandLine.2.8.3/tools/NuGet.exe";
var solution = "src/ScriptCs.Engines.sln";
var output = "artifacts/output";
var logs = "artifacts/logs";
var packs = new[]
{
"src/ScriptCs.Engine.Common/ScriptCs.Engine.Common",
"src/ScriptCs.CSharp/ScriptCs.CSharp",
"src/ScriptCs.VisualBasic/ScriptCs.VisualBasic",
};
// solution agnostic tasks
var bau = Require<Bau>();
bau
.Task("default").DependsOn("pack")
.Task("logs").Do(() => CreateDirectory(logs))
.MSBuild("clean").DependsOn("logs").Do(msb => Configure(msb, "Clean"))
.Task("clobber").DependsOn("clean").Do(() => DeleteDirectory(output))
.Exec("restore").Do(exec => exec.Run(nugetCommand).With("restore", solution))
.MSBuild("build").DependsOn("clean", "restore", "logs").Do(msb => Configure(msb, "Build"))
.Task("output").Do(() => CreateDirectory(output))
.Task("pack").DependsOn("build", "clobber", "output").Do(() =>
{
foreach (var pack in packs)
{
File.Copy(pack + ".nuspec", pack + ".nuspec.original", true);
}
try
{
foreach (var pack in packs)
{
File.WriteAllText(pack + ".nuspec", File.ReadAllText(pack + ".nuspec").Replace("0.0.0", version + versionSuffix));
var project = pack + ".csproj";
bau.CurrentTask.LogInfo("Packing '" + project + "'...");
new Exec { Name = "pack " + project }
.Run(nugetCommand)
.With(
"pack", project,
"-OutputDirectory", output,
"-Properties", "Configuration=Release",
"-IncludeReferencedProjects",
"-Verbosity " + nugetVerbosity)
.Execute();
}
}
finally
{
foreach (var pack in packs)
{
File.Copy(pack + ".nuspec.original", pack + ".nuspec", true);
File.Delete(pack + ".nuspec.original");
}
}
})
.Run();
void Configure(MSBuild msb, string target)
{
msb.MSBuildVersion = "net45";
msb.Solution = solution;
msb.Targets = new[] { target, };
msb.Properties = new { Configuration = "Release" };
msb.MaxCpuCount = -1;
msb.NodeReuse = false;
msb.Verbosity = Verbosity.Minimal;
msb.NoLogo = true;
msb.FileLoggers.Add(
new FileLogger
{
FileLoggerParameters = new FileLoggerParameters
{
PerformanceSummary = true,
Summary = true,
Verbosity = msBuildFileVerbosity,
LogFile = logs + "/" + target + ".log",
}
});
}
void CreateDirectory(string name)
{
if (!Directory.Exists(name))
{
Directory.CreateDirectory(name);
System.Threading.Thread.Sleep(100); // HACK (adamralph): wait for the directory to be created
}
}
void DeleteDirectory(string name)
{
if (Directory.Exists(name))
{
Directory.Delete(name, true);
}
}