Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9475c00
[msbuild] Fix duplicated property declaration.
rolfbjarne May 2, 2024
02aa4c3
[msbuild] Refactor out function in CollectBundleResource to make code…
rolfbjarne Apr 29, 2024
c55bab1
[msbuild] Refactor out function in CompileSceneKitAssets to make code…
rolfbjarne Apr 29, 2024
77e4f70
[msbuild] Add support for bundling original resources in libraries. F…
rolfbjarne Feb 1, 2024
490614e
[msbuild] Add support for packing/unpacking PartialAppManifest items.
rolfbjarne Apr 30, 2024
e14dfc5
[tests] Automatically set properties for remote builds.
rolfbjarne Feb 1, 2024
85fa443
[tests] Add test.
rolfbjarne Jan 30, 2024
efbb53c
[msbuild] Honor the LogicalName metadata on TextureAtlas items.
rolfbjarne Apr 30, 2024
67954f7
[msbuild] Fix LogicalName for SceneKitAsset items.
rolfbjarne May 2, 2024
bb1e94c
Auto-format source code
May 3, 2024
2177ffd
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne May 6, 2024
8b0ad44
Try another method of fixing atlas textures.
rolfbjarne May 7, 2024
8ecc619
Merge branch 'main' into msbuild-bundle-original-resources-in-libraries
rolfbjarne May 23, 2024
cfa94e1
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne May 24, 2024
2fd38d8
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne May 30, 2024
cc79482
[devops] Unset MAC_AGENT_IP for local testing.
rolfbjarne Jun 4, 2024
8a73137
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 4, 2024
57ee5de
[tests] Adjust to accept Windows-style paths.
rolfbjarne Jun 4, 2024
b5bdd82
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 5, 2024
782b2ff
[msbuild] Don't execute the _CreateEmbeddedResources and _PackLibrary…
rolfbjarne Jun 5, 2024
8abbc2d
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 5, 2024
b9d659b
[tests] Adjust expected output in an MSBuild test.
rolfbjarne Jun 6, 2024
76da034
Merge branch 'main' into msbuild-bundle-original-resources-in-libraries
rolfbjarne Jun 6, 2024
fd1fcff
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 7, 2024
9dc54f5
Update expected file paths in tests.
rolfbjarne Jun 7, 2024
bd09355
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 7, 2024
5539271
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 10, 2024
8ef6f84
Always collect bundle resources if we're bundling original resources.
rolfbjarne Jun 10, 2024
5763594
[msbuild] Don't call _ResolveUniversalTypeIdentifiers when bundling o…
rolfbjarne Jun 10, 2024
bb37489
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 10, 2024
2c26edf
Add debug spew.
rolfbjarne Jun 11, 2024
740ac04
Merge remote-tracking branch 'origin/main' into msbuild-bundle-origin…
rolfbjarne Jun 12, 2024
2954c94
Fix warning causing test failure.
rolfbjarne Jun 17, 2024
68ddde6
Merge branch 'main' into msbuild-bundle-original-resources-in-libraries
rolfbjarne Jun 20, 2024
3bcd674
Merge branch 'main' into msbuild-bundle-original-resources-in-libraries
rolfbjarne Jun 25, 2024
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
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<!-- outer build for multi-rid build -->
<BuildDependsOn Condition="'$(RuntimeIdentifiers)' != ''">
_ErrorRuntimeIdentifiersClash;
BuildOnlySettings;
_CollectBundleResources;
_RunRidSpecificBuild;
_DetectAppManifest;
Expand Down
75 changes: 45 additions & 30 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CollectBundleResources.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -31,6 +33,8 @@ public class CollectBundleResources : XamarinTask, ICancelableTask {
[Output]
public ITaskItem [] BundleResourcesWithLogicalNames { get; set; } = Array.Empty<ITaskItem> ();

public ITaskItem [] UnpackedResources { get; set; } = Array.Empty<ITaskItem> ();

#endregion

static bool CanOptimize (string path)
Expand Down Expand Up @@ -68,37 +72,8 @@ bool ExecuteImpl ()
var bundleResources = new List<ITaskItem> ();

foreach (var item in BundleResources) {
// Skip anything with the PublishFolderType metadata, these are copied directly to the ResolvedFileToPublish item group instead.
var publishFolderType = item.GetMetadata ("PublishFolderType");
if (!string.IsNullOrEmpty (publishFolderType))
continue;

var logicalName = BundleResource.GetLogicalName (ProjectDir, prefixes, item, !string.IsNullOrEmpty (SessionId));
// We need a physical path here, ignore the Link element
var path = item.GetMetadata ("FullPath");

if (!File.Exists (path)) {
Log.LogError (MSBStrings.E0099, logicalName, path);
continue;
}

if (logicalName.StartsWith (".." + Path.DirectorySeparatorChar, StringComparison.Ordinal)) {
Log.LogError (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0100, logicalName);
continue;
}

if (logicalName == "Info.plist") {
Log.LogWarning (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0101);
if (!TryCreateItemWithLogicalName (this, item, ProjectDir, prefixes, SessionId, out var bundleResource))
continue;
}

if (BundleResource.IsIllegalName (logicalName, out var illegal)) {
Log.LogError (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0102, illegal);
continue;
}

var bundleResource = new TaskItem (item);
bundleResource.SetMetadata ("LogicalName", logicalName);

bool optimize = false;

Expand All @@ -122,11 +97,51 @@ bool ExecuteImpl ()
bundleResources.Add (bundleResource);
}

bundleResources.AddRange (UnpackedResources);

BundleResourcesWithLogicalNames = bundleResources.ToArray ();

return !Log.HasLoggedErrors;
}

