2019-07-13 04:07:31 +03:00
|
|
|
#load "poco.cake"
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-31 09:58:03 +03:00
|
|
|
// Podfile basic structure
|
|
|
|
var PODFILE_BEGIN = new [] {
|
|
|
|
"platform :ios, '{0}'",
|
|
|
|
"install! 'cocoapods', :integrate_targets => false",
|
|
|
|
"use_frameworks!",
|
|
|
|
};
|
|
|
|
var PODFILE_TARGET = new [] {
|
|
|
|
"target 'XamarinGoogle' do",
|
|
|
|
};
|
|
|
|
var PODFILE_END = new [] {
|
|
|
|
"end",
|
|
|
|
};
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
void AddArtifactDependencies (List<Artifact> list, Artifact [] dependencies)
|
|
|
|
{
|
|
|
|
if (dependencies == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list.AddRange (dependencies);
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
foreach (var dependency in dependencies)
|
|
|
|
AddArtifactDependencies (list, dependency.Dependencies);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateVersionInCsproj (Artifact artifact)
|
|
|
|
{
|
|
|
|
var componentGroup = artifact.ComponentGroup.ToString ();
|
|
|
|
var csprojPath = $"./source/{componentGroup}/{artifact.CsprojName}/{artifact.CsprojName}.csproj";
|
|
|
|
XmlPoke(csprojPath, "/Project/PropertyGroup/FileVersion", artifact.NugetVersion);
|
|
|
|
XmlPoke(csprojPath, "/Project/PropertyGroup/PackageVersion", artifact.NugetVersion);
|
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
void CreateAndInstallPodfile (Artifact artifact)
|
2016-04-20 21:40:45 +03:00
|
|
|
{
|
2019-07-13 04:07:31 +03:00
|
|
|
if (artifact.PodSpecs?.Length == 0)
|
2016-04-20 21:40:45 +03:00
|
|
|
return;
|
2019-07-13 04:07:31 +03:00
|
|
|
|
|
|
|
var podfile = new List<string> ();
|
|
|
|
var podfileBegin = new List<string> (PODFILE_BEGIN);
|
|
|
|
|
|
|
|
podfileBegin [0] = string.Format (podfileBegin [0], artifact.MinimunSupportedVersion);
|
|
|
|
podfile.AddRange (podfileBegin);
|
|
|
|
|
2019-07-31 09:58:03 +03:00
|
|
|
if (artifact.ExtraPodfileLines != null)
|
|
|
|
podfile.AddRange (artifact.ExtraPodfileLines);
|
|
|
|
|
|
|
|
podfile.AddRange (PODFILE_TARGET);
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
foreach (var podSpec in artifact.PodSpecs) {
|
|
|
|
if (podSpec.FrameworkSource != FrameworkSource.Pods)
|
|
|
|
continue;
|
|
|
|
|
2019-09-28 08:17:14 +03:00
|
|
|
podfile.AddRange (podSpec.BuildPodLines ());
|
2019-07-13 04:07:31 +03:00
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-09-28 08:17:14 +03:00
|
|
|
if (podfile.Count == PODFILE_BEGIN.Length + PODFILE_TARGET.Length + (artifact.ExtraPodfileLines?.Length ?? 0))
|
2019-07-13 04:07:31 +03:00
|
|
|
return;
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
podfile.AddRange (PODFILE_END);
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
var podfilePath = $"./externals/{artifact.Id}";
|
|
|
|
EnsureDirectoryExists (podfilePath);
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
FileWriteLines ($"{podfilePath}/Podfile", podfile.ToArray ());
|
|
|
|
CocoaPodInstall (podfilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuildSdkOnPodfile (Artifact artifact)
|
2016-04-20 21:40:45 +03:00
|
|
|
{
|
2019-07-13 04:07:31 +03:00
|
|
|
if (artifact.PodSpecs?.Length == 0)
|
2018-03-19 23:00:48 +03:00
|
|
|
return;
|
|
|
|
|
2019-09-28 08:17:14 +03:00
|
|
|
var baseArch = Platform.iOSArmV7;
|
|
|
|
var platforms = new [] { baseArch, Platform.iOSArm64, Platform.iOSSimulator64, Platform.iOSSimulator };
|
2019-07-13 04:07:31 +03:00
|
|
|
var podsProject = "./Pods/Pods.xcodeproj";
|
|
|
|
var workingDirectory = (DirectoryPath)$"./externals/{artifact.Id}";
|
|
|
|
|
|
|
|
foreach (var podSpec in artifact.PodSpecs)
|
|
|
|
{
|
2019-09-28 08:17:14 +03:00
|
|
|
if (podSpec.FrameworkSource != FrameworkSource.Pods)
|
2019-07-13 04:07:31 +03:00
|
|
|
continue;
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
var framework = $"{podSpec.FrameworkName}.framework";
|
|
|
|
var paths = GetDirectories($"{workingDirectory}/Pods/**/{framework}");
|
|
|
|
|
|
|
|
if (paths?.Count <= 0) {
|
2019-09-28 08:17:14 +03:00
|
|
|
if (!podSpec.CanBeBuild)
|
|
|
|
continue;
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
BuildXcodeFatFramework (podsProject, podSpec.TargetName, platforms, libraryTitle: podSpec.FrameworkName, workingDirectory: workingDirectory);
|
|
|
|
CopyDirectory ($"{workingDirectory}/{framework}", $"./externals/{framework}");
|
|
|
|
} else {
|
|
|
|
foreach (var path in paths)
|
|
|
|
CopyDirectory (path, $"./externals/{framework}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanVisualStudioSolution ()
|
2016-04-20 21:40:45 +03:00
|
|
|
{
|
2019-07-13 04:07:31 +03:00
|
|
|
MSBuild(SOLUTION_PATH, c => {
|
|
|
|
c.Configuration = "Release";
|
|
|
|
c.Restore = true;
|
|
|
|
c.MaxCpuCount = 0;
|
|
|
|
c.Targets.Add("Clean");
|
|
|
|
});
|
|
|
|
|
|
|
|
var deleteDirectorySettings = new DeleteDirectorySettings {
|
|
|
|
Recursive = true,
|
|
|
|
Force = true
|
|
|
|
};
|
|
|
|
|
|
|
|
var bins = GetDirectories("./**/bin");
|
|
|
|
DeleteDirectories (bins, deleteDirectorySettings);
|
|
|
|
|
|
|
|
var objs = GetDirectories("./**/obj");
|
|
|
|
DeleteDirectories (objs, deleteDirectorySettings);
|
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-08-09 00:07:22 +03:00
|
|
|
void RestoreVisualStudioSolution ()
|
|
|
|
{
|
|
|
|
MSBuild(SOLUTION_PATH, c => {
|
|
|
|
c.Restore = true;
|
|
|
|
c.MaxCpuCount = 0;
|
|
|
|
c.Targets.Clear();
|
|
|
|
c.Targets.Add("Restore");
|
|
|
|
});
|
2019-08-27 08:41:15 +03:00
|
|
|
NuGetRestore (SOLUTION_PATH);
|
2019-08-09 00:07:22 +03:00
|
|
|
}
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
void BuildXcodeFatLibrary (FilePath xcodeProject, string target, Platform [] platforms, string libraryTitle = null, string librarySuffix = null, DirectoryPath workingDirectory = null)
|
|
|
|
{
|
|
|
|
if (!IsRunningOnUnix())
|
|
|
|
{
|
|
|
|
Warning("{0} is not available on the current platform.", "xcodebuild");
|
2016-04-20 21:40:45 +03:00
|
|
|
return;
|
2019-07-13 04:07:31 +03:00
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
libraryTitle = libraryTitle ?? target;
|
|
|
|
workingDirectory = workingDirectory ?? Directory("./externals/");
|
|
|
|
var libraryFile = (FilePath)(librarySuffix != null ? $"{libraryTitle}.{librarySuffix}" : $"{libraryTitle}");
|
|
|
|
var archsFiles = new List<FilePath> ();
|
|
|
|
|
|
|
|
var buildArch = new Action<string, string, FilePath>((sdk, arch, dest) => {
|
|
|
|
if (FileExists(dest))
|
|
|
|
return;
|
|
|
|
|
|
|
|
XCodeBuild(new XCodeBuildSettings
|
|
|
|
{
|
|
|
|
Project = workingDirectory.CombineWithFilePath(xcodeProject).ToString(),
|
|
|
|
Target = target,
|
|
|
|
Sdk = sdk,
|
|
|
|
Arch = arch,
|
|
|
|
Configuration = "Release",
|
2019-08-09 08:22:16 +03:00
|
|
|
Verbose = true
|
2016-04-20 21:40:45 +03:00
|
|
|
});
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
var outputPath = workingDirectory.Combine("build").Combine($"Release-{sdk}").Combine (target).CombineWithFilePath($"lib{libraryTitle}.a");
|
|
|
|
CopyFile(outputPath, dest);
|
|
|
|
});
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
foreach (var platform in platforms) {
|
|
|
|
var archFile = $"{libraryTitle}-{platform.Arch}";
|
|
|
|
archsFiles.Add (archFile);
|
|
|
|
buildArch (platform.Sdk, platform.Arch, workingDirectory.CombineWithFilePath (archFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
RunLipoCreate (workingDirectory, libraryTitle, archsFiles.ToArray ());
|
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
void BuildXcodeFatFramework (FilePath xcodeProject, string target, Platform [] platforms, string libraryTitle = null, string librarySuffix = null, DirectoryPath workingDirectory = null)
|
2016-04-20 21:40:45 +03:00
|
|
|
{
|
2019-07-13 04:07:31 +03:00
|
|
|
if (!IsRunningOnUnix ()) {
|
|
|
|
Warning("{0} is not available on the current platform.", "xcodebuild");
|
|
|
|
return;
|
|
|
|
}
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
libraryTitle = libraryTitle ?? target;
|
|
|
|
workingDirectory = workingDirectory ?? Directory("./externals/");
|
|
|
|
var libraryFile = (FilePath)(librarySuffix != null ? $"{libraryTitle}.{librarySuffix}" : $"{libraryTitle}");
|
|
|
|
var fatFramework = (DirectoryPath)$"{libraryTitle}.framework";
|
|
|
|
var fatFrameworkPath = workingDirectory.Combine (fatFramework);
|
|
|
|
var archsPaths = new List<FilePath> ();
|
|
|
|
|
|
|
|
var buildArch = new Action<string, string, DirectoryPath> ((sdk, arch, dest) => {
|
|
|
|
if (DirectoryExists (dest))
|
|
|
|
return;
|
|
|
|
|
|
|
|
XCodeBuild (new XCodeBuildSettings {
|
|
|
|
Project = workingDirectory.CombineWithFilePath (xcodeProject).ToString (),
|
|
|
|
Target = target,
|
|
|
|
Sdk = sdk,
|
|
|
|
Arch = arch,
|
|
|
|
Configuration = "Release",
|
2019-08-09 08:22:16 +03:00
|
|
|
Verbose = true
|
2019-07-13 04:07:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
var outputPath = workingDirectory.Combine ("build").Combine ($"Release-{sdk}").Combine (target).Combine (fatFramework);
|
|
|
|
CopyDirectory (outputPath, dest);
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach (var platform in platforms) {
|
|
|
|
var archPath = (DirectoryPath)$"{libraryTitle}-{platform.Arch}.framework";
|
|
|
|
archsPaths.Add (archPath.CombineWithFilePath (libraryTitle));
|
|
|
|
buildArch (platform.Sdk, platform.Arch, workingDirectory.Combine (archPath));
|
|
|
|
|
|
|
|
if (!DirectoryExists (fatFrameworkPath))
|
|
|
|
CopyDirectory (workingDirectory.Combine (archPath), fatFrameworkPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
RunLipoCreate (workingDirectory, fatFramework.CombineWithFilePath (libraryFile), archsPaths.ToArray ());
|
|
|
|
|
|
|
|
if (libraryTitle != target && FileExists (fatFrameworkPath.CombineWithFilePath (target)))
|
|
|
|
DeleteFile (fatFrameworkPath.CombineWithFilePath (target));
|
2016-04-20 21:40:45 +03:00
|
|
|
}
|
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
bool TargetExistsInXcodeProject (FilePath xcodeProject, string target, DirectoryPath workingDirectory = null)
|
|
|
|
{
|
|
|
|
workingDirectory = workingDirectory ?? Directory("./externals/");
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
var processSettings = new ProcessSettings {
|
|
|
|
Arguments = $"-project {workingDirectory.CombineWithFilePath (xcodeProject)} -list",
|
|
|
|
RedirectStandardOutput = true
|
|
|
|
};
|
2016-04-20 21:40:45 +03:00
|
|
|
|
2019-07-13 04:07:31 +03:00
|
|
|
using(var process = StartAndReturnProcess("xcodebuild", processSettings))
|
|
|
|
{
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
foreach (var line in process.GetStandardOutput ())
|
|
|
|
if (line.Contains (target))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|