-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dotnet] Add support for 'dotnet pack'. Fixes #12631. #12900
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a little confusing to me...
From quick googling, it looks like the '@this' allows you to use '@this' as a variable name, but why do we want to do this here?
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.
This is an extension method, which allows you to write methods that kind of work like instance methods. In instance methods you use
this
to refer to the instance, and while you can't usethis
in an extension method, you can use@this
(the@
sign makes it so thatthis
isn't a keyword, just a normal variable name), and that makes it look more like an instance method. In other words: it's just a convention to make extension methods look more like instance methods.