Skip to content

Commit

Permalink
Merge branch 'main' into msbuild-compile-api-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Jun 6, 2023
2 parents 5d99902 + 11e7883 commit d7d10c7
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 129 deletions.
6 changes: 3 additions & 3 deletions Make.config
Expand Up @@ -198,9 +198,9 @@ MACCATALYST_NUGET_VERSION_NO_METADATA=$(MACCATALYST_NUGET_VERSION)$(NUGET_PREREL
MACCATALYST_NUGET_VERSION_FULL=$(MACCATALYST_NUGET_VERSION_NO_METADATA)+$(NUGET_BUILD_METADATA)

# Xcode version should have both a major and a minor version (even if the minor version is 0)
XCODE_VERSION=14.3
XCODE_URL=https://dl.internalx.com/internal-files/xcodes/Xcode_14.3.xip
XCODE_DEVELOPER_ROOT=/Applications/Xcode_14.3.0.app/Contents/Developer
XCODE_VERSION=14.3.1
XCODE_URL=https://dl.internalx.com/internal-files/xcodes/Xcode_14.3.1.xip
XCODE_DEVELOPER_ROOT=/Applications/Xcode_14.3.1.app/Contents/Developer
XCODE_PRODUCT_BUILD_VERSION:=$(shell /usr/libexec/PlistBuddy -c 'Print :ProductBuildVersion' $(XCODE_DEVELOPER_ROOT)/../version.plist 2>/dev/null || echo " $(shell tput setaf 1 2>/dev/null)The required Xcode ($(XCODE_VERSION)) is not installed in $(basename $(basename $(XCODE_DEVELOPER_ROOT)))$(shell tput sgr0 2>/dev/null)" >&2)

# Tell both Xcode and our build logic which Xcode we're using.
Expand Down
115 changes: 68 additions & 47 deletions src/Foundation/NSFileManager.cs
Expand Up @@ -26,11 +26,15 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
using CoreFoundation;
using ObjCRuntime;

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

#nullable enable

namespace Foundation {

// This is a convenience enum around a set of native strings.
Expand All @@ -57,15 +61,15 @@ public class NSFileAttributes {
public bool? AppendOnly { get; set; }
public bool? Busy { get; set; }
public bool? ExtensionHidden { get; set; }
public NSDate CreationDate { get; set; }
public string OwnerAccountName { get; set; }
public string GroupOwnerAccountName { get; set; }
public NSDate? CreationDate { get; set; }
public string? OwnerAccountName { get; set; }
public string? GroupOwnerAccountName { get; set; }
public nint? SystemNumber { get; set; } // NSInteger
public nuint? DeviceIdentifier { get; set; } // unsigned long
public nuint? GroupOwnerAccountID { get; set; } // unsigned long

public bool? Immutable { get; set; }
public NSDate ModificationDate { get; set; }
public NSDate? ModificationDate { get; set; }
public nuint? OwnerAccountID { get; set; } // unsigned long
public nuint? HfsCreatorCode { get; set; }
public nuint? HfsTypeCode { get; set; } // unsigned long
Expand All @@ -83,7 +87,7 @@ public class NSFileAttributes {
internal NSDictionary ToDictionary ()
{
NSFileType? type;
NSString v = null;
NSString? v = null;
var dict = new NSMutableDictionary ();
if (AppendOnly.HasValue)
dict.SetObject (NSNumber.FromBoolean (AppendOnly.Value), NSFileManager.AppendOnly);
Expand Down Expand Up @@ -158,7 +162,8 @@ internal NSDictionary ToDictionary ()
case NSFileProtection.CompleteUntilFirstUserAuthentication:
v = NSFileManager.FileProtectionCompleteUntilFirstUserAuthentication; break;
}
dict.SetObject (v, NSFileManager.FileProtectionKey);
if (v is not null)
dict.SetObject (v, NSFileManager.FileProtectionKey);
}
#endif
return dict;
Expand Down Expand Up @@ -222,7 +227,7 @@ internal NSDictionary ToDictionary ()
}
#endregion

public static NSFileAttributes FromDictionary (NSDictionary dict)
public static NSFileAttributes? FromDictionary (NSDictionary dict)
{
if (dict is null)
return null;
Expand All @@ -247,9 +252,7 @@ public static NSFileAttributes FromDictionary (NSDictionary dict)
ret.SystemFileNumber = fetch_nuint (dict, NSFileManager.SystemFileNumber);
ret.Size = fetch_ulong (dict, NSFileManager.Size);

NSString name;

name = dict.ObjectForKey (NSFileManager.NSFileType) as NSString;
var name = dict.ObjectForKey (NSFileManager.NSFileType) as NSString;
if (name is not null) {
NSFileType? type = null;

Expand Down Expand Up @@ -314,7 +317,7 @@ internal NSFileSystemAttributes (NSDictionary dict)
// "The value corresponds to the value of st_dev, as returned by stat(2)" => st_dev is defined to be int32_t in all architectures.
public uint Number { get; internal set; }

internal static NSFileSystemAttributes FromDictionary (NSDictionary dict)
internal static NSFileSystemAttributes? FromDictionary (NSDictionary dict)
{
if (dict is null)
return null;
Expand All @@ -341,108 +344,99 @@ public partial class NSFileManager {
[DllImport (Constants.FoundationLibrary)]
static extern IntPtr NSUserName ();

public static string UserName {
public static string? UserName {
get {
using (var nsstring = ObjCRuntime.Runtime.GetNSObject<NSString> (NSUserName ()))
return nsstring.ToString ();
return CFString.FromHandle (NSUserName ());
}
}

[DllImport (Constants.FoundationLibrary)]
static extern IntPtr NSFullUserName ();

public static string FullUserName {
public static string? FullUserName {
get {
using (var nsstring = ObjCRuntime.Runtime.GetNSObject<NSString> (NSFullUserName ()))
return nsstring.ToString ();
return CFString.FromHandle (NSFullUserName ());
}
}

[DllImport (Constants.FoundationLibrary)]
static extern IntPtr NSHomeDirectory ();

public static string HomeDirectory {
public static string? HomeDirectory {
get {
using (var nsstring = ObjCRuntime.Runtime.GetNSObject<NSString> (NSHomeDirectory ()))
return nsstring.ToString ();
return CFString.FromHandle (NSHomeDirectory ());
}
}

[DllImport (Constants.FoundationLibrary)]
static extern IntPtr NSHomeDirectoryForUser (/* NSString */IntPtr userName);

public static string GetHomeDirectory (string userName)
public static string? GetHomeDirectory (string userName)
{
if (userName is null)
throw new ArgumentNullException (nameof (userName));

using (var nsstring = new NSString (userName))
using (var homeDir = ObjCRuntime.Runtime.GetNSObject<NSString> (NSHomeDirectoryForUser (nsstring.GetHandle ())))
return homeDir.ToString ();
var userNamePtr = CFString.CreateNative (userName);
var rv = CFString.FromHandle (NSHomeDirectoryForUser (userNamePtr));
CFString.ReleaseNative (userNamePtr);
return rv;
}

[DllImport (Constants.FoundationLibrary)]
static extern IntPtr NSTemporaryDirectory ();

public static string TemporaryDirectory {
public static string? TemporaryDirectory {
get {
using (var nsstring = ObjCRuntime.Runtime.GetNSObject<NSString> (NSTemporaryDirectory ()))
return nsstring.ToString ();
return CFString.FromHandle (NSTemporaryDirectory ());
}
}

public bool SetAttributes (NSFileAttributes attributes, string path, out NSError error)
{
if (attributes is null)
throw new ArgumentNullException ("attributes");
throw new ArgumentNullException (nameof (attributes));
return SetAttributes (attributes.ToDictionary (), path, out error);
}

public bool SetAttributes (NSFileAttributes attributes, string path)
{
if (attributes is null)
throw new ArgumentNullException ("attributes");
throw new ArgumentNullException (nameof (attributes));

return SetAttributes (attributes.ToDictionary (), path, out _);
}

public bool CreateDirectory (string path, bool createIntermediates, NSFileAttributes attributes, out NSError error)
public bool CreateDirectory (string path, bool createIntermediates, NSFileAttributes? attributes, out NSError error)
{
var dict = attributes is null ? null : attributes.ToDictionary ();
return CreateDirectory (path, createIntermediates, dict, out error);
return CreateDirectory (path, createIntermediates, attributes?.ToDictionary (), out error);
}

public bool CreateDirectory (string path, bool createIntermediates, NSFileAttributes attributes)
public bool CreateDirectory (string path, bool createIntermediates, NSFileAttributes? attributes)
{
NSError error;
var dict = attributes is null ? null : attributes.ToDictionary ();
return CreateDirectory (path, createIntermediates, dict, out error);
return CreateDirectory (path, createIntermediates, attributes?.ToDictionary (), out var _);
}

public bool CreateFile (string path, NSData data, NSFileAttributes attributes)
public bool CreateFile (string path, NSData data, NSFileAttributes? attributes)
{
var dict = attributes is null ? null : attributes.ToDictionary ();
return CreateFile (path, data, dict);
return CreateFile (path, data, attributes?.ToDictionary ());
}

public NSFileAttributes GetAttributes (string path, out NSError error)
public NSFileAttributes? GetAttributes (string path, out NSError error)
{
return NSFileAttributes.FromDictionary (_GetAttributes (path, out error));
}

public NSFileAttributes GetAttributes (string path)
public NSFileAttributes? GetAttributes (string path)
{
NSError error;
return NSFileAttributes.FromDictionary (_GetAttributes (path, out error));
return NSFileAttributes.FromDictionary (_GetAttributes (path, out var _));
}

public NSFileSystemAttributes GetFileSystemAttributes (string path)
public NSFileSystemAttributes? GetFileSystemAttributes (string path)
{
NSError error;
return NSFileSystemAttributes.FromDictionary (_GetFileSystemAttributes (path, out error));
return NSFileSystemAttributes.FromDictionary (_GetFileSystemAttributes (path, out var _));
}

public NSFileSystemAttributes GetFileSystemAttributes (string path, out NSError error)
public NSFileSystemAttributes? GetFileSystemAttributes (string path, out NSError error)
{
return NSFileSystemAttributes.FromDictionary (_GetFileSystemAttributes (path, out error));
}
Expand All @@ -458,5 +452,32 @@ public NSFileSystemAttributes GetFileSystemAttributes (string path, out NSError
// ignore boolean return value
set { ChangeCurrentDirectory (value); }
}

public static NSError SetSkipBackupAttribute (string filename, bool skipBackup)
{
if (filename is null)
throw new ArgumentNullException (nameof (filename));

using (var url = NSUrl.FromFilename (filename)) {
url.SetResource (NSUrl.IsExcludedFromBackupKey, (NSNumber) (skipBackup ? 1 : 0), out var error);
return error;
}
}

public static bool GetSkipBackupAttribute (string filename)
{
return GetSkipBackupAttribute (filename, out var _);
}

public static bool GetSkipBackupAttribute (string filename, out NSError error)
{
if (filename is null)
throw new ArgumentNullException (nameof (filename));

using (var url = NSUrl.FromFilename (filename)) {
url.TryGetResource (NSUrl.IsExcludedFromBackupKey, out var value, out error);
return (error is null) && ((long) ((NSNumber) value) == 1);
}
}
}
}
50 changes: 0 additions & 50 deletions src/Foundation/NSFileManager.iOS.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/ObjCRuntime/Runtime.CoreCLR.cs
Expand Up @@ -500,7 +500,7 @@ static IntPtr WriteStructure (object obj)
static IntPtr GetAssemblyName (IntPtr gchandle)
{
var asm = (Assembly?) GetGCHandleTarget (gchandle);
return Marshal.StringToHGlobalAuto (Path.GetFileName (asm?.Location));
return Marshal.StringToHGlobalAuto (asm?.GetName ()?.Name);
}

static IntPtr GetAssemblyLocation (IntPtr gchandle)
Expand Down
1 change: 0 additions & 1 deletion src/frameworks.sources
Expand Up @@ -821,7 +821,6 @@ FOUNDATION_SOURCES = \
Foundation/NSFastEnumerationState.cs \
Foundation/NSFastEnumerator.cs \
Foundation/NSFileManager.cs \
Foundation/NSFileManager.iOS.cs \
Foundation/NSFileManagerDelegate.cs \
Foundation/NSFormatter.cs \
Foundation/NSHost.cs \
Expand Down
7 changes: 1 addition & 6 deletions tests/bgen/bgen-tests.csproj
Expand Up @@ -5,6 +5,7 @@
<RootNamespace>bgen_tests</RootNamespace>

<IsPackable>false</IsPackable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,12 +30,6 @@
<Compile Include="..\generator\BGenTool.cs">
<Link>BGenTool.cs</Link>
</Compile>
<Compile Include="..\..\src\bgen\AttributeFactory.ConstructorArguments.cs">
<Link>AttributeFactory.ConstructorArguments.cs</Link>
</Compile>
<Compile Include="..\..\src\bgen\AttributeFactory.cs">
<Link>AttributeFactory.cs</Link>
</Compile>
<Compile Include="..\generator\AttributeFactoryTests.cs">
<Link>AttributeFactoryTests.cs</Link>
</Compile>
Expand Down
12 changes: 12 additions & 0 deletions tests/common/TestRuntime.cs
Expand Up @@ -478,6 +478,18 @@ public static bool CheckXcodeVersion (int major, int minor, int build = 0)
return CheckMacSystemVersion (12, 1);
#else
throw new NotImplementedException ();
#endif
case 3:
#if __WATCHOS__
return CheckWatchOSSystemVersion (8, 5);
#elif __TVOS__
return ChecktvOSSystemVersion (15, 4);
#elif __IOS__
return CheckiOSSystemVersion (15, 4);
#elif MONOMAC
return CheckMacSystemVersion (12, 3);
#else
throw new NotImplementedException ();
#endif
default:
throw new NotImplementedException ();
Expand Down
4 changes: 2 additions & 2 deletions tests/generator/BGenTool.cs
Expand Up @@ -353,14 +353,14 @@ public void AssertMethod (string typename, string method, MethodAttributes? attr
Assert.AreEqual (attributes.Value, m.Attributes, "Attributes for {0}", m.FullName);
}

public void AssertNoMethod (string typename, string method, string returnType = null, params string [] parameterTypes)
public void AssertNoMethod (string typename, string method, string? returnType = null, params string [] parameterTypes)
{
var m = FindMethod (typename, method, returnType, parameterTypes);
if (m is not null)
Assert.Fail ($"Unexpectedly found method '{method}' with signature '{string.Join ("', '", parameterTypes)}' on the type '{typename}'.");
}

MethodDefinition? FindMethod (string typename, string method, string returnType, params string [] parameterTypes)
MethodDefinition? FindMethod (string typename, string method, string? returnType, params string [] parameterTypes)
{
var assembly = LoadAssembly ();
var t = assembly.MainModule.Types.FirstOrDefault ((v) => v.FullName == typename);
Expand Down
2 changes: 1 addition & 1 deletion tests/mmptest/src/MMPTest.cs
Expand Up @@ -611,7 +611,7 @@ public void MM0132 (string opt)
"<LinkMode>Full</LinkMode>",
};
var rv = TI.TestUnifiedExecutable (test, shouldFail: false);
rv.Messages.AssertWarning (132, $"Unknown optimization: '{opt}'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock, register-protocols, inline-dynamic-registration-supported, static-block-to-delegate-lookup, trim-architectures, inline-is-arm64-calling-convention, cctor-beforefieldinit, custom-attributes-removal, experimental-xforms-product-type.");
rv.Messages.AssertWarning (132, $"Unknown optimization: '{opt}'. Valid optimizations are: remove-uithread-checks, dead-code-elimination, inline-isdirectbinding, inline-intptr-size, blockliteral-setupblock, register-protocols, inline-dynamic-registration-supported, static-block-to-delegate-lookup, trim-architectures, inline-is-arm64-calling-convention, cctor-beforefieldinit, custom-attributes-removal, experimental-xforms-product-type, redirect-class-handles.");
rv.Messages.AssertErrorCount (0);
});
}
Expand Down

0 comments on commit d7d10c7

Please sign in to comment.