Reduced build time avoiding building same framework several times

This commit is contained in:
SotoiGhost 2019-10-02 15:42:18 -05:00
Родитель 4b829fea02
Коммит d7687b97c4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 72EA2B8D62E38FAB
2 изменённых файлов: 83 добавлений и 3 удалений

Просмотреть файл

@ -1,4 +1,4 @@
#addin nuget:?package=Cake.XCode&version=4.1.0
#addin nuget:?package=Cake.XCode&version=4.2.0
#addin nuget:?package=Cake.Xamarin.Build&version=4.1.1
#addin nuget:?package=Cake.FileHelpers&version=3.2.0

Просмотреть файл

@ -77,6 +77,8 @@ void BuildSdkOnPodfile (Artifact artifact)
var podsProject = "./Pods/Pods.xcodeproj";
var workingDirectory = (DirectoryPath)$"./externals/{artifact.Id}";
var podSpecsToBuild = new List<PodSpec> ();
foreach (var podSpec in artifact.PodSpecs)
{
if (podSpec.FrameworkSource != FrameworkSource.Pods)
@ -89,13 +91,21 @@ void BuildSdkOnPodfile (Artifact artifact)
if (!podSpec.CanBeBuild)
continue;
BuildXcodeFatFramework (podsProject, podSpec.TargetName, platforms, libraryTitle: podSpec.FrameworkName, workingDirectory: workingDirectory);
CopyDirectory ($"{workingDirectory}/{framework}", $"./externals/{framework}");
podSpecsToBuild.Add (podSpec);
// 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}");
}
}
BuildXcodeFatFramework (podsProject, podSpecsToBuild.ToArray (), platforms, workingDirectory: workingDirectory);
foreach (var podSpec in podSpecsToBuild) {
var framework = $"{podSpec.FrameworkName}.framework";
CopyDirectory ($"{workingDirectory}/{framework}", $"./externals/{framework}");
}
}
void CleanVisualStudioSolution ()
@ -216,6 +226,76 @@ void BuildXcodeFatFramework (FilePath xcodeProject, string target, Platform [] p
DeleteFile (fatFrameworkPath.CombineWithFilePath (target));
}
void BuildXcodeFatFramework (FilePath xcodeProject, PodSpec [] podSpecs, Platform [] platforms, DirectoryPath workingDirectory = null, Dictionary<string, string> buildSettings = null)
{
if (!IsRunningOnUnix ()) {
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
workingDirectory = workingDirectory ?? Directory("./externals/");
foreach (var podSpec in podSpecs) {
var target = podSpec.TargetName;
var libraryTitle = podSpec.FrameworkName;
var fatFramework = (DirectoryPath)$"{libraryTitle}.framework";
foreach (var platform in platforms) {
var sdk = platform.Sdk;
var arch = platform.Arch;
var platformFramework = (DirectoryPath)$"{libraryTitle}-{arch}.framework";
var platformFrameworkPath = workingDirectory.Combine (platformFramework);
if (DirectoryExists (platformFrameworkPath))
continue;
var buildPath = buildSettings != null && buildSettings.ContainsKey ("SYMROOT") ?
Directory (buildSettings ["SYMROOT"]) : workingDirectory.Combine ("build");
XCodeBuild (new XCodeBuildSettings {
Project = workingDirectory.CombineWithFilePath (xcodeProject).ToString (),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
Verbose = true,
BuildSettings = buildSettings
});
var releasePath = buildPath.Combine ($"Release-{sdk}");
foreach (var p in podSpecs) {
var outputPath = releasePath.Combine (p.TargetName);
var lt = p.FrameworkName;
var ff = (DirectoryPath)$"{lt}.framework";
var frameworkOutputPath = outputPath.Combine (ff);
if (!DirectoryExists (frameworkOutputPath))
continue;
var fatFrameworkPath = workingDirectory.Combine (ff);
if (!DirectoryExists (fatFrameworkPath))
CopyDirectory (frameworkOutputPath, fatFrameworkPath);
var pf = (DirectoryPath)$"{lt}-{arch}.framework";
var pfp = workingDirectory.Combine (pf);
CopyDirectory (frameworkOutputPath, pfp);
}
}
var archPaths = new List<FilePath> ();
var paths = GetFiles ($"{workingDirectory}/{libraryTitle}-*/{libraryTitle}");
foreach (var path in paths)
archPaths.Add (path);
RunLipoCreate (workingDirectory, fatFramework.CombineWithFilePath (libraryTitle), archPaths.ToArray ());
}
}
bool TargetExistsInXcodeProject (FilePath xcodeProject, string target, DirectoryPath workingDirectory = null)
{
workingDirectory = workingDirectory ?? Directory("./externals/");