Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Link storyboards as part of the IBTool task if Xcode >= 7.0 #45

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions msbuild/Xamarin.MacDev.Tasks.Core/Tasks/IBToolTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using Xamarin.MacDev;

namespace Xamarin.MacDev.Tasks
{
public abstract class IBToolTaskBase : XcodeCompilerToolTask
Expand Down Expand Up @@ -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<string, string> environment, ProcessArgumentBuilder args, ITaskItem[] items)
{
environment.Add ("IBSC_MINIMUM_COMPATIBILITY_VERSION", minimumDeploymentTarget);
Expand Down Expand Up @@ -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<ITaskItem> ();
var outputManifests = new List<ITaskItem> ();
var compiled = new List<ITaskItem> ();
bool changed = false;

if (InterfaceDefinitions.Length > 0) {
if (AppManifest != null) {
Expand Down Expand Up @@ -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);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Extra {} (I think, I'm not great with the mono style, if not, sorry for the noise).

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);
Expand All @@ -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);
}
Expand All @@ -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<ITaskItem> ();
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 ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Xamarin.MacDev.Tasks
{
public abstract class XcodeCompilerToolTask : Task
{
protected bool Link { get; set; }
IList<string> prefixes;
string toolExe;

Expand All @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big issue, but I think you can do:

var ibtool = Path.Combine ("obj", "iPhoneSimulator", "Debug", AppleSdkSettings.XcodeVersion.Major >= 7 ? "ibtool-link": "ibtool");

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);
Expand Down