Skip to content

Commit

Permalink
[msbuild] Share the Pack/UnpackLibraryResources targets between Xamar…
Browse files Browse the repository at this point in the history
…in.iOS and Xamarin.Mac. (xamarin#9471)

There were 2 differences that had to be reconciled:

* The Xamarin.Mac version took 'IntermediateOutputPath' as the intermediate
  output path, while the Xamarin.iOS version used
  'DeviceSpecificIntermediateOutputPath'.
  'DeviceSpecificIntermediateOutputPath' is defined to be
  'IntermediateOutputPath' for Xamarin.Mac, so make the shared version use
  'DeviceSpecificIntermediateOutputPath', since that works in both cases.

* The Xamarin.Mac version was writing the output of PackLibraryResources to
  the FileWrites item group. This was removed on purpose from the Xamarin.iOS
  version in e97d69b, so it seemed best to
  leave it out in the shared version as well.

Also re-use the _EmbeddedResourcePrefix variable to determine the resource prefix.
  • Loading branch information
rolfbjarne committed Aug 25, 2020
1 parent 622656a commit 18ca278
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 51 deletions.
24 changes: 0 additions & 24 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,6 @@ Copyright (C) 2014 Xamarin. All rights reserved.
</CreateInstallerPackage>
</Target>

<Target Name="_PackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'false'" DependsOnTargets="_CollectBundleResources">
<PackLibraryResources
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="xammac"
BundleResourcesWithLogicalNames="@(_BundleResourceWithLogicalName)">
<Output TaskParameter="EmbeddedResources" ItemName="EmbeddedResource" />
</PackLibraryResources>
</Target>

<Target Name="_UnpackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="ResolveReferences;_CollectBundleResources">
<UnpackLibraryResources
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="xammac"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(IntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ReferencePath)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="FileWrites" />
</UnpackLibraryResources>
</Target>

<Target Name="_GenerateBundleName">
<PropertyGroup>
<AppBundleDir>$(OutputPath)$(_AppBundleName)$(AppBundleExtension)</AppBundleDir>
Expand Down
4 changes: 0 additions & 4 deletions msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ Copyright (C) 2020 Microsoft. All rights reserved.
</Target>

<Target Name="_CreateEmbeddedResources" DependsOnTargets="_CollectBundleResources">
<PropertyGroup>
<_EmbeddedResourcePrefix Condition="'$(_PlatformName)' == 'macOS'">xammac</_EmbeddedResourcePrefix>
<_EmbeddedResourcePrefix Condition="'$(_PlatformName)' != 'macOS'">monotouch</_EmbeddedResourcePrefix>
</PropertyGroup>
<CreateEmbeddedResources BundleResources="@(_BundleResourceWithLogicalName)" Prefix="$(_EmbeddedResourcePrefix)">
<Output ItemName="EmbeddedResource" TaskParameter="EmbeddedResources" />
</CreateEmbeddedResources>
Expand Down
4 changes: 4 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ Copyright (C) 2020 Microsoft. All rights reserved.
<!-- EnableOnDemandResources: default to true for Xamarin.iOS and false for Xamarin.Mac -->
<EnableOnDemandResources Condition="'$(_PlatformName)' == 'macOS' And '$(EnableOnDemandResources)' == ''">false</EnableOnDemandResources>
<EnableOnDemandResources Condition="'$(_PlatformName)' != 'macOS' And '$(EnableOnDemandResources)' == ''">true</EnableOnDemandResources>

<!-- This is the prefix used for embedded resources, both for library projects and binding projects -->
<_EmbeddedResourcePrefix Condition="'$(_PlatformName)' == 'macOS'">xammac</_EmbeddedResourcePrefix>
<_EmbeddedResourcePrefix Condition="'$(_PlatformName)' != 'macOS'">monotouch</_EmbeddedResourcePrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(IsBindingProject)' == 'true'">
Expand Down
23 changes: 23 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,29 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</DetectSdkLocations>
</Target>

<Target Name="_PackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'false'" DependsOnTargets="_CollectBundleResources">
<PackLibraryResources
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="$(_EmbeddedResourcePrefix)"
BundleResourcesWithLogicalNames="@(_BundleResourceWithLogicalName)">
<Output TaskParameter="EmbeddedResources" ItemName="EmbeddedResource" />
</PackLibraryResources>
</Target>

<Target Name="_UnpackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="ResolveReferences;_CollectBundleResources">
<UnpackLibraryResources
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="$(_EmbeddedResourcePrefix)"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ReferencePath);@(ReferenceDependencyPaths)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
</UnpackLibraryResources>
</Target>

<Target Name="_ParseBundlerArguments">
<ParseBundlerArguments
ExtraArgs="$(_BundlerArguments)"
Expand Down
23 changes: 0 additions & 23 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -359,29 +359,6 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
</MetalLib>
</Target>

<Target Name="_PackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'false'" DependsOnTargets="_CollectBundleResources">
<PackLibraryResources
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
Prefix="monotouch"
BundleResourcesWithLogicalNames="@(_BundleResourceWithLogicalName)">
<Output TaskParameter="EmbeddedResources" ItemName="EmbeddedResource" />
</PackLibraryResources>
</Target>

<Target Name="_UnpackLibraryResources" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="ResolveReferences;_CollectBundleResources">
<UnpackLibraryResources
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
Prefix="monotouch"
NoOverwrite="@(_BundleResourceWithLogicalName)"
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferencedLibraries="@(ReferencePath);@(ReferenceDependencyPaths)">
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
</UnpackLibraryResources>
</Target>

<Target Name="_GenerateBundleName" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="_ComputeTargetArchitectures;_GenerateAppBundleName;_GenerateAppExBundleName">
<PropertyGroup>
<_AppResourcesPath>$(_AppBundlePath)</_AppResourcesPath>
Expand Down

0 comments on commit 18ca278

Please sign in to comment.