-
Notifications
You must be signed in to change notification settings - Fork 519
/
Step_GenerateFiles.cs
247 lines (212 loc) · 10.3 KB
/
Step_GenerateFiles.cs
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Xamarin.Android.Prepare
{
partial class Step_GenerateFiles : Step
{
bool atBuildStart;
bool onlyRequired;
public Step_GenerateFiles (bool atBuildStart, bool onlyRequired = false)
: base ("Generating files required by the build")
{
this.atBuildStart = atBuildStart;
this.onlyRequired = onlyRequired;
}
#pragma warning disable CS1998
protected override async Task<bool> Execute (Context context)
{
List<GeneratedFile>? filesToGenerate = GetFilesToGenerate (context);
if (filesToGenerate != null && filesToGenerate.Count > 0) {
foreach (GeneratedFile gf in filesToGenerate) {
if (gf == null)
continue;
Log.Status ("Generating ");
Log.Status (Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, gf.OutputPath), ConsoleColor.White);
if (!String.IsNullOrEmpty (gf.InputPath))
Log.StatusLine ($" {context.Characters.LeftArrow} ", Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, gf.InputPath), leadColor: ConsoleColor.Cyan, tailColor: ConsoleColor.White);
else
Log.StatusLine ();
gf.Generate (context);
}
}
return true;
}
#pragma warning restore CS1998
List<GeneratedFile>? GetFilesToGenerate (Context context)
{
if (atBuildStart) {
if (onlyRequired) {
return new List<GeneratedFile> {
Get_MonoGitHash_props (context),
Get_Configuration_Generated_Props (context),
Get_Cmake_XA_Build_Configuration (context),
new GeneratedMonodroidCmakeFiles (Configurables.Paths.BuildBinDir),
};
} else {
return new List <GeneratedFile> {
Get_Configuration_OperatingSystem_props (context),
Get_Configuration_Generated_Props (context),
Get_Cmake_XA_Build_Configuration (context),
new GeneratedMonodroidCmakeFiles (Configurables.Paths.BuildBinDir),
Get_Ndk_projitems (context),
Get_XABuildConfig_cs (context),
Get_mingw_32_cmake (context),
Get_mingw_64_cmake (context),
Get_MonoGitHash_props (context),
};
}
}
if (onlyRequired)
return null;
var steps = new List <GeneratedFile> {
new GeneratedProfileAssembliesProjitemsFile (Configurables.Paths.ProfileAssembliesProjitemsPath),
new GeneratedMonoAndroidProjitemsFile (),
};
AddOSSpecificSteps (context, steps);
AddUnixPostBuildSteps (context, steps);
return steps;
}
partial void AddUnixPostBuildSteps (Context context, List<GeneratedFile> steps);
partial void AddOSSpecificSteps (Context context, List<GeneratedFile> steps);
GeneratedFile Get_Cmake_XA_Build_Configuration (Context context)
{
const string OutputFileName = "xa_build_configuration.cmake";
var runtimePackVersion = context.BundledPreviewRuntimePackVersion;
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("arm", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM64@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("arm64", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("x86", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86_64@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("x86_64", runtimePackVersion)) },
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BuildToolsScriptsDir, $"{OutputFileName}.in"),
Path.Combine (Configurables.Paths.BuildBinDir, OutputFileName)
);
string GetNetCoreAppRuntimePath (string androidTarget, string version)
{
return Path.Combine (
Configurables.Paths.XAPackagesDir,
$"microsoft.netcore.app.runtime.android-{androidTarget}",
version,
"runtimes",
$"android-{androidTarget}"
);
}
}
GeneratedFile Get_Configuration_Generated_Props (Context context)
{
const string OutputFileName = "Configuration.Generated.props";
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@XA_PACKAGES_DIR@", Configurables.Paths.XAPackagesDir },
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BootstrapResourcesDir, $"{OutputFileName}.in"),
Configurables.Paths.ConfigurationPropsGeneratedPath
);
}
GeneratedFile Get_Configuration_OperatingSystem_props (Context context)
{
const string OutputFileName = "Configuration.OperatingSystem.props";
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@OS_NAME@", context.OS.Name ?? String.Empty },
{ "@HOST_OS_FLAVOR@", context.OS.Flavor ?? String.Empty },
{ "@OS_RELEASE@", context.OS.Release ?? String.Empty },
{ "@HOST_TRIPLE@", context.OS.Triple ?? String.Empty },
{ "@HOST_TRIPLE32@", context.OS.Triple32 ?? String.Empty },
{ "@HOST_TRIPLE64@", context.OS.Triple64 ?? String.Empty },
{ "@HOST_CPUS@", context.OS.CPUCount.ToString () },
{ "@ARCHITECTURE_BITS@", context.OS.Is64Bit ? "64" : "32" },
{ "@HOST_CC@", context.OS.CC ?? String.Empty },
{ "@HOST_CXX@", context.OS.CXX ?? String.Empty },
{ "@HOST_CC32@", context.OS.CC32 ?? String.Empty },
{ "@HOST_CC64@", context.OS.CC64 ?? String.Empty },
{ "@HOST_CXX32@", context.OS.CXX32 ?? String.Empty },
{ "@HOST_CXX64@", context.OS.CXX64 ?? String.Empty },
{ "@HOST_HOMEBREW_PREFIX@", context.OS.HomebrewPrefix ?? String.Empty },
{ "@JavaSdkDirectory@", context.OS.JavaHome },
{ "@javac@", context.OS.JavaCPath },
{ "@java@", context.OS.JavaPath },
{ "@jar@", context.OS.JarPath },
{ "@NDK_LLVM_TAG@", $"{context.OS.Type.ToLowerInvariant ()}-x86_64" },
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BootstrapResourcesDir, $"{OutputFileName}.in"),
Path.Combine (BuildPaths.XamarinAndroidSourceRoot, OutputFileName)
);
}
GeneratedFile Get_XABuildConfig_cs (Context context)
{
const string OutputFileName = "XABuildConfig.cs";
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@NDK_REVISION@", context.BuildInfo.NDKRevision },
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
{ "@NDK_MINIMUM_API_AVAILABLE@", context.BuildInfo.NDKMinimumApiAvailable },
{ "@NDK_VERSION_MAJOR@", context.BuildInfo.NDKVersionMajor },
{ "@NDK_VERSION_MINOR@", context.BuildInfo.NDKVersionMinor },
{ "@NDK_VERSION_MICRO@", context.BuildInfo.NDKVersionMicro },
{ "@NDK_ARMEABI_V7_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidArmV7a].ToString () },
{ "@NDK_ARM64_V8A_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidArmV8a].ToString () },
{ "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidX86].ToString () },
{ "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidX86_64].ToString () },
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BuildToolsScriptsDir, $"{OutputFileName}.in"),
Path.Combine (Configurables.Paths.BuildBinDir, OutputFileName)
);
}
GeneratedFile Get_Ndk_projitems (Context context)
{
const string OutputFileName = "Ndk.projitems";
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
{ "@NDK_ARMEABI_V7_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidArmV7a].ToString () },
{ "@NDK_ARMEABI_V7_API_NET6@", BuildAndroidPlatforms.NdkMinimumAPI [BuildAndroidPlatforms.AndroidArmV7a_NET6].ToString () },
{ "@NDK_ARM64_V8A_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidArmV8a].ToString () },
{ "@NDK_ARM64_V8A_API_NET6@", BuildAndroidPlatforms.NdkMinimumAPI [BuildAndroidPlatforms.AndroidArmV8a_NET6].ToString () },
{ "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidX86].ToString () },
{ "@NDK_X86_API_NET6@", BuildAndroidPlatforms.NdkMinimumAPI [BuildAndroidPlatforms.AndroidX86_NET6].ToString () },
{ "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI [AbiNames.TargetJit.AndroidX86_64].ToString () },
{ "@NDK_X86_64_API_NET6@", BuildAndroidPlatforms.NdkMinimumAPI [BuildAndroidPlatforms.AndroidX86_64_NET6].ToString () },
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BuildToolsScriptsDir, $"{OutputFileName}.in"),
Path.Combine (Configurables.Paths.BuildBinDir, OutputFileName)
);
}
GeneratedFile Get_mingw_32_cmake (Context context)
{
return Get_mingw_cmake (context, Configurables.Paths.Mingw32CmakeTemplatePath, Configurables.Paths.Mingw32CmakePath);
}
GeneratedFile Get_mingw_64_cmake (Context context)
{
return Get_mingw_cmake (context, Configurables.Paths.Mingw64CmakeTemplatePath, Configurables.Paths.Mingw64CmakePath);
}
GeneratedFile Get_mingw_cmake (Context context, string input, string output)
{
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@HOMEBREW_PREFIX@", context.OS.HomebrewPrefix ?? String.Empty },
};
return new GeneratedPlaceholdersFile (replacements, Path.Combine (input), Path.Combine (output));
}
public GeneratedFile Get_MonoGitHash_props (Context context)
{
const string OutputFileName = "MonoGitHash.props";
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@MONO_COMMIT_HASH@", context.BuildInfo.MonoHash }
};
return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BootstrapResourcesDir, $"{OutputFileName}.in"),
Path.Combine (Configurables.Paths.BuildBinDir, OutputFileName)
);
}
}
}