This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
/
poco.cake
313 lines (256 loc) · 10.1 KB
/
poco.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
enum ComponentGroup
{
Firebase,
Google,
MLKit
}
enum FrameworkSource
{
Targets,
Pods,
Custom
}
struct Arch
{
public static Arch ArmV7 { get; } = new Arch("armv7");
public static Arch ArmV7k { get; } = new Arch("armv7k");
public static Arch Arm64 { get; } = new Arch("arm64");
public static Arch Arm64e { get; } = new Arch("arm64e");
public static Arch Arm64_32 { get; } = new Arch("arm64_32");
public static Arch i386 { get; } = new Arch("i386");
public static Arch x86_64 { get; } = new Arch("x86_64");
public string Value { get; private set; }
Arch (string value)
{
Value = value;
}
public override string ToString () => Value;
}
struct Sdk
{
public static Sdk iPhoneOS { get; } = new Sdk("iphoneos");
public static Sdk iPhoneSimulator { get; } = new Sdk("iphonesimulator");
public static Sdk macCatalyst { get; } = new Sdk("maccatalyst");
public static Sdk macOS { get; } = new Sdk("macosx");
public static Sdk tvOS { get; } = new Sdk("appletvos");
public static Sdk tvSimulator { get; } = new Sdk("appletvsimulator");
public static Sdk watchOS { get; } = new Sdk("watchos");
public static Sdk watchSimulator { get; } = new Sdk("watchsimulator");
public string Value { get; private set; }
Sdk (string value)
{
Value = value;
}
public override string ToString () => Value;
}
struct PlatformV2
{
#region Properties
public Sdk Sdk { get; private set; }
// If null, default archs will be used at build time.
public Arch[] Archs { get; private set; }
#endregion
#region Constructors
PlatformV2 (Sdk sdk, Arch[] archs) {
Sdk = sdk;
Archs = archs;
}
#endregion
#region Public Functionality
public static PlatformV2 Create (Sdk sdk, Arch[] archs = null) => new PlatformV2 (sdk, archs);
public override string ToString () => $"{Sdk} => {string.Join (", ", Archs)}";
#endregion
}
struct Platform
{
#region Properties
public string Arch { get; private set; }
public string Sdk { get; private set; }
public static Platform iOSSimulator { get; } = new Platform ("i386", "iphonesimulator");
public static Platform iOSSimulator64 { get; } = new Platform ("x86_64", "iphonesimulator");
public static Platform iOSArmV7 { get; } = new Platform ("armv7", "iphoneos");
public static Platform iOSArmV7s { get; } = new Platform ("armv7s", "iphoneos");
public static Platform iOSArm64 { get; } = new Platform ("arm64", "iphoneos");
#endregion
#region Constructors
Platform (string arch, string sdk) {
Arch = arch;
Sdk = sdk;
}
#endregion
#region Public Functionality
public static Platform Create (string arch, string sdk) => new Platform (arch, sdk);
public override string ToString () => $"{Arch} => {Sdk}";
#endregion
#region Operations
public static bool operator == (Platform first, Platform second) =>
string.Equals (first.ToString (), second.ToString ());
public static bool operator != (Platform first, Platform second) =>
!string.Equals (first.ToString (), second.ToString ());
public override bool Equals (object obj) =>
obj is Platform platform && this == platform;
public override int GetHashCode () =>
base.GetHashCode ();
#endregion
}
class Repository
{
// The url of the repo where the podspec lives.
public string Url { get; private set; }
// The name of the branch that the repo will use.
public string Branch { get; private set; }
// The name of the tag that the repo will use.
// If null, Branch value will be used.
public string Tag { get; private set; }
// The name of the tag that the repo will use.
// If null, Tag value will be used.
public string Commit { get; private set; }
public Repository (string url, string branch = null, string tag = null, string commit = null)
{
Url = url;
Branch = branch;
Tag = tag;
Commit = commit;
}
}
class PodSpec
{
public enum PodSource {
PodVersion,
LocalPath,
Repository
}
// The podspec name
public string Name { get; private set; }
// The podspec version if any, the component version otherwise.
public string Version { get; private set; }
// The local path where the podspec lives in your machine.
public FilePath LocalPath { get; private set; }
// The repo data where the podspec is fetch.
public Repository Repository { get; private set; }
// Target used to build the Xcode Pods project.
// If null, Name property value will be used.
public string TargetName { get; private set; }
// Overrides the default framework's name built with Pods project and Xcode.
// If null, Name property value will be used.
public string FrameworkName { get; private set; }
// The desired subspec to be used.
// If null, default subspecs defined within the podspec will be used.
public string [] SubSpecs { get; private set; }
// If true and when Subspecs property is not null, default subspecs
// defined within the podspec will added to the Podfile. Otherwise,
// only subSpecs specified in Subspecs will be used. False by default.
public bool UseDefaultSubspecs { get; private set; }
// Specify the source where the framework will be gotten.
// From a .targets file by default.
public FrameworkSource FrameworkSource { get; private set; }
// If true, the podspec can be built using Xcode. True by default.
public bool CanBeBuild { get; private set; }
public PodSource Source { get; private set; }
PodSpec () { }
static PodSpec Create (string name, string version, FilePath localPath, Repository repository, string targetName, string frameworkName, FrameworkSource frameworkSource, string [] subSpecs, bool useDefaultSubspecs, bool canBeBuild, PodSource source)
{
return new PodSpec {
Name = name,
Version = version,
LocalPath = localPath,
Repository = repository,
TargetName = targetName ?? name,
FrameworkName = frameworkName ?? name,
FrameworkSource = frameworkSource,
SubSpecs = subSpecs,
UseDefaultSubspecs = useDefaultSubspecs,
CanBeBuild = canBeBuild,
Source = source
};
}
public static PodSpec Create (string name, string version, string targetName = null, string frameworkName = null, FrameworkSource frameworkSource = FrameworkSource.Targets, string [] subSpecs = null, bool useDefaultSubspecs = false, bool canBeBuild = true)
=> Create (name, version, null, null, targetName ?? name, frameworkName ?? name, frameworkSource, subSpecs, useDefaultSubspecs, canBeBuild, PodSource.PodVersion);
public static PodSpec Create (string name, FilePath localPath, string targetName = null, string frameworkName = null, FrameworkSource frameworkSource = FrameworkSource.Targets, string [] subSpecs = null, bool useDefaultSubspecs = false, bool canBeBuild = true)
=> Create (name, null, localPath, null, targetName ?? name, frameworkName ?? name, frameworkSource, subSpecs, useDefaultSubspecs, canBeBuild, PodSource.LocalPath);
public static PodSpec Create (string name, Repository repository, string targetName = null, string frameworkName = null, FrameworkSource frameworkSource = FrameworkSource.Targets, string [] subSpecs = null, bool useDefaultSubspecs = false, bool canBeBuild = true)
=> Create (name, null, null, repository, targetName ?? name, frameworkName ?? name, frameworkSource, subSpecs, useDefaultSubspecs, canBeBuild, PodSource.Repository);
public string [] BuildPodLines ()
{
var podLines = new List<string> ();
var podLine = BuildBasePodLine ();
if (SubSpecs == null) {
podLines.Add (string.Format (podLine, Name));
return podLines.ToArray ();
}
if (UseDefaultSubspecs)
podLines.Add (string.Format (podLine, Name));
foreach (var subSpec in SubSpecs)
podLines.Add (string.Format (podLine, $"{Name}/{subSpec}"));
return podLines.ToArray ();
}
string BuildBasePodLine ()
{
switch (Source) {
case PodSource.PodVersion:
return $"\tpod '{{0}}', '{Version}'";
case PodSource.LocalPath:
return $"\tpod '{{0}}', :path => '{LocalPath.FullPath}'";
case PodSource.Repository:
var pod = $"\tpod '{{0}}', :git => '{Repository.Url}'";
if (!string.IsNullOrWhiteSpace (Repository.Branch))
pod += $", :branch => '{Repository.Branch}'";
else if (!string.IsNullOrWhiteSpace (Repository.Tag))
pod += $", :tag => '{Repository.Tag}'";
else if (!string.IsNullOrWhiteSpace (Repository.Commit))
pod += $", :commit => '{Repository.Commit}'";
return pod;
}
return null;
}
}
class Artifact : IEquatable<Artifact>
{
// The id of the component.
public string Id { get; set; }
// The version to be published on NuGet.
public string NugetVersion { get; set; }
// The minimun iOS supported version of the component.
public string MinimunSupportedVersion { get; set; }
// If it's a Firebase or Google component.
public ComponentGroup ComponentGroup { get; set; }
// The C# project name. This will have the Id property value if not specified.
public string CsprojName { get; set; }
// Other Google/Firebase components that make this component work.
public Artifact [] Dependencies { get; set; }
// The component build order.
public int BuildOrder { get => Dependencies?.Length + 1 ?? 1; }
// The specs used in the Podfile.
public PodSpec [] PodSpecs { get; set; }
// Extra code to be added to Podfile.
public string [] ExtraPodfileLines { get; set; }
// The samples created to test the component.
public string [] Samples { get; set; }
// If true, this is ignored by the build.
// false by default.
public bool Ignore { get; set; }
public Artifact (string id, string nugetVersion, string minimunSupportedVersion, ComponentGroup componentType, string csprojName = null, Artifact [] dependencies = null, PodSpec [] podSpecs = null, string [] extraPodfileLines = null, string [] samples = null, bool ignore = false)
{
Id = id;
NugetVersion = nugetVersion;
MinimunSupportedVersion = minimunSupportedVersion;
ComponentGroup = componentType;
CsprojName = csprojName ?? id;
Dependencies = dependencies;
PodSpecs = podSpecs;
ExtraPodfileLines = extraPodfileLines;
Samples = samples;
Ignore = ignore;
}
public bool Equals (Artifact other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
return Id == other.Id;
}
public override int GetHashCode()
{
int hashCode = Id.GetHashCode();
return hashCode ^ hashCode;
}
}