-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[msbuild] Add support for bundling original resources in libraries. F…
…ixes #19028. (#20822) If a library references resources, until now we've pre-compile/pre-processed some of those before embedding them the library. This applies to resources of the following item groups: * AtlasTexture * BundleResource * Collada * CoreMLModel * ImageAsset * InterfaceDefinition * SceneKitAsset However, pre-processing resources as a few problems: * It requires a native (Xcode) toolchain. * This is unfortunate when building from Windows: the current approach is that when building a library as a referenced project, the remoting part is skipped, so all such resources are just dropped. * It also means building on Linux doesn't work. * It makes it impossible to merge resources with the same name, if we wanted to do that. So I'm adding support for bundling the original resources in library projects. This is enabled using the MSBuild property `BundleOriginalResources=true`, which is turned off by default for .NET 9 and turned on by default for .NET 10+. Additionally I've added `PartialAppManifest` items to the list of bundled resources from class libraries. This means that there are numerous task we don't have to remote to the Mac anymore (when bundling original resources) - in particular libraries can be fully built on Windows (or any other platform) now. Fixes #19028. Fixes #19513.
- Loading branch information
1 parent
37963c3
commit 2943ab0
Showing
15 changed files
with
701 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
msbuild/Xamarin.MacDev.Tasks/Tasks/CollectPackLibraryResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using Xamarin.Localization.MSBuild; | ||
using Xamarin.Messaging.Build.Client; | ||
|
||
namespace Xamarin.MacDev.Tasks { | ||
// This task will collect several item groups with various types of assets/resources, | ||
// add/compute the LogicalName value for each of them, and then add them to the | ||
// ItemsWithLogicalNames item group. The items in this item group will have the | ||
// 'OriginalItemGroup' metadata set indicating where they came from. | ||
public class CollectPackLibraryResources : XamarinTask, IHasProjectDir, IHasResourcePrefix { | ||
#region Inputs | ||
|
||
public ITaskItem [] AtlasTextures { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] BundleResources { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] ImageAssets { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] InterfaceDefinitions { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] ColladaAssets { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] CoreMLModels { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] PartialAppManifests { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public ITaskItem [] SceneKitAssets { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
[Required] | ||
public string ProjectDir { get; set; } = string.Empty; | ||
|
||
[Required] | ||
public string ResourcePrefix { get; set; } = string.Empty; | ||
|
||
#endregion | ||
|
||
#region Outputs | ||
|
||
// These items will have the following metadata set: | ||
// * LogicalName | ||
// * OriginalItemGroup: the name of the originating item group | ||
[Output] | ||
public ITaskItem [] ItemsWithLogicalNames { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
#endregion | ||
|
||
public override bool Execute () | ||
{ | ||
var prefixes = BundleResource.SplitResourcePrefixes (ResourcePrefix); | ||
var rv = new List<ITaskItem> (); | ||
|
||
var resources = new [] { | ||
new { Name = "AtlasTexture", Items = AtlasTextures }, | ||
new { Name = "BundleResource", Items = BundleResources }, | ||
new { Name = "Collada", Items = ColladaAssets }, | ||
new { Name = "CoreMLModel", Items = CoreMLModels }, | ||
new { Name = "ImageAsset", Items = ImageAssets }, | ||
new { Name = "InterfaceDefinition", Items = InterfaceDefinitions }, | ||
new { Name = "PartialAppManifest", Items = PartialAppManifests }, | ||
new { Name = "SceneKitAsset", Items = SceneKitAssets }, | ||
}; | ||
|
||
foreach (var kvp in resources) { | ||
var itemName = kvp.Name; | ||
var items = kvp.Items; | ||
|
||
foreach (var item in items) { | ||
if (!CollectBundleResources.TryCreateItemWithLogicalName (this, item, out var itemWithLogicalName)) | ||
continue; | ||
|
||
itemWithLogicalName.SetMetadata ("OriginalItemGroup", itemName); | ||
rv.Add (itemWithLogicalName); | ||
} | ||
} | ||
|
||
ItemsWithLogicalNames = rv.ToArray (); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.