[xcode16] Merge main into xcode16.

This commit is contained in:
Rolf Bjarne Kvinge 2024-09-10 18:59:19 +02:00
Родитель 674ded4af4 39459a2352
Коммит 1417b22b99
19 изменённых файлов: 350 добавлений и 20 удалений

Просмотреть файл

@ -28,7 +28,7 @@ jobs:
set -ex
git config user.email "github-actions-single-platform-branch-updater@xamarin.com"
git config user.name "GitHub Actions Single Platform Branch Updater"
for platform in dotnet-iOS dotnet-tvOS dotnet-MacCatalyst dotnet-macOS dotnet legacy legacy-iOS legacy-macOS; do
for platform in dotnet-iOS dotnet-tvOS dotnet-MacCatalyst dotnet-macOS dotnet; do
git checkout -b release-test/only-$platform origin/release-test/only-$platform
git merge origin/main
git push

Просмотреть файл

@ -2250,6 +2250,8 @@ Currently, these types are supported:
* `nint`
* `nuint`
* `int`, `uint`
* `long`, `ulong`
* `NSNumber`
* `NSString` (this is the default if none is specified)

Просмотреть файл

@ -17,6 +17,7 @@ public class NamespaceCache {
public ICollection<string> UINamespaces { get; private set; }
public ICollection<string> ImplicitNamespaces { get; private set; }
public ICollection<string> NamespacesThatConflictWithTypes { get; private set; }
public ICollection<string> TypesInMultipleNamespaces { get; private set; }
public NamespaceCache (PlatformName currentPlatform, string customObjCRuntimeNS, bool skipSystemDrawing)
{
@ -154,6 +155,10 @@ public class NamespaceCache {
"AudioUnit",
};
TypesInMultipleNamespaces = new HashSet<string> {
"NWEndpoint", // Both in Network and NetworkExtension
};
if (!skipSystemDrawing)
ImplicitNamespaces.Add ("System.Drawing");
}

Просмотреть файл

@ -94,7 +94,14 @@ public partial class Generator {
var isBackingFieldValueType = backingFieldType.IsValueType;
var visibility = is_internal ? "internal" : "public";
if (backingFieldType != TypeCache.System_nint && backingFieldType != TypeCache.System_nuint && backingFieldType != TypeCache.NSString && backingFieldType != TypeCache.NSNumber) {
if (backingFieldType != TypeCache.System_nint &&
backingFieldType != TypeCache.System_nuint &&
backingFieldType != TypeCache.System_Int32 &&
backingFieldType != TypeCache.System_Int64 &&
backingFieldType != TypeCache.System_UInt32 &&
backingFieldType != TypeCache.System_UInt64 &&
backingFieldType != TypeCache.NSString &&
backingFieldType != TypeCache.NSNumber) {
exceptions.Add (ErrorHelper.CreateError (1088 /* The backing field type '{0}' is invalid. Valid backing field types are: "NSString", "NSNumber", "nint" and "nuint". */, backingFieldType.FullName));
backingFieldType = TypeCache.NSString;
}

Просмотреть файл

@ -167,7 +167,22 @@ public partial class Generator : IMemberGatherer {
return false;
}
return type.IsInterface;
// If any of the interfaces this type implements is an NSObject,
// then this type is also an NSObject
var ifaces = type.GetInterfaces ();
foreach (var iface in ifaces)
if (IsNSObject (iface))
return true;
if (type.IsInterface) {
var bta = ReflectionExtensions.GetBaseTypeAttribute (type, this);
if (bta?.BaseType is not null)
return IsNSObject (bta.BaseType);
return false;
}
return false;
}
public string PrimitiveType (Type t, bool formatted = false)
@ -604,8 +619,10 @@ public partial class Generator : IMemberGatherer {
invoke.AppendFormat (" Runtime.GetINativeObject<{1}> ({0}, false)!", safe_name, pi.ParameterType);
} else if (isForced) {
invoke.AppendFormat (" Runtime.GetINativeObject<{1}> ({0}, true, {2})!", safe_name, TypeManager.RenderType (pi.ParameterType), isForcedOwns);
} else {
} else if (IsNSObject (pi.ParameterType)) {
invoke.AppendFormat (" Runtime.GetNSObject<{1}> ({0})!", safe_name, TypeManager.RenderType (pi.ParameterType));
} else {
invoke.AppendFormat (" Runtime.GetINativeObject<{1}> ({0}, false)!", safe_name, TypeManager.RenderType (pi.ParameterType));
}
continue;
}
@ -716,6 +733,11 @@ public partial class Generator : IMemberGatherer {
invoke.AppendFormat ("CFArray.ArrayFromHandle<{0}> ({1})!", TypeManager.FormatType (null, et), safe_name);
continue;
}
if (TypeCache.INativeObject.IsAssignableFrom (et)) {
pars.Add (new TrampolineParameterInfo (NativeHandleType, safe_name));
invoke.AppendFormat ("NSArray.ArrayFromHandle<{0}> ({1})!", TypeManager.FormatType (t, et), safe_name);
continue;
}
}
if (pi.ParameterType.IsPointer && pi.ParameterType.GetElementType ().IsValueType) {
@ -894,6 +916,9 @@ public partial class Generator : IMemberGatherer {
return safe_name + ".Handle";
}
if (TypeCache.INativeObject.IsAssignableFrom (pi.ParameterType))
return $"{safe_name}.GetHandle ()";
// This means you need to add a new MarshalType in the method "Go"
throw new BindingException (1002, true, pi.ParameterType.FullName, mi.DeclaringType.FullName, mi.Name.GetSafeParamName ());
}

