Skip to content

Commit

Permalink
[msbuild] Promote '_PartialAppManifest' to a public item group ('Part…
Browse files Browse the repository at this point in the history
…ialAppManifest'). Fixes #10646. (#12417)

* A couple of other changes to make sure we never overwrite the
  PartialAppManifest item group (as opposed to adding to it).
* Add tests.

Fixes #10646.
  • Loading branch information
rolfbjarne authored Aug 12, 2021
1 parent ef6793f commit aee4cc0
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public override bool Execute ()
if (!Compile (plist))
return false;

// Merge with any partial plists generated by the Asset Catalog compiler...
// Merge with any partial plists...
MergePartialPlistTemplates (plist);

CompiledAppManifest = new TaskItem (Path.Combine (AppManifestBundleDirectory, "Info.plist"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public override bool Execute ()
}

BundleResources = bundleResources.ToArray ();

if (PartialAppManifests != null)
partialPlists.AddRange (PartialAppManifests);
PartialAppManifests = partialPlists.ToArray ();

return !Log.HasLoggedErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ public override bool Execute ()
{
var document = XDocument.Load (this.File.ItemSpec);

this.Items = document.Root
var items = document.Root
.Elements (ItemGroupElementName)
.SelectMany (element => element.Elements ())
.Select (element => this.CreateItemFromElement (element))
.ToArray ();
.ToList ();

if (Items != null)
items.AddRange (Items);

Items = items.ToArray ();

return true;
}
Expand Down
16 changes: 8 additions & 8 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.

<Target Name="_CompileAppManifest"
DependsOnTargets="$(_CompileAppManifestDependsOn)"
Inputs="$(_AppManifest);@(_PartialAppManifest)"
Inputs="$(_AppManifest);@(PartialAppManifest)"
Outputs="$(_AppBundlePath)$(_AppBundleManifestRelativePath)Info.plist" >
<CompileAppManifest
SessionId="$(BuildSessionId)"
Expand All @@ -307,7 +307,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
IsWatchExtension="$(IsWatchExtension)"
IsXPCService="$(IsXPCService)"
MinimumOSVersion="$(_MinimumOSVersion)"
PartialAppManifests="@(_PartialAppManifest)"
PartialAppManifests="@(PartialAppManifest)"
ResourceRules="$(_PreparedResourceRules)"
TargetArchitectures="$(TargetArchitectures)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Expand Down Expand Up @@ -439,7 +439,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- If _BeforeCoreCompileImageAssets did not delete the generated items lists from _CoreCompileImageAsset, then we read them
since that target won't run and we need the output items that are cached in those files, which includes full metadata -->
<ReadItemsFromFile File="$(_ACTool_PartialAppManifestCache)" Condition="Exists('$(_ACTool_PartialAppManifestCache)')">
<Output TaskParameter="Items" ItemName="_PartialAppManifest" />
<Output TaskParameter="Items" ItemName="PartialAppManifest" />
</ReadItemsFromFile>
<ReadItemsFromFile File="$(_ACTool_BundleResourceCache)" Condition="Exists('$(_ACTool_BundleResourceCache)')">
<Output TaskParameter="Items" ItemName="_BundleResourceWithLogicalName" />
Expand Down Expand Up @@ -476,7 +476,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
SdkVersion="$(_SdkVersion)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
<Output TaskParameter="PartialAppManifest" ItemName="_PartialAppManifest" />
<Output TaskParameter="PartialAppManifest" ItemName="PartialAppManifest" />
<Output TaskParameter="BundleResources" ItemName="_BundleResourceWithLogicalName" />

<!-- Local items to be persisted to items files -->
Expand All @@ -485,7 +485,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</ACTool>

<!-- Cache the generated outputs items for incremental build support -->
<WriteItemsToFile Items="@(_ACTool_PartialAppManifest)" ItemName="_PartialAppManifest" File="$(_ACTool_PartialAppManifestCache)" Overwrite="true" IncludeMetadata="true" />
<WriteItemsToFile Items="@(_ACTool_PartialAppManifest)" ItemName="PartialAppManifest" File="$(_ACTool_PartialAppManifestCache)" Overwrite="true" IncludeMetadata="true" />
<WriteItemsToFile Items="@(_ACTool_BundleResources)" ItemName="_BundleResourceWithLogicalName" File="$(_ACTool_BundleResourceCache)" Overwrite="true" IncludeMetadata="true" />
<ItemGroup>
<FileWrites Include="$(_ACTool_PartialAppManifestCache);$(_ACTool_BundleResourceCache)" />
Expand Down Expand Up @@ -703,7 +703,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- If _BeforeCompileCoreMLModels did not delete the generated items lists from _CoreCompileCoreMLModels, then we read them
since that target won't run and we need the output items that are cached in those files, which includes full metadata -->
<ReadItemsFromFile File="$(_CoreMLModel_PartialAppManifestCache)" Condition="Exists('$(_CoreMLModel_PartialAppManifestCache)')">
<Output TaskParameter="Items" ItemName="_PartialAppManifest" />
<Output TaskParameter="Items" ItemName="PartialAppManifest" />
</ReadItemsFromFile>
<ReadItemsFromFile File="$(_CoreMLModel_BundleResourceCache)" Condition="Exists('$(_CoreMLModel_BundleResourceCache)')">
<Output TaskParameter="Items" ItemName="_BundleResourceWithLogicalName" />
Expand All @@ -727,15 +727,15 @@ Copyright (C) 2018 Microsoft. All rights reserved.
ResourcePrefix="$(_ResourcePrefix)"
SdkDevPath="$(_SdkDevPath)">
<Output TaskParameter="BundleResources" ItemName="_BundleResourceWithLogicalName" />
<Output TaskParameter="PartialAppManifests" ItemName="_PartialAppManifest" />
<Output TaskParameter="PartialAppManifests" ItemName="PartialAppManifest" />

<!-- Local items to be persisted to items files -->
<Output TaskParameter="PartialAppManifests" ItemName="_CoreMLModel_PartialAppManifest" />
<Output TaskParameter="BundleResources" ItemName="_CoreMLModel_BundleResources" />
</CoreMLCompiler>

<!-- Cache the generated outputs items for incremental build support -->
<WriteItemsToFile Items="@(_CoreMLModel_PartialAppManifest)" ItemName="_PartialAppManifest" File="$(_CoreMLModel_PartialAppManifestCache)" Overwrite="true" IncludeMetadata="true" />
<WriteItemsToFile Items="@(_CoreMLModel_PartialAppManifest)" ItemName="PartialAppManifest" File="$(_CoreMLModel_PartialAppManifestCache)" Overwrite="true" IncludeMetadata="true" />
<WriteItemsToFile Items="@(_CoreMLModel_BundleResources)" ItemName="_BundleResourceWithLogicalName" File="$(_CoreMLModel_BundleResourceCache)" Overwrite="true" IncludeMetadata="true" />
<ItemGroup>
<FileWrites Include="$(_CoreMLModel_PartialAppManifestCache);$(_CoreMLModel_BundleResourceCache)" />
Expand Down
19 changes: 19 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Runtime.InteropServices;

using Foundation;

namespace MySimpleApp
{
public class Program
{
static int Main (string[] args)
{
GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly

Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD"));

return args.Length;
}
}
}
6 changes: 6 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/dotnet/MyPartialAppManifestApp/MacCatalyst/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
20 changes: 20 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TOP=../../..

include $(TOP)/Make.config

prepare:
cd .. && $(MAKE) global.json NuGet.config
rm -Rf */bin */obj

all-ios: prepare
$(DOTNET6) build iOS/*.csproj /bl

all-mac: prepare
$(DOTNET6) build macOS/*.csproj /bl

run-mac:
./macOS/bin/Debug/net6.0-macos/osx-x64/$(notdir $(CURDIR)).app/Contents/MacOS/$(notdir $(CURDIR))

diag:
cd .. && $(MAKE) global.json NuGet.config
$(DOTNET6) build /v:diag *binlog
8 changes: 8 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/Partial.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Something</key>
<string>SomeValue</string>
</dict>
</plist>
8 changes: 8 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- We need this because some tests will build this project for 32-bit targets -->
<key>MinimumOSVersion</key>
<string>10.0</string></dict>
</plist>
1 change: 1 addition & 0 deletions tests/dotnet/MyPartialAppManifestApp/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
9 changes: 9 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/macOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- We need this because we'd otherwise default to the latest macOS version we support (currently 12.0), and we'll want to execute on earlier versions -->
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/dotnet/MyPartialAppManifestApp/macOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-macos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
16 changes: 16 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>

<ApplicationTitle>MyPartialAppManifestApp</ApplicationTitle>
<ApplicationId>com.xamarin.mypartialappmanifestapp</ApplicationId>
<ApplicationVersion>3.14</ApplicationVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="../*.cs" />
<None Include="Info.plist" />
<PartialAppManifest Include="../Partial.plist" />
</ItemGroup>
</Project>
28 changes: 28 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TOP=../../../..
include $(TOP)/Make.config

prepare:
$(Q) $(MAKE) -C $(TOP)/tests/dotnet copy-dotnet-config

reload:
$(Q) rm -Rf $(TOP)/tests/dotnet/packages
$(Q) $(MAKE) -C $(TOP) -j8 all
$(Q) $(MAKE) -C $(TOP) -j8 install
$(Q) git clean -xfdq

reload-and-build:
$(Q) $(MAKE) reload
$(Q) $(MAKE) build

reload-and-run:
$(Q) $(MAKE) reload
$(Q) $(MAKE) run

build: prepare
$(Q) $(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS)

run: prepare
$(Q) $(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS) -t:Run

diag: prepare
$(Q) $(DOTNET6) build /v:diag msbuild.binlog
6 changes: 6 additions & 0 deletions tests/dotnet/MyPartialAppManifestApp/tvOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/dotnet/MyPartialAppManifestApp/tvOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
34 changes: 34 additions & 0 deletions tests/dotnet/UnitTests/PartialAppManifestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;

using NUnit.Framework;

using Xamarin.Utils;
using Xamarin.MacDev;

namespace Xamarin.Tests {
public class PartialAppManifestTest : TestBaseClass {

[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
public void Build (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MyPartialAppManifestApp";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = new Dictionary<string, string> (verbosity);
SetRuntimeIdentifiers (properties, runtimeIdentifiers);

DotNet.AssertBuild (project_path, properties);

var infoPlistPath = GetInfoPListPath (platform, appPath);
var infoPlist = PDictionary.FromFile (infoPlistPath);
Assert.AreEqual ("com.xamarin.mypartialappmanifestapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MyPartialAppManifestApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
Assert.AreEqual ("SomeValue", infoPlist.GetString ("Something").Value, "Something");
}
}
}
15 changes: 0 additions & 15 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,6 @@ void AssertThatLinkerDidNotExecute (ExecutionResult result)
Assert.That (output, Does.Not.Contain ("LinkerConfiguration:"), "Custom steps did not run as expected.");
}

string GetInfoPListPath (ApplePlatform platform, string app_directory)
{
switch (platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
return Path.Combine (app_directory, "Info.plist");
case ApplePlatform.MacOSX:
case ApplePlatform.MacCatalyst:
return Path.Combine (app_directory, "Contents", "Info.plist");
default:
throw new NotImplementedException ($"Unknown platform: {platform}");
}
}

void AssertAppContents (ApplePlatform platform, string app_directory)
{
var info_plist_path = GetInfoPListPath (platform, app_directory);
Expand Down
16 changes: 16 additions & 0 deletions tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,21 @@ protected void Clean (string project_path)
Directory.Delete (dir, true);
}
}

protected string GetInfoPListPath (ApplePlatform platform, string app_directory)
{
switch (platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
return Path.Combine (app_directory, "Info.plist");
case ApplePlatform.MacOSX:
case ApplePlatform.MacCatalyst:
return Path.Combine (app_directory, "Contents", "Info.plist");
default:
throw new NotImplementedException ($"Unknown platform: {platform}");
}
}

}
}

4 comments on commit aee4cc0

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (only version changes)

Packages generated

View packages

Test results

1 tests failed, 232 tests passed.

Failed tests

  • Documentation/All: Failed

Pipeline on Agent XAMBOT-1038.BigSur'
[msbuild] Promote '_PartialAppManifest' to a public item group ('PartialAppManifest'). Fixes #10646. (#12417)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[msbuild] Promote '_PartialAppManifest' to a public item group ('PartialAppManifest'). Fixes #10646. (#12417)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Tests failed on macOS M1 - Mac Big Sur (11.5) ❌

Tests failed on M1 - Mac Big Sur (11.5).

Failed tests are:

  • xammac_tests

Pipeline on Agent
[msbuild] Promote '_PartialAppManifest' to a public item group ('PartialAppManifest'). Fixes #10646. (#12417)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[msbuild] Promote '_PartialAppManifest' to a public item group ('PartialAppManifest'). Fixes #10646. (#12417)

Please sign in to comment.