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

Xamarin.Mac Extension Support #44

Closed
wants to merge 12 commits into from
Closed
13 changes: 10 additions & 3 deletions msbuild/Xamarin.Mac.Tasks/Tasks/CompileAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public override bool Execute ()
Log.LogTaskProperty ("Architecture", Architecture);
Log.LogTaskProperty ("AssemblyName", AssemblyName);
Log.LogTaskProperty ("BundleIdentifier", BundleIdentifier);
Log.LogTaskProperty ("IsAppExtension", IsAppExtension);
Log.LogTaskProperty ("PartialAppManifests", PartialAppManifests);

try {
Expand All @@ -38,12 +39,18 @@ public override bool Execute ()
return false;
}

if (AssemblyName.IndexOf ('.') != AssemblyName.LastIndexOf ('.'))
LogAppManifestError ("The assembly name ({0}) cannot contain more than one dot.", AssemblyName);
Copy link
Member

Choose a reason for hiding this comment

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

What happens if an assembly has more than one dot?

I ran into something similar for iOS, and added the same check, but it turned out lots of people have assemblies with more than one dot, so it became problematic. After some investigation it turned out that the problem wasn't more than one dot, but executables that ended with .app.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this was part of the code I copied over from iOS (when I first looked at extensions last may). I'll update it to check for the .app instead like iOS is doing now


plist[ManifestKeys.CFBundleExecutable] = new PString (AssemblyName);

plist.SetIfNotPresent (ManifestKeys.CFBundleIdentifier, BundleIdentifier);
plist.SetIfNotPresent (ManifestKeys.CFBundleInfoDictionaryVersion, "6.0");
plist.SetIfNotPresent ("MonoBundleExecutable", AssemblyName + ".exe");
if (!IsAppExtension)
plist.SetIfNotPresent ("MonoBundleExecutable", AssemblyName + ".exe");
plist.SetIfNotPresent (ManifestKeys.CFBundleExecutable, AssemblyName);
plist.SetIfNotPresent (ManifestKeys.CFBundleName, AppBundleName);
plist.SetIfNotPresent (ManifestKeys.CFBundlePackageType, "APPL");
plist.SetIfNotPresent (ManifestKeys.CFBundlePackageType, IsAppExtension ? "XPC!" : "APPL");
plist.SetIfNotPresent (ManifestKeys.CFBundleSignature, "????");
plist.SetIfNotPresent (ManifestKeys.CFBundleVersion, "1.0");

Expand All @@ -56,4 +63,4 @@ public override bool Execute ()
return !Log.HasLoggedErrors;
}
}
}
}
14 changes: 11 additions & 3 deletions msbuild/Xamarin.Mac.Tasks/Tasks/Mmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ protected override string ToolName {
[Required]
public string SdkVersion { get; set; }

public bool IsAppExtension { get; set; }

public bool UseXamMacFullFramework { get; set; }

public string ApplicationName { get; set; }
Expand Down Expand Up @@ -163,8 +165,10 @@ protected override string GenerateCommandLineCommands ()
args.AddQuoted ("/assembly:" + Path.GetFullPath (asm));
}

if (!string.IsNullOrEmpty (ApplicationAssembly))
args.AddQuoted (Path.GetFullPath (ApplicationAssembly));
if (!string.IsNullOrEmpty(ApplicationAssembly))
{
Copy link
Member

Choose a reason for hiding this comment

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

Code style. You forgot the space between IsNullOrEmpty and the (

Copy link
Member

Choose a reason for hiding this comment

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

The opening brace also goes on the same line as the if.

args.AddQuoted(Path.GetFullPath(ApplicationAssembly + (IsAppExtension ? ".dll" : ".exe")));
}

Copy link
Member

Choose a reason for hiding this comment

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

Same, style issue.

if (!string.IsNullOrWhiteSpace (ExtraArguments))
args.Add (ExtraArguments);
Expand All @@ -173,6 +177,9 @@ protected override string GenerateCommandLineCommands ()
foreach (var nr in NativeReferences)
args.AddQuoted ("/native-reference:" + Path.GetFullPath (nr));
}

if (IsAppExtension)
args.AddQuoted ("/extension");

args.Add ("/sdkroot");
args.AddQuoted (SdkRoot);
Expand All @@ -190,7 +197,7 @@ protected override string GenerateCommandLineCommands ()
public override bool Execute ()
{
Log.LogTaskName ("Mmp");
Log.LogTaskProperty ("ApplicationAssembly", ApplicationAssembly);
Log.LogTaskProperty ("ApplicationAssembly", ApplicationAssembly + (IsAppExtension ? ".dll" : ".exe"));
Log.LogTaskProperty ("ApplicationName", ApplicationName);
Log.LogTaskProperty ("Architecture", Architecture);
Log.LogTaskProperty ("Debug", Debug);
Expand All @@ -210,6 +217,7 @@ public override bool Execute ()
Log.LogTaskProperty ("AppManifest", AppManifest);
Log.LogTaskProperty ("SdkVersion", SdkVersion);
Log.LogTaskProperty ("NativeReferences", NativeReferences);
Log.LogTaskProperty ("IsAppExtension", IsAppExtension);

return base.Execute ();
}
Expand Down
36 changes: 36 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.CSharp.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
***********************************************************************************************
Xamarin.Mac.AppExtension.CSharp.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

