-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for 'dotnet pack', by: 1. Add a workaround for the fact that as soon as a project has a 'NativeReference' item, .NET's MSBuild logic wants to include a 'Native.$(AssemblyName).manifest' file in the NuGet. This obviously breaks, because we don't create such a file, so we work around it by removing the file in question from the corresponding item groups. 2. Add any binding resource packages to the NuGet. 3. Add tests. Fixes #12631.
- Loading branch information
1 parent
44f570e
commit 62bdd68
Showing
6 changed files
with
276 additions
and
7 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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
using System; | ||
|
||
namespace Xamarin.Utils { | ||
public static class ApplePlatformExtensionsWithVersions { | ||
public static string ToFrameworkWithDefaultVersion (this ApplePlatform @this) | ||
{ | ||
var netVersion = "net6.0"; | ||
switch (@this) { | ||
case ApplePlatform.iOS: | ||
return netVersion + "-ios" + SdkVersions.iOS; | ||
case ApplePlatform.MacOSX: | ||
return netVersion + "-macos" + SdkVersions.OSX; | ||
case ApplePlatform.TVOS: | ||
return netVersion + "-tvos" + SdkVersions.TVOS; | ||
case ApplePlatform.MacCatalyst: | ||
return netVersion + "-maccatalyst" + SdkVersions.MacCatalyst; | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
|
||
using NUnit.Framework; | ||
|
||
using Xamarin.Utils; | ||
using Xamarin.MacDev; | ||
|
||
namespace Xamarin.Tests { | ||
public class PackTest : TestBaseClass { | ||
|
||
|
||
[Test] | ||
[TestCase (ApplePlatform.iOS)] | ||
[TestCase (ApplePlatform.MacCatalyst)] | ||
[TestCase (ApplePlatform.TVOS)] | ||
[TestCase (ApplePlatform.MacOSX)] | ||
public void BindingProject (ApplePlatform platform) | ||
{ | ||
var project = "bindings-test"; | ||
Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
||
var project_path = Path.Combine (Configuration.RootPath, "tests", project, "dotnet", platform.AsString (), $"{project}.csproj"); | ||
Clean (project_path); | ||
Configuration.CopyDotNetSupportingFiles (Path.GetDirectoryName (project_path)); | ||
|
||
var tmpdir = Cache.CreateTemporaryDirectory (); | ||
var outputPath = Path.Combine (tmpdir, "OutputPath"); | ||
var intermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath"); | ||
var properties = GetDefaultProperties (); | ||
properties ["OutputPath"] = outputPath + Path.DirectorySeparatorChar; | ||
properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar; | ||
|
||
var rv =DotNet.AssertPackFailure (project_path, properties); | ||
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray (); | ||
Assert.AreEqual (1, errors.Length, "Error count"); | ||
Assert.AreEqual ($"Creating a NuGet package is not supported for projects that have ObjcBindingNativeLibrary items. Migrate to use NativeReference items instead.", errors [0].Message, "Error message"); | ||
} | ||
|
||
[Test] | ||
[TestCase (ApplePlatform.iOS, true)] | ||
[TestCase (ApplePlatform.iOS, false)] | ||
[TestCase (ApplePlatform.MacCatalyst, true)] | ||
[TestCase (ApplePlatform.MacCatalyst, false)] | ||
[TestCase (ApplePlatform.TVOS, true)] | ||
[TestCase (ApplePlatform.TVOS, false)] | ||
[TestCase (ApplePlatform.MacOSX, true)] | ||
[TestCase (ApplePlatform.MacOSX, false)] | ||
public void BindingFrameworksProject (ApplePlatform platform, bool noBindingEmbedding) | ||
{ | ||
var project = "bindings-framework-test"; | ||
Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
||
var project_path = Path.Combine (Configuration.RootPath, "tests", project, "dotnet", platform.AsString (), $"{project}.csproj"); | ||
Clean (project_path); | ||
Configuration.CopyDotNetSupportingFiles (Path.GetDirectoryName (project_path)); | ||
|
||
var tmpdir = Cache.CreateTemporaryDirectory (); | ||
var outputPath = Path.Combine (tmpdir, "OutputPath"); | ||
var intermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath"); | ||
var properties = GetDefaultProperties (); | ||
properties ["OutputPath"] = outputPath + Path.DirectorySeparatorChar; | ||
properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar; | ||
properties ["NoBindingEmbedding"] = noBindingEmbedding ? "true" : "false"; | ||
|
||
DotNet.AssertPack (project_path, properties); | ||
|
||
var nupkg = Path.Combine (outputPath, project + ".1.0.0.nupkg"); | ||
Assert.That (nupkg, Does.Exist, "nupkg existence"); | ||
|
||
var archive = ZipFile.OpenRead (nupkg); | ||
var files = archive.Entries.Select (v => v.FullName).ToHashSet (); | ||
var hasSymlinks = noBindingEmbedding && (platform == ApplePlatform.MacCatalyst || platform == ApplePlatform.MacOSX); | ||
if (noBindingEmbedding) { | ||
Assert.That (archive.Entries.Count, Is.EqualTo (hasSymlinks ? 6 : 10), $"nupkg file count - {nupkg}"); | ||
} else { | ||
Assert.That (archive.Entries.Count, Is.EqualTo (5), $"nupkg file count - {nupkg}"); | ||
} | ||
Assert.That (files, Does.Contain (project + ".nuspec"), "nuspec"); | ||
Assert.That (files, Does.Contain ("_rels/.rels"), ".rels"); | ||
Assert.That (files, Does.Contain ("[Content_Types].xml"), "[Content_Types].xml"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.dll"), $"{project}.dll"); | ||
Assert.That (files, Has.Some.Matches<string> (v => v.StartsWith ("package/services/metadata/core-properties/", StringComparison.Ordinal) && v.EndsWith (".psmdcp", StringComparison.Ordinal)), "psmdcp"); | ||
if (noBindingEmbedding) { | ||
if (hasSymlinks) { | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources.zip"), $"{project}.resources.zip"); | ||
} else { | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XStaticArTest.framework/XStaticArTest"), $"XStaticArTest.framework/XStaticArTest"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XStaticObjectTest.framework/XStaticObjectTest"), $"XStaticObjectTest.framework/XStaticObjectTest"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XTest.framework/XTest"), $"XTest.framework/XTest"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/XTest.framework/Info.plist"), $"XTest.framework/Info.plist"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources/manifest"), $"manifest"); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
[TestCase (ApplePlatform.iOS, true)] | ||
[TestCase (ApplePlatform.iOS, false)] | ||
[TestCase (ApplePlatform.MacCatalyst, true)] | ||
[TestCase (ApplePlatform.MacCatalyst, false)] | ||
[TestCase (ApplePlatform.TVOS, true)] | ||
[TestCase (ApplePlatform.TVOS, false)] | ||
[TestCase (ApplePlatform.MacOSX, true)] | ||
[TestCase (ApplePlatform.MacOSX, false)] | ||
public void BindingXcFrameworksProject (ApplePlatform platform, bool noBindingEmbedding) | ||
{ | ||
var project = "bindings-xcframework-test"; | ||
Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
||
var project_path = Path.Combine (Configuration.RootPath, "tests", project, "dotnet", platform.AsString (), $"{project}.csproj"); | ||
Clean (project_path); | ||
Configuration.CopyDotNetSupportingFiles (Path.GetDirectoryName (project_path)); | ||
|
||
var tmpdir = Cache.CreateTemporaryDirectory (); | ||
var outputPath = Path.Combine (tmpdir, "OutputPath"); | ||
var intermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath"); | ||
var properties = GetDefaultProperties (); | ||
properties ["OutputPath"] = outputPath + Path.DirectorySeparatorChar; | ||
properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar; | ||
properties ["NoBindingEmbedding"] = noBindingEmbedding ? "true" : "false"; | ||
properties ["AssemblyName"] = project; | ||
|
||
DotNet.AssertPack (project_path, properties); | ||
|
||
var nupkg = Path.Combine (outputPath, project + ".1.0.0.nupkg"); | ||
Assert.That (nupkg, Does.Exist, "nupkg existence"); | ||
|
||
var archive = ZipFile.OpenRead (nupkg); | ||
var files = archive.Entries.Select (v => v.FullName).ToHashSet (); | ||
Assert.That (archive.Entries.Count, Is.EqualTo (noBindingEmbedding ? 6 : 5), $"nupkg file count - {nupkg}"); | ||
Assert.That (files, Does.Contain (project + ".nuspec"), "nuspec"); | ||
Assert.That (files, Does.Contain ("_rels/.rels"), ".rels"); | ||
Assert.That (files, Does.Contain ("[Content_Types].xml"), "[Content_Types].xml"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.dll"), $"{project}.dll"); | ||
Assert.That (files, Has.Some.Matches<string> (v => v.StartsWith ("package/services/metadata/core-properties/", StringComparison.Ordinal) && v.EndsWith (".psmdcp", StringComparison.Ordinal)), "psmdcp"); | ||
if (noBindingEmbedding) { | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.resources.zip"), $"{project}.resources.zip"); | ||
} | ||
} | ||
|
||
[Test] | ||
[TestCase (ApplePlatform.iOS)] | ||
[TestCase (ApplePlatform.MacCatalyst)] | ||
[TestCase (ApplePlatform.TVOS)] | ||
[TestCase (ApplePlatform.MacOSX)] | ||
public void LibraryProject (ApplePlatform platform) | ||
{ | ||
var project = "MyClassLibrary"; | ||
Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
||
var project_path = GetProjectPath (project, runtimeIdentifiers: string.Empty, platform: platform, out var appPath); | ||
Clean (project_path); | ||
var properties = GetDefaultProperties (); | ||
|
||
DotNet.AssertPack (project_path, properties); | ||
|
||
var nupkg = Path.Combine (Path.GetDirectoryName (project_path)!, "bin", "Debug", project + ".1.0.0.nupkg"); | ||
Assert.That (nupkg, Does.Exist, "nupkg existence"); | ||
|
||
var archive = ZipFile.OpenRead (nupkg); | ||
var files = archive.Entries.Select (v => v.FullName).ToHashSet (); | ||
Assert.That (archive.Entries.Count, Is.EqualTo (5), "nupkg file count"); | ||
Assert.That (files, Does.Contain (project + ".nuspec"), "nuspec"); | ||
Assert.That (files, Does.Contain ("_rels/.rels"), ".rels"); | ||
Assert.That (files, Does.Contain ("[Content_Types].xml"), "[Content_Types].xml"); | ||
Assert.That (files, Does.Contain ($"lib/{platform.ToFrameworkWithDefaultVersion ()}/{project}.dll"), $"{project}.dll"); | ||
Assert.That (files, Has.Some.Matches<string> (v => v.StartsWith ("package/services/metadata/core-properties/", StringComparison.Ordinal) && v.EndsWith (".psmdcp", StringComparison.Ordinal)), "psmdcp"); | ||
} | ||
} | ||
} |
62bdd68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 Tests failed catastrophically on Build (no summary found). 🔥
Result file $(TEST_SUMMARY_PATH) not found.
Pipeline on Agent
[dotnet] Add support for 'dotnet pack'. Fixes #12631. (#12900)
62bdd68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ [CI Build] Tests passed on Build. ✅
Tests passed 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
🎉 All 218 tests passed 🎉
Pipeline on Agent XAMBOT-1038.BigSur'
[dotnet] Add support for 'dotnet pack'. Fixes #12631. (#12900)
62bdd68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.
Pipeline on Agent
[dotnet] Add support for 'dotnet pack'. Fixes #12631. (#12900)
62bdd68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.
Pipeline on Agent
[dotnet] Add support for 'dotnet pack'. Fixes #12631. (#12900)