public static bool TryCreateItemWithLogicalName (Task task, ITaskItem item, string projectDir, IList<string> prefixes, string sessionId, [NotNullWhen (true)] out TaskItem? itemWithLogicalName)
{
itemWithLogicalName = null;

// Skip anything with the PublishFolderType metadata, these are copied directly to the ResolvedFileToPublish item group instead.
var publishFolderType = item.GetMetadata ("PublishFolderType");
if (!string.IsNullOrEmpty (publishFolderType))
return false;

var logicalName = BundleResource.GetLogicalName (projectDir, prefixes, item, !string.IsNullOrEmpty (sessionId));
// We need a physical path here, ignore the Link element
var path = item.GetMetadata ("FullPath");

if (!File.Exists (path)) {
task.Log.LogError (MSBStrings.E0099, logicalName, path);
return false;
}

if (logicalName.StartsWith (".." + Path.DirectorySeparatorChar, StringComparison.Ordinal)) {
task.Log.LogError (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0100, logicalName);
return false;
}

if (logicalName == "Info.plist") {
task.Log.LogWarning (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0101);
return false;
}

if (BundleResource.IsIllegalName (logicalName, out var illegal)) {
task.Log.LogError (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0102, illegal);
return false;
}

itemWithLogicalName = new TaskItem (item);
itemWithLogicalName.SetMetadata ("LogicalName", logicalName);
return true;
}

public void Cancel ()
{
if (ShouldExecuteRemotely ())
Expand Down
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 {
#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, ProjectDir, prefixes, SessionId, out var itemWithLogicalName))
continue;

itemWithLogicalName.SetMetadata ("OriginalItemGroup", itemName);
rv.Add (itemWithLogicalName);
}
}

ItemsWithLogicalNames = rv.ToArray ();

return !Log.HasLoggedErrors;
}
}
}
23 changes: 16 additions & 7 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ Task CopySceneKitAssets (string scnassets, string output, string intermediate)
return ExecuteAsync (GetFullPathToTool (), args, sdkDevPath: SdkDevPath, environment: environment, showErrorIfFailure: true);
}