This file imports the version- and platform-specific targets for the project importing
this file. This file also defines targets to produce an error if the specified targets
file does not exist, but the project is built anyway (command-line or IDE build).

Copyright (C) 2014 Xamarin. All rights reserved.
***********************************************************************************************
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets')"/>

<PropertyGroup>
<!-- Version/fx properties -->
<TargetFrameworkVersion Condition="'$(TargetFrameworkIdentifier)' == '' And '$(TargetFrameworkVersion)' ==''">v4.5</TargetFrameworkVersion>
<!-- work around a bug in the Mono Microsoft.CSharp.Targets that defaults the compiler to gmcs -->
<!-- this is fixed in mono/master (2014-03-05), but we'll keep this workaround here for a while -->
<CscToolPath Condition="'$(OS)' == 'Unix'">/Library/Frameworks/Mono.framework/Commands</CscToolPath>
<CscToolExe Condition="'$(OS)' == 'Unix'">mcs</CscToolExe>

Copy link
Member

Choose a reason for hiding this comment

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

Small question, is this going to be used by VS? I'm wondering about when these two conditions are not met.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently there's no support to build mac projects in VS, only in XS on a mac

<DefineConstants>__UNIFIED__;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="Xamarin.Mac.AppExtension.Common.targets" />

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>
</Project>
32 changes: 32 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
***********************************************************************************************
Xamarin.Mac.AppExtension.Common.props

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

This file defines default properties for OS X App Extension projects.

Copyright (C) 2013-2014 Xamarin. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.props"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.props')"/>

<!-- This is used to determine whether Xamarin.Mac.AppExtension.Common.targets needs to import
Xamarin.Mac.AppExtension.Common.props itself, or whether it has been imported previously,
e.g. by the project itself. -->
<PropertyGroup>
<_XamarinAppExtensionCommonPropsHasBeenImported>true</_XamarinAppExtensionCommonPropsHasBeenImported>
<IsAppExtension>True</IsAppExtension>
<IsAppExtension Condition="'$(IsAppExtension)' == ''">True</IsAppExtension>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.props"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.props')"/>

</Project>
59 changes: 59 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.Common.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
***********************************************************************************************
Xamarin.Mac.AppExtension.Common.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

This file imports the version- and platform-specific targets for the project importing
this file. This file also defines targets to produce an error if the specified targets
file does not exist, but the project is built anyway (command-line or IDE build).

Copyright (C) 2013-2014 Xamarin. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsAppExtension>True</IsAppExtension>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)Xamarin.Mac.Common.targets" />

<Import Project="$(MSBuildThisFileDirectory)Xamarin.Mac.AppExtension.Common.props"
Condition="'$(_XamarinAppExtensionCommonPropsHasBeenImported)' != 'true'" />

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets')"/>

<!-- Override GetTargetPath, Build, and Rebuild -->
<Target Name="GetBundleTargetPath" DependsOnTargets="_GenerateBundleName;$(GetTargetPathDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="Build" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(BuildDependsOn)" Outputs="$(_AppExtensionBundlePath)" />
<Target Name="Rebuild" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(RebuildDependsOn)" Outputs="$(_AppExtensionBundlePath)" />

<Target Name="_GenerateBundleName" DependsOnTargets="_DetectSigningIdentity">
<PropertyGroup>
<AppBundleDir Condition="'$(AppBundleDir)' == ''">$(OutputPath)$(DeviceSpecificOutputPath)$(_AppBundleName).appex</AppBundleDir>
<_AppBundlePath>$(AppBundleDir)\</_AppBundlePath>

<_AppResourcesPath>$(_AppBundlePath)Contents\Resources\</_AppResourcesPath>

<!-- needed for GetTargetPath/Build/Rebuild task outputs -->
<_AppExtensionBundlePath>$(MSBuildProjectDirectory)\$(AppBundleDir)</_AppExtensionBundlePath>
</PropertyGroup>
<ItemGroup>
<_AppExtensionBundlePath Include="$(MSBuildProjectDirectory)\$(AppBundleDir)">
<!-- We need this metadata to fix the source in VS -->
<BuildSessionId>$(BuildSessionId)</BuildSessionId>
<BuildServerPath>..\..\$(BuildAppName)\$(BuildSessionId)\$(AppBundleDir)</BuildServerPath>
</_AppExtensionBundlePath>
</ItemGroup>
</Target>

<Target Name="CreateIpa"/>

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>

</Project>
1 change: 1 addition & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved.
<XamMacArch Condition="'$(XamMacArch)' == ''">x86_64</XamMacArch>
<MonoMacResourcePrefix Condition="'$(MonoMacResourcePrefix)' == ''">Resources</MonoMacResourcePrefix>
<XamMacResourcePrefix Condition="'$(XamMacResourcePrefix)' == ''">$(MonoMacResourcePrefix)</XamMacResourcePrefix>
<IsAppExtension Condition="'$(IsAppExtension)' == ''">False</IsAppExtension>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.props"
Expand Down
Loading