[Xcode14] Merge main into xcode14.

This commit is contained in:
Manuel de la Pena 2022-07-26 11:15:34 -04:00
Родитель ca8e5cb068 af0b059176
Коммит 4c4b906bc4
41 изменённых файлов: 776 добавлений и 354 удалений

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

@ -105,6 +105,9 @@ package:
$(CP) $(MACCORE_PATH)/release/*.zip ../package
$(CP) $(MACCORE_PATH)/release/*updateinfo ../package
dotnet-install-system:
$(Q) $(MAKE) -C dotnet install-system
install-system: install-system-ios install-system-mac
@# Clean up some old files
$(Q) rm -Rf /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS

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

@ -14,7 +14,7 @@
<!-- Begin: Package sources from dotnet-aspnetcore -->
<!-- End: Package sources from dotnet-aspnetcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-pub-dotnet-runtime-4d6a40a" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-4d6a40ac/nuget/v3/index.json" />
<add key="darc-pub-dotnet-runtime-f8bf0fc" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-f8bf0fcc/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-runtime -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" protocolVersion="3" />

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

@ -213,12 +213,12 @@ nupkgs/$(1).$(2).nupkg: $(3) $(WORKLOAD_TARGETS) package/$(1)/package.csproj $(w
endef
# Create the NuGet packaging targets. It's amazing what make allows you to do...
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Sdk,$($(platform)_NUGET_VERSION_NO_METADATA),$($(platform)_NUGET_TARGETS),,$(DOTNET_VERSION_BAND))))
$(foreach platform,$(DOTNET_WINDOWS_PLATFORMS),$(eval $(call CreateWindowsNuGetTemplate,Microsoft.$(platform).Windows.Sdk,$(IOS_WINDOWS_NUGET_VERSION_NO_METADATA),$($(platform)_WINDOWS_NUGET_TARGETS),,$(DOTNET_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Ref,$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Templates,$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Sdk,$($(platform)_NUGET_VERSION_NO_METADATA),$($(platform)_NUGET_TARGETS),,$(DOTNET_MANIFEST_VERSION_BAND))))
$(foreach platform,$(DOTNET_WINDOWS_PLATFORMS),$(eval $(call CreateWindowsNuGetTemplate,Microsoft.$(platform).Windows.Sdk,$(IOS_WINDOWS_NUGET_VERSION_NO_METADATA),$($(platform)_WINDOWS_NUGET_TARGETS),,$(DOTNET_MANIFEST_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Ref,$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_MANIFEST_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Templates,$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_MANIFEST_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreateNuGetTemplate,Microsoft.NET.Sdk.$(platform),$($(platform)_NUGET_VERSION_NO_METADATA),,.Manifest-$(MANIFEST_VERSION_BAND),$(MANIFEST_VERSION_BAND))))
$(foreach platform,$(DOTNET_PLATFORMS),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Runtime.$(rid),$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_VERSION_BAND)))))
$(foreach platform,$(DOTNET_PLATFORMS),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(eval $(call CreateNuGetTemplate,Microsoft.$(platform).Runtime.$(rid),$($(platform)_NUGET_VERSION_NO_METADATA),,,$(DOTNET_MANIFEST_VERSION_BAND)))))
# Copy the nuget from the temporary directory into the final directory
$(DOTNET_NUPKG_DIR)/%.nupkg: nupkgs/%.nupkg | $(DOTNET_NUPKG_DIR)
@ -292,8 +292,8 @@ define CreatePackage
$(TMP_PKG_DIR)/Microsoft.$1.Workload.$2.pkg: $($(1)_NUGET_TARGETS) $(WORKLOAD_TARGETS) Makefile | $(TMP_PKG_DIR)
$$(Q) rm -f $$@
$$(Q) rm -rf tmpdir/Microsoft.NET.Sdk.$1.$2/
$$(Q) mkdir -p tmpdir/Microsoft.NET.Sdk.$1.$2/usr/local/share/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) $$(CP) -r Workloads/Microsoft.NET.Sdk.$1 tmpdir/Microsoft.NET.Sdk.$1.$2/usr/local/share/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) mkdir -p tmpdir/Microsoft.NET.Sdk.$1.$2/usr/local/share/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q) $$(CP) -r Workloads/Microsoft.NET.Sdk.$1 tmpdir/Microsoft.NET.Sdk.$1.$2/usr/local/share/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q_GEN) pkgbuild --quiet --version '$2' --root tmpdir/Microsoft.NET.Sdk.$1.$2 --component-plist PackageInfo.plist --install-location / --identifier com.microsoft.net.$3.workload.pkg $$@.tmp
$$(Q) mv $$@.tmp $$@
@ -346,11 +346,11 @@ PACKAGE_TARGETS += $(DOTNET_PKG_DIR)/Microsoft.$1.Bundle.$2.pkg
$(TMP_PKG_DIR)/Microsoft.$1.Bundle.$2.zip: $($(1)_NUGET_TARGETS) $(WORKLOAD_TARGETS) Makefile $(REF_PACK_$(4)) $(SDK_PACK_$(4)) $(TEMPLATE_PACKS_$(4)) | $(TMP_PKG_DIR)
$$(Q) rm -rf $$@ $$@.tmpdir $$@.tmp
$$(Q) mkdir -p $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) mkdir -p $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q) mkdir -p $$@.tmpdir/dotnet/packs/Microsoft.$1.Sdk
$$(Q) mkdir -p $$@.tmpdir/dotnet/packs/Microsoft.$1.Ref
$$(Q) mkdir -p $$@.tmpdir/dotnet/template-packs
$$(Q) $(CP) -r Workloads/Microsoft.NET.Sdk.$1 $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) $(CP) -r Workloads/Microsoft.NET.Sdk.$1 $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q) $(CP) -r $(DOTNET_DESTDIR)/Microsoft.$1.Sdk $$@.tmpdir/dotnet/packs/Microsoft.$1.Sdk/$2
$$(Q) $(CP) -r $(DOTNET_DESTDIR)/Microsoft.$1.Ref $$@.tmpdir/dotnet/packs/Microsoft.$1.Ref/$2
$$(Q) $(CP) $(TEMPLATE_PACKS_$(4)) $$@.tmpdir/dotnet/template-packs/$(subst +$(NUGET_BUILD_METADATA),,$(notdir $(TEMPLATE_PACKS_$(4))))
@ -359,18 +359,27 @@ $(TMP_PKG_DIR)/Microsoft.$1.Bundle.$2.zip: $($(1)_NUGET_TARGETS) $(WORKLOAD_TARG
$$(Q) echo Created $$@
PACKAGE_TARGETS += $(DOTNET_PKG_DIR)/Microsoft.$1.Bundle.$2.zip
install-system-$(3): $(DOTNET_PKG_DIR)/Microsoft.$1.Bundle.$2.pkg
$(Q) echo "Installing $$<..."
$(Q) sudo installer -pkg "$$<" -target / $$(INSTALLER_VERBOSITY)
$(Q) echo "Installed $$<"
$(Q) echo "Execute this in the project directory to be built for NuGet to find the runtime packs:"
$(Q) echo " nuget sources add -Name local-macios-packages -ConfigFile NuGet.config -Source file://$(abspath $(DOTNET_NUPKG_DIR))"
INSTALL_SYSTEM_PACKAGE_TARGETS += install-system-$(3)
endef
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call CreatePackage,$(platform),$($(platform)_NUGET_VERSION_NO_METADATA),$(shell echo $(platform) | tr A-Z a-z),$(shell echo $(platform) | tr a-z A-Z))))
define CreateWindowsBundle
$(TMP_PKG_DIR)/Microsoft.$1.Windows.Bundle.$2.zip: $($(1)_NUGET_TARGETS) $($(1)_WINDOWS_NUGET_TARGETS) $(WORKLOAD_TARGETS) Makefile $(REF_PACK_$(4)) $(SDK_PACK_$(4)) $(SDK_PACK_$(4)_WINDOWS) $(TEMPLATE_PACKS_$(4)) | $(TMP_PKG_DIR)
$$(Q) rm -rf $$@ $$@.tmpdir $$@.tmp
$$(Q) mkdir -p $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) mkdir -p $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q) mkdir -p $$@.tmpdir/dotnet/packs/Microsoft.$1.Sdk
$$(Q) mkdir -p $$@.tmpdir/dotnet/packs/Microsoft.$1.Windows.Sdk
$$(Q) mkdir -p $$@.tmpdir/dotnet/packs/Microsoft.$1.Ref
$$(Q) mkdir -p $$@.tmpdir/dotnet/template-packs
$$(Q) $(CP) -r Workloads/Microsoft.NET.Sdk.$1 $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_VERSION_BAND)/
$$(Q) $(CP) -r Workloads/Microsoft.NET.Sdk.$1 $$@.tmpdir/dotnet/sdk-manifests/$(DOTNET_MANIFEST_VERSION_BAND)/
$$(Q) $(CP) -r $(DOTNET_DESTDIR)/Microsoft.$1.Sdk $$@.tmpdir/dotnet/packs/Microsoft.$1.Sdk/$2
$$(Q) $(CP) -r $(DOTNET_DESTDIR)/Microsoft.$1.Windows.Sdk $$@.tmpdir/dotnet/packs/Microsoft.$1.Windows.Sdk/$2
$$(Q) $(CP) -r $(DOTNET_DESTDIR)/Microsoft.$1.Ref $$@.tmpdir/dotnet/packs/Microsoft.$1.Ref/$2
@ -422,6 +431,12 @@ TARGETS += $(WORKLOAD_TARGETS) $(WINDOWS_PACKAGE_TARGETS)
msi: $(MSI_TARGETS)
package: $(PACKAGE_TARGETS) $(MSI_TARGETS) $(WINDOWS_PACKAGE_TARGETS)
install-system:
@# We don't want to execute these in parallel
@for target in $(INSTALL_SYSTEM_PACKAGE_TARGETS); do \
$(MAKE) $$target; \
done
ifdef ENABLE_DOTNET
all-local:: $(TARGETS)
endif

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

@ -10,7 +10,7 @@
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Ref" Version="6.0.8">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>4d6a40ac22fc008d5fe22f1e776f58ecc7e5fdc3</Sha>
<Sha>f8bf0fcc30d2e1f606266db1b644266c7bdbf063</Sha>
</Dependency>
<!-- This is required for our test apps to build; in some cases Microsoft.AspNetCore.App is pulled in, and when building test apps the build needs to be able to resolve that -->
<Dependency Name="Microsoft.AspNetCore.App.Ref" Version="6.0.5" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">

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

@ -1,4 +1,4 @@
NEEDED_MONO_VERSION := dffa5ab92245f2419238a35b7c2052e9a24036b4
NEEDED_MONO_VERSION := 2a19f878dab8d2e62123e0bf29453de553f5402a
NEEDED_MONO_BRANCH := 2020-02
MONO_DIRECTORY := mono

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

@ -73,6 +73,7 @@ MTOUCH_VERBOSITY=-q
DOTNET_PACK_VERBOSITY=--verbosity:quiet --nologo
DOTNET_BUILD_VERBOSITY=--verbosity quiet --nologo -consoleLoggerParameters:NoSummary
NUGET_VERBOSITY=-verbosity quiet
INSTALLER_VERBOSITY=
else
# CI build
XBUILD_VERBOSITY=/nologo /verbosity:normal
@ -82,6 +83,7 @@ MTOUCH_VERBOSITY=-vvvv
DOTNET_PACK_VERBOSITY=
DOTNET_BUILD_VERBOSITY=
NUGET_VERBOSITY=
INSTALLER_VERBOSITY=
endif
else
# verbose build
@ -92,6 +94,7 @@ MTOUCH_VERBOSITY=-vvvv
DOTNET_PACK_VERBOSITY=--verbosity:detailed
DOTNET_BUILD_VERBOSITY=--verbosity detailed
NUGET_VERBOSITY=-verbosity detailed
INSTALLER_VERBOSITY=-verbose -dumplog
endif
MSBUILD_VERBOSITY=$(XBUILD_VERBOSITY)
MSBUILD_VERBOSITY_QUIET=$(XBUILD_VERBOSITY_QUIET)

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

@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MessagingVersion>1.6.24</MessagingVersion>
<MessagingVersion>1.6.60</MessagingVersion>
<HotRestartVersion>1.0.93</HotRestartVersion>
</PropertyGroup>
</Project>

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

@ -21,7 +21,7 @@ namespace Xamarin.Messaging.Build {
var dotnetPath = Path.Combine (sdkRootPath, "dotnet", "dotnet");
if (File.Exists (dotnetPath)) {
Environment.SetEnvironmentVariable ("HOME", Path.Combine (sdkRootPath, ".home"));
Environment.SetEnvironmentVariable ("DOTNET_CUSTOM_HOME", Path.Combine (sdkRootPath, ".home"));
} else {
//In case the XMA dotnet has not been installed yet
dotnetPath = "/usr/local/share/dotnet/dotnet";
@ -34,7 +34,7 @@ namespace Xamarin.Messaging.Build {
internal void LoadTasks (Assembly assembly) => tasks.AddRange (assembly.GetTypes ());
internal void LoadXamarinTasks () => LoadTasks (typeof (iOS.Tasks.CompileAppManifest).Assembly);
internal void LoadXamarinTasks () => LoadTasks (typeof (iOS.Tasks.MTouch).Assembly);
public ExecuteTaskResult Execute (string taskName, string inputs)
{

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

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="System.IO.Abstractions" Version="6.0.27" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="GitInfo" Version="2.1.2" />
<PackageReference Include="GitInfo" Version="2.2.0" />
<!-- We only include build assets to get targets related to agent generation, the assemblies come from Xamarin.iOS.Tasks -->
<PackageReference Include="Xamarin.Messaging.Core" Version="$(MessagingVersion)" IncludeAssets="build" />
</ItemGroup>

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

@ -1,17 +0,0 @@
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
#nullable enable
namespace Xamarin.Mac.Tasks {
public abstract class CompileAppManifestTaskCore : CompileAppManifestTaskBase {
protected override bool Compile (PDictionary plist)
{
if (!IsAppExtension || (IsAppExtension && IsXPCService))
plist.SetIfNotPresent ("MonoBundleExecutable", AssemblyName + ".exe");
return !Log.HasLoggedErrors;
}
}
}

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

@ -1,14 +0,0 @@
//
// CompileAppManifestTask.cs
//
// Author:
// Aaron Bockover <abock@xamarin.com>
//
// Copyright 2014 Xamarin Inc.
#nullable enable
namespace Xamarin.Mac.Tasks {
public class CompileAppManifest : CompileAppManifestTaskCore {
}
}

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

@ -1,8 +0,0 @@
using Xamarin.MacDev.Tasks;
namespace Xamarin.Mac.Tasks
{
public class PrepareNativeReferences : PrepareNativeReferencesTaskBase
{
}
}

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

@ -268,7 +268,13 @@ namespace Xamarin.MacDev.Tasks {
BTouchToolPath = PathUtils.ConvertToMacPath (BTouchToolPath);
DotNetCscCompiler = PathUtils.ConvertToMacPath (DotNetCscCompiler);
if (!IsDotNet) {
if (IsDotNet) {
var customHome = Environment.GetEnvironmentVariable ("DOTNET_CUSTOM_HOME");
if(!string.IsNullOrEmpty(customHome)) {
EnvironmentVariables = EnvironmentVariables.CopyAndAdd ($"HOME={customHome}");
}
} else {
ToolExe = BTouchToolExe;
ToolPath = BTouchToolPath;
}

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

@ -91,6 +91,8 @@ namespace Xamarin.MacDev.Tasks
#endregion
protected TargetArchitecture architectures;
IPhoneDeviceType supportedDevices;
AppleSdkVersion sdkVersion;
public override bool Execute ()
{
@ -296,7 +298,20 @@ namespace Xamarin.MacDev.Tasks
return rv;
}
protected abstract bool Compile (PDictionary plist);
bool Compile (PDictionary plist)
{
switch (Platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.WatchOS:
case ApplePlatform.MacCatalyst:
return CompileMobile (plist);
case ApplePlatform.MacOSX:
return CompileMac (plist);
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
protected void LogAppManifestError (string format, params object[] args)
{
@ -423,5 +438,225 @@ namespace Xamarin.MacDev.Tasks
break;
}
}
bool CompileMac (PDictionary plist)
{
if (!IsAppExtension || (IsAppExtension && IsXPCService))
plist.SetIfNotPresent ("MonoBundleExecutable", AssemblyName + ".exe");
return !Log.HasLoggedErrors;
}
bool CompileMobile (PDictionary plist)
{
var currentSDK = Sdks.GetAppleSdk (Platform);
sdkVersion = AppleSdkVersion.Parse (DefaultSdkVersion);
if (!currentSDK.SdkIsInstalled (sdkVersion, SdkIsSimulator)) {
Log.LogError (null, null, null, null, 0, 0, 0, 0, MSBStrings.E0013, Platform, sdkVersion);
return false;
}
supportedDevices = plist.GetUIDeviceFamily ();
var sdkSettings = currentSDK.GetSdkSettings (sdkVersion, SdkIsSimulator);
var dtSettings = currentSDK.GetAppleDTSettings ();
SetValue (plist, ManifestKeys.BuildMachineOSBuild, dtSettings.BuildMachineOSBuild);
// We have an issue here, this is for consideration by the platform:
// CFLocaleCopyCurrent(), used in the mono code to get the current locale (locale.c line 421), will return the value of the application's CFBundleDevelopmentRegion Info.plist key if all of the following conditions are true:
//
// * CFBundleDevelopmentRegion is present in the Info.plist
// * The CFBundleDevelopmentRegion language is in the list of preferred languages on the iOS device, but isn't the first one
// * There are no localized resources (i.e. no .lproj directory) in the app for the first preferred locale
//
// This differs from iOS 10 where the presence of the CFBundleDevelopmentRegion key had no effect. Commenting this line out, ensures that CurrentCulture is correct and behaves like the iOS 10 version.
// plist.SetIfNotPresent (ManifestKeys.CFBundleDevelopmentRegion, "en");
if (Platform == ApplePlatform.iOS) {
var executable = plist.GetCFBundleExecutable ();
if (executable.EndsWith (".app", StringComparison.Ordinal))
LogAppManifestError (MSBStrings.E0014, executable);
}
if (!string.IsNullOrEmpty (ResourceRules))
plist.SetIfNotPresent (ManifestKeys.CFBundleResourceSpecification, Path.GetFileName (ResourceRules));
if (!plist.ContainsKey (ManifestKeys.CFBundleSupportedPlatforms))
plist [ManifestKeys.CFBundleSupportedPlatforms] = new PArray { SdkPlatform };
string? dtCompiler = null;
string? dtPlatformBuild = null;
string? dtSDKBuild = null;
string? dtPlatformName;
string? dtPlatformVersion = null;
string? dtXcode = null;
string? dtXcodeBuild = null;
if (!SdkIsSimulator) {
dtCompiler = sdkSettings.DTCompiler;
dtPlatformBuild = dtSettings.DTPlatformBuild;
dtSDKBuild = sdkSettings.DTSDKBuild;
}
dtPlatformName = SdkPlatform.ToLowerInvariant ();
if (!SdkIsSimulator)
dtPlatformVersion = dtSettings.DTPlatformVersion;
var dtSDKName = sdkSettings.CanonicalName;
// older sdksettings didn't have a canonicalname for sim
if (SdkIsSimulator && string.IsNullOrEmpty (dtSDKName)) {
var deviceSdkSettings = currentSDK.GetSdkSettings (sdkVersion, false);
dtSDKName = deviceSdkSettings.AlternateSDK;
}
if (!SdkIsSimulator) {
dtXcode = AppleSdkSettings.DTXcode;
dtXcodeBuild = dtSettings.DTXcodeBuild;
}
SetValueIfNotNull (plist, "DTCompiler", dtCompiler);
SetValueIfNotNull (plist, "DTPlatformBuild", dtPlatformBuild);
SetValueIfNotNull (plist, "DTSDKBuild", dtSDKBuild);
plist.SetIfNotPresent ("DTPlatformName", dtPlatformName);
SetValueIfNotNull (plist, "DTPlatformVersion", dtPlatformVersion);
SetValue (plist, "DTSDKName", dtSDKName);
SetValueIfNotNull (plist, "DTXcode", dtXcode);
SetValueIfNotNull (plist, "DTXcodeBuild", dtXcodeBuild);
SetDeviceFamily (plist);
if (IsWatchExtension) {
if (Debug)
SetAppTransportSecurity (plist);
}
SetRequiredArchitectures (plist);
return !Log.HasLoggedErrors;
}
void SetValueIfNotNull (PDictionary dict, string key, string? value)
{
if (value is null)
return;
SetValue (dict, key, value);
}
void SetRequiredArchitectures (PDictionary plist)
{
PObject capabilities;
if (plist.TryGetValue (ManifestKeys.UIRequiredDeviceCapabilities, out capabilities)) {
if (capabilities is PArray) {
var architectureValues = new HashSet<string> (new [] { "armv6", "armv7", "arm64" });
var array = (PArray) capabilities;
// Remove any architecture values
for (int i = 0; i < array.Count; i++) {
var value = array [i] as PString;
if (value is null || !architectureValues.Contains (value.Value))
continue;
array.RemoveAt (i);
}
// If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
switch (architectures) {
case TargetArchitecture.ARM64:
array.Add (new PString ("arm64"));
break;
case TargetArchitecture.ARMv7:
array.Add (new PString ("armv7"));
break;
}
} else if (capabilities is PDictionary) {
var dict = (PDictionary) capabilities;
switch (architectures) {
case TargetArchitecture.ARM64:
dict ["arm64"] = new PBoolean (true);
dict.Remove ("armv6");
dict.Remove ("armv7");
break;
case TargetArchitecture.ARMv7:
dict ["armv7"] = new PBoolean (true);
dict.Remove ("armv6");
dict.Remove ("arm64");
break;
default:
dict.Remove ("armv6");
dict.Remove ("armv7");
dict.Remove ("arm64");
break;
}
}
} else {
var array = new PArray ();
// If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
switch (architectures) {
case TargetArchitecture.ARM64:
array.Add (new PString ("arm64"));
break;
case TargetArchitecture.ARMv7:
array.Add (new PString ("armv7"));
break;
}
if (array.Count > 0)
plist.Add (ManifestKeys.UIRequiredDeviceCapabilities, array);
}
}
void SetDeviceFamily (PDictionary plist)
{
var uiDeviceFamily = IPhoneDeviceType.NotSet;
switch (Platform) {
case ApplePlatform.iOS:
if (!IsAppExtension)
plist.SetIfNotPresent (ManifestKeys.LSRequiresIPhoneOS, true);
uiDeviceFamily = IPhoneDeviceType.IPhone;
break;
case ApplePlatform.WatchOS:
uiDeviceFamily = IPhoneDeviceType.Watch;
break;
case ApplePlatform.TVOS:
uiDeviceFamily = IPhoneDeviceType.TV;
break;
}
// Don't set UIDeviceFamily if the plist already contains it
if (uiDeviceFamily != IPhoneDeviceType.NotSet && supportedDevices == IPhoneDeviceType.NotSet)
plist.SetUIDeviceFamily (uiDeviceFamily);
}
void SetAppTransportSecurity (PDictionary plist)
{
// Debugging over http has a couple of gotchas:
// * We can't use https, because that requires a valid server certificate,
// which we can't ensure.
// It would also require a hostname for the mac, which it might not have either.
// * NSAppTransportSecurity/NSExceptionDomains does not allow exceptions based
// on IP address (only hostname).
// * Which means the only way to make sure watchOS allows connections from
// the app on device to the mac is to disable App Transport Security altogether.
// Good news: watchOS 3 will apparently not apply ATS when connecting
// directly to IP addresses, which means we won't have to do this at all
// (sometime in the future).
PDictionary ats;
if (!plist.TryGetValue (ManifestKeys.NSAppTransportSecurity, out ats))
plist.Add (ManifestKeys.NSAppTransportSecurity, ats = new PDictionary ());
if (ats.GetBoolean (ManifestKeys.NSAllowsArbitraryLoads)) {
Log.LogMessage (MessageImportance.Low, MSBStrings.M0017);
} else {
Log.LogMessage (MessageImportance.Low, MSBStrings.M0018);
ats.SetBooleanOrRemove (ManifestKeys.NSAllowsArbitraryLoads, true);
}
}
}
}

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

@ -90,11 +90,19 @@ namespace Xamarin.MacDev.Tasks {
File.WriteAllText (projectPath, csproj);
var arguments = new List<string> ();
if (IsDotNet) {
var environment = default (Dictionary<string, string>);
if (IsDotNet) {
executable = Environment.GetEnvironmentVariable ("DOTNET_HOST_PATH");
if (string.IsNullOrEmpty (executable))
executable = "dotnet";
arguments.Add ("build");
var customHome = Environment.GetEnvironmentVariable ("DOTNET_CUSTOM_HOME");
if (!string.IsNullOrEmpty (customHome)) {
environment = new Dictionary<string, string> { { "HOME", customHome } };
}
} else {
executable = "/Library/Frameworks/Mono.framework/Commands/msbuild";
}
@ -108,7 +116,7 @@ namespace Xamarin.MacDev.Tasks {
arguments.Add (projectPath);
ExecuteAsync (executable, arguments).Wait ();
ExecuteAsync (executable, arguments, environment: environment).Wait ();
var computedPropertes = File.ReadAllLines (outputFile);
foreach (var line in computedPropertes) {
var property = line.Substring (0, line.IndexOf ('='));

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

@ -74,8 +74,15 @@ namespace Xamarin.MacDev.Tasks {
arguments.Add ("/t:ComputeAotCompilerPath");
arguments.Add (projectPath);
var environment = default (Dictionary<string, string>);
var customHome = Environment.GetEnvironmentVariable ("DOTNET_CUSTOM_HOME");
if (!string.IsNullOrEmpty (customHome)) {
environment = new Dictionary<string, string> { { "HOME", customHome } };
}
try {
ExecuteAsync (executable, arguments).Wait ();
ExecuteAsync (executable, arguments, environment: environment).Wait ();
return File.ReadAllText (outputFile).Trim ();
} finally {
File.Delete (projectPath);

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

@ -6,9 +6,9 @@ using Xamarin.Messaging.Build.Client;
#nullable enable
namespace Xamarin.iOS.Tasks
namespace Xamarin.MacDev.Tasks
{
public class CompileAppManifest : CompileAppManifestTaskCore, ITaskCallback, ICancelableTask
public class CompileAppManifest : CompileAppManifestTaskBase, ITaskCallback, ICancelableTask
{
public override bool Execute ()
{

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

@ -7,7 +7,7 @@ using Microsoft.Build.Utilities;
using Xamarin.MacDev.Tasks;
using Xamarin.Messaging.Build.Client;
namespace Xamarin.iOS.Tasks
namespace Xamarin.MacDev.Tasks
{
public class PrepareNativeReferences : PrepareNativeReferencesTaskBase, ITaskCallback, ICancelableTask
{

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

@ -37,7 +37,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CollectAssetPacks" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CollectITunesArtwork" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CollectITunesSourceFiles" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CompileITunesMetadata" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateAssetPack" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
@ -46,7 +45,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.GetMlaunchArguments" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.MTouch" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.ParseDeviceSpecificBuildInformation" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.ResolveNativeWatchApp" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.ResolveUniversalTypeIdentifiers" AssemblyFile="Xamarin.iOS.Tasks.dll" />
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.ValidateAppBundleTask" AssemblyFile="$(_TaskAssemblyName)" />
@ -54,11 +52,9 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask Condition="'$(_PlatformName)' != 'macOS'" TaskName="Xamarin.iOS.Tasks.WriteAssetPackManifest" AssemblyFile="$(_TaskAssemblyName)" />
<!-- Xamarin.Mac-specific tasks. Some of these are duplicated with the Xamarin.iOS ones above, and should eventually be re-namespaced to be in Xamarin.MacDev -->
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.CreateEmbeddedResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.DetectSigningIdentity" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.Mmp" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask Condition="'$(_PlatformName)' == 'macOS'" TaskName="Xamarin.Mac.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
<!-- Tasks shared between Xamarin.iOS and Xamarin.Mac -->
<UsingTask TaskName="Xamarin.MacDev.Tasks.ACTool" AssemblyFile="$(_TaskAssemblyName)" />
@ -71,6 +67,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask TaskName="Xamarin.MacDev.Tasks.Codesign" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.CodesignVerify" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.CollectBundleResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileAppManifest" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileEntitlements" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.CompileSceneKitAssets" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ComputeBundleLocation" AssemblyFile="$(_TaskAssemblyName)" />
@ -104,6 +101,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<UsingTask TaskName="Xamarin.MacDev.Tasks.OptimizePropertyList" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.PackLibraryResources" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ParseBundlerArguments" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.PrepareNativeReferences" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.PrepareResourceRules" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.PropertyListEditor" AssemblyFile="$(_TaskAssemblyName)" />
<UsingTask TaskName="Xamarin.MacDev.Tasks.ReadAppManifest" AssemblyFile="$(_TaskAssemblyName)" />

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

@ -1,236 +0,0 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Build.Framework;
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
using Xamarin.Utils;
using Xamarin.Localization.MSBuild;
#nullable enable
namespace Xamarin.iOS.Tasks
{
public abstract class CompileAppManifestTaskCore : CompileAppManifestTaskBase
{
IPhoneDeviceType supportedDevices;
AppleSdkVersion sdkVersion;
bool IsIOS { get { return Platform == ApplePlatform.iOS; } }
protected override bool Compile (PDictionary plist)
{
var currentSDK = Sdks.GetAppleSdk (Platform);
sdkVersion = AppleSdkVersion.Parse (DefaultSdkVersion);
if (!currentSDK.SdkIsInstalled (sdkVersion, SdkIsSimulator)) {
Log.LogError (null, null, null, null, 0, 0, 0, 0, MSBStrings.E0013, Platform, sdkVersion);
return false;
}
supportedDevices = plist.GetUIDeviceFamily ();
var sdkSettings = currentSDK.GetSdkSettings (sdkVersion, SdkIsSimulator);
var dtSettings = currentSDK.GetAppleDTSettings ();
SetValue (plist, ManifestKeys.BuildMachineOSBuild, dtSettings.BuildMachineOSBuild);
// We have an issue here, this is for consideration by the platform:
// CFLocaleCopyCurrent(), used in the mono code to get the current locale (locale.c line 421), will return the value of the application's CFBundleDevelopmentRegion Info.plist key if all of the following conditions are true:
//
// * CFBundleDevelopmentRegion is present in the Info.plist
// * The CFBundleDevelopmentRegion language is in the list of preferred languages on the iOS device, but isn't the first one
// * There are no localized resources (i.e. no .lproj directory) in the app for the first preferred locale
//
// This differs from iOS 10 where the presence of the CFBundleDevelopmentRegion key had no effect. Commenting this line out, ensures that CurrentCulture is correct and behaves like the iOS 10 version.
// plist.SetIfNotPresent (ManifestKeys.CFBundleDevelopmentRegion, "en");
if (IsIOS) {
var executable = plist.GetCFBundleExecutable ();
if (executable.EndsWith (".app", StringComparison.Ordinal))
LogAppManifestError (MSBStrings.E0014, executable);
}
if (!string.IsNullOrEmpty (ResourceRules))
plist.SetIfNotPresent (ManifestKeys.CFBundleResourceSpecification, Path.GetFileName (ResourceRules));
if (!plist.ContainsKey (ManifestKeys.CFBundleSupportedPlatforms))
plist[ManifestKeys.CFBundleSupportedPlatforms] = new PArray { SdkPlatform };
string? dtCompiler = null;
string? dtPlatformBuild = null;
string? dtSDKBuild = null;
string? dtPlatformName;
string? dtPlatformVersion = null;
string? dtXcode = null;
string? dtXcodeBuild = null;
if (!SdkIsSimulator) {
dtCompiler = sdkSettings.DTCompiler;
dtPlatformBuild = dtSettings.DTPlatformBuild;
dtSDKBuild = sdkSettings.DTSDKBuild;
}
dtPlatformName = SdkPlatform.ToLowerInvariant ();
if (!SdkIsSimulator)
dtPlatformVersion = dtSettings.DTPlatformVersion;
var dtSDKName = sdkSettings.CanonicalName;
// older sdksettings didn't have a canonicalname for sim
if (SdkIsSimulator && string.IsNullOrEmpty (dtSDKName)) {
var deviceSdkSettings = currentSDK.GetSdkSettings (sdkVersion, false);
dtSDKName = deviceSdkSettings.AlternateSDK;
}
if (!SdkIsSimulator) {
dtXcode = AppleSdkSettings.DTXcode;
dtXcodeBuild = dtSettings.DTXcodeBuild;
}
SetValueIfNotNull (plist, "DTCompiler", dtCompiler);
SetValueIfNotNull (plist, "DTPlatformBuild", dtPlatformBuild);
SetValueIfNotNull (plist, "DTSDKBuild", dtSDKBuild);
plist.SetIfNotPresent ("DTPlatformName", dtPlatformName);
SetValueIfNotNull (plist, "DTPlatformVersion", dtPlatformVersion);
SetValue (plist, "DTSDKName", dtSDKName);
SetValueIfNotNull (plist, "DTXcode", dtXcode);
SetValueIfNotNull (plist, "DTXcodeBuild", dtXcodeBuild);
SetDeviceFamily (plist);
if (IsWatchExtension) {
if (Debug)
SetAppTransportSecurity (plist);
}
SetRequiredArchitectures (plist);
return !Log.HasLoggedErrors;
}
void SetValueIfNotNull (PDictionary dict, string key, string? value)
{
if (value is null)
return;
SetValue (dict, key, value);
}
void SetRequiredArchitectures (PDictionary plist)
{
PObject capabilities;
if (plist.TryGetValue (ManifestKeys.UIRequiredDeviceCapabilities, out capabilities)) {
if (capabilities is PArray) {
var architectureValues = new HashSet<string> (new[] { "armv6", "armv7", "arm64" });
var array = (PArray) capabilities;
// Remove any architecture values
for (int i = 0; i < array.Count; i++) {
var value = array[i] as PString;
if (value is null || !architectureValues.Contains (value.Value))
continue;
array.RemoveAt (i);
}
// If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
switch (architectures) {
case TargetArchitecture.ARM64:
array.Add (new PString ("arm64"));
break;
case TargetArchitecture.ARMv7:
array.Add (new PString ("armv7"));
break;
}
} else if (capabilities is PDictionary) {
var dict = (PDictionary) capabilities;
switch (architectures) {
case TargetArchitecture.ARM64:
dict["arm64"] = new PBoolean (true);
dict.Remove ("armv6");
dict.Remove ("armv7");
break;
case TargetArchitecture.ARMv7:
dict["armv7"] = new PBoolean (true);
dict.Remove ("armv6");
dict.Remove ("arm64");
break;
default:
dict.Remove ("armv6");
dict.Remove ("armv7");
dict.Remove ("arm64");
break;
}
}
} else {
var array = new PArray ();
// If-and-only-if the TargetArchitecture is a single architecture, set it as a required device capability
switch (architectures) {
case TargetArchitecture.ARM64:
array.Add (new PString ("arm64"));
break;
case TargetArchitecture.ARMv7:
array.Add (new PString ("armv7"));
break;
}
if (array.Count > 0)
plist.Add (ManifestKeys.UIRequiredDeviceCapabilities, array);
}
}
void SetDeviceFamily (PDictionary plist)
{
var uiDeviceFamily = IPhoneDeviceType.NotSet;
switch (Platform) {
case ApplePlatform.iOS:
if (!IsAppExtension)
plist.SetIfNotPresent (ManifestKeys.LSRequiresIPhoneOS, true);
uiDeviceFamily = IPhoneDeviceType.IPhone;
break;
case ApplePlatform.WatchOS:
uiDeviceFamily = IPhoneDeviceType.Watch;
break;
case ApplePlatform.TVOS:
uiDeviceFamily = IPhoneDeviceType.TV;
break;
}
// Don't set UIDeviceFamily if the plist already contains it
if (uiDeviceFamily != IPhoneDeviceType.NotSet && supportedDevices == IPhoneDeviceType.NotSet)
plist.SetUIDeviceFamily (uiDeviceFamily);
}
void SetAppTransportSecurity (PDictionary plist)
{
// Debugging over http has a couple of gotchas:
// * We can't use https, because that requires a valid server certificate,
// which we can't ensure.
// It would also require a hostname for the mac, which it might not have either.
// * NSAppTransportSecurity/NSExceptionDomains does not allow exceptions based
// on IP address (only hostname).
// * Which means the only way to make sure watchOS allows connections from
// the app on device to the mac is to disable App Transport Security altogether.
// Good news: watchOS 3 will apparently not apply ATS when connecting
// directly to IP addresses, which means we won't have to do this at all
// (sometime in the future).
PDictionary ats;
if (!plist.TryGetValue (ManifestKeys.NSAppTransportSecurity, out ats))
plist.Add (ManifestKeys.NSAppTransportSecurity, ats = new PDictionary ());
if (ats.GetBoolean (ManifestKeys.NSAllowsArbitraryLoads)) {
Log.LogMessage (MessageImportance.Low, MSBStrings.M0017);
} else {
Log.LogMessage (MessageImportance.Low, MSBStrings.M0018);
ats.SetBooleanOrRemove (ManifestKeys.NSAllowsArbitraryLoads, true);
}
}
}
}

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

@ -3,6 +3,7 @@ using Microsoft.Build.Utilities;
using System.IO;
using System.IO.Compression;
using Xamarin.iOS.Windows;
using Xamarin.MacDev;
namespace Xamarin.iOS.HotRestart.Tasks {
public class PrepareAppBundle : Task {
@ -36,6 +37,10 @@ namespace Xamarin.iOS.HotRestart.Tasks {
"Xamarin.PreBuilt.iOS.app.zip");
ZipFile.ExtractToDirectory (preBuiltAppBundlePath, AppBundlePath);
// Ensure the archived-expanded-entitlements.xcent is empty. If there are any entitlements in that file, the new signature will be invalid
new PDictionary ().Save (Path.Combine (AppBundlePath, "archived-expanded-entitlements.xcent"));
File.WriteAllText (Path.Combine (AppBundlePath, "Extracted"), string.Empty);
}

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

@ -60,6 +60,12 @@ xamarin_bridge_setup ()
void
xamarin_bridge_initialize ()
{
#if DOTNET
bool use_mono_workaround = xamarin_init_mono_debug && getenv ("XAMARIN_SKIP_INTERPRETER_DEBUGGING_WORKAROUND") == 0;
#else
bool use_mono_workaround = false;
#endif
if (xamarin_register_modules != NULL)
xamarin_register_modules ();
DEBUG_LAUNCH_TIME_PRINT ("\tAOT register time");
@ -69,9 +75,9 @@ xamarin_bridge_initialize ()
DEBUG_LAUNCH_TIME_PRINT ("\tDebug init time");
#endif
if (xamarin_init_mono_debug)
if (xamarin_init_mono_debug && !use_mono_workaround)
mono_debug_init (MONO_DEBUG_FORMAT_MONO);
mono_install_assembly_preload_hook (xamarin_assembly_preload_hook, NULL);
mono_install_load_aot_data_hook (xamarin_load_aot_data, xamarin_free_aot_data, NULL);
@ -85,7 +91,32 @@ xamarin_bridge_initialize ()
mono_install_unhandled_exception_hook (xamarin_unhandled_exception_handler, NULL);
mono_install_ftnptr_eh_callback (xamarin_ftnptr_exception_handler);
mono_jit_init_version ("MonoTouch", "mobile");
const char *argc[] = {
"",
"--interp=-all",
"",
NULL,
};
if (use_mono_workaround) {
// This is a workaround for a runtime bug that prevents debugging from working properly.
// We call mono_main to disable interpreter optimizations when debugging, because
// mono's own interpreter initialization doesn't take into account that the debugger
// might be attached, and the subsequent optimizations can break the debugger.
// The stdout dance is to hide mono's "helpful" output telling us the command line
// arguments are incorrect (which they would be normally, but we're abusing mono_main
// to get the side effects).
fflush (stdout);
int originalStdout = dup (STDOUT_FILENO);
int devnull = open ("/dev/null", O_RDWR);
dup2 (devnull, STDOUT_FILENO);
mono_main (2, (char**)argc);
fflush (stdout);
dup2 (originalStdout, STDOUT_FILENO);
} else {
mono_jit_init_version ("MonoTouch", "mobile");
}
/*
As part of mono initialization a preload hook is added that overrides ours, so we need to re-instate it here.
This is wasteful, but there's no way to manipulate the preload hook list except by adding to it.

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

@ -36,5 +36,5 @@ using System.Runtime.CompilerServices;
// - Assembly B should build just fine, because those two versions of Microsoft.*.dll have the exact same API.
// To avoid scenarios where everybody would have to update to the latest patch version of Microsoft.*.dll
// in order to compile stuff, we erase the third and fourth number and only use 0 for both.
[assembly: AssemblyVersion ("@NUGET_VERSION_MAJOR@.@NUGET_VERSION_MINOR@.0.0")]
[assembly: AssemblyVersion ("@NUGET_VERSION_MAJOR@.@NUGET_VERSION_MINOR@.@NUGET_VERSION_THIRD_DIGIT_WORKAROUND@.0")]
#endif

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

@ -4,8 +4,7 @@
<method signature="System.Void WarnOnce()" body="stub" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false" />
</type>
<type fullname="ObjCRuntime.Runtime">
<method signature="System.Boolean get_IsCoreCLR()" body="stub" value="false" feature="ObjCRuntime.Runtime.IsCoreCLR" featurevalue="false" />
<method signature="System.Boolean get_IsCoreCLR()" body="stub" value="true" feature="ObjCRuntime.Runtime.IsCoreCLR" featurevalue="true" />
<method signature="System.Boolean get_IsCoreCLR()" body="stub" value="true" />
</type>
<type fullname="AppKit.NSApplication">
<method signature="System.Void EnsureEventAndDelegateAreNotMismatched(System.Object,System.Type)" body="stub" feature="System.Diagnostics.Debugger.IsSupported" featurevalue="false" />

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

@ -29,6 +29,23 @@ GENERATOR_FLAGS=-process-enums -core -nologo -nostdlib -noconfig -native-excepti
GENERATOR_TF_VERSION=$(subst net,,$(DOTNET_TFM))
# This is a workaround to create assemblies with a higher version than the
# stable versions we released for Xcode 13.3. The stable versions we released
# for Xcode 13.3 has a <osmajor>.<osminor>.300 version number, but that
# version scheme has been changed, where the third digit from now on will
# always be 0 in the assembly version. However, this means that until Apple
# releases new OS versions (and we bind those versions), the assembly version
# will be lower than the stable version wherever we've implemented the new
# versioning scheme. This complicates testing, so just bump the third digit to
# 600 until we're using a new Xcode (and thus presumably new OS versions as
# well). This workaround can be removed at that point, but implement it so
# that it will just be skipped/ignored if it isn't removed.
ifeq ($(XCODE_VERSION),13.3)
NUGET_VERSION_THIRD_DIGIT_WORKAROUND=600
else
NUGET_VERSION_THIRD_DIGIT_WORKAROUND=0
endif
DOTNET_REFERENCES = \
/r:$(DOTNET_BCL_DIR)/System.Buffers.dll \
/r:$(DOTNET_BCL_DIR)/System.Collections.Concurrent.dll \
@ -177,6 +194,7 @@ $(IOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in | $(IOS_BUILD_DI
-e 's|@NUGET_VERSION_NO_METADATA@|$(IOS_NUGET_VERSION_NO_METADATA)|g' \
-e 's|@NUGET_VERSION_MAJOR@|$(IOS_NUGET_VERSION_MAJOR)|g' \
-e 's|@NUGET_VERSION_MINOR@|$(IOS_NUGET_VERSION_MINOR)|g' \
-e 's|@NUGET_VERSION_THIRD_DIGIT_WORKAROUND@|$(NUGET_VERSION_THIRD_DIGIT_WORKAROUND)|g' \
-e 's|@NUGET_VERSION_REV@|$(IOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(IOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|iOS|g' \
@ -550,6 +568,7 @@ $(MAC_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in | $(MAC_BUILD_DI
-e 's|@NUGET_VERSION_NO_METADATA@|$(MACOS_NUGET_VERSION_NO_METADATA)|g' \
-e 's|@NUGET_VERSION_MAJOR@|$(MACOS_NUGET_VERSION_MAJOR)|g' \
-e 's|@NUGET_VERSION_MINOR@|$(MACOS_NUGET_VERSION_MINOR)|g' \
-e 's|@NUGET_VERSION_THIRD_DIGIT_WORKAROUND@|$(NUGET_VERSION_THIRD_DIGIT_WORKAROUND)|g' \
-e 's|@NUGET_VERSION_REV@|$(MACOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(MACOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|macOS|g' \
@ -1161,6 +1180,7 @@ $(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.con
-e 's|@NUGET_VERSION_NO_METADATA@|$(TVOS_NUGET_VERSION_NO_METADATA)|g' \
-e 's|@NUGET_VERSION_MAJOR@|$(TVOS_NUGET_VERSION_MAJOR)|g' \
-e 's|@NUGET_VERSION_MINOR@|$(TVOS_NUGET_VERSION_MINOR)|g' \
-e 's|@NUGET_VERSION_THIRD_DIGIT_WORKAROUND@|$(NUGET_VERSION_THIRD_DIGIT_WORKAROUND)|g' \
-e 's|@NUGET_VERSION_REV@|$(TVOS_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(TVOS_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|tvOS|g' \
@ -1379,6 +1399,7 @@ $(MACCATALYST_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/M
-e 's|@NUGET_VERSION_NO_METADATA@|$(MACCATALYST_NUGET_VERSION_NO_METADATA)|g' \
-e 's|@NUGET_VERSION_MAJOR@|$(MACCATALYST_NUGET_VERSION_MAJOR)|g' \
-e 's|@NUGET_VERSION_MINOR@|$(MACCATALYST_NUGET_VERSION_MINOR)|g' \
-e 's|@NUGET_VERSION_THIRD_DIGIT_WORKAROUND@|$(NUGET_VERSION_THIRD_DIGIT_WORKAROUND)|g' \
-e 's|@NUGET_VERSION_REV@|$(MACCATALYST_NUGET_VERSION_PATCH)|g' \
-e 's|@NUGET_VERSION_BUILD@|$(MACCATALYST_NUGET_COMMIT_DISTANCE)|g' \
-e 's|@DOTNET_PLATFORM@|MacCatalyst|g' \

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

@ -165,10 +165,9 @@ namespace Security {
else
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnData);
IntPtr ptr;
status = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
status = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
if (status == SecStatusCode.Success)
return Runtime.GetNSObject<NSData> (ptr, false);
return Runtime.GetNSObject<NSData> (ptr, true);
return null;
}
}
@ -185,14 +184,18 @@ namespace Security {
else
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnData);
IntPtr ptr;
status = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
status = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
n = null;
if (status == SecStatusCode.Success){
if (max == 1)
return new NSData [] { Runtime.GetNSObject<NSData> (ptr, false)! };
// From the header docs, it's guaranteed the function will return an array only if we pass max > 1.
return NSArray.ArrayFromHandle<NSData> (ptr);
// By default, this function returns only the first match found.
// To obtain more than one matching item at a time, specify the search key kSecMatchLimit with a value greater than 1.
// The result will be an object of type CFArrayRef containing up to that number of matching items.
if (max == 1)
return new NSData [] { Runtime.GetNSObject<NSData> (ptr, true)! };
return CFArray.ArrayFromHandle<NSData> (ptr, true)!;
}
return null;
}
@ -219,10 +222,9 @@ namespace Security {
SetLimit (copy, 1);
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnAttributes);
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnData);
IntPtr ptr;
result = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
result = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
if (result == SecStatusCode.Success)
return new SecRecord (new NSMutableDictionary (ptr, false));
return new SecRecord (new NSMutableDictionary (ptr, true));
return null;
}
}
@ -237,11 +239,13 @@ namespace Security {
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnData);
var n = SetLimit (copy, max);
IntPtr ptr;
result = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
result = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
n = null;
if (result == SecStatusCode.Success)
return NSArray.ArrayFromHandleFunc<SecRecord> (ptr, (element) => new SecRecord (Runtime.GetNSObject<NSMutableDictionary> (element, false)!))!;
return CFArray.ArrayFromHandleFunc<SecRecord> (ptr, (element) => {
var dictionary = Runtime.GetNSObject<NSMutableDictionary> (element, false)!;
return new SecRecord (dictionary);
}, releaseHandle: true)!;
return null;
}
}
@ -257,20 +261,23 @@ namespace Security {
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnRef);
SetLimit (copy, max);
IntPtr ptr;
result = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
result = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
if ((result == SecStatusCode.Success) && (ptr != IntPtr.Zero)) {
var array = NSArray.ArrayFromHandle<INativeObject> (ptr, p => {
var array = CFArray.ArrayFromHandleFunc<INativeObject> (ptr, p => {
nint cfType = CFType.GetTypeID (p);
CFObject.CFRetain (p);
if (cfType == SecCertificate.GetTypeID ())
return new SecCertificate (p, true);
else if (cfType == SecKey.GetTypeID ())
return new SecKey (p, true);
else if (cfType == SecIdentity.GetTypeID ())
return new SecIdentity (p, true);
else
else {
CFObject.CFRelease (p);
throw new Exception (String.Format ("Unexpected type: 0x{0:x}", cfType));
})!;
}
}, releaseHandle: true)!;
return array;
}
return null;
@ -551,8 +558,7 @@ namespace Security {
copy.LowlevelSetObject (CFBoolean.TrueHandle, SecItem.ReturnRef);
SetLimit (copy, 1);
IntPtr ptr;
result = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
result = SecItem.SecItemCopyMatching (copy.Handle, out var ptr);
if ((result == SecStatusCode.Success) && (ptr != IntPtr.Zero)) {
nint cfType = CFType.GetTypeID (ptr);

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

@ -12,9 +12,14 @@ using CoreGraphics;
using Foundation;
using ObjCRuntime;
using System;
using System.ComponentModel;
namespace UIKit {
#if XAMCORE_5_0
#error All PDF public name instances in this file need to be turned into Pdf. e.g. EndPDFContext into EndPdfContext.
#endif
public static class UIGraphics {
[DllImport (Constants.UIKitLibrary)]
extern static IntPtr UIGraphicsGetCurrentContext ();
@ -125,10 +130,16 @@ namespace UIKit {
[DllImport (Constants.UIKitLibrary)]
extern static void UIGraphicsEndPDFContext ();
public static void EndPDFContent () {
public static void EndPDFContext () {
UIGraphicsEndPDFContext ();
}
#if !XAMCORE_5_0
[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete ("Use 'EndPDFContext' instead.")]
public static void EndPDFContent () => EndPDFContext ();
#endif
public static UIImage GetImageFromCurrentImageContext ()
{
using (var pool = new NSAutoreleasePool ()) {

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

@ -13322,6 +13322,7 @@ namespace AppKit {
[Deprecated (PlatformName.MacOSX, 12, 0, message: "Use 'AllowedContentTypes' instead.")]
[Export ("allowedFileTypes")]
[NullAllowed]
string [] AllowedFileTypes { get; set; }
[Mac (11, 0)]

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

@ -7,6 +7,8 @@ using Microsoft.Build.Utilities;
using Xamarin.MacDev;
using System.Linq;
using Xamarin.MacDev.Tasks;
namespace Xamarin.iOS.Tasks
{
[TestFixture]
@ -26,7 +28,7 @@ namespace Xamarin.iOS.Tasks
get; set;
}
protected CompileAppManifestTaskCore Task {
protected CompileAppManifest Task {
get; set;
}

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

@ -37,44 +37,75 @@
<_PackNativePath>runtimes/$(_RuntimeIdentifier)/native</_PackNativePath>
</PropertyGroup>
<ItemGroup>
<!-- FrameworksInRuntimesNativeDirectory1.framework -->
<DotnetPlatforms Include="$(DOTNET_PLATFORMS)" />
<DotnetPlatforms>
<Platform>%(Identity)</Platform>
</DotnetPlatforms>
</ItemGroup>
<PropertyGroup>
<iOS_Included Condition="@(DotnetPlatforms->AnyHaveMetadataValue('Platform', 'iOS'))">true</iOS_Included>
<tvOS_Included Condition="@(DotnetPlatforms->AnyHaveMetadataValue('Platform', 'tvOS'))">true</tvOS_Included>
<macOS_Included Condition="@(DotnetPlatforms->AnyHaveMetadataValue('Platform', 'macOS'))">true</macOS_Included>
<MacCatalyst_Included Condition="@(DotnetPlatforms->AnyHaveMetadataValue('Platform', 'MacCatalyst'))">true</MacCatalyst_Included>
</PropertyGroup>
<!-- FrameworksInRuntimesNativeDirectory1.framework -->
<ItemGroup Condition="'$(iOS_Included)' == 'true'">
<!-- iOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/ios-arm64/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/ios-arm64/native/FrameworksInRuntimesNativeDirectory1.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/ios-arm/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/ios-arm/native/FrameworksInRuntimesNativeDirectory1.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/iossimulator-x64/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/iossimulator-x64/native/FrameworksInRuntimesNativeDirectory1.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/iossimulator-x86/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/iossimulator-x86/native/FrameworksInRuntimesNativeDirectory1.framework/" />
</ItemGroup>
<ItemGroup Condition="'$(tvOS_Included)' == 'true'">
<!-- tvOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/tvos-arm64/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/tvos-arm64/native/FrameworksInRuntimesNativeDirectory1.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/tvossimulator-x64/FrameworksInRuntimesNativeDirectory1.framework/*" IsNative="true" PackagePath="runtimes/tvossimulator-x64/native/FrameworksInRuntimesNativeDirectory1.framework/" />
</ItemGroup>
<ItemGroup Condition="'$(macOS_Included)' == 'true'">
<!-- macOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/osx-x64/FrameworksInRuntimesNativeDirectory1.framework.zip" IsNative="true" PackagePath="runtimes/osx-x64/native/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/osx-arm64/FrameworksInRuntimesNativeDirectory1.framework.zip" IsNative="true" PackagePath="runtimes/osx-arm64/native/" />
</ItemGroup>
<ItemGroup Condition="'$(MacCatalyst_Included)' == 'true'">
<!-- Mac Catalyst -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/maccatalyst-x64/FrameworksInRuntimesNativeDirectory1.framework.zip" IsNative="true" PackagePath="runtimes/maccatalyst-x64/native/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/maccatalyst-arm64/FrameworksInRuntimesNativeDirectory1.framework.zip" IsNative="true" PackagePath="runtimes/maccatalyst-arm64/native/" />
</ItemGroup>
<!-- FrameworksInRuntimesNativeDirectory2.framework -->
<!-- FrameworksInRuntimesNativeDirectory2.framework -->
<ItemGroup Condition="'$(iOS_Included)' == 'true'">
<!-- iOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/ios-arm64/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/ios-arm64/native/FrameworksInRuntimesNativeDirectory2.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/ios-arm/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/ios-arm/native/FrameworksInRuntimesNativeDirectory2.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/iossimulator-x64/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/iossimulator-x64/native/FrameworksInRuntimesNativeDirectory2.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/iossimulator-x86/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/iossimulator-x86/native/FrameworksInRuntimesNativeDirectory2.framework/" />
</ItemGroup>
<ItemGroup Condition="'$(tvOS_Included)' == 'true'">
<!-- tvOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/tvos-arm64/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/tvos-arm64/native/FrameworksInRuntimesNativeDirectory2.framework/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/tvossimulator-x64/FrameworksInRuntimesNativeDirectory2.framework/*" IsNative="true" PackagePath="runtimes/tvossimulator-x64/native/FrameworksInRuntimesNativeDirectory2.framework/" />
</ItemGroup>
<ItemGroup Condition="'$(macOS_Included)' == 'true'">
<!-- macOS -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/osx-x64/FrameworksInRuntimesNativeDirectory2.framework.zip" IsNative="true" PackagePath="runtimes/osx-x64/native/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/osx-arm64/FrameworksInRuntimesNativeDirectory2.framework.zip" IsNative="true" PackagePath="runtimes/osx-arm64/native/" />
</ItemGroup>
<ItemGroup Condition="'$(MacCatalyst_Included)' == 'true'">
<!-- Mac Catalyst -->
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/maccatalyst-x64/FrameworksInRuntimesNativeDirectory2.framework.zip" IsNative="true" PackagePath="runtimes/maccatalyst-x64/native/" />
<_PackageFiles Include="$(TestFrameworksDirectory)/.libs/maccatalyst-arm64/FrameworksInRuntimesNativeDirectory2.framework.zip" IsNative="true" PackagePath="runtimes/maccatalyst-arm64/native/" />
</ItemGroup>
<ItemGroup>
<!-- Set TargetPath=PackagePath for all files -->
<_PackageFiles TargetPath="%(PackagePath)" />
</ItemGroup>

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

@ -10,6 +10,7 @@ PACKAGE_ID=$(shell grep PackageId FrameworksInRuntimesNativeDirectory.csproj | s
PACKAGE_VERSION=$(shell grep '<PackageVersion>' FrameworksInRuntimesNativeDirectory.csproj | sed 's_.*<PackageVersion>\(.*\)</PackageVersion>.*_\1_')
# Test case for https://github.com/xamarin/xamarin-macios/issues/12440
.libs/FrameworksInRuntimesNativeDirectory.nupkg: export DOTNET_PLATFORMS:=$(shell echo $(DOTNET_PLATFORMS) | tr ' ' ';')
.libs/FrameworksInRuntimesNativeDirectory.nupkg: FrameworksInRuntimesNativeDirectory.csproj $(wildcard *.cs) | .libs
$(Q) mkdir -p $(abspath $(NUGET_TEST_FEED))
$(Q_GEN) $(DOTNET) pack /bl $(DOTNET_PACK_VERBOSITY) $<

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

@ -4945,10 +4945,12 @@ namespace Registrar {
string wrapperName;
if (!signatures.TryGetValue (signature.ToString (), out wrapperName)) {
var name = "xamarin_pinvoke_wrapper_" + method.Name;
var methodName = method.Name.Replace ('<', '_').Replace ('>', '_').Replace ('|', '_');
var baseName = "xamarin_pinvoke_wrapper_" + methodName;
var name = baseName;
var counter = 0;
while (names.Contains (name)) {
name = "xamarin_pinvoke_wrapper_" + method.Name + (++counter).ToString ();
name = baseName + (++counter).ToString ();
}
names.Add (name);
signatures [signature.ToString ()] = wrapperName = name;

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

@ -26,6 +26,8 @@ $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mla
$(Q) mkdir -p $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/
$(Q) $(CP) -R $(TOP)/packages/microsoft.tools.mlaunch/$(MLAUNCH_NUGET_VERSION)/mlaunch/bin/mlaunch $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/
$(Q) $(CP) -R $(TOP)/packages/microsoft.tools.mlaunch/$(MLAUNCH_NUGET_VERSION)/mlaunch/lib/mlaunch $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/
$(Q) chmod a+x $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch
$(Q) chmod a+x $(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch
define DotNetInstall
$$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/bin/mlaunch: $$(DOWNLOAD_STAMP_FILE)
@ -35,6 +37,8 @@ $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/bin/mlaunch: $$(DOWNLOAD_STAMP_FILE)
$$(Q) mkdir -p $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/lib
$$(Q) $$(CP) -R $(TOP)/packages/microsoft.tools.mlaunch/$$(MLAUNCH_NUGET_VERSION)/mlaunch/bin/mlaunch $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/bin/mlaunch
$$(Q) $$(CP) -R $(TOP)/packages/microsoft.tools.mlaunch/$$(MLAUNCH_NUGET_VERSION)/mlaunch/lib/mlaunch $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/lib
$$(Q) chmod a+x $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/bin/mlaunch
$$(Q) chmod a+x $$(DOTNET_DESTDIR)/Microsoft.$(1).Sdk/tools/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch
endef
$(foreach platform,$(DOTNET_PLATFORMS_MOBILE),$(eval $(call DotNetInstall,$(platform))))

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

@ -64,7 +64,7 @@ namespace Microsoft.MaciOS.Nnyeah {
if (CreateReworker (map) is Reworker reworker) {
reworker.WarningIssued += (_, e) => warnings.Add (e.HelpfulMessage ());
reworker.Transformed += (_, e) => warnings.Add (e.HelpfulMessage ());
reworker.Transformed += (_, e) => transforms.Add (e.HelpfulMessage ());
try {
using var ostm = new FileStream (Outfile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

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

@ -0,0 +1,50 @@
using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace Microsoft.MaciOS.Nnyeah {
public static class InstructionExtensions {
// The ctor for Instruction is internal and there is no clone/copy method,
// therefore we have to drill through the types.
public static Instruction Copy (this Instruction i)
{
if (i.Operand is null)
return Instruction.Create (i.OpCode);
switch (i.Operand) {
case TypeReference tr:
return Instruction.Create (i.OpCode, tr);
case CallSite cs:
return Instruction.Create (i.OpCode, cs);
case MethodReference mr:
return Instruction.Create (i.OpCode, mr);
case FieldReference fr:
return Instruction.Create (i.OpCode, fr);
case string str:
return Instruction.Create (i.OpCode, str);
case sbyte sb:
return Instruction.Create (i.OpCode, sb);
case byte b:
return Instruction.Create (i.OpCode, b);
case int it:
return Instruction.Create (i.OpCode, it);
case long lg:
return Instruction.Create (i.OpCode, lg);
case float ft:
return Instruction.Create (i.OpCode, ft);
case double db:
return Instruction.Create (i.OpCode, db);
case Instruction instr:
return Instruction.Create (i.OpCode, instr);
case Instruction [] instrArr:
return Instruction.Create (i.OpCode, instrArr);
case VariableDefinition vd:
return Instruction.Create (i.OpCode, vd);
case ParameterDefinition pd:
return Instruction.Create (i.OpCode, pd);
default: // can't happen (in theory)
throw new InvalidOperationException ();
}
}
}
}

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

@ -0,0 +1,19 @@
using System;
using Mono.Cecil;
namespace Microsoft.MaciOS.Nnyeah {
public static class MethodReferenceExtensions {
public static MethodReference WithParameters (this MethodReference reference, params TypeReference [] types)
{
foreach (var type in types) {
reference.Parameters.Add (new ParameterDefinition (type));
}
return reference;
}
public static MethodReference WithParameter (this MethodReference reference, TypeReference type)
{
reference.Parameters.Add (new ParameterDefinition (type));
return reference;
}
}
}

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

@ -2,13 +2,15 @@ using System;
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Linq;
namespace Microsoft.MaciOS.Nnyeah {
public class MethodTransformations {
static List<Transformation>? allTransforms;
static Dictionary<string, Transformation>? transformTable;
public Dictionary<string, Transformation> GetTransforms (ModuleContainer modules, Func<List<bool>, CustomAttribute> attrBuilder)
public Dictionary<string, Transformation> GetTransforms (ModuleContainer modules, Func<List<bool>, CustomAttribute> attrBuilder,
TypeReference nfloatTypeRef)
{
var moduleToEdit = modules.ModuleToEdit;
if (transformTable is not null) {
@ -157,7 +159,6 @@ namespace Microsoft.MaciOS.Nnyeah {
Instruction.Create (OpCodes.Call, mref),
Instruction.Create (OpCodes.Conv_I) }));
var nfloatTypeRef = new TypeReference ("System.Runtime.InteropServices", "NFloat", moduleToEdit, moduleToEdit.TypeSystem.CoreLibrary);
mref = new MethodReference (".ctor", moduleToEdit.TypeSystem.Void, nfloatTypeRef);
mref.Parameters.Add (new ParameterDefinition (moduleToEdit.TypeSystem.Double));
mref = moduleToEdit.ImportReference (mref);
@ -307,7 +308,6 @@ namespace Microsoft.MaciOS.Nnyeah {
allTransforms.Add (new Transformation ("System.Boolean System.nuint::TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.nuint&)",
Instruction.Create (OpCodes.Call, mref)));
decimalTypeReference = new TypeReference ("System", "Decimal", moduleToEdit, moduleToEdit.TypeSystem.CoreLibrary);
mref = new MethodReference ("op_Implicit", decimalTypeReference, decimalTypeReference);
mref.Parameters.Add (new ParameterDefinition (moduleToEdit.TypeSystem.UInt64));
mref = moduleToEdit.ImportReference (mref);
@ -326,7 +326,6 @@ namespace Microsoft.MaciOS.Nnyeah {
Instruction.Create (OpCodes.Call, mref),
Instruction.Create (OpCodes.Conv_U) }));
nfloatTypeRef = new TypeReference ("System.Runtime.InteropServices", "NFloat", moduleToEdit, moduleToEdit.TypeSystem.CoreLibrary);
mref = new MethodReference (".ctor", moduleToEdit.TypeSystem.Void, nfloatTypeRef);
mref.Parameters.Add (new ParameterDefinition (moduleToEdit.TypeSystem.Double));
mref = moduleToEdit.ImportReference (mref);
@ -351,6 +350,117 @@ namespace Microsoft.MaciOS.Nnyeah {
//"System.nuint System.nuint::op_Explicit(System.nfloat)"
allTransforms.Add (NewOneParamCtorXform ("System.Void System.nfloat::.ctor(System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewOneParamCtorXform ("System.Void System.nfloat::.ctor(System.Single)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Single));
allTransforms.Add (NewOneParamCtorXform ("System.Void System.nfloat::.ctor(System.Double)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Double));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.SByte)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.SByte));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Byte)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Byte));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Char)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Char));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.IntPtr)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.IntPtr));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Int16)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Int16));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.UInt16)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.UInt16));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Int32)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Int32));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.UInt32)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.UInt32));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Int64)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Int64));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.UInt64)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.UInt64));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Implicit(System.Single)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Implicit", moduleToEdit.TypeSystem.Single));
allTransforms.Add (NewFuncXform ("System.Double System.nfloat::op_Implicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Double, "op_Implicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.IntPtr System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.IntPtr, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.SByte System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.SByte, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Byte System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Byte, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Char System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Char, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Int16 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int16, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.IntU16 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.UInt16, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Int32 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int32, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.UInt32 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.UInt32, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Int64 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int64, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.UInt64 System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.UInt64, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Single System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Single, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Explicit(System.Double)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Explicit", moduleToEdit.TypeSystem.Double));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Explicit(System.IntPtr)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Explicit", moduleToEdit.TypeSystem.IntPtr));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Explicit(System.Decimal)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Explicit", decimalTypeReference));
allTransforms.Add (NewFuncXform ("System.Decimal System.nfloat::op_Explicit(System.nfloat)", moduleToEdit, nfloatTypeRef, decimalTypeReference, "op_Explicit", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_UnaryPlus(System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_UnaryPlus", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_UnaryNegation(System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_UnaryNegation", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Increment(System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Increment", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Decrement(System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Decrement", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Addition(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Addition", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Subtraction(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Subtraction", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Multiply(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Multiply", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Division(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Division", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::op_Modulus(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, nfloatTypeRef, "op_Modulus", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_Equality(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_Equality", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_Inequality(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_Inequality", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_LessThan(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_LessThan", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_GreaterThan(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_GreaterThan", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_LessThanOrEqual(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_LessThanOrEqual", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::op_GreaterThanOrEqual(System.nfloat,System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "op_GreaterThanOrEqual", nfloatTypeRef, nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Int32 System.nfloat::CompareTo(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int32, "CompareTo", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Int32 System.nfloat::CompareTo(System.Object)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int32, "CompareTo", moduleToEdit.TypeSystem.Object));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::Equals(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "Equals", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::Equals(System.Object)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "Equals", moduleToEdit.TypeSystem.Object));
allTransforms.Add (NewFuncXform ("System.Int32 System.nfloat::GetHashCode()", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Int32, "GetHashCode"));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::IsNaN(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "IsNaN", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::IsInfinity(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "IsInfinity", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::IsPositiveInfinity(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "IsPositiveInfinity", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.Boolean System.nfloat::IsNegativeInfinity(System.nfloat)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.Boolean, "IsNegativeInfinity", nfloatTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::Parse(System.String,System.IFormatProvider)",
moduleToEdit, nfloatTypeRef, nfloatTypeRef, "Parse", moduleToEdit.TypeSystem.String, formatProviderTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::Parse(System.String,System.Globalization.NumberStyles)",
moduleToEdit, nfloatTypeRef, nfloatTypeRef, "Parse", moduleToEdit.TypeSystem.String, globNumberStylesTypeRef));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::Parse(System.String)",
moduleToEdit, nfloatTypeRef, nfloatTypeRef, "Parse", moduleToEdit.TypeSystem.String));
allTransforms.Add (NewFuncXform ("System.nfloat System.nfloat::Parse(System.String,System.Globalization.NumberStyles,System.IFormatProvider)",
moduleToEdit, nfloatTypeRef, nfloatTypeRef, "Parse", moduleToEdit.TypeSystem.String, globNumberStylesTypeRef, formatProviderTypeRef));
var nfloatRefParam = new ParameterDefinition (nfloatTypeRef);
nfloatRefParam.CustomAttributes.Add (attrBuilder (singleBool));
nfloatRefParam.IsOut = true;
mref = new MethodReference ("TryParse", boolType, nfloatTypeRef);
mref.Parameters.Add (stringParam);
mref.Parameters.Add (nfloatRefParam);
mref = moduleToEdit.ImportReference (mref);
allTransforms.Add (new Transformation ("System.Boolean System.nfloat::TryParse(System.String,System.nfloat&)",
Instruction.Create (OpCodes.Call, mref)));
mref = new MethodReference ("TryParse", boolType, nfloatTypeRef);
mref.Parameters.Add (stringParam);
mref.Parameters.Add (globNumberStylesParam);
mref.Parameters.Add (formatProviderParam);
mref.Parameters.Add (nfloatRefParam);
mref = moduleToEdit.ImportReference (mref);
allTransforms.Add (new Transformation ("System.Boolean System.nfloat::TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.nfloat&)",
Instruction.Create (OpCodes.Call, mref)));
allTransforms.Add (NewFuncXform ("System.String System.nfloat::ToString()", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.String, "ToString"));
allTransforms.Add (NewFuncXform ("System.String System.nfloat::ToString(System.IFormatProvider)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.String, "ToString", formatProviderTypeRef));
allTransforms.Add (NewFuncXform ("System.String System.nfloat::ToString(System.String)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.String, "ToString", moduleToEdit.TypeSystem.String));
allTransforms.Add (NewFuncXform ("System.String System.nfloat::ToString(System.String,System.IFormatProvider)", moduleToEdit, nfloatTypeRef, moduleToEdit.TypeSystem.String, "ToString", moduleToEdit.TypeSystem.String, formatProviderTypeRef));
allTransforms.Add (NewFuncXform ("System.TypeCode System.nfloat::GetTypeCode()", moduleToEdit, nfloatTypeRef, typeCodeRef, "GetTypeCode"));
var getConstantRef = GetGetConstantRef (modules.MicrosoftModule, moduleToEdit);
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Video()", 0));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Audio()", 1));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Text()", 2));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_ClosedCaption()", 3));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Subtitle()", 4));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Timecode()", 5));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_TimedMetadata()", 6));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Muxed()", 7));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_MetadataObject()", 8));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_Metadata()", 9));
allTransforms.Add (AVMediaTypeTransform (getConstantRef, "Foundation.NSString AVFoundation.AVMediaType::get_DepthData()", 10));
transformTable = new Dictionary<string, Transformation> ();
foreach (var xform in allTransforms) {
@ -359,6 +469,49 @@ namespace Microsoft.MaciOS.Nnyeah {
return transformTable;
}
static Transformation AVMediaTypeTransform (MethodReference getConstantRef, string oldSignature, int constant)
{
return new Transformation (oldSignature,
TransformationAction.Replace,
new List<Instruction> () {
Instruction.Create (OpCodes.Ldc_I4, constant),
Instruction.Create (OpCodes.Call, getConstantRef),
});
}
static MethodReference GetGetConstantRef (ModuleDefinition msModule, ModuleDefinition moduleToEdit)
{
var mediaTypesExtensionsDef = msModule.GetType ("AVFoundation.AVMediaTypesExtensions");
var avMediaTypesExtensionsRef = moduleToEdit.ImportReference (mediaTypesExtensionsDef);
var getConstantDef = mediaTypesExtensionsDef.Methods.FirstOrDefault (m => m.Name == "GetConstant");
return moduleToEdit.ImportReference (getConstantDef);
}
static Transformation NewOneParamCtorXform (string oldSignature, ModuleDefinition moduleToEdit, TypeReference owningType,
TypeReference parameterType)
{
var mref = new MethodReference (".ctor", moduleToEdit.TypeSystem.Void, owningType)
.WithParameter (parameterType);
moduleToEdit.ImportReference (mref);
return new Transformation (oldSignature,
TransformationAction.Replace,
new List<Instruction> () {
Instruction.Create (OpCodes.Newobj, mref)
});
}
static Transformation NewFuncXform (string oldSignature, ModuleDefinition moduleToEdit, TypeReference owningType,
TypeReference returnType, string methodName, params TypeReference [] parameterTypes)
{
var mref = new MethodReference (methodName, returnType, owningType)
.WithParameters (parameterTypes);
moduleToEdit.ImportReference (mref);
return new Transformation (oldSignature,
TransformationAction.Replace,
new List<Instruction> () {
Instruction.Create (OpCodes.Call, mref)
});
}
static Transformation [] transforms = new Transformation [] {
new Transformation (
@ -845,6 +998,10 @@ namespace Microsoft.MaciOS.Nnyeah {
Errors.N0002),
new Transformation ("System.Void System.nuint::CopyArray(System.nuint[],System.Int32,System.IntPtr,System.Int32)",
Errors.N0002),
new Transformation ("System.Void System.nfloat::CopyArray(System.IntPtr,System.nfloat[],System.Int32,System.Int32)",
Errors.N0002),
new Transformation ("System.Void System.nfloat::CopyArray(System.nfloat[],System.Int32,System.IntPtr,System.Int32)",
Errors.N0002),
};
}
}

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

@ -118,13 +118,12 @@ namespace Microsoft.MaciOS.Nnyeah {
}
if (!ModuleToEdit.TryGetTypeReference ("System.nfloat", out NfloatTypeReference)) {
NfloatTypeReference = EmptyTypeReference;
NewNfloatTypeReference = EmptyTypeReference;
} else {
NewNfloatTypeReference = ModuleToEdit.ImportReference (new TypeReference ("System.Runtime.InteropServices", "NFloat", null, InteropServicesAssembly, true));
}
NewNfloatTypeReference = ModuleToEdit.ImportReference (new TypeReference ("System.Runtime.InteropServices", "NFloat", null, InteropServicesAssembly, true));
NewNativeHandleTypeDefinition = modules.MicrosoftModule.Types.First (t => t.FullName == "ObjCRuntime.NativeHandle");
var nativeHandleOpImplicit = NewNativeHandleTypeDefinition.Resolve ().GetMethods ().First (m => m.FullName == "ObjCRuntime.NativeHandle ObjCRuntime.NativeHandle::op_Implicit(System.IntPtr)");
ReplacePlatformAssemblyReference ();
ConstructorTransforms = new ConstructorTransforms (ModuleToEdit.ImportReference (NewNativeHandleTypeDefinition), ModuleToEdit.TypeSystem.Boolean, ModuleToEdit.ImportReference (nativeHandleOpImplicit), WarningIssued, Transformed);
NativeHandleGetHandleReference = NewNativeHandleTypeDefinition.Methods.First (m => m.Name == "get_Handle");
@ -197,7 +196,8 @@ namespace Microsoft.MaciOS.Nnyeah {
typeDef.CustomAttributes.Add (attr_Embedded);
// add [AttributeUsage(...)]
var attrUsageCtorReference = new MethodReference (".ctor", module.TypeSystem.Void, AttributeTargetsTypeReference);
module.ImportReference (AttributeUsageTypeReference);
var attrUsageCtorReference = new MethodReference (".ctor", module.TypeSystem.Void, AttributeUsageTypeReference);
attrUsageCtorReference.HasThis = true;
attrUsageCtorReference.Parameters.Add (new ParameterDefinition (AttributeTargetsTypeReference));
module.ImportReference (attrUsageCtorReference);
@ -269,7 +269,7 @@ namespace Microsoft.MaciOS.Nnyeah {
Dictionary<string, Transformation> LoadMethodSubs ()
{
var methodSubSource = new MethodTransformations ();
var subs = methodSubSource.GetTransforms (Modules, NativeIntAttribute);
var subs = methodSubSource.GetTransforms (Modules, NativeIntAttribute, NewNfloatTypeReference);
return subs;
}
@ -284,7 +284,6 @@ namespace Microsoft.MaciOS.Nnyeah {
public void Rework (Stream stm)
{
ReplacePlatformAssemblyReference ();
foreach (var type in ModuleToEdit.Types) {
ReworkType (type);
}
@ -318,7 +317,7 @@ namespace Microsoft.MaciOS.Nnyeah {
{
for (int i = ModuleToEdit.AssemblyReferences.Count - 1; i >= 0; i--) {
if (IsXamarinReference (ModuleToEdit.AssemblyReferences [i])) {
ModuleToEdit.AssemblyReferences[i] = new AssemblyNameReference (Modules.MicrosoftModule.Assembly.Name.Name, Modules.MicrosoftModule.Assembly.Name.Version);
ModuleToEdit.AssemblyReferences [i] = AssemblyNameReference.Parse (Modules.MicrosoftModule.Assembly.ToString ());
}
}
}

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

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
namespace Microsoft.MaciOS.Nnyeah {
public class Transformation {
@ -39,33 +40,64 @@ namespace Microsoft.MaciOS.Nnyeah {
public bool TryPerformTransform (Instruction old, MethodBody body)
{
var instructionsCopy = CopyInstructions ();
var il = body.GetILProcessor ();
body.SimplifyMacros ();
switch (Action) {
case TransformationAction.Remove:
var @new = Instruction.Create (OpCodes.Nop);
il.InsertAfter (old, @new);
PatchReferences (body, old, @new);
il.Remove (old);
break;
case TransformationAction.Insert:
foreach (var instr in Instructions) {
foreach (var instr in instructionsCopy) {
il.InsertBefore (old, AddVariableIfNeeded (body, instr));
}
break;
case TransformationAction.Append:
foreach (var instr in Enumerable.Reverse (Instructions)) {
foreach (var instr in Enumerable.Reverse (instructionsCopy)) {
il.InsertAfter (old, AddVariableIfNeeded (body, instr));
}
break;
case TransformationAction.Replace:
foreach (var instr in Instructions) {
il.InsertBefore (old, AddVariableIfNeeded (body, instr));
foreach (var instr in Enumerable.Reverse (instructionsCopy)) {
il.InsertAfter (old, AddVariableIfNeeded (body, instr));
}
var newInstr = instructionsCopy [0];
PatchReferences (body, old, @newInstr);
il.Remove (old);
break;
case TransformationAction.Warn:
body.OptimizeMacros ();
return false;
}
body.OptimizeMacros ();
return true;
}
List<Instruction> CopyInstructions ()
{
var instrs = new List<Instruction> (Instructions.Count);
instrs.AddRange (Instructions.Select (i => i. Copy()));
return instrs;
}
static void PatchReferences (MethodBody body, Instruction old, Instruction @new)
{
foreach (var instruction in body.Instructions) {
if (instruction.Operand is Instruction target && target == old) {
instruction.Operand = @new;
} else if (instruction.Operand is Instruction [] targets) {
for (int i = 0; i < targets.Length; i++) {
if (targets [i] == old) {
targets [i] = @new;
}
}
}
}
}
static Instruction AddVariableIfNeeded (MethodBody body, Instruction instr)
{
if (instr.Operand is VariableDefinition variable && !body.Variables.Contains (variable))

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

@ -283,5 +283,20 @@ public class Foo : NSObject {
AssertInstruction (instructions [createInstructionIndex - 1], "ldloc");
AssertNativeHandleCtorCalled (instructions);
}
[Test]
public async Task OneReferenceThanks ()
{
var pathToModule = await TestRunning.BuildTemporaryLibrary (@"
using System;
using Foundation;
public class Foo : NSObject {
public Foo (IntPtr p) : base (p) { }
}");
var editedModule = ReworkerHelper.GetReworkedModule (pathToModule)!;
var totalMSModules = editedModule.AssemblyReferences.Count ((nameRef => nameRef.Name == "Microsoft.macOS"));
Assert.AreEqual (1, totalMSModules, "More than one Microsoft.macOS reference");
}
}
}

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

@ -5,6 +5,7 @@ using NUnit.Framework;
using Mono.Cecil;
using Microsoft.MaciOS.Nnyeah;
using Xamarin;
using System.Linq;
namespace Microsoft.MaciOS.Nnyeah.Tests {
@ -38,5 +39,40 @@ public class Foo {{
var platform = module.XamarinPlatformName ();
Assert.AreEqual (Microsoft.MaciOS.Nnyeah.PlatformName.None, platform, "still has Xamarin dependency");
}
[TestCase]
public async Task CorrectAttributes ()
{
var dir = Cache.CreateTemporaryDirectory ("CorrectAttributes");
var code = @"
using System;
public class Foo {
public nint Ident (nint e) => e;
}
";
await TestRunning.BuildLibrary (code, "NoName", dir);
var expectedOutputFile = Path.Combine (dir, "NoName.dll");
var targetRewrite = Path.Combine (dir, "NoNameRemoved.dll");
Assert.DoesNotThrow (() => {
AssemblyConverter.Convert (Compiler.XamarinPlatformLibraryPath (PlatformName.macOS),
Compiler.MicrosoftPlatformLibraryPath (PlatformName.macOS), expectedOutputFile,
targetRewrite, verbose: false, forceOverwrite: true, suppressWarnings: true);
}, $"Failed to process assembly for type nint");
Assert.IsTrue (File.Exists (targetRewrite), $"target file not created for type nint");
var module = ModuleDefinition.ReadModule (targetRewrite);
var nativeIntAttribute = module.GetType ("System.Runtime.CompilerServices.NativeIntegerAttribute")!;
Assert.IsTrue (ContainsAttribute (nativeIntAttribute, "System.Runtime.CompilerServices.CompilerGeneratedAttribute"), "No CompilerGenerateAttribute");
Assert.IsTrue (ContainsAttribute (nativeIntAttribute, "Microsoft.CodeAnalysis.EmbeddedAttribute"), "No Microsoft.CodeAnalysis.EmbeddedAttribute");
Assert.IsTrue (ContainsAttribute (nativeIntAttribute, "System.AttributeUsageAttribute"), "No System.AttributeUsageAttribute");
}
static bool ContainsAttribute (TypeDefinition theType, string attributeName)
{
return theType.CustomAttributes.Any (attr => attr.AttributeType.FullName == attributeName);
}
}
}