Просмотреть файл

@ -300,12 +300,17 @@ public class TypeManager {
if (t.Namespace is not null) {
string ns = t.Namespace;
if (NamespaceCache.ImplicitNamespaces.Contains (ns) || t.IsGenericType) {
var isImplicitNamespace = NamespaceCache.ImplicitNamespaces.Contains (ns);
var isInMultipleNamespaces = IsInMultipleNamespaces (t);
var nonGlobalCandidate = isImplicitNamespace && !isInMultipleNamespaces;
if (nonGlobalCandidate || t.IsGenericType) {
var targs = t.GetGenericArguments ();
if (targs.Length == 0)
return t.Name + nullable;
return $"global::{t.Namespace}." + t.Name.RemoveArity () + "<" + string.Join (", ", targs.Select (l => FormatTypeUsedIn (null, l)).ToArray ()) + ">" + nullable;
}
if (isInMultipleNamespaces)
return "global::" + t.FullName + nullable;
if (NamespaceCache.NamespacesThatConflictWithTypes.Contains (ns))
return "global::" + t.FullName + nullable;
if (t.Name == t.Namespace)
@ -317,6 +322,17 @@ public class TypeManager {
return t.FullName + nullable;
}
bool IsInMultipleNamespaces (Type? type)
{
if (type is null)
return false;
if (NamespaceCache.TypesInMultipleNamespaces.Contains (type.Name))
return true;
return IsInMultipleNamespaces (type.GetElementType ());
}
// TODO: If we ever have an API with nested properties of the same name more than
// 2 deep, we'll need to have this return a list of PropertyInfo and comb through them all.
public PropertyInfo? GetParentTypeWithSameNamedProperty (BaseTypeAttribute bta, string propertyName)

Просмотреть файл

@ -316,8 +316,6 @@ function xcodebuild_download_selected_platforms ()
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform iOS
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform tvOS' $1"
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform tvOS
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform watchOS' $1"
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform watchOS
}
function download_xcode_platforms ()

Просмотреть файл

@ -5,7 +5,7 @@
<RootNamespace>bgen_tests</RootNamespace>
<IsPackable>false</IsPackable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -78,9 +78,9 @@ endif
ifeq ($(RID),)
ifeq ($(PLATFORM),iOS)
RID=ios-arm64
RID=iossimulator-arm64
else ifeq ($(PLATFORM),tvOS)
RID=tvos-arm64
RID=tvossimulator-arm64
else ifeq ($(PLATFORM),MacCatalyst)
ifeq ($(CONFIG),Release)
RID=maccatalyst-x64;maccatalyst-arm64

Просмотреть файл

@ -404,6 +404,20 @@ namespace GeneratorTests {
Assert.AreEqual (expectedAttributes, renderedAttributes, "Introduced attributes");
}
[Test]
[TestCase (Profile.iOS)]
public void INativeObjectsInBlocks (Profile profile)
{
var bgen = new BGenTool ();
bgen.Profile = profile;
bgen.Defines = BGenTool.GetDefaultDefines (bgen.Profile);
bgen.AddTestApiDefinition ("tests/inativeobjects-in-blocks.cs");
bgen.AddExtraSourcesRelativeToGeneratorDirectory ("tests/inativeobjects-in-blocks-sources.cs");
bgen.CreateTemporaryBinding ();
bgen.AssertExecute ("build");
bgen.AssertNoWarnings ();
}
[Test]
public void Bug36457 ()
{
@ -526,6 +540,13 @@ namespace GeneratorTests {
BuildFile (Profile.iOS, "sof20696157.cs");
}
[Test]
[TestCase (Profile.iOS)]
public void TypesInMultipleNamespaces (Profile profile)
{
BuildFile (profile, "tests/types-in-multiple-namespaces.cs");
}
[Test]
public void HyphenInName ()
{
@ -598,6 +619,14 @@ namespace GeneratorTests {
BuildFile (Profile.iOS, "multiple-api-definitions2-a.cs", "multiple-api-definitions2-b.cs");
}
[Test]
[TestCase (Profile.iOS)]
public void INativeObjectArraysInBlocks (Profile profile)
{
BuildFile (profile, "tests/inativeobject-arrays-in-blocks.cs");
}
[Test]
[TestCase (Profile.iOS)]
public void ClassNameCollision (Profile profile)
@ -1670,6 +1699,10 @@ namespace GeneratorTests {
new { BackingFieldType = "NSNumber", NullableType = "Foundation.NSNumber", RenderedBackingFieldType = "Foundation.NSNumber", SimplifiedNullableType = "Foundation.NSNumber" },
new { BackingFieldType = "NSInteger", NullableType = $"System.Nullable`1<{nintName}>", RenderedBackingFieldType = nintName, SimplifiedNullableType = "System.Nullable`1" },
new { BackingFieldType = "NSUInteger", NullableType = $"System.Nullable`1<{nuintName}>", RenderedBackingFieldType = nuintName, SimplifiedNullableType = "System.Nullable`1" },
new { BackingFieldType = "Int32", NullableType = $"System.Nullable`1<System.Int32>", RenderedBackingFieldType = "System.Int32", SimplifiedNullableType = "System.Nullable`1" },
new { BackingFieldType = "Int64", NullableType = $"System.Nullable`1<System.Int64>", RenderedBackingFieldType = "System.Int64", SimplifiedNullableType = "System.Nullable`1" },
new { BackingFieldType = "UInt32", NullableType = $"System.Nullable`1<System.UInt32>", RenderedBackingFieldType = "System.UInt32", SimplifiedNullableType = "System.Nullable`1" },
new { BackingFieldType = "UInt64", NullableType = $"System.Nullable`1<System.UInt64>", RenderedBackingFieldType = "System.UInt64", SimplifiedNullableType = "System.Nullable`1" },
};
foreach (var tc in testCases) {
@ -1698,15 +1731,7 @@ namespace GeneratorTests {
public void UnderlyingFieldType (Profile profile)
{
Configuration.IgnoreIfIgnoredPlatform (profile.AsPlatform ());
var bgen = BuildFile (profile, true, true, "tests/underlyingfieldtype.cs");
#if NET
const string nintName = "System.IntPtr";
const string nuintName = "System.UIntPtr";
#else
const string nintName = "System.nint";
const string nuintName = "System.nuint";
#endif
BuildFile (profile, true, true, "tests/underlyingfieldtype.cs");
}
[Test]

Просмотреть файл

@ -27,6 +27,7 @@ namespace Xamarin.Tests {
public List<string> ApiDefinitions = new List<string> ();
public List<string> Sources = new List<string> ();
public List<string> ExtraSources = new List<string> ();
public List<string> References = new List<string> ();
#if NET
public List<string>? CompileCommand = null;
@ -72,6 +73,16 @@ namespace Xamarin.Tests {
ApiDefinitions.Add (Path.Combine (Configuration.SourceRoot, "tests", "generator", filename));
}
public void AddExtraSourcesRelativeToGeneratorDirectory (string pathRelativeToGeneratorDirectory)
{
ExtraSources.Add (GetFullPathRelativeToGeneratorDirectory (pathRelativeToGeneratorDirectory));
}
public string GetFullPathRelativeToGeneratorDirectory (string pathRelativeToGeneratorDirectory)
{
return Path.Combine (Configuration.SourceRoot, "tests", "generator", pathRelativeToGeneratorDirectory);
}
public AssemblyDefinition ApiAssembly {
get {
return LoadAssembly ();
@ -170,6 +181,9 @@ namespace Xamarin.Tests {
foreach (var s in Sources)
sb.Add ($"-s={s}");
foreach (var x in ExtraSources)
sb.Add ($"-x={x}");
if (ReferenceBclByDefault) {
if (tf is null) {
// do nothing

Просмотреть файл

@ -20,6 +20,30 @@ namespace BackingField {
C,
}
[BackingFieldType (typeof (Int32))]
enum Int32FieldType {
[Field ("DField", "__Internal")]
D,
}
[BackingFieldType (typeof (Int64))]
enum Int64FieldType {
[Field ("EField", "__Internal")]
E,
}
[BackingFieldType (typeof (UInt32))]
enum UInt32FieldType {
[Field ("FField", "__Internal")]
F,
}
[BackingFieldType (typeof (UInt64))]
enum UInt64FieldType {
[Field ("GField", "__Internal")]
G,
}
[BaseType (typeof (NSObject))]
interface SomeObj {
[Export ("nsIntegerField")]
@ -30,5 +54,17 @@ namespace BackingField {
[Export ("nsNumberField")]
NSNumberFieldType NSNumberField { get; set; }
[Export ("int32Field")]
Int32FieldType Int32Field { get; set; }
[Export ("int64Field")]
Int64FieldType Int64Field { get; set; }
[Export ("uint32Field")]
UInt32FieldType UInt32Field { get; set; }
[Export ("uint64Field")]
UInt64FieldType UInt64Field { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,16 @@
using System;
using CoreFoundation;
using CoreVideo;
using Foundation;
using ObjCRuntime;
namespace NS {
delegate void NEDatagramAndFlowEndpointsRead ([NullAllowed] CVPixelBuffer [] remoteEndpoints);
[BaseType (typeof (NSObject))]
interface INativeObjectInBlocks {
[Export ("someOtherProperty")]
NEDatagramAndFlowEndpointsRead SomeOtherProperty { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,9 @@
using System;
using CoreFoundation;
using Foundation;
using ObjCRuntime;
namespace NS {
public partial class DispatchData2 : NativeObject { }
}

Просмотреть файл

@ -0,0 +1,21 @@
using System;
using CoreFoundation;
using Foundation;
using ObjCRuntime;
namespace NS {
[Partial]
interface DispatchData2 {
}
delegate void DispatchB (DispatchData2 data);
delegate void DispatchA (DispatchData2 data, [BlockCallback] DispatchB dispatch);
[BaseType (typeof (NSObject))]
interface INativeObjectInBlocks {
[Export ("someProperty")]
DispatchA SomeProperty { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,15 @@
using System;
using CoreFoundation;
using Foundation;
using ObjCRuntime;
namespace NS {
delegate void D1 ([NullAllowed] Network.NWEndpoint remoteEndpoints);
[BaseType (typeof (NSObject))]
interface TypesInMultipleNamespaces {
[Export ("someProperty")]
D1 SomeProperty { get; set; }
}
}

Просмотреть файл

@ -448,6 +448,11 @@ class BuildConfiguration {
$this.StoreParentBuildVariables($configuration)
# store if dotnet has been enabled
$variableName = "ENABLE_DOTNET"
$variableValue = [Environment]::GetEnvironmentVariable($variableName)
$configuration | Add-Member -NotePropertyName $variableName -NotePropertyValue $variableValue
# For each .NET platform we support, add a INCLUDE_DOTNET_<platform> variable specifying whether that platform is enabled or not.
$dotnetPlatforms = $configuration.DOTNET_PLATFORMS.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)
foreach ($platform in $dotnetPlatforms) {
@ -479,6 +484,36 @@ class BuildConfiguration {
}
}
# store all the variables needed when classic xamarin has been enabled
$configuration | Add-Member -NotePropertyName "INCLUDE_XAMARIN_LEGACY" -NotePropertyValue $Env:INCLUDE_XAMARIN_LEGACY
# if xamarin legacy has been included, check if we need to include the xamarin sdk for each of the platforms, otherewise it will be
# false for all
$xamarinPlatforms = @("ios", "macos", "tvos", "watchos", "maccatalyst")
if ($configuration.INCLUDE_XAMARIN_LEGACY -eq "true") {
foreach ($platform in $xamarinPlatforms) {
$variableName = "INCLUDE_LEGACY_$($platform.ToUpper())"
$variableValue = [Environment]::GetEnvironmentVariable("$variableName")
$configuration | Add-Member -NotePropertyName $variableName -NotePropertyValue $variableValue
}
} else {
foreach ($platform in $xamarinPlatforms) {
$variableName = "INCLUDE_LEGACY_$($platform.ToUpper())"
$configuration | Add-Member -NotePropertyName $variableName -NotePropertyValue "false"
}
}
# add all the include platforms as well as the nuget os version
foreach ($platform in $xamarinPlatforms) {
$variableName = "INCLUDE_$($platform.ToUpper())"
$variableValue = [Environment]::GetEnvironmentVariable("$variableName")
$configuration | Add-Member -NotePropertyName $variableName -NotePropertyValue $variableValue
$variableName = "$($platform.ToUpper())__NUGET_OS_VERSION"
$variableValue = [Environment]::GetEnvironmentVariable("$variableName")
$configuration | Add-Member -NotePropertyName $variableName -NotePropertyValue $variableValue
}
# calculate the commit to later share it with the cascade pipelines
if ($Env:BUILD_REASON -eq "PullRequest") {
$changeId = $configuration.PARENT_BUILD_BUILD_SOURCEBRANCH.Replace("refs/pull/", "").Replace("/merge", "")

Просмотреть файл

@ -0,0 +1,106 @@
# yamllint disable rule:line-length
# This job will parse all the labels present in a PR, will set
# the tags for the build AND will set a number of configuration
# variables to be used by the rest of the projects
parameters:
- name: uploadArtifacts
type: boolean
default: false
- name: use1ES
type: boolean
default: false
- name: repositoryAlias
type: string
default: self
- name: commit
type: string
default: HEAD
- name: uploadPrefix
type: string
default: '$(MaciosUploadPrefix)'
- name: testConfigurations
type: object
default: []
- name: supportedPlatforms
type: object
default: []
- name: testsLabels
type: string
default: ''
- name: statusContext
type: string
default: ''
steps:
- template: checkout.yml
parameters:
isPR: true
repositoryAlias: ${{ parameters.repositoryAlias }}
commit: ${{ parameters.commit }}
- download: macios
displayName: Download Build Config
artifact: build-configuration
- pwsh: |
Get-ChildItem -Path "$(Pipeline.Workspace)/macios" -Recurse -Force
displayName: 'Display downloads'
timeoutInMinutes: 5
- bash: ./xamarin-macios/tools/devops/automation/scripts/bash/configure-platforms.sh
name: configure_platforms
displayName: 'Configure platforms'
- pwsh: |
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY/xamarin-macios/tools/devops/automation/scripts/MaciosCI.psd1
$jsonPath = Join-Path -Path "$(Build.ArtifactStagingDirectory)" -ChildPath "configuration.json"
Write-Host "##vso[task.setvariable variable=CONFIG_PATH]$jsonPath"
New-BuildConfiguration -ConfigFile $jsonPath
env:
GITHUB_TOKEN: $(GitHub.Token)
ACCESSTOKEN: $(AzDoBuildAccess.Token)
name: labels
displayName: 'Configure build'
- bash: ./xamarin-macios/tools/devops/automation/scripts/bash/configure-decisions.sh
name: decisions
displayName: 'Make decisions'
- pwsh: $(System.DefaultWorkingDirectory)/xamarin-macios/tools/devops/automation/scripts/show_env.ps1
displayName: 'Show Environment'
- pwsh: |
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY/xamarin-macios/tools/devops/automation/scripts/MaciosCI.psd1
# load the configuration files and set the required variables to be used in the later stages
$configPath = Get-ChildItem -Path "$(Pipeline.Workspace)/macios/build-configuration/configuration.json" -Recurse -Force
$config = Import-BuildConfiguration -ConfigFile $configPath
$testMatrix = $config.TEST_MATRIX
Write-Host "##vso[task.setvariable variable=TEST_MATRIX;isOutput=true]$testMatrix"
name: test_matrix
displayName: 'Create tests strategy matrix'
# upload config to be consumed later
- ${{ if eq(parameters.uploadArtifacts, true) }}:
- ${{ if eq(parameters.use1ES, true) }}:
- task: 1ES.PublishPipelineArtifact@1
displayName: 'Publish Artifact: configuration.json'
inputs:
path: '$(Build.ArtifactStagingDirectory)/configuration.json'
artifact: '${{ parameters.uploadPrefix }}build-configuration'
continueOnError: true
- ${{ else }}:
- task: PublishPipelineArtifact@1
displayName: 'Publish Artifact: configuration.json'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/configuration.json'
artifactName: '${{ parameters.uploadPrefix }}build-configuration'
continueOnError: true

Просмотреть файл

@ -296,7 +296,7 @@ stages:
BRANCH_NAME: $[ replace(variables['Build.SourceBranch'], 'refs/heads/', '') ]
steps:
- template: common/configure.yml
- template: common/load_configuration.yml
parameters:
repositoryAlias: ${{ parameters.repositoryAlias }}
commit: ${{ parameters.commit }}