From 7ee37c1803663346d2e5faa0b8b2b5d84632a5bb Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 12 May 2016 15:24:54 -0400 Subject: [PATCH] [msbuild] Link storyboards as part of the IBTool task if Xcode >= 7.0 Fixes issue #40583 --- .../Tasks/IBToolTaskBase.cs | 74 +++++++++++-------- .../Tasks/XcodeCompilerToolTask.cs | 3 +- .../Xamarin.iOS.Common.targets | 1 + .../TargetTests/TargetTests.cs | 8 +- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/IBToolTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/IBToolTaskBase.cs index ac0061fc6127..5996b3bcd84a 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/IBToolTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/IBToolTaskBase.cs @@ -5,8 +5,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using Xamarin.MacDev; - namespace Xamarin.MacDev.Tasks { public abstract class IBToolTaskBase : XcodeCompilerToolTask @@ -37,6 +35,10 @@ protected override string ToolName { protected abstract bool AutoActivateCustomFonts { get; } + protected bool CanLinkStoryboards { + get { return AppleSdkSettings.XcodeVersion.Major >= 7; } + } + protected override void AppendCommandLineArguments (IDictionary environment, ProcessArgumentBuilder args, ITaskItem[] items) { environment.Add ("IBSC_MINIMUM_COMPATIBILITY_VERSION", minimumDeploymentTarget); @@ -183,9 +185,10 @@ public override bool Execute () var ibtoolManifestDir = Path.Combine (IntermediateOutputPath, ToolName + "-manifests"); var ibtoolOutputDir = Path.Combine (IntermediateOutputPath, ToolName); - var linkOutputDir = Path.Combine (IntermediateOutputPath, ToolName + "-link"); var bundleResources = new List (); var outputManifests = new List (); + var compiled = new List (); + bool changed = false; if (InterfaceDefinitions.Length > 0) { if (AppManifest != null) { @@ -218,21 +221,24 @@ public override bool Execute () continue; } - if (UseCompilationDirectory) { - rpath = Path.Combine (ibtoolOutputDir, Path.GetDirectoryName (bundleName)); - output = new TaskItem (rpath); - outputDir = rpath; + rpath = Path.Combine (ibtoolOutputDir, bundleName); + outputDir = Path.GetDirectoryName (rpath); + output = new TaskItem (rpath); - output.SetMetadata ("LogicalName", Path.GetDirectoryName (bundleName)); - } else { - rpath = Path.Combine (ibtoolOutputDir, bundleName); - outputDir = Path.GetDirectoryName (rpath); - output = new TaskItem (rpath); + output.SetMetadata ("LogicalName", bundleName); + output.SetMetadata ("Optimize", "false"); - output.SetMetadata ("LogicalName", bundleName); + if (Path.GetExtension (bundleName) != ".plist") { + // Don't include Watch storyboards that got compiled to plists + compiled.Add (output); } - output.SetMetadata ("Optimize", "false"); + if (UseCompilationDirectory) { + // Note: When using --compilation-directory, we need to specify the output path as the parent directory + output = new TaskItem (output); + output.ItemSpec = Path.GetDirectoryName (output.ItemSpec); + output.SetMetadata ("LogicalName", Path.GetDirectoryName (bundleName)); + } if (!string.IsNullOrEmpty (resourceTags)) output.SetMetadata ("ResourceTags", resourceTags); @@ -256,6 +262,8 @@ public override bool Execute () return false; } + + changed = true; } else { Log.LogMessage (MessageImportance.Low, "Skipping `{0}' as the output file, `{1}', is newer.", item.ItemSpec, manifest.ItemSpec); } @@ -281,38 +289,40 @@ public override bool Execute () var output = new TaskItem (ibtoolOutputDir); output.SetMetadata ("LogicalName", ""); - bundleResources.AddRange (GetCompiledBundleResources (output)); + if (!CanLinkStoryboards) + bundleResources.AddRange (GetCompiledBundleResources (output)); } - if (IsWatch2App) { - Link = true; - if (InterfaceDefinitions.Length > 0) { - var linkItems = new List (); - foreach (var item in InterfaceDefinitions) { - var linkInput = new TaskItem (item); - linkInput.ItemSpec = Path.Combine (ibtoolOutputDir, Path.GetFileName (item.ItemSpec) + "c"); - linkItems.Add (linkInput); - } + if (CanLinkStoryboards && compiled.Count > 0) { + var linkOutputDir = Path.Combine (IntermediateOutputPath, ToolName + "-link"); + var manifest = new TaskItem (Path.Combine (ibtoolManifestDir, "link")); + var output = new TaskItem (linkOutputDir); - var output = new TaskItem (linkOutputDir); - var manifest = new TaskItem (Path.Combine (ibtoolManifestDir, "link")); + if (changed) { + if (Directory.Exists (output.ItemSpec)) + Directory.Delete (output.ItemSpec, true); + + if (File.Exists (manifest.ItemSpec)) + File.Delete (manifest.ItemSpec); Directory.CreateDirectory (Path.GetDirectoryName (manifest.ItemSpec)); Directory.CreateDirectory (output.ItemSpec); - if (Compile (linkItems.ToArray (), output, manifest) != 0) { + Link = true; + + if (Compile (compiled.ToArray (), output, manifest) != 0) { if (File.Exists (manifest.ItemSpec)) File.Delete (manifest.ItemSpec); return false; } + } - output = new TaskItem (linkOutputDir); - output.SetMetadata ("LogicalName", ""); - bundleResources.AddRange (GetCompiledBundleResources (output)); + output = new TaskItem (linkOutputDir); + output.SetMetadata ("LogicalName", ""); - outputManifests.Add (manifest); - } + bundleResources.AddRange (GetCompiledBundleResources (output)); + outputManifests.Add (manifest); } BundleResources = bundleResources.ToArray (); diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/XcodeCompilerToolTask.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/XcodeCompilerToolTask.cs index 9bafe86c07d3..d6096e54beae 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/XcodeCompilerToolTask.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/XcodeCompilerToolTask.cs @@ -14,6 +14,7 @@ namespace Xamarin.MacDev.Tasks { public abstract class XcodeCompilerToolTask : Task { + protected bool Link { get; set; } IList prefixes; string toolExe; @@ -37,8 +38,6 @@ public abstract class XcodeCompilerToolTask : Task [Required] public string SdkPlatform { get; set; } - public bool Link { get; set; } - string sdkDevPath; public string SdkDevPath { get { return string.IsNullOrEmpty (sdkDevPath) ? "/" : sdkDevPath; } diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets index 22230d3d1a8e..39608cec8b21 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets @@ -353,6 +353,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. Directories="$(DeviceSpecificIntermediateOutputPath)actool; $(DeviceSpecificIntermediateOutputPath)assetpacks; $(DeviceSpecificIntermediateOutputPath)ibtool; + $(DeviceSpecificIntermediateOutputPath)ibtool-link; $(DeviceSpecificIntermediateOutputPath)ibtool-manifests; $(DeviceSpecificIntermediateOutputPath)ipa; $(DeviceSpecificIntermediateOutputPath)metal; diff --git a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs index 473e6bcb671f..bc6712303db0 100644 --- a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs +++ b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs @@ -435,10 +435,14 @@ public void UnpackLibraryResources_LibraryProject () public void BundleResources () { var actool = Path.Combine ("obj", "iPhoneSimulator", "Debug", "actool", "bundle"); - var ibtool = Path.Combine ("obj", "iPhoneSimulator", "Debug", "ibtool"); - var path = Path.Combine (MonoTouchProjectPath, "Info.plist"); var plist = PDictionary.FromFile (path); + string ibtool; + + if (AppleSdkSettings.XcodeVersion.Major >= 7) + ibtool = Path.Combine ("obj", "iPhoneSimulator", "Debug", "ibtool-link"); + else + ibtool = Path.Combine ("obj", "iPhoneSimulator", "Debug", "ibtool"); plist.SetMinimumOSVersion ("6.1"); plist.Save (path, true);