static bool TryGetScnAssetsPath (string file, out string scnassets)
{
scnassets = file;
while (scnassets.Length > 0 && Path.GetExtension (scnassets).ToLowerInvariant () != ".scnassets")
scnassets = Path.GetDirectoryName (scnassets);
return scnassets.Length > 0;
}

public override bool Execute ()
{
if (ShouldExecuteRemotely ()) {
Expand All @@ -141,15 +149,9 @@ public override bool Execute ()
continue;

// get the .scnassets directory path
var scnassets = Path.GetDirectoryName (asset.ItemSpec);
while (scnassets.Length > 0 && Path.GetExtension (scnassets).ToLowerInvariant () != ".scnassets")
scnassets = Path.GetDirectoryName (scnassets);

if (scnassets.Length == 0)
if (!TryGetScnAssetsPath (asset.ItemSpec, out var scnassets))
continue;

asset.RemoveMetadata ("LogicalName");

var bundleName = BundleResource.GetLogicalName (ProjectDir, prefixes, asset, !string.IsNullOrEmpty (SessionId));
var output = new TaskItem (Path.Combine (intermediate, bundleName));

Expand All @@ -160,6 +162,13 @@ public override bool Execute ()
// .. but we really want it to be for @scnassets, so set ItemSpec accordingly
scnassetsItem.ItemSpec = scnassets;

// .. and set LogicalName, the original one is for @asset
if (!TryGetScnAssetsPath (bundleName, out var logicalScnAssetsPath)) {
Log.LogError (null, null, null, asset.ItemSpec, $"Unable to compute the path of the *.scnassets path from the item's LogicalName '{bundleName}'");
continue;
}
scnassetsItem.SetMetadata ("LogicalName", logicalScnAssetsPath);

// .. and remove the @OriginalItemSpec which is for @asset
scnassetsItem.RemoveMetadata ("OriginalItemSpec");

Expand Down
3 changes: 3 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CoreMLCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public override bool Execute ()
var bundleResources = new List<ITaskItem> ();
var partialPlists = new List<ITaskItem> ();

// Log.LogWarning ($"IntermediateOutputPath: {IntermediateOutputPath}");
// Log.LogWarning ($"CoreML output dir: {coremlcOutputDir}");

if (Models.Length > 0) {
Directory.CreateDirectory (coremlcOutputDir);

Expand Down
29 changes: 1 addition & 28 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CreateEmbeddedResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,8 @@ public class CreateEmbeddedResources : XamarinTask {
[Output]
public ITaskItem [] EmbeddedResources { get; set; } = Array.Empty<ITaskItem> ();

static string EscapeMangledResource (string name)
{
var mangled = new StringBuilder ();

for (int i = 0; i < name.Length; i++) {
switch (name [i]) {
case '\\': mangled.Append ("_b"); break;
case '/': mangled.Append ("_f"); break;
case '_': mangled.Append ("__"); break;
default: mangled.Append (name [i]); break;
}
}

return mangled.ToString ();
}

public override bool Execute ()
{
if (ShouldExecuteRemotely ()) {
foreach (var bundleResource in this.BundleResources) {
var logicalName = bundleResource.GetMetadata ("LogicalName");

if (!string.IsNullOrEmpty (logicalName)) {
logicalName = logicalName.Replace ("\\", "/");
bundleResource.SetMetadata ("LogicalName", logicalName);
}
}
}

EmbeddedResources = new ITaskItem [BundleResources.Length];

for (int i = 0; i < BundleResources.Length; i++) {
Expand All @@ -56,7 +29,7 @@ public override bool Execute ()
bundleResource.CopyMetadataTo (embeddedResource);

// mangle the resource name
var logicalName = "__" + Prefix + "_content_" + EscapeMangledResource (bundleResource.GetMetadata ("LogicalName"));
var logicalName = "__" + Prefix + "_content_" + PackLibraryResources.EscapeMangledResource (bundleResource.GetMetadata ("LogicalName"));
embeddedResource.SetMetadata ("LogicalName", logicalName);

// add it to the output connection
Expand Down
Loading