-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdependencies-tasks.cake
185 lines (148 loc) · 6.67 KB
/
dependencies-tasks.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#l "dependencies-variables.cake"
using System.Xml.Linq;
//-------------------------------------------------------------
public class DependenciesProcessor : ProcessorBase
{
public DependenciesProcessor(BuildContext buildContext)
: base(buildContext)
{
}
public override bool HasItems()
{
return BuildContext.Dependencies.Items.Count > 0;
}
public override async Task PrepareAsync()
{
BuildContext.CakeContext.Information($"Checking '{BuildContext.Dependencies.Items.Count}' dependencies");
if (!HasItems())
{
return;
}
// We need to go through this twice because a dependency can be a dependency of a dependency
var dependenciesToBuild = new List<string>();
// Check whether projects should be processed, `.ToList()`
// is required to prevent issues with foreach
for (int i = 0; i < 3; i++)
{
foreach (var dependency in BuildContext.Dependencies.Items.ToList())
{
if (dependenciesToBuild.Contains(dependency))
{
// Already done
continue;
}
BuildContext.CakeContext.Information($"Checking dependency '{dependency}' using run {i + 1}");
if (BuildContext.Dependencies.ShouldBuildDependency(dependency, dependenciesToBuild))
{
BuildContext.CakeContext.Information($"Dependency '{dependency}' should be included");
dependenciesToBuild.Add(dependency);
}
}
}
// TODO: How to determine the sort order? E.g. dependencies of dependencies?
foreach (var dependency in BuildContext.Dependencies.Items.ToList())
{
if (!dependenciesToBuild.Contains(dependency))
{
BuildContext.CakeContext.Information($"Skipping dependency '{dependency}' because no dependent projects are included");
BuildContext.Dependencies.Dependencies.Remove(dependency);
BuildContext.Dependencies.Items.Remove(dependency);
}
}
}
public override async Task UpdateInfoAsync()
{
if (!HasItems())
{
return;
}
foreach (var dependency in BuildContext.Dependencies.Items)
{
CakeContext.Information("Updating version for dependency '{0}'", dependency);
var projectFileName = GetProjectFileName(BuildContext, dependency);
CakeContext.TransformConfig(projectFileName, new TransformationCollection
{
{ "Project/PropertyGroup/PackageVersion", BuildContext.General.Version.NuGet }
});
}
}
public override async Task BuildAsync()
{
if (!HasItems())
{
return;
}
foreach (var dependency in BuildContext.Dependencies.Items)
{
BuildContext.CakeContext.LogSeparator("Building dependency '{0}'", dependency);
var projectFileName = GetProjectFileName(BuildContext, dependency);
var msBuildSettings = new MSBuildSettings
{
Verbosity = Verbosity.Quiet,
//Verbosity = Verbosity.Diagnostic,
ToolVersion = MSBuildToolVersion.Default,
Configuration = BuildContext.General.Solution.ConfigurationName,
MSBuildPlatform = MSBuildPlatform.x86, // Always require x86, see platform for actual target platform,
PlatformTarget = PlatformTarget.MSIL
};
ConfigureMsBuild(BuildContext, msBuildSettings, dependency, "build");
// Note: we need to set OverridableOutputPath because we need to be able to respect
// AppendTargetFrameworkToOutputPath which isn't possible for global properties (which
// are properties passed in using the command line)
var isCppProject = IsCppProject(projectFileName);
if (isCppProject)
{
// Special C++ exceptions
msBuildSettings.MSBuildPlatform = MSBuildPlatform.Automatic;
msBuildSettings.PlatformTarget = PlatformTarget.Win32;
}
// SourceLink specific stuff
if (IsSourceLinkSupported(BuildContext, dependency, projectFileName))
{
var repositoryUrl = BuildContext.General.Repository.Url;
var repositoryCommitId = BuildContext.General.Repository.CommitId;
CakeContext.Information("Repository url is specified, enabling SourceLink to commit '{0}/commit/{1}'",
repositoryUrl, repositoryCommitId);
// TODO: For now we are assuming everything is git, we might need to change that in the future
// See why we set the values at https://github.com/dotnet/sourcelink/issues/159#issuecomment-427639278
msBuildSettings.WithProperty("EnableSourceLink", "true");
msBuildSettings.WithProperty("EnableSourceControlManagerQueries", "false");
msBuildSettings.WithProperty("PublishRepositoryUrl", "true");
msBuildSettings.WithProperty("RepositoryType", "git");
msBuildSettings.WithProperty("RepositoryUrl", repositoryUrl);
msBuildSettings.WithProperty("RevisionId", repositoryCommitId);
InjectSourceLinkInProjectFile(BuildContext, dependency, projectFileName);
}
RunMsBuild(BuildContext, dependency, projectFileName, msBuildSettings, "build");
// Specific code signing, requires the following MSBuild properties:
// * CodeSignEnabled
// * CodeSignCommand
//
// This feature is built to allow projects that have post-build copy
// steps (e.g. for assets) to be signed correctly before being embedded
if (ShouldSignImmediately(BuildContext, dependency))
{
SignProjectFiles(BuildContext, dependency);
}
}
}
public override async Task PackageAsync()
{
if (!HasItems())
{
return;
}
// No packaging required for dependencies
}
public override async Task DeployAsync()
{
if (!HasItems())
{
return;
}
// No deployment required for dependencies
}
public override async Task FinalizeAsync()
{
}
}