From 0500cd819cbde514423118a59291a4b8bc68a332 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 25 Feb 2020 11:23:55 +0100 Subject: [PATCH 01/25] [src] Create bgen subdirectory and move the bgen script there. --- src/Makefile.generator | 4 ++-- src/{ => bgen}/bgen | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => bgen}/bgen (100%) diff --git a/src/Makefile.generator b/src/Makefile.generator index cc590b3178f4..3e639ae27935 100644 --- a/src/Makefile.generator +++ b/src/Makefile.generator @@ -36,7 +36,7 @@ IOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch-native \ -$(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/bgen: bgen | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin +$(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/bgen: bgen/bgen | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin $(Q) $(CP) $< $@ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin/btouch: Makefile.generator | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/bin @@ -124,7 +124,7 @@ MAC_TARGETS += \ MAC_TARGETS += \ $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bmac \ -$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen: bgen | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin +$(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen: bgen/bgen | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin $(Q) $(CP) $< $@ $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin/bgen-classic: Makefile.generator | $(MAC_DESTDIR)$(MAC_FRAMEWORK_CURRENT_DIR)/bin diff --git a/src/bgen b/src/bgen/bgen similarity index 100% rename from src/bgen rename to src/bgen/bgen From eef4ea79c99ccc9aa27d5ff40ee0177983a0e4c5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 5 Mar 2020 23:43:01 +0100 Subject: [PATCH 02/25] [builds] Download the netcore 3.1 assemblies to use as reference assemblies for .NET 5. I couldn't figure out how to make nuget install these into the system, so I decided to just download the package locally instead. This is just temporary until we get real .NET 5 reference assemblies. --- Make.config | 3 +++ builds/Makefile | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Make.config b/Make.config index 196e0d87e9d9..655baafda24c 100644 --- a/Make.config +++ b/Make.config @@ -374,6 +374,9 @@ endif DOTNET_VERSION=3.1.100 DOTNET_URL=https://download.visualstudio.microsoft.com/download/pr/787e81f1-f0da-4e3b-a989-8a199132ed8c/61a8dba81fbf2b3d533562d7b96443ec/dotnet-sdk-3.1.100-osx-x64.pkg +DOTNET_BCL_REF_URL=https://www.nuget.org/api/v2/package/Microsoft.NETCore.App.Ref/3.1.0 +DOTNET_BCL_REF_NAME=microsoft.netcore.app.ref.3.1.0.nupkg +DOTNET_BCL_DIR:=$(abspath $(TOP)/builds/downloads/$(basename $(DOTNET_BCL_REF_NAME)))/ref/netcoreapp3.1 .SUFFIXES: MAKEFLAGS += --no-builtin-rules diff --git a/builds/Makefile b/builds/Makefile index 5ef9382e0b99..0e0344b4e85c 100644 --- a/builds/Makefile +++ b/builds/Makefile @@ -15,14 +15,20 @@ download-mono: downloads/$(basename $(MONO_IOS_FILENAME)) downloads/$(basename $ downloads/$(basename $(MONO_IOS_FILENAME)): MONO_URL=$(MONO_IOS_URL) downloads/$(basename $(MONO_MAC_FILENAME)): MONO_URL=$(MONO_MAC_URL) +downloads/$(DOTNET_BCL_REF_NAME): MONO_URL=$(DOTNET_BCL_REF_URL) include $(TOP)/mk/colors.mk +DOWNLOADS = \ + downloads/$(MONO_IOS_FILENAME) \ + downloads/$(MONO_MAC_FILENAME) \ + downloads/$(DOTNET_BCL_REF_NAME) \ + # This target downloads the mono archives, there's one for Xamarin.iOS and one for Xamarin.Mac. # If doing many clean builds, it's possible to copy the downloaded zip file to ~/Library/Caches/xamarin-macios # to avoid having to download it every time. The zip files have to be copied manually, otherwise # we'd end up filling up a lot of hard drives around the world. -downloads/$(MONO_IOS_FILENAME) downloads/$(MONO_MAC_FILENAME): +$(DOWNLOADS): $(Q) mkdir -p downloads $(Q) echo "Downloading $(MONO_URL)..." $(Q) if test -f ~/Library/Caches/xamarin-macios/$(notdir $@); then \ @@ -49,9 +55,25 @@ downloads/%: downloads/%.7z $(Q) mv $@.tmp $@ $(Q) echo "Unzipped $*." +downloads/%: downloads/%.nupkg + $(Q) echo "Unzipping $*..." + $(Q) rm -Rf $@.tmp + $(Q) unzip -d $@.tmp $< + $(Q) find $@.tmp -exec touch {} + + $(Q) mv $@.tmp $@ + $(Q) echo "Unzipped $*." + .stamp-download-mono: download-mono $(TOP)/Make.config $(TOP)/mk/mono.mk $(Q) touch $@ +DOTNET_DOWNLOADS = \ + downloads/$(basename $(DOTNET_BCL_REF_NAME)) \ + +dotnet: $(DOTNET_DOWNLOADS) +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_DOWNLOADS) +endif + clean-local:: $(Q) rm -Rf downloads .stamp-download-mono From 5135ce2251628428f760406e94dcdb0a88cd10f9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 16:04:24 +0100 Subject: [PATCH 03/25] [bgen] Build bgen as a .netcoreapp 3.1. Build bgen as a .netcoreapp 3.1 in addition to the managed executable we're already creating. --- mk/quiet.mk | 3 + src/Makefile | 9 + src/Makefile.generator | 10 ++ src/bgen/bgen.csproj | 390 +++++++++++++++++++++++++++++++++++++++++ src/bgen/bgen.sln | 17 ++ 5 files changed, 429 insertions(+) create mode 100644 src/bgen/bgen.csproj create mode 100644 src/bgen/bgen.sln diff --git a/mk/quiet.mk b/mk/quiet.mk index 78ac89c21b4c..fc8dcfb6825a 100644 --- a/mk/quiet.mk +++ b/mk/quiet.mk @@ -31,6 +31,9 @@ Q_XBUILD=$(if $(V),,@echo "XBUILD $(@F)";) Q_TT= $(if $(V),,@echo "TT $(@F)";) Q_BUILD=$(if $(V),,@echo "BUILD $(@F)";) +Q_DOTNET_BUILD=$(if $(V),,@echo "CSC [dotnet] $(@F)";) +Q_DOTNET_GEN =$(if $(V),,@echo "GEN [dotnet] $(@F)";) + Q_PROF_MCS = $(if $(V),,@echo "MCS [$(1)] $(@F)";) Q_PROF_CSC = $(if $(V),,@echo "CSC [$(1)] $(@F)";) Q_PROF_GEN = $(if $(V),,@echo "GEN [$(1)] $(@F)";) diff --git a/src/Makefile b/src/Makefile index a937b0648e00..3cd0b49bb284 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,6 +2,7 @@ TOP=.. include $(TOP)/Make.config BUILD_DIR=build +DOTNET_BUILD_DIR=build/dotnet PROJECT_DIR=. include $(TOP)/src/frameworks.sources @@ -865,6 +866,14 @@ $(COMMON_TARGET_DIRS): install-local:: $(INSTALL_TARGETS) all-local:: $(ALL_TARGETS) +$(DOTNET_TARGETS_DIRS): + $(Q) mkdir -p $@ + +dotnet: $(DOTNET_TARGETS) +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_TARGETS) +endif + project-files: $(PROJECT_FILES) # Using .SECONDARY can cause make to go into an infinite loop. diff --git a/src/Makefile.generator b/src/Makefile.generator index 3e639ae27935..483b486570b9 100644 --- a/src/Makefile.generator +++ b/src/Makefile.generator @@ -11,6 +11,16 @@ $(BUILD_DIR)/generator.csproj.inc: Makefile.generator $(TOP)/tools/common/create $(BUILD_DIR)/common/bgen.exe: $(generator_dependencies) Makefile.generator $(BUILD_DIR)/generator-frameworks.g.cs $(Q_GEN) $(SYSTEM_MSBUILD) $(XBUILD_VERBOSITY) /p:Configuration=Debug generator.csproj /p:IntermediateOutputPath=$(BUILD_DIR)/IDE/obj/common/ /p:OutputPath=$(BUILD_DIR)/common +$(DOTNET_BUILD_DIR)/bgen/bgen: $(generator_dependencies) Makefile.generator $(BUILD_DIR)/generator-frameworks.g.cs | $(DOTNET_BUILD_DIR)/bgen + $(Q_DOTNET_BUILD) dotnet build $(XBUILD_VERBOSITY) /p:Configuration=Debug bgen/bgen.csproj + $(Q) $(CP) bgen/bin/Debug/netcoreapp3.1/bgen* $(dir $@) + +DOTNET_TARGETS += \ + $(DOTNET_BUILD_DIR)/bgen/bgen \ + +DOTNET_TARGETS_DIRS += \ + $(DOTNET_BUILD_DIR)/bgen \ + # # Common # diff --git a/src/bgen/bgen.csproj b/src/bgen/bgen.csproj new file mode 100644 index 000000000000..9ca889a60f70 --- /dev/null +++ b/src/bgen/bgen.csproj @@ -0,0 +1,390 @@ + + + + + netcoreapp3.1 + Exe + DEBUG;BGENERATOR;NET_4_0;NO_AUTHENTICODE;STATIC;NO_SYMBOL_WRITER + + + + + + + + + true + $(MSBuildThisFileDirectory)/../.. + $(MSBuildThisFileDirectory)/../build/dotnet + $(RepositoryPath)/builds + $(BUILD_DIR)\ + ..\build\ + + + + + generator-errors.md + + + ikvm\ITypeOwner.cs + + + ikvm\SymbolSupport.cs + + + ikvm\CryptoConvert.cs + + + ikvm\AmbiguousMatchException.cs + + + ikvm\Assembly.cs + + + ikvm\AssemblyName.cs + + + ikvm\BadImageFormatException.cs + + + ikvm\Binder.cs + + + ikvm\ConstructorInfo.cs + + + ikvm\CustomAttributeData.cs + + + ikvm\CustomAttributeNamedArgument.cs + + + ikvm\CustomAttributeTypedArgument.cs + + + ikvm\CustomModifiers.cs + + + ikvm\Enums.cs + + + ikvm\EventInfo.cs + + + ikvm\ExceptionHandlingClause.cs + + + ikvm\FieldInfo.cs + + + ikvm\FieldSignature.cs + + + ikvm\Fusion.cs + + + ikvm\GenericWrappers.cs + + + ikvm\InterfaceMapping.cs + + + ikvm\LocalVariableInfo.cs + + + ikvm\ManifestResourceInfo.cs + + + ikvm\MarshalSpec.cs + + + ikvm\MemberInfo.cs + + + ikvm\MethodBase.cs + + + ikvm\MethodBody.cs + + + ikvm\MethodImplMap.cs + + + ikvm\MethodInfo.cs + + + ikvm\MethodSignature.cs + + + ikvm\Missing.cs + + + ikvm\Module.cs + + + ikvm\ParameterInfo.cs + + + ikvm\ParameterModifier.cs + + + ikvm\Projection.cs + + + ikvm\PropertyInfo.cs + + + ikvm\PropertySignature.cs + + + ikvm\Signature.cs + + + ikvm\StandAloneMethodSig.cs + + + ikvm\StrongNameKeyPair.cs + + + ikvm\Type.cs + + + ikvm\TypeInfo.cs + + + ikvm\TypeNameParser.cs + + + ikvm\Universe.cs + + + ikvm\Util.cs + + + ikvm\coreclr.cs + + + ikvm\AssemblyBuilder.cs + + + ikvm\ConstructorBuilder.cs + + + ikvm\CustomAttributeBuilder.cs + + + ikvm\CustomModifiersBuilder.cs + + + ikvm\EnumBuilder.cs + + + ikvm\Enums.cs + + + ikvm\EventBuilder.cs + + + ikvm\ExceptionHandler.cs + + + ikvm\FieldBuilder.cs + + + ikvm\ILGenerator.cs + + + ikvm\MethodBuilder.cs + + + ikvm\ModuleBuilder.cs + + + ikvm\OpCode.cs + + + ikvm\OpCodes.cs + + + ikvm\ParameterBuilder.cs + + + ikvm\PropertyBuilder.cs + + + ikvm\SignatureHelper.cs + + + ikvm\Tokens.cs + + + ikvm\TypeBuilder.cs + + + ikvm\CliHeader.cs + + + ikvm\MetadataRW.cs + + + ikvm\Tables.cs + + + ikvm\AssemblyReader.cs + + + ikvm\Authenticode.cs + + + ikvm\ByteReader.cs + + + ikvm\EventInfoImpl.cs + + + ikvm\Field.cs + + + ikvm\GenericTypeParameter.cs + + + ikvm\MetadataReader.cs + + + ikvm\Method.cs + + + ikvm\ModuleReader.cs + + + ikvm\PEReader.cs + + + ikvm\PropertyInfoImpl.cs + + + ikvm\ResourceModule.cs + + + ikvm\TypeDefImpl.cs + + + ikvm\ByteBuffer.cs + + + ikvm\Heaps.cs + + + ikvm\MetadataWriter.cs + + + ikvm\ModuleWriter.cs + + + ikvm\PEWriter.cs + + + ikvm\ResourceSection.cs + + + ikvm\TextSection.cs + + + ikvm\VersionInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execution.cs + + + ..\Resources.resx + + + + + ResXFileCodeGenerator + ..\Resources.Designer.cs + + + + + Project + + $(ProjectDir) + true + + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + Project + @build/dotnet/$(RunConfiguration)/$(RunConfiguration).rsp + .. + false + + + + + + + + + diff --git a/src/bgen/bgen.sln b/src/bgen/bgen.sln new file mode 100644 index 000000000000..711581dd3257 --- /dev/null +++ b/src/bgen/bgen.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bgen", "bgen.csproj", "{B42BBC30-27F6-4C49-8727-216DC75B042C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal From d2420661dac9235040e9ddfc8b8af8c1c99905f2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 12:29:52 +0100 Subject: [PATCH 04/25] Add .NET 5 target frameworks. --- tools/common/TargetFramework.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/common/TargetFramework.cs b/tools/common/TargetFramework.cs index 4a07c1f688de..2037c39532be 100644 --- a/tools/common/TargetFramework.cs +++ b/tools/common/TargetFramework.cs @@ -41,16 +41,26 @@ public struct TargetFramework : IEquatable public static readonly TargetFramework Xamarin_Mac_2_0_Mobile = Parse ("Xamarin.Mac,Version=v2.0,Profile=Mobile"); public static readonly TargetFramework Xamarin_Mac_4_5_Full = Parse ("Xamarin.Mac,Version=v4.5,Profile=Full"); public static readonly TargetFramework Xamarin_Mac_4_5_System = Parse ("Xamarin.Mac,Version=v4.5,Profile=System"); + + public static readonly TargetFramework DotNet_5_0_iOS = Parse (".NETCoreApp,Version=5.0,Profile=ios"); // Short form: net5.0-ios + public static readonly TargetFramework DotNet_5_0_tvOS = Parse (".NETCoreApp,Version=5.0,Profile=tvos"); // Short form: net5.0-tvos + public static readonly TargetFramework DotNet_5_0_watchOS = Parse (".NETCoreApp,Version=5.0,Profile=watchos"); // Short form: net5.0-watchos + public static readonly TargetFramework DotNet_5_0_macOS = Parse (".NETCoreApp,Version=5.0,Profile=macos"); // Short form: net5.0-macos #if MTOUCH public static readonly TargetFramework [] ValidFrameworks = new TargetFramework[] { Xamarin_iOS_1_0, Xamarin_WatchOS_1_0, Xamarin_TVOS_1_0 }; #elif BGENERATOR public static readonly TargetFramework [] ValidFrameworks = new TargetFramework[] { Xamarin_iOS_1_0, Xamarin_TVOS_1_0, Xamarin_WatchOS_1_0, - Xamarin_Mac_2_0_Mobile, Xamarin_Mac_4_5_Full, Xamarin_Mac_4_5_System + Xamarin_Mac_2_0_Mobile, Xamarin_Mac_4_5_Full, Xamarin_Mac_4_5_System, + DotNet_5_0_iOS, DotNet_5_0_macOS, DotNet_5_0_tvOS, DotNet_5_0_watchOS, }; #endif + public bool IsDotNet { + get { return Identifier == ".NETCoreApp" && Version.Major >= 5; } + } + public static TargetFramework Parse (string targetFrameworkString) { TargetFramework targetFramework; @@ -209,6 +219,19 @@ public ApplePlatform Platform { return ApplePlatform.WatchOS; case "Xamarin.TVOS": return ApplePlatform.TVOS; + case ".NETCoreApp": + switch (Profile) { + case "ios": + return ApplePlatform.iOS; + case "tvos": + return ApplePlatform.TVOS; + case "watchos": + return ApplePlatform.WatchOS; + case "macos": + return ApplePlatform.MacOSX; + default: + throw new InvalidOperationException (string.Format ("Invalid .NETCoreApp Profile for Apple platforms: {0}", Profile)); + } default: return ApplePlatform.MacOSX; } From d659a8626eb8803fc28bb56df907d2af9bc247fe Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 19:16:03 +0100 Subject: [PATCH 05/25] [bgen] Don't try to load assemblies we've already loaded. IKVM has a bug where it doesn't correctly compare assemblies, which means it can end up loading the same assembly (in particular any System.Runtime whose version > 4.0, but likely others as well) more than once. This is bad, because we compare types based on reference equality, which breaks down when there are multiple instances of the same type. So just don't ask IKVM to load assemblies that have already been loaded. --- src/btouch.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/btouch.cs b/src/btouch.cs index 6b798b88dfb7..59473a0038ab 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -481,6 +481,18 @@ int Main3 (string [] args) } foreach (var r in references) { + // IKVM has a bug where it doesn't correctly compare assemblies, which means it + // can end up loading the same assembly (in particular any System.Runtime whose + // version > 4.0, but likely others as well) more than once. This is bad, because + // we compare types based on reference equality, which breaks down when there are + // multiple instances of the same type. + // + // So just don't ask IKVM to load assemblies that have already been loaded. + var fn = Path.GetFileNameWithoutExtension (r); + var assemblies = universe.GetAssemblies (); + if (assemblies.Any ((v) => v.GetName ().Name == fn)) + continue; + if (File.Exists (r)) { try { universe.LoadFile (r); From 72626bdb8ce8d19068e065d69766937545d0591a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 08:19:50 +0100 Subject: [PATCH 06/25] [src] Hide API usage that doesn't compile (but which we'll have to return to) with .NET5 behind a DOTNET_TODO define. --- src/Compression/Compression.cs | 11 +++++++++++ src/ObjCRuntime/Runtime.cs | 7 +++++-- src/System.Net.Http/CFNetworkHandler.cs | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Compression/Compression.cs b/src/Compression/Compression.cs index 52f307bb35f2..c5eadbb882cf 100644 --- a/src/Compression/Compression.cs +++ b/src/Compression/Compression.cs @@ -300,11 +300,19 @@ private static void ThrowCannotWriteToDeflateStreamException() throw new InvalidOperationException ("Writing to the compression stream is not supported."); } +#if !DOTNET_TODO + // DOTNET_TODO: TaskToApm is internal API in mscorlib, so we can't use it. + // Although I'm not sure if we even need to override these methods, + // the base class implementation works (but synchronously), + // and the documentation recommends using ReadAsync instead. + // If we decide to implement this, we could just copy the TaskToApm implementation: + // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/mscorlib/system/threading/Tasks/TaskToApm.cs public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => TaskToApm.Begin(ReadAsync (buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); public override int EndRead (IAsyncResult asyncResult) => TaskToApm.End (asyncResult); +#endif // !DOTNET_TODO public override Task ReadAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { @@ -547,10 +555,13 @@ protected override void Dispose (bool disposing) } } +#if !DOTNET_TODO + // DOTNET_TODO: See comment about TaskToApm elsewhere in this file. public override IAsyncResult BeginWrite (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => TaskToApm.Begin(WriteAsync (array, offset, count, CancellationToken.None), asyncCallback, asyncState); public override void EndWrite (IAsyncResult asyncResult) => TaskToApm.End (asyncResult); +#endif // !DOTNET_TODO public override Task WriteAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 1fa55aa45c02..2ae6af6b7e3f 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -254,9 +254,11 @@ unsafe static void Initialize (InitializationOptions* options) RegisterDelegates (options); Class.Initialize (options); Mono.SystemDependencyProvider.Initialize (); +#endif InitializePlatform (options); -#if !XAMMAC_SYSTEM_MONO +#if !XAMMAC_SYSTEM_MONO && !DOTNET_TODO + // DOTNET_TODO: https://github.com/dotnet/runtime/issues/32543 UseAutoreleasePoolInThreadPool = true; #endif IsARM64CallingConvention = GetIsARM64CallingConvention (); // Can only be done after Runtime.Arch is set (i.e. InitializePlatform has been called). @@ -270,7 +272,8 @@ unsafe static void Initialize (InitializationOptions* options) #endif } -#if !XAMMAC_SYSTEM_MONO +#if !XAMMAC_SYSTEM_MONO && !DOTNET_TODO + // DOTNET_TODO: https://github.com/dotnet/runtime/issues/32543 static bool has_autoreleasepool_in_thread_pool; public static bool UseAutoreleasePoolInThreadPool { get { diff --git a/src/System.Net.Http/CFNetworkHandler.cs b/src/System.Net.Http/CFNetworkHandler.cs index 60e252ea49b0..aca58ed233aa 100644 --- a/src/System.Net.Http/CFNetworkHandler.cs +++ b/src/System.Net.Http/CFNetworkHandler.cs @@ -381,6 +381,9 @@ void HandleHasBytesAvailableEvent (object sender, CFStream.StreamEventArgs e) void AddCookie (string value, Uri uri, string header) { +#if !DOTNET_TODO + // DOTNET_TODO: CookieCollection.CookieCutter is internal to mscorlib: + // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/System/net/System/Net/cookiecontainer.cs#L632 CookieCollection cookies1 = null; try { cookies1 = cookies.CookieCutter (uri, header, value, false); @@ -389,6 +392,7 @@ void AddCookie (string value, Uri uri, string header) if (cookies1 != null && cookies1.Count != 0) cookies.Add (cookies1); +#endif } static bool IsContentHeader (string header) From 11fb1fd2c469c86a0728a2a3be8731685ea13638 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 08:20:11 +0100 Subject: [PATCH 07/25] [src] Adjust to .NET 5 API. --- src/CFNetwork/Content.cs | 2 +- src/CFNetwork/MessageHandler.cs | 2 +- src/Foundation/NSUrlSessionHandler.cs | 7 +++++-- src/ObjCRuntime/Runtime.cs | 4 ++++ src/Security/Certificate.cs | 2 +- src/System.Net.Http/CFContentStream.cs | 5 ++++- src/System.Net.Http/CFNetworkHandler.cs | 5 ++++- 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/CFNetwork/Content.cs b/src/CFNetwork/Content.cs index 630c4b367a08..bc6bdd471acc 100644 --- a/src/CFNetwork/Content.cs +++ b/src/CFNetwork/Content.cs @@ -46,7 +46,7 @@ internal Content (WebResponseStream stream) this.responseStream = stream; } -#if MONOMAC && XAMCORE_2_0 +#if (MONOMAC && XAMCORE_2_0) && !DOTNET internal #endif protected override bool TryComputeLength (out long length) diff --git a/src/CFNetwork/MessageHandler.cs b/src/CFNetwork/MessageHandler.cs index 7e4faeb71505..c002a2d78c33 100644 --- a/src/CFNetwork/MessageHandler.cs +++ b/src/CFNetwork/MessageHandler.cs @@ -78,7 +78,7 @@ public WorkerThread WorkerThread { CFHTTPAuthentication auth; #region implemented abstract members of HttpMessageHandler -#if MONOMAC && XAMCORE_2_0 +#if (MONOMAC && XAMCORE_2_0) && !DOTNET internal #endif protected override async Task SendAsync (HttpRequestMessage request, diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index 777ea3c81e72..e1beadafd0e7 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -473,7 +473,7 @@ async Task CreateRequest (HttpRequestMessage request) return nsrequest; } -#if SYSTEM_NET_HTTP || MONOMAC +#if (SYSTEM_NET_HTTP || MONOMAC) && !DOTNET internal #endif protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) @@ -935,7 +935,10 @@ protected override Task SerializeToStreamAsync (Stream stream, TransportContext return content.CopyToAsync (stream, bufferSize, cancellationToken); } - protected internal override bool TryComputeLength (out long length) +#if !DOTNET + internal +#endif + protected override bool TryComputeLength (out long length) { if (!content.CanSeek) { length = 0; diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 2ae6af6b7e3f..c94719f662e4 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -253,6 +253,10 @@ unsafe static void Initialize (InitializationOptions* options) Registrar = new DynamicRegistrar (); RegisterDelegates (options); Class.Initialize (options); +#if !DOTNET + // This is not needed for .NET 5: + // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-588331822 + // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-589356481 Mono.SystemDependencyProvider.Initialize (); #endif InitializePlatform (options); diff --git a/src/Security/Certificate.cs b/src/Security/Certificate.cs index 8053e492c0c1..af79c56a6a4b 100644 --- a/src/Security/Certificate.cs +++ b/src/Security/Certificate.cs @@ -28,7 +28,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if XAMARIN_APPLETLS || WATCH +#if (XAMARIN_APPLETLS || WATCH) && !DOTNET #define NATIVE_APPLE_CERTIFICATE #endif diff --git a/src/System.Net.Http/CFContentStream.cs b/src/System.Net.Http/CFContentStream.cs index bdd3518ad57b..d964f3c569cd 100644 --- a/src/System.Net.Http/CFContentStream.cs +++ b/src/System.Net.Http/CFContentStream.cs @@ -147,7 +147,10 @@ protected override async Task SerializeToStreamAsync (Stream stream, TransportCo } } - protected internal override bool TryComputeLength (out long length) +#if !DOTNET + internal +#endif + protected override bool TryComputeLength (out long length) { length = 0; return false; diff --git a/src/System.Net.Http/CFNetworkHandler.cs b/src/System.Net.Http/CFNetworkHandler.cs index aca58ed233aa..0d27de714532 100644 --- a/src/System.Net.Http/CFNetworkHandler.cs +++ b/src/System.Net.Http/CFNetworkHandler.cs @@ -194,7 +194,10 @@ CFHTTPMessage CreateWebRequestAsync (HttpRequestMessage request) return req; } - protected internal override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) +#if !DOTNET + internal +#endif + protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) { return await SendAsync (request, cancellationToken, true).ConfigureAwait (false); } From 4648db4e939d791f9fddb2b7c3da94fdf808f15d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Feb 2020 19:21:34 +0100 Subject: [PATCH 08/25] [src] Build platform assemblies referencing the .NET5 BCL. --- src/Makefile | 264 ++++++++++++++++++++++++++++++++++++++++- src/Makefile.generator | 4 + 2 files changed, 267 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 3cd0b49bb284..3d231c4ed1fa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,6 +18,54 @@ IOS_BUILD_DIR=$(BUILD_DIR)/ios WATCH_BUILD_DIR=$(BUILD_DIR)/watch TVOS_BUILD_DIR=$(BUILD_DIR)/tvos +MACOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/macos +IOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/ios +WATCHOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/watchos +TVOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/tvos + +GENERATOR_FLAGS=-process-enums -core -nologo -nostdlib -noconfig -native-exception-marshalling --ns:ObjCRuntime + +DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /target:library /debug /unsafe /define:DOTNET /define:DOTNET_TODO \ + /r:$(DOTNET_BCL_DIR)/mscorlib.dll \ + /r:$(DOTNET_BCL_DIR)/System.Buffers.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.Concurrent.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.NonGeneric.dll \ + /r:$(DOTNET_BCL_DIR)/System.Console.dll \ + /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Debug.dll \ + /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Tools.dll \ + /r:$(DOTNET_BCL_DIR)/System.dll \ + /r:$(DOTNET_BCL_DIR)/System.Drawing.Primitives.dll \ + /r:$(DOTNET_BCL_DIR)/System.IO.Compression.dll \ + /r:$(DOTNET_BCL_DIR)/System.IO.FileSystem.dll \ + /r:$(DOTNET_BCL_DIR)/System.Linq.dll \ + /r:$(DOTNET_BCL_DIR)/System.Memory.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Http.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.NameResolution.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Primitives.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Requests.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Security.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.ServicePoint.dll \ + /r:$(DOTNET_BCL_DIR)/System.Net.Sockets.dll \ + /r:$(DOTNET_BCL_DIR)/System.ObjectModel.dll \ + /r:$(DOTNET_BCL_DIR)/System.Text.RegularExpressions.dll \ + /r:$(DOTNET_BCL_DIR)/System.Resources.ResourceManager.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.Extensions.dll \ + /r:$(DOTNET_BCL_DIR)/System.Runtime.InteropServices.dll \ + /r:$(DOTNET_BCL_DIR)/System.Security.Cryptography.X509Certificates.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.Tasks.dll \ + /r:$(DOTNET_BCL_DIR)/System.Threading.Thread.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.ReaderWriter.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.Serialization.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.XmlSerializer.dll \ + +DOTNET_GENERATOR_FLAGS=$(GENERATOR_FLAGS) -compiler=$(SYSTEM_CSC) $(DOTNET_FLAGS) --lib=$(DOTNET_BCL_DIR) -attributelib:$(DOTNET_BINDING_ATTRIBUTES) +DOTNET_GENERATOR=$(DOTNET_BUILD_DIR)/bgen/bgen +DOTNET_BINDING_ATTRIBUTES=$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll + include $(TOP)/opentk/Makefile.include # @@ -79,6 +127,10 @@ IOS_GENERATOR_FLAGS = -inline-selectors -d:IOS -process-enums -warnaserror:$(IOS IOS_DEFINES = -define:IPHONE -define:IOS -define:MONOTOUCH -d:__IOS__ $(APPLETLS_DEFINES) -d:SYSTEM_NET_HTTP -d:XAMCORE_2_0 -d:__UNIFIED__ IOS_GENERATOR=$(BUILD_DIR)/common/bgen.exe IOS_GENERATE=$(SYSTEM_MONO) --debug $(IOS_GENERATOR) + +IOS_CORE_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) +IOS_CORE_DEFINES=-define:COREBUILD $(IOS_DEFINES) $(IOS_native_DEFINES) + $(IOS_BUILD_DIR)/Constants.cs: Constants.iOS.cs.in Makefile $(TOP)/Make.config.inc | $(IOS_BUILD_DIR) $(call Q_PROF_GEN,ios) sed \ -e "s/@VERSION@/$(IOS_PACKAGE_VERSION_MAJOR).$(IOS_PACKAGE_VERSION_MINOR).$(IOS_PACKAGE_VERSION_REV)/g" \ @@ -102,6 +154,19 @@ $(IOS_BUILD_DIR)/native/core.dll: $(IOS_CORE_SOURCES) frameworks.sources $(IOS_BUILD_DIR)/native/generated_sources: $(IOS_GENERATOR) $(IOS_APIS) $(IOS_BUILD_DIR)/native/core.dll $(IOS_BUILD_DIR)/native/Xamarin.iOS.BindingAttributes.dll $(BUILD_DIR)/ios.rsp $(call Q_PROF_GEN,ios) $(IOS_GENERATE) @$(BUILD_DIR)/ios.rsp +### .NET ### + +$(IOS_DOTNET_BUILD_DIR)/core-ios.dll: $(IOS_CORE_SOURCES) frameworks.sources | $(IOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(IOS_CORE_WARNINGS_TO_FIX) \ + $(IOS_CORE_DEFINES) \ + $(IOS_CORE_SOURCES) \ + -out:$@ + +$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources: $(DOTNET_GENERATOR) $(IOS_APIS) $(IOS_DOTNET_BUILD_DIR)/core-ios.dll $(DOTNET_BINDING_ATTRIBUTES) $(IOS_DOTNET_BUILD_DIR)/ios.rsp | $(IOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(IOS_DOTNET_BUILD_DIR)/ios.rsp + $(BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources $(Q_GEN) echo \ $(IOS_GENERATOR_FLAGS) \ @@ -118,6 +183,21 @@ $(BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources $(IOS_APIS) \ > $@ +$(IOS_DOTNET_BUILD_DIR)/ios.rsp: Makefile Makefile.generator frameworks.sources | $(IOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(IOS_GENERATOR_FLAGS) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(IOS_GENERATOR_WARNASERROR) \ + -sourceonly=$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources \ + -tmpdir=$(IOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(IOS_DOTNET_BUILD_DIR)/core-ios.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=ios \ + $(IOS_APIS) \ + > $@ + +$(IOS_DOTNET_BUILD_DIR)/Xamarin.iOS.dll: $(IOS_DOTNET_BUILD_DIR)/64/Xamarin.iOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + define IOS_TARGETS_template # Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.pdb: $$(IOS_SOURCES) $(IOS_BUILD_DIR)/native/generated_sources $(PRODUCT_KEY_PATH) @@ -130,6 +210,16 @@ $(IOS_BUILD_DIR)/native-$(1)%Xamarin.iOS.dll $(IOS_BUILD_DIR)/native-$(1)%Xamari $$(IOS_CSC_FLAGS_XI) \ $$(IOS_SOURCES) @$(IOS_BUILD_DIR)/native/generated_sources +$(IOS_DOTNET_BUILD_DIR)/$(1)/Xamarin.iOS.dll: $$(IOS_SOURCES) $$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources $(PRODUCT_KEY_PATH) | $(IOS_DOTNET_BUILD_DIR)/$(1) + $$(call Q_PROF_CSC,dotnet/$(1)-bit) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$$@ -unsafe -optimize \ + $$(ARGS_$(1)) \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $$(IOS_DEFINES) \ + $$(IOS_native_DEFINES) \ + $$(IOS_CORE_WARNINGS_TO_FIX) \ + $$(IOS_CSC_FLAGS_XI) \ + $$(IOS_SOURCES) @$(IOS_DOTNET_BUILD_DIR)/ios-generated-sources + endef $(IOS_BUILD_DIR)/compat/%: $(MACIOS_BINARIES_PATH)/% | $(IOS_BUILD_DIR)/compat @@ -220,6 +310,17 @@ IOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/64bits/Xamarin.iOS.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/64bits/Xamarin.iOS.pdb \ +DOTNET_TARGETS += \ + $(IOS_DOTNET_BUILD_DIR)/32/Xamarin.iOS.dll \ + $(IOS_DOTNET_BUILD_DIR)/64/Xamarin.iOS.dll \ + $(IOS_DOTNET_BUILD_DIR)/Xamarin.iOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(IOS_DOTNET_BUILD_DIR) \ + $(IOS_DOTNET_BUILD_DIR)/32 \ + $(IOS_DOTNET_BUILD_DIR)/64 \ + $(IOS_DOTNET_BUILD_DIR)/generated-sources \ + $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1/%.dll: $(IOS_BUILD_DIR)/compat/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1 $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/2.1/Facades $(Q) install -m 0755 $< $@ @@ -291,6 +392,9 @@ MAC_mobile_ARGS = MAC_BOOTSTRAP_DEFINES = $(MAC_COMMON_DEFINES),COREBUILD MAC_GENERATED_DEFINES = -d:MONOMAC -d:XAMCORE_2_0 -d:__UNIFIED__ +MAC_CORE_DEFINES = $(MAC_BOOTSTRAP_DEFINES) +MAC_CORE_WARNINGS_TO_FIX = -nowarn:3021,612,618,1635 + $(MAC_BUILD_DIR)/$(1)/$(3).pdb: $(MAC_BUILD_DIR)/$(1)/$(3).dll SN_KEY = $(PRODUCT_KEY_PATH) @@ -420,6 +524,55 @@ $(MAC_BUILD_DIR)/%-reference/Xamarin.Mac.pdb: $(MAC_BUILD_DIR)/%-64/Xamarin.Mac. @mkdir -p $(@D) $(Q) $(CP) $^ $@ +### .NET ### + +$(MACOS_DOTNET_BUILD_DIR)/core-macos.dll: $(MAC_CORE_SOURCES) frameworks.sources | $(MACOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ \ + $(MAC_CORE_WARNINGS_TO_FIX) \ + $(MAC_CORE_DEFINES) \ + $(MAC_CORE_SOURCES) \ + -out:$@ \ + +$(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources: $(DOTNET_GENERATOR) $(MAC_APIS) $(MACOS_DOTNET_BUILD_DIR)/core-macos.dll $(DOTNET_BINDING_ATTRIBUTES) $(MACOS_DOTNET_BUILD_DIR)/macos.rsp | $(MACOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(MACOS_DOTNET_BUILD_DIR)/macos.rsp + +$(MACOS_DOTNET_BUILD_DIR)/macos.rsp: Makefile Makefile.generator frameworks.sources | $(MACOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(MAC_GENERATED_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) \ + -warnaserror:$(MAC_GENERATOR_WARNASERROR) \ + -sourceonly:$(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources \ + -tmpdir:$(MACOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib:$(MACOS_DOTNET_BUILD_DIR)/core-macos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=macos \ + $(MAC_APIS) \ + > $@ + +$(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll: $(MACOS_DOTNET_BUILD_DIR)/macos-generated-sources $(MAC_SOURCES) $(MAC_CFNETWORK_SOURCES) $(SN_KEY) | $(MACOS_DOTNET_BUILD_DIR)/64 + $(Q_DOTNET_BUILD) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(SN_KEY) \ + $(MAC_COMMON_DEFINES) \ + $(ARGS_64) \ + -nowarn:3021,1635,612,618,0219,0414,$(MAC_WARNINGS_TO_FIX) \ + $(MAC_CSC_FLAGS_XM) \ + $(MAC_CFNETWORK_SOURCES) $(MAC_HTTP_SOURCES) $(SHARED_SYSTEM_DRAWING_SOURCES) $(APPLETLS_DEFINES) -D:XAMARIN_MODERN -D:UNIFIED -D:__UNIFIED__ \ + $(MAC_SOURCES) \ + @$< + +$(MACOS_DOTNET_BUILD_DIR)/Xamarin.Mac.dll: $(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + +DOTNET_TARGETS += \ + $(MACOS_DOTNET_BUILD_DIR)/64/Xamarin.Mac.dll \ + $(MACOS_DOTNET_BUILD_DIR)/Xamarin.Mac.dll \ + +DOTNET_TARGETS_DIRS += \ + $(MACOS_DOTNET_BUILD_DIR) \ + $(MACOS_DOTNET_BUILD_DIR)/generated-sources \ + $(MACOS_DOTNET_BUILD_DIR)/64 \ + MAC_VARIANTS_TARGETS = \ $(MAC_BUILD_DIR)/mobile-64/Xamarin.Mac.dll \ $(MAC_BUILD_DIR)/full-64/Xamarin.Mac.dll \ @@ -517,6 +670,11 @@ WATCH_GENERATOR=$(BUILD_DIR)/common/bgen.exe WATCH_GENERATE=$(SYSTEM_MONO) --debug $(WATCH_GENERATOR) WATCH_GENERATED_DEFINES= -d:WATCH -d:XAMCORE_3_0 -d:XAMCORE_2_0 -d:__UNIFIED__ +WATCHOS_CORE_DEFINES = $(WATCH_DEFINES) -define:COREBUILD +WATCHOS_CORE_WARNINGS_TO_FIX = -nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + +WATCHOS_WARNINGS_TO_FIX = -nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + WATCHOS_EXTRA_CORE_SOURCES = \ $(WATCH_BUILD_DIR)/Constants.cs \ $(WATCH_BUILD_DIR)/AssemblyInfo.cs \ @@ -590,6 +748,45 @@ $(BUILD_DIR)/watchos.rsp: Makefile Makefile.generator frameworks.sources --target-framework=Xamarin.WatchOS,v1.0 \ > $@ +### .NET ### + +$(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll: $(WATCHOS_CORE_SOURCES) frameworks.sources | $(WATCHOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(WATCHOS_CORE_WARNINGS_TO_FIX) \ + $(WATCHOS_CORE_DEFINES) \ + $(WATCHOS_CORE_SOURCES) \ + -out:$@ \ + +$(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources: $(DOTNET_GENERATOR) $(WATCHOS_APIS) $(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll $(DOTNET_BINDING_ATTRIBUTES) $(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp | $(WATCHOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp + +$(WATCHOS_DOTNET_BUILD_DIR)/watchos.rsp: Makefile Makefile.generator frameworks.sources | $(WATCHOS_DOTNET_BUILD_DIR) + $(Q) echo \ + $(WATCH_GENERATED_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(WATCH_GENERATOR_WARNASERROR) \ + -sourceonly=$(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources \ + -tmpdir=$(WATCHOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(WATCHOS_DOTNET_BUILD_DIR)/core-watchos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=watchos \ + $(WATCHOS_APIS) \ + > $@ + +$(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll: $(WATCHOS_DOTNET_BUILD_DIR)/watchos-generated-sources $(WATCHOS_SOURCES) $(PRODUCT_KEY_PATH) | $(WATCHOS_DOTNET_BUILD_DIR)/32 + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $(WATCH_DEFINES) \ + $(ARGS_32) \ + $(WATCHOS_WARNINGS_TO_FIX) \ + $(IOS_CSC_FLAGS_XI) \ + $(WATCHOS_SOURCES) \ + @$< + +$(WATCHOS_DOTNET_BUILD_DIR)/Xamarin.WatchOS.dll: $(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + $(WATCH_BUILD_DIR)/watch-32/Xamarin.WatchOS%dll $(WATCH_BUILD_DIR)/watch-32/Xamarin.WatchOS%pdb: $(WATCHOS_SOURCES) $(WATCH_BUILD_DIR)/watch/generated_sources $(PRODUCT_KEY_PATH) | $(WATCH_BUILD_DIR)/watch-32 $(call Q_PROF_CSC,watch) $(WATCH_CSC) -nologo -out:$(basename $@).dll -target:library -debug -unsafe -optimize \ -publicsign -keyfile:$(PRODUCT_KEY_PATH) $(WATCH_DEFINES) \ @@ -644,6 +841,15 @@ WATCH_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/MonoTouch.NUnitLite.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/MonoTouch.NUnitLite.pdb +DOTNET_TARGETS += \ + $(WATCHOS_DOTNET_BUILD_DIR)/32/Xamarin.WatchOS.dll \ + $(WATCHOS_DOTNET_BUILD_DIR)/Xamarin.WatchOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(WATCHOS_DOTNET_BUILD_DIR) \ + $(WATCHOS_DOTNET_BUILD_DIR)/generated-sources \ + $(WATCHOS_DOTNET_BUILD_DIR)/32 \ + # reference assemblies, this is just for compilation with XS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/%.dll: $(WATCH_BUILD_DIR)/reference/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.WatchOS/Facades $(Q) install -m 0755 $< $@ @@ -681,6 +887,11 @@ TVOS_GENERATOR=$(BUILD_DIR)/common/bgen.exe TVOS_GENERATE=$(SYSTEM_MONO) --debug $(TVOS_GENERATOR) TVOS_GENERATED_DEFINES= -d:TVOS -d:XAMCORE_3_0 -d:XAMCORE_2_0 -d:__UNIFIED__ +TVOS_CORE_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) +TVOS_CORE_DEFINES=$(TVOS_DEFINES) -d:COREBUILD +TVOS_GENERATOR_DEFINES = $(TVOS_GENERATED_DEFINES) +TVOS_WARNINGS_TO_FIX=-nowarn:219,618,114,414,1635,3021,$(IOS_WARNINGS_THAT_YOU_SHOULD_FIX) + TVOS_EXTRA_CORE_SOURCES = \ $(TVOS_BUILD_DIR)/Constants.cs \ $(TVOS_BUILD_DIR)/AssemblyInfo.cs \ @@ -721,7 +932,6 @@ $(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.con $(Q) rm -f $@.tmp $(Q) touch $@ - $(TVOS_BUILD_DIR)/tvos/core.dll: $(TVOS_CORE_SOURCES) frameworks.sources Makefile | $(TVOS_BUILD_DIR)/tvos @mkdir -p $(TVOS_BUILD_DIR)/tvos $(call Q_PROF_CSC,tvos) $(TV_CSC) -nologo -out:$@ -target:library -debug -unsafe \ @@ -753,6 +963,45 @@ $(BUILD_DIR)/tvos.rsp: Makefile Makefile.generator frameworks.sources --target-framework=Xamarin.TVOS,v1.0 \ > $@ +### .NET ### + +$(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll: $(TVOS_CORE_SOURCES) frameworks.sources Makefile | $(TVOS_DOTNET_BUILD_DIR) + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) \ + $(TVOS_CORE_WARNINGS_TO_FIX) \ + $(TVOS_CORE_DEFINES) \ + $(TVOS_CORE_SOURCES) \ + -out:$@ \ + +$(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources: $(DOTNET_GENERATOR) $(TVOS_APIS) $(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll $(DOTNET_BINDING_ATTRIBUTES) $(TVOS_DOTNET_BUILD_DIR)/tvos.rsp | $(TVOS_DOTNET_BUILD_DIR)/generated-sources + $(Q_DOTNET_GEN) $< @$(TVOS_DOTNET_BUILD_DIR)/tvos.rsp + +$(TVOS_DOTNET_BUILD_DIR)/tvos.rsp: Makefile Makefile.generator frameworks.sources + $(Q) echo \ + $(TVOS_GENERATOR_DEFINES) \ + $(DOTNET_GENERATOR_FLAGS) -inline-selectors \ + -warnaserror:$(TVOS_GENERATOR_WARNASERROR) \ + -sourceonly=$(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources \ + -tmpdir=$(TVOS_DOTNET_BUILD_DIR)/generated-sources \ + -baselib=$(TVOS_DOTNET_BUILD_DIR)/core-tvos.dll \ + --target-framework=.NETCoreApp,Version=5.0,Profile=tvos \ + $(TVOS_APIS) \ + > $@ + +$(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll: $(TVOS_DOTNET_BUILD_DIR)/tvos-generated-sources $(TVOS_SOURCES) $(PRODUCT_KEY_PATH) | $(TVOS_DOTNET_BUILD_DIR)/64 + $(Q_DOTNET_GEN) \ + $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ -optimize \ + -publicsign -keyfile:$(PRODUCT_KEY_PATH) \ + $(TVOS_DEFINES) \ + $(ARGS_64) \ + $(TVOS_WARNINGS_TO_FIX) \ + $(IOS_CSC_FLAGS_XI) \ + $(TVOS_SOURCES) \ + @$< + +$(TVOS_DOTNET_BUILD_DIR)/Xamarin.TVOS.dll: $(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll + $(Q_STRIP) mono-cil-strip -q $< $@ + $(TVOS_BUILD_DIR)/tvos-64/Xamarin.TVOS%dll $(TVOS_BUILD_DIR)/tvos-64/Xamarin.TVOS%pdb: $(TVOS_SOURCES) $(TVOS_BUILD_DIR)/tvos/generated_sources $(PRODUCT_KEY_PATH) | $(TVOS_BUILD_DIR)/tvos-64 $(call Q_PROF_CSC,tvos) $(TV_CSC) -nologo -out:$(basename $@).dll -target:library -debug -unsafe -optimize \ -publicsign -keyfile:$(PRODUCT_KEY_PATH) $(TVOS_DEFINES) \ @@ -821,6 +1070,15 @@ TVOS_TARGETS += \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/MonoTouch.NUnitLite.dll \ $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/MonoTouch.NUnitLite.pdb +DOTNET_TARGETS += \ + $(TVOS_DOTNET_BUILD_DIR)/64/Xamarin.TVOS.dll \ + $(TVOS_DOTNET_BUILD_DIR)/Xamarin.TVOS.dll \ + +DOTNET_TARGETS_DIRS += \ + $(TVOS_DOTNET_BUILD_DIR) \ + $(TVOS_DOTNET_BUILD_DIR)/generated-sources \ + $(TVOS_DOTNET_BUILD_DIR)/64 \ + # reference assemblies, this is just for compilation with XS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/%.dll: $(TVOS_BUILD_DIR)/reference/%.dll | $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS $(IOS_DESTDIR)$(MONOTOUCH_PREFIX)/lib/mono/Xamarin.TVOS/Facades $(Q) install -m 0755 $< $@ @@ -874,6 +1132,10 @@ ifdef ENABLE_DOTNET all-local:: $(DOTNET_TARGETS) endif +ifdef ENABLE_DOTNET +all-local:: $(DOTNET_TARGETS) +endif + project-files: $(PROJECT_FILES) # Using .SECONDARY can cause make to go into an infinite loop. diff --git a/src/Makefile.generator b/src/Makefile.generator index 483b486570b9..3b78c1eb7605 100644 --- a/src/Makefile.generator +++ b/src/Makefile.generator @@ -19,6 +19,7 @@ DOTNET_TARGETS += \ $(DOTNET_BUILD_DIR)/bgen/bgen \ DOTNET_TARGETS_DIRS += \ + $(DOTNET_BUILD_DIR) \ $(DOTNET_BUILD_DIR)/bgen \ # @@ -29,6 +30,9 @@ $(BUILD_DIR)/generator-frameworks.g.cs: frameworks.sources Makefile.generator ge @mkdir -p $(dir $@) @./generate-frameworks.csharp '$(IOS_FRAMEWORKS)' '$(MAC_FRAMEWORKS)' '$(WATCHOS_FRAMEWORKS)' '$(TVOS_FRAMEWORKS)' > $@ +$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll: generator-attributes.cs Makefile.generator | $(DOTNET_BUILD_DIR) + $(Q_DOTNET_BUILD) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ $< + # # Xamarin.iOS (btouch) # From 9b65dd5383b5d2a3c7970cc4069366b620a92e9c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 5 Mar 2020 23:45:16 +0100 Subject: [PATCH 09/25] [bgen] Don't yield the old-style location for product assemblies when running in .NET mode. Assemblies will still be found in .NET mode as long as the right -lib: is passed to bgen. --- src/btouch.cs | 54 ++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/btouch.cs b/src/btouch.cs index 59473a0038ab..4ff16f3edc3e 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -70,6 +70,10 @@ public static string ToolName { get { return "bgen"; } } + bool IsDotNet { + get { return TargetFramework.IsDotNet; } + } + static void ShowHelp (OptionSet os) { Console.WriteLine ("{0} - Mono Objective-C API binder", ToolName); @@ -117,31 +121,33 @@ string GetAttributeLibraryPath () IEnumerable GetLibraryDirectories () { - switch (CurrentPlatform) { - case PlatformName.iOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.iOS"); - break; - case PlatformName.WatchOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.WatchOS"); - break; - case PlatformName.TvOS: - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.TVOS"); - break; - case PlatformName.MacOSX: - if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) { - yield return Path.Combine (GetSDKRoot (), "lib", "reference", "full"); - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); - } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { - yield return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5"; - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); - } else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) { - yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac"); - } else { - throw ErrorHelper.CreateError (1053, target_framework); + if (!IsDotNet) { + switch (CurrentPlatform) { + case PlatformName.iOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.iOS"); + break; + case PlatformName.WatchOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.WatchOS"); + break; + case PlatformName.TvOS: + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.TVOS"); + break; + case PlatformName.MacOSX: + if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) { + yield return Path.Combine (GetSDKRoot (), "lib", "reference", "full"); + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); + } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { + yield return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5"; + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5"); + } else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) { + yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac"); + } else { + throw ErrorHelper.CreateError (1053, target_framework); + } + break; + default: + throw new BindingException (1047, CurrentPlatform); } - break; - default: - throw new BindingException (1047, CurrentPlatform); } foreach (var lib in libs) yield return lib; From 342e60cc273cfd5946ae07ba68ae754ff9dbd15c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 5 Mar 2020 23:46:02 +0100 Subject: [PATCH 10/25] [bgen] Don't fix references when in .NET mode. --- src/btouch.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/btouch.cs b/src/btouch.cs index 4ff16f3edc3e..ba9b7ec500da 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -340,24 +340,30 @@ int Main3 (string [] args) nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.iOS/Xamarin.iOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.iOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.iOS", references); + } break; case ApplePlatform.TVOS: CurrentPlatform = PlatformName.TvOS; nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.TVOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.TVOS", references); + } break; case ApplePlatform.WatchOS: CurrentPlatform = PlatformName.WatchOS; nostdlib = true; if (string.IsNullOrEmpty (baselibdll)) baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll"); - references.Add ("Facades/System.Drawing.Common"); - ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.WatchOS", references); + if (!IsDotNet) { + references.Add ("Facades/System.Drawing.Common"); + ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.WatchOS", references); + } break; case ApplePlatform.MacOSX: CurrentPlatform = PlatformName.MacOSX; From 36db0dd10146bd2c3a39bcb108a09c8b1eb6739e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 5 Mar 2020 23:46:20 +0100 Subject: [PATCH 11/25] [bgen] .NET 5 has System.Drawing.dll, no need to skip it. --- src/btouch.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/btouch.cs b/src/btouch.cs index ba9b7ec500da..60308acda01d 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -387,6 +387,8 @@ int Main3 (string [] args) } else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) { skipSystemDrawing = false; ReferenceFixer.FixSDKReferences ("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5", references, forceSystemDrawing : true); + } else if (target_framework == TargetFramework.DotNet_5_0_macOS) { + skipSystemDrawing = false; } else { throw ErrorHelper.CreateError (1053, target_framework); } From 2fa69897136efc69b4af8d545136716d3b40a4f5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 5 Mar 2020 23:54:50 +0100 Subject: [PATCH 12/25] [bgen] Intercept IKVM's assembly resolution to find assemblies ourselves. IKVM will try to use reflection, which doesn't work in .NET 5. --- src/Resources.Designer.cs | 6 ++++++ src/Resources.resx | 6 ++++++ src/btouch.cs | 33 +++++++++++++++++++++++++++++++++ src/xlf/Resources.cs.xlf | 8 ++++++++ src/xlf/Resources.de.xlf | 8 ++++++++ src/xlf/Resources.es.xlf | 8 ++++++++ src/xlf/Resources.fr.xlf | 8 ++++++++ src/xlf/Resources.it.xlf | 8 ++++++++ src/xlf/Resources.ja.xlf | 8 ++++++++ src/xlf/Resources.ko.xlf | 8 ++++++++ src/xlf/Resources.pl.xlf | 8 ++++++++ src/xlf/Resources.pt-BR.xlf | 8 ++++++++ src/xlf/Resources.ru.xlf | 8 ++++++++ src/xlf/Resources.tr.xlf | 8 ++++++++ src/xlf/Resources.zh-Hans.xlf | 8 ++++++++ src/xlf/Resources.zh-Hant.xlf | 8 ++++++++ 16 files changed, 149 insertions(+) diff --git a/src/Resources.Designer.cs b/src/Resources.Designer.cs index 83c1cdd205ff..7dfbcb130d4a 100644 --- a/src/Resources.Designer.cs +++ b/src/Resources.Designer.cs @@ -605,6 +605,12 @@ internal static string BI1080 { } } + internal static string BI1081 { + get { + return ResourceManager.GetString("BI1081", resourceCulture); + } + } + internal static string BI1101 { get { return ResourceManager.GetString("BI1101", resourceCulture); diff --git a/src/Resources.resx b/src/Resources.resx index 7daf260182c7..1b414190d074 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -766,6 +766,12 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/btouch.cs b/src/btouch.cs index 60308acda01d..656761092b06 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -455,6 +455,39 @@ int Main3 (string [] args) universe = new Universe (UniverseOptions.EnableFunctionPointers | UniverseOptions.ResolveMissingMembers | UniverseOptions.MetadataOnly); + if (IsDotNet) { + // IKVM tries uses reflection to locate assemblies on disk, but .NET doesn't include reflection so that fails. + // Instead intercept assembly resolution and look for assemblies where we know they are. + var resolved_assemblies = new Dictionary (); + universe.AssemblyResolve += (object sender, IKVM.Reflection.ResolveEventArgs rea) => { + var an = new AssemblyName (rea.Name); + + // Check if we've already found this assembly + if (resolved_assemblies.TryGetValue (an.Name, out var rv)) + return rv; + + // Check if the assembly has already been loaded into IKVM + var assemblies = universe.GetAssemblies (); + foreach (var asm in assemblies) { + if (asm.GetName ().Name == an.Name) { + resolved_assemblies [an.Name] = asm; + return asm; + } + } + + // Look in the references to find a matching one and get the path from there. + foreach (var r in references) { + var fn = Path.GetFileNameWithoutExtension (r); + if (fn == an.Name) { + rv = universe.LoadFile (r); + resolved_assemblies [an.Name] = rv; + return rv; + } + } + + throw ErrorHelper.CreateError (1081, rea.Name); + }; + } Assembly api; try { diff --git a/src/xlf/Resources.cs.xlf b/src/xlf/Resources.cs.xlf index 492cbda7464f..d6799ffefeab 100644 --- a/src/xlf/Resources.cs.xlf +++ b/src/xlf/Resources.cs.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.de.xlf b/src/xlf/Resources.de.xlf index a2d5352b8575..3cd6db26e77e 100644 --- a/src/xlf/Resources.de.xlf +++ b/src/xlf/Resources.de.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.es.xlf b/src/xlf/Resources.es.xlf index 5985b82bc31c..32b94f25400e 100644 --- a/src/xlf/Resources.es.xlf +++ b/src/xlf/Resources.es.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.fr.xlf b/src/xlf/Resources.fr.xlf index 7d66a9157a1d..d89f13e67c63 100644 --- a/src/xlf/Resources.fr.xlf +++ b/src/xlf/Resources.fr.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.it.xlf b/src/xlf/Resources.it.xlf index c6872587853c..70f8de50cbb6 100644 --- a/src/xlf/Resources.it.xlf +++ b/src/xlf/Resources.it.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ja.xlf b/src/xlf/Resources.ja.xlf index f991fb3e6a8e..8daac048a46a 100644 --- a/src/xlf/Resources.ja.xlf +++ b/src/xlf/Resources.ja.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ko.xlf b/src/xlf/Resources.ko.xlf index 2b31a5fda8e3..236d7e8be8c3 100644 --- a/src/xlf/Resources.ko.xlf +++ b/src/xlf/Resources.ko.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.pl.xlf b/src/xlf/Resources.pl.xlf index 9b93f48c6a50..28d154ef75b1 100644 --- a/src/xlf/Resources.pl.xlf +++ b/src/xlf/Resources.pl.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.pt-BR.xlf b/src/xlf/Resources.pt-BR.xlf index 022853d3abf0..d3108891ed35 100644 --- a/src/xlf/Resources.pt-BR.xlf +++ b/src/xlf/Resources.pt-BR.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.ru.xlf b/src/xlf/Resources.ru.xlf index 203333416d95..fbc267c05e30 100644 --- a/src/xlf/Resources.ru.xlf +++ b/src/xlf/Resources.ru.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.tr.xlf b/src/xlf/Resources.tr.xlf index 2380420a8e13..d73ff2f83e99 100644 --- a/src/xlf/Resources.tr.xlf +++ b/src/xlf/Resources.tr.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.zh-Hans.xlf b/src/xlf/Resources.zh-Hans.xlf index 6cf316a00a94..b1014ea85d71 100644 --- a/src/xlf/Resources.zh-Hans.xlf +++ b/src/xlf/Resources.zh-Hans.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] diff --git a/src/xlf/Resources.zh-Hant.xlf b/src/xlf/Resources.zh-Hant.xlf index 5b8a61413e56..af789b5a43f6 100644 --- a/src/xlf/Resources.zh-Hant.xlf +++ b/src/xlf/Resources.zh-Hant.xlf @@ -735,6 +735,14 @@ + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + Unable to find the assembly '{0}'. Add it as a reference using its full path. + + + + Trying to use a string as a [Target] From 7a1a8bbf0bc46e48dcc3f8afc14b00ea6b22345d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 6 Mar 2020 18:29:56 +0100 Subject: [PATCH 13/25] [bgen] Add netcore version of the generator tests. --- src/bgen/bgen.sln | 6 +++++ tests/bgen/bgen-tests.csproj | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/bgen/bgen-tests.csproj diff --git a/src/bgen/bgen.sln b/src/bgen/bgen.sln index 711581dd3257..f2f8607d4df9 100644 --- a/src/bgen/bgen.sln +++ b/src/bgen/bgen.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bgen", "bgen.csproj", "{B42BBC30-27F6-4C49-8727-216DC75B042C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bgen-tests", "..\..\tests\bgen\bgen-tests.csproj", "{5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,5 +15,9 @@ Global {B42BBC30-27F6-4C49-8727-216DC75B042C}.Debug|Any CPU.Build.0 = Debug|Any CPU {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.ActiveCfg = Release|Any CPU {B42BBC30-27F6-4C49-8727-216DC75B042C}.Release|Any CPU.Build.0 = Release|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5711BDD2-4E98-43B5-8BAE-EC5DF4CC5628}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/tests/bgen/bgen-tests.csproj b/tests/bgen/bgen-tests.csproj new file mode 100644 index 000000000000..9a70dc9ce8e3 --- /dev/null +++ b/tests/bgen/bgen-tests.csproj @@ -0,0 +1,52 @@ + + + + netcoreapp3.1 + bgen_tests + + false + + + + + + + + + + + + + + + Asserts.cs + + + BGenTests.cs + + + BGenTool.cs + + + ErrorTests.cs + + + GeneratorTests.cs + + + Configuration.cs + + + ExecutionHelper.cs + + + Profile.cs + + + Cache.cs + + + StringUtils.cs + + + From 1fc2f8e3c2421e4680833afc15764206b5c351d2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 9 Mar 2020 12:56:38 +0100 Subject: [PATCH 14/25] [xharness] Add support for running the generator tests in .NET mode. This also meant adding support for running .NET tests in xharness. Some refactoring was done to extract common code to shared members, in order to avoid duplicating a lot of code. --- tests/xharness/Jenkins/Jenkins.cs | 25 +++++++++ .../Jenkins/TestTasks/DotNetBuildTask.cs | 19 +++++++ .../Jenkins/TestTasks/DotNetTestTask.cs | 36 +++++++++++++ .../xharness/Jenkins/TestTasks/MSBuildTask.cs | 35 +++++++----- .../Jenkins/TestTasks/NUnitExecuteTask.cs | 54 +++++-------------- .../xharness/Jenkins/TestTasks/RunTestTask.cs | 46 +++++++++++++++- .../xharness/Jenkins/TestTasks/RunXtroTask.cs | 3 -- tests/xharness/Logging/ILog.cs | 6 +++ tests/xharness/xharness.csproj | 3 ++ 9 files changed, 171 insertions(+), 56 deletions(-) create mode 100644 tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs create mode 100644 tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs diff --git a/tests/xharness/Jenkins/Jenkins.cs b/tests/xharness/Jenkins/Jenkins.cs index a441ac4ab016..7aee70cf484f 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -740,6 +740,7 @@ void SelectTestsByModifiedFiles (int pull_request) "src/generator.cs", "src/generator-", "src/Makefile.generator", + "tests/bgen", "tests/generator", "tests/common", }; @@ -1093,11 +1094,28 @@ Task PopulateTasksAsync () TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "generator", "generator-tests.csproj"))), Platform = TestPlatform.iOS, TestName = "Generator tests", + Mode = "NUnit", Timeout = TimeSpan.FromMinutes (10), Ignored = !IncludeBtouch, }; Tasks.Add (runGenerator); + var buildDotNetGenerator = new DotNetBuildTask { + Jenkins = this, + TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "bgen", "bgen-tests.csproj"))), + SpecifyPlatform = false, + SpecifyConfiguration = false, + Platform = TestPlatform.iOS, + }; + var runDotNetGenerator = new DotNetTestTask (buildDotNetGenerator) { + TestProject = buildDotNetGenerator.TestProject, + Platform = TestPlatform.iOS, + TestName = "Generator tests", + Mode = ".NET", + Ignored = !IncludeBtouch, + }; + Tasks.Add (runDotNetGenerator); + var run_mmp = new MakeTask { Jenkins = this, @@ -1748,6 +1766,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) var allNUnitTasks = new List (); var allMakeTasks = new List (); var allDeviceTasks = new List (); + var allDotNetTestTasks = new List (); foreach (var task in Tasks) { var aggregated = task as AggregatedRunSimulatorTask; if (aggregated != null) { @@ -1779,6 +1798,11 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) continue; } + if (task is DotNetTestTask dotnet) { + allDotNetTestTasks.Add (dotnet); + continue; + } + throw new NotImplementedException (); } @@ -1789,6 +1813,7 @@ void GenerateReportImpl (Stream stream, StreamWriter markdown_summary = null) allTasks.AddRange (allNUnitTasks); allTasks.AddRange (allMakeTasks); allTasks.AddRange (allDeviceTasks); + allTasks.AddRange (allDotNetTestTasks); } var failedTests = allTasks.Where ((v) => v.Failed); diff --git a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs new file mode 100644 index 000000000000..c36c5ed813ba --- /dev/null +++ b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace Xharness.Jenkins.TestTasks { + class DotNetBuildTask : MSBuildTask { + protected override string ToolName { + get { return "dotnet"; } + } + + protected override List ToolArguments { + get { + var args = base.ToolArguments; + // 'dotnet build' takes almost the same arguments as 'msbuild', so just massage a little bit. + args.Remove ("--"); + args.Insert (0, "build"); + return args; + } + } + } +} diff --git a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs new file mode 100644 index 000000000000..ccc7e351a5d6 --- /dev/null +++ b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Threading.Tasks; +using Xamarin.Utils; +using Xharness.Execution; +using Xharness.Logging; + +namespace Xharness.Jenkins.TestTasks { + class DotNetTestTask : RunTestTask { + public DotNetTestTask (DotNetBuildTask build_task) + : base (build_task) + { + } + + protected override async Task RunTestAsync () + { + using (var resource = await NotifyAndAcquireDesktopResourceAsync ()) { + var trx = Logs.Create ($"results-{Timestamp}.trx", LogType.TrxLog.ToString ()); + var html = Logs.Create ($"results-{Timestamp}.html", LogType.HtmlLog.ToString ()); + + var args = new List { + "test", + BuildTask.ProjectFile, + "--results-directory:" + Logs.Directory, + "--logger:console;verbosity=detailed", + "--logger:trx;LogFileName=" + Path.GetFileName (trx.FullPath), + "--logger:html;LogFileName=" + Path.GetFileName (html.FullPath) + }; + + await ExecuteProcessAsync ("dotnet", args); + } + } + } +} diff --git a/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs b/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs index 62fad23e6b45..ab0f6adaee1c 100644 --- a/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs +++ b/tests/xharness/Jenkins/TestTasks/MSBuildTask.cs @@ -13,26 +13,37 @@ class MSBuildTask : BuildProjectTask { public ILog BuildLog; + protected virtual string ToolName { + get { return Harness.XIBuildPath; } + } + + protected virtual List ToolArguments { + get { + var binlogPath = BuildLog.FullPath.Replace (".txt", ".binlog"); + + var args = new List (); + args.Add ("--"); + args.Add ("/verbosity:diagnostic"); + args.Add ($"/bl:{binlogPath}"); + if (SpecifyPlatform) + args.Add ($"/p:Platform={ProjectPlatform}"); + if (SpecifyConfiguration) + args.Add ($"/p:Configuration={ProjectConfiguration}"); + args.Add (ProjectFile); + return args; + } + } + protected override async Task ExecuteAsync () { using (var resource = await NotifyAndAcquireDesktopResourceAsync ()) { BuildLog = Logs.Create ($"build-{Platform}-{Timestamp}.txt", LogType.BuildLog.ToString ()); - var binlogPath = BuildLog.FullPath.Replace (".txt", ".binlog"); await RestoreNugetsAsync (BuildLog, resource, useXIBuild: true); using (var xbuild = new Process ()) { - xbuild.StartInfo.FileName = Harness.XIBuildPath; - var args = new List (); - args.Add ("--"); - args.Add ("/verbosity:diagnostic"); - args.Add ($"/bl:{binlogPath}"); - if (SpecifyPlatform) - args.Add ($"/p:Platform={ProjectPlatform}"); - if (SpecifyConfiguration) - args.Add ($"/p:Configuration={ProjectConfiguration}"); - args.Add (ProjectFile); - xbuild.StartInfo.Arguments = StringUtils.FormatArguments (args); + xbuild.StartInfo.FileName = ToolName; + xbuild.StartInfo.Arguments = StringUtils.FormatArguments (ToolArguments); SetEnvironmentVariables (xbuild); xbuild.StartInfo.EnvironmentVariables ["MSBuildExtensionsPath"] = null; LogEvent (BuildLog, "Building {0} ({1})", TestName, Mode); diff --git a/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs b/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs index 1eeef4ee939e..c9b9a17a77e3 100644 --- a/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs +++ b/tests/xharness/Jenkins/TestTasks/NUnitExecuteTask.cs @@ -17,11 +17,8 @@ class NUnitExecuteTask : RunTestTask { public string TestLibrary; public string TestExecutable; - public string WorkingDirectory; public bool ProduceHtmlReport = true; public bool InProcess; - public TimeSpan Timeout = TimeSpan.FromMinutes (10); - IProcessManager ProcessManager { get; set; } = new ProcessManager (); public NUnitExecuteTask (BuildToolTask build_task) : base (build_task) @@ -120,45 +117,22 @@ protected override async Task RunTestAsync () var xmlLog = Logs.CreateFile ($"log-{Timestamp}.xml", LogType.XmlLog.ToString ()); var log = Logs.Create ($"execute-{Timestamp}.txt", LogType.ExecutionLog.ToString ()); FindNUnitConsoleExecutable (log); - using (var proc = new Process ()) { - proc.StartInfo.WorkingDirectory = WorkingDirectory; - proc.StartInfo.FileName = Harness.XIBuildPath; - var args = new List (); - args.Add ("-t"); - args.Add ("--"); - args.Add (Path.GetFullPath (TestExecutable)); - args.Add (Path.GetFullPath (TestLibrary)); - if (IsNUnit3) { - args.Add ("-result=" + xmlLog + ";format=nunit2"); - args.Add ("--labels=All"); - if (InProcess) - args.Add ("--inprocess"); - } else { - args.Add ("-xml=" + xmlLog); - args.Add ("-labels"); - } - proc.StartInfo.Arguments = StringUtils.FormatArguments (args); - SetEnvironmentVariables (proc); - foreach (DictionaryEntry de in proc.StartInfo.EnvironmentVariables) - log.WriteLine ($"export {de.Key}={de.Value}"); - Jenkins.MainLog.WriteLine ("Executing {0} ({1})", TestName, Mode); - if (!Harness.DryRun) { - ExecutionResult = TestExecutingResult.Running; - var result = await ProcessManager.RunAsync (proc, log, Timeout); - if (result.TimedOut) { - FailureMessage = $"Execution timed out after {Timeout.TotalMinutes} minutes."; - log.WriteLine (FailureMessage); - ExecutionResult = TestExecutingResult.TimedOut; - } else if (result.Succeeded) { - ExecutionResult = TestExecutingResult.Succeeded; - } else { - ExecutionResult = TestExecutingResult.Failed; - FailureMessage = $"Execution failed with exit code {result.ExitCode}"; - } - } - Jenkins.MainLog.WriteLine ("Executed {0} ({1})", TestName, Mode); + var args = new List (); + args.Add ("-t"); + args.Add ("--"); + args.Add (Path.GetFullPath (TestExecutable)); + args.Add (Path.GetFullPath (TestLibrary)); + if (IsNUnit3) { + args.Add ("-result=" + xmlLog + ";format=nunit2"); + args.Add ("--labels=All"); + if (InProcess) + args.Add ("--inprocess"); + } else { + args.Add ("-xml=" + xmlLog); + args.Add ("-labels"); } + await ExecuteProcessAsync (log, Harness.XIBuildPath, args); if (ProduceHtmlReport) { try { diff --git a/tests/xharness/Jenkins/TestTasks/RunTestTask.cs b/tests/xharness/Jenkins/TestTasks/RunTestTask.cs index 652b3a729658..27c94952fe02 100644 --- a/tests/xharness/Jenkins/TestTasks/RunTestTask.cs +++ b/tests/xharness/Jenkins/TestTasks/RunTestTask.cs @@ -1,6 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Xamarin.Utils; +using Xharness.Execution; using Xharness.Logging; namespace Xharness.Jenkins.TestTasks @@ -8,7 +13,10 @@ namespace Xharness.Jenkins.TestTasks internal abstract class RunTestTask : TestTask { public readonly BuildToolTask BuildTask; + public TimeSpan Timeout = TimeSpan.FromMinutes (10); public double TimeoutMultiplier { get; set; } = 1; + IProcessManager ProcessManager { get; } = new ProcessManager (); + public string WorkingDirectory; public RunTestTask (BuildToolTask build_task) { @@ -105,5 +113,41 @@ public override void Reset () base.Reset (); BuildTask.Reset (); } + + protected Task ExecuteProcessAsync (string filename, List arguments) + { + return ExecuteProcessAsync (null, filename, arguments); + } + + protected async Task ExecuteProcessAsync (ILog log, string filename, List arguments) + { + if (log == null) + log = Logs.Create ($"execute-{Timestamp}.txt", LogType.ExecutionLog.ToString ()); + + using var proc = new Process (); + proc.StartInfo.FileName = filename; + proc.StartInfo.Arguments = StringUtils.FormatArguments (arguments); + if (!string.IsNullOrEmpty (WorkingDirectory)) + proc.StartInfo.WorkingDirectory = WorkingDirectory; + SetEnvironmentVariables (proc); + foreach (DictionaryEntry de in proc.StartInfo.EnvironmentVariables) + log.WriteLine ($"export {de.Key}={de.Value}"); + Jenkins.MainLog.WriteLine ("Executing {0} ({1})", TestName, Mode); + if (!Harness.DryRun) { + ExecutionResult = TestExecutingResult.Running; + var result = await ProcessManager.RunAsync (proc, log, Timeout); + if (result.TimedOut) { + FailureMessage = $"Execution timed out after {Timeout.TotalMinutes} minutes."; + log.WriteLine (FailureMessage); + ExecutionResult = TestExecutingResult.TimedOut; + } else if (result.Succeeded) { + ExecutionResult = TestExecutingResult.Succeeded; + } else { + ExecutionResult = TestExecutingResult.Failed; + FailureMessage = $"Execution failed with exit code {result.ExitCode}"; + } + } + Jenkins.MainLog.WriteLine ("Executed {0} ({1})", TestName, Mode); + } } } diff --git a/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs b/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs index 6884e2e9a6da..c0a93467ae68 100644 --- a/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs +++ b/tests/xharness/Jenkins/TestTasks/RunXtroTask.cs @@ -7,9 +7,6 @@ namespace Xharness.Jenkins.TestTasks { class RunXtroTask : MacExecuteTask { - - public string WorkingDirectory; - public RunXtroTask (BuildToolTask build_task) : base (build_task) { } diff --git a/tests/xharness/Logging/ILog.cs b/tests/xharness/Logging/ILog.cs index 2f2ad5c24e56..fed96b84e33c 100644 --- a/tests/xharness/Logging/ILog.cs +++ b/tests/xharness/Logging/ILog.cs @@ -14,6 +14,8 @@ public enum LogType { TestLog, ExtensionTestLog, ExecutionLog, + TrxLog, + HtmlLog, } public static class LogTypeExtensions { @@ -37,6 +39,10 @@ public static string ToString (this LogType type) return "Extension test log"; case LogType.ExecutionLog: return "Execution log"; + case LogType.TrxLog: + return "Test log (trx)"; + case LogType.HtmlLog: + return "Test log (html)"; default: throw new ArgumentException ($"Unknown type for {nameof (type)}"); } diff --git a/tests/xharness/xharness.csproj b/tests/xharness/xharness.csproj index 49439ea84896..6c929a413cb9 100644 --- a/tests/xharness/xharness.csproj +++ b/tests/xharness/xharness.csproj @@ -10,6 +10,7 @@ xharness xharness v4.7.2 + 8.0 true @@ -145,6 +146,8 @@ + + From 0c10206459f3452e03f0fbbf876a81f878a8a95a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 10 Mar 2020 08:04:02 +0100 Subject: [PATCH 15/25] [System.Net.Http] Add issue about CFNetworkHandler .NET todo. --- src/System.Net.Http/CFNetworkHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Net.Http/CFNetworkHandler.cs b/src/System.Net.Http/CFNetworkHandler.cs index 0d27de714532..f4fee5029e2d 100644 --- a/src/System.Net.Http/CFNetworkHandler.cs +++ b/src/System.Net.Http/CFNetworkHandler.cs @@ -387,6 +387,7 @@ void AddCookie (string value, Uri uri, string header) #if !DOTNET_TODO // DOTNET_TODO: CookieCollection.CookieCutter is internal to mscorlib: // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/System/net/System/Net/cookiecontainer.cs#L632 + // https://github.com/xamarin/xamarin-macios/issues/8072 CookieCollection cookies1 = null; try { cookies1 = cookies.CookieCutter (uri, header, value, false); From 398989a050a91fd88ae53de6094823d641ccc067 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 10 Mar 2020 08:05:07 +0100 Subject: [PATCH 16/25] [Compression] Obsolete [Begin|End][Read|Write] in .NET. --- src/Compression/Compression.cs | 77 +++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/src/Compression/Compression.cs b/src/Compression/Compression.cs index c5eadbb882cf..e5e53ba31414 100644 --- a/src/Compression/Compression.cs +++ b/src/Compression/Compression.cs @@ -300,19 +300,37 @@ private static void ThrowCannotWriteToDeflateStreamException() throw new InvalidOperationException ("Writing to the compression stream is not supported."); } -#if !DOTNET_TODO - // DOTNET_TODO: TaskToApm is internal API in mscorlib, so we can't use it. - // Although I'm not sure if we even need to override these methods, - // the base class implementation works (but synchronously), - // and the documentation recommends using ReadAsync instead. - // If we decide to implement this, we could just copy the TaskToApm implementation: - // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/mscorlib/system/threading/Tasks/TaskToApm.cs - public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => - TaskToApm.Begin(ReadAsync (buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); - - public override int EndRead (IAsyncResult asyncResult) => - TaskToApm.End (asyncResult); -#endif // !DOTNET_TODO +#if DOTNET + #pragma warning disable 0809 // Obsolete member 'CompressionStream.BeginRead(...)' overrides non-obsolete member 'Stream.BeginRead(...)' + [Obsolete ("Use 'ReadAsync' instead. This method is synchronous.")] +#endif + public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) + { +#if DOTNET + // TaskToApm is internal API in mscorlib, so we can't use it. + // In any case, the documentation recommends using ReadAsync instead, + // so obsolete this method and just call the base method implementation, + // which should still work (just synchronously). + return base.BeginRead (buffer, offset, count, asyncCallback, asyncState); +#else + return TaskToApm.Begin(ReadAsync (buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); +#endif + } + +#if DOTNET + [Obsolete ("Use 'EndRead' instead.")] +#endif + public override int EndRead (IAsyncResult asyncResult) + { +#if DOTNET + return base.EndRead (asyncResult); +#else + return TaskToApm.End (asyncResult); +#endif + } +#if DOTNET + #pragma warning restore 0809 +#endif public override Task ReadAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { @@ -555,13 +573,34 @@ protected override void Dispose (bool disposing) } } -#if !DOTNET_TODO - // DOTNET_TODO: See comment about TaskToApm elsewhere in this file. - public override IAsyncResult BeginWrite (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => - TaskToApm.Begin(WriteAsync (array, offset, count, CancellationToken.None), asyncCallback, asyncState); +#if DOTNET + #pragma warning disable 0809 // Obsolete member 'CompressionStream.BeginWrite(...)' overrides non-obsolete member 'Stream.BeginWrite(...)' + [Obsolete ("Use 'BeginWrite' instead. This method is synchronous.")] +#endif + public override IAsyncResult BeginWrite (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) + { +#if DOTNET + // See comment about TaskToApm elsewhere in this file. + return base.BeginWrite (array, offset, count, asyncCallback, asyncState); +#else + return TaskToApm.Begin(WriteAsync (array, offset, count, CancellationToken.None), asyncCallback, asyncState); +#endif + } - public override void EndWrite (IAsyncResult asyncResult) => TaskToApm.End (asyncResult); -#endif // !DOTNET_TODO +#if DOTNET + [Obsolete ("Use 'EndWrite' instead.")] +#endif + public override void EndWrite (IAsyncResult asyncResult) + { +#if DOTNET + base.EndWrite (asyncResult); +#else + TaskToApm.End (asyncResult); +#endif + } +#if DOTNET + #pragma warning restore 0809 +#endif public override Task WriteAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { From 7bef994405a30fdd0ac116bb065cd33c60dd9f5c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 10 Mar 2020 08:05:51 +0100 Subject: [PATCH 17/25] Revert whitespace change. --- src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile b/src/Makefile index 3d231c4ed1fa..56c9e9805f62 100644 --- a/src/Makefile +++ b/src/Makefile @@ -932,6 +932,7 @@ $(TVOS_BUILD_DIR)/AssemblyInfo.cs: $(TOP)/src/AssemblyInfo.cs.in $(TOP)/Make.con $(Q) rm -f $@.tmp $(Q) touch $@ + $(TVOS_BUILD_DIR)/tvos/core.dll: $(TVOS_CORE_SOURCES) frameworks.sources Makefile | $(TVOS_BUILD_DIR)/tvos @mkdir -p $(TVOS_BUILD_DIR)/tvos $(call Q_PROF_CSC,tvos) $(TV_CSC) -nologo -out:$@ -target:library -debug -unsafe \ From d7d9baef2dacf5d045afaf4de5d72d8af358a241 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 10 Mar 2020 13:41:14 +0100 Subject: [PATCH 18/25] Use full path to the 'dotnet' executable. This way we don't have to change PATH on bots. It always makes it easier to use a different location for the executable in the future if we wished to. --- Make.config | 1 + src/Makefile.generator | 2 +- tests/Makefile | 2 ++ tests/xharness/Harness.cs | 2 ++ tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs | 2 +- tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs | 2 +- 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Make.config b/Make.config index 655baafda24c..3e22d3fa43b5 100644 --- a/Make.config +++ b/Make.config @@ -374,6 +374,7 @@ endif DOTNET_VERSION=3.1.100 DOTNET_URL=https://download.visualstudio.microsoft.com/download/pr/787e81f1-f0da-4e3b-a989-8a199132ed8c/61a8dba81fbf2b3d533562d7b96443ec/dotnet-sdk-3.1.100-osx-x64.pkg +DOTNET=/usr/local/share/dotnet/dotnet DOTNET_BCL_REF_URL=https://www.nuget.org/api/v2/package/Microsoft.NETCore.App.Ref/3.1.0 DOTNET_BCL_REF_NAME=microsoft.netcore.app.ref.3.1.0.nupkg DOTNET_BCL_DIR:=$(abspath $(TOP)/builds/downloads/$(basename $(DOTNET_BCL_REF_NAME)))/ref/netcoreapp3.1 diff --git a/src/Makefile.generator b/src/Makefile.generator index 3b78c1eb7605..bafdcb69917a 100644 --- a/src/Makefile.generator +++ b/src/Makefile.generator @@ -12,7 +12,7 @@ $(BUILD_DIR)/common/bgen.exe: $(generator_dependencies) Makefile.generator $(BUI $(Q_GEN) $(SYSTEM_MSBUILD) $(XBUILD_VERBOSITY) /p:Configuration=Debug generator.csproj /p:IntermediateOutputPath=$(BUILD_DIR)/IDE/obj/common/ /p:OutputPath=$(BUILD_DIR)/common $(DOTNET_BUILD_DIR)/bgen/bgen: $(generator_dependencies) Makefile.generator $(BUILD_DIR)/generator-frameworks.g.cs | $(DOTNET_BUILD_DIR)/bgen - $(Q_DOTNET_BUILD) dotnet build $(XBUILD_VERBOSITY) /p:Configuration=Debug bgen/bgen.csproj + $(Q_DOTNET_BUILD) $(DOTNET) build $(XBUILD_VERBOSITY) /p:Configuration=Debug bgen/bgen.csproj $(Q) $(CP) bgen/bin/Debug/netcoreapp3.1/bgen* $(dir $@) DOTNET_TARGETS += \ diff --git a/tests/Makefile b/tests/Makefile index e13dc2b7218b..2fb37bb66b16 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -95,6 +95,7 @@ test.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @echo "MONO_IOS_SDK_DESTDIR=$(MONO_IOS_SDK_DESTDIR)" >> $@ @echo "MONO_MAC_SDK_DESTDIR=$(MONO_MAC_SDK_DESTDIR)" >> $@ @echo "ENABLE_XAMARIN=$(ENABLE_XAMARIN)" >> $@ + @echo "DOTNET=$(DOTNET)" >> $@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @rm -f $@ @@ -105,6 +106,7 @@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk @echo "INCLUDE_DEVICE=$(INCLUDE_DEVICE)" >> $@ @echo "MONO_IOS_SDK_DESTDIR=$(MONO_IOS_SDK_DESTDIR)" >> $@ @echo "MONO_MAC_SDK_DESTDIR=$(MONO_MAC_SDK_DESTDIR)" >> $@ + @echo "DOTNET=$(DOTNET)" >> $@ clean-local:: $(Q) $(SYSTEM_XBUILD) /t:Clean /p:Platform=iPhoneSimulator /p:Configuration=$(CONFIG) $(XBUILD_VERBOSITY) tests.sln diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 21065aa8ab0c..b003f58a5c43 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -98,6 +98,7 @@ public static string RootDirectory { public string MONO_MAC_SDK_DESTDIR { get; set; } public bool IncludeMac32 { get; set; } public bool ENABLE_XAMARIN { get; set; } + public string DOTNET { get; set; } // Run public AppRunnerTarget Target { get; set; } @@ -263,6 +264,7 @@ void LoadConfig () MONO_IOS_SDK_DESTDIR = make_config ["MONO_IOS_SDK_DESTDIR"]; MONO_MAC_SDK_DESTDIR = make_config ["MONO_MAC_SDK_DESTDIR"]; ENABLE_XAMARIN = make_config.ContainsKey ("ENABLE_XAMARIN") && !string.IsNullOrEmpty (make_config ["ENABLE_XAMARIN"]); + DOTNET = make_config ["DOTNET"]; } int AutoConfigureMac (bool generate_projects) diff --git a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs index c36c5ed813ba..3806842c972b 100644 --- a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs +++ b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs @@ -3,7 +3,7 @@ namespace Xharness.Jenkins.TestTasks { class DotNetBuildTask : MSBuildTask { protected override string ToolName { - get { return "dotnet"; } + get { return Harness.DOTNET; } } protected override List ToolArguments { diff --git a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs index ccc7e351a5d6..f9598716cf1c 100644 --- a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs +++ b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs @@ -29,7 +29,7 @@ protected override async Task RunTestAsync () "--logger:html;LogFileName=" + Path.GetFileName (html.FullPath) }; - await ExecuteProcessAsync ("dotnet", args); + await ExecuteProcessAsync (Harness.DOTNET, args); } } } From 187a5d748f6f1cf822ee75f299279ffed781ac10 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 10 Mar 2020 17:43:58 +0100 Subject: [PATCH 19/25] [bgen] Don't handle resources quite yet in the .NET version of bgen. --- src/bgen/bgen.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bgen/bgen.csproj b/src/bgen/bgen.csproj index 9ca889a60f70..fcebddf9e6ca 100644 --- a/src/bgen/bgen.csproj +++ b/src/bgen/bgen.csproj @@ -9,11 +9,11 @@ - + - true + $(MSBuildThisFileDirectory)/../.. $(MSBuildThisFileDirectory)/../build/dotnet $(RepositoryPath)/builds From 2f2c8c31c4e95e91377f7b1c80b387c55f0e9258 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 11 Mar 2020 11:02:14 +0100 Subject: [PATCH 20/25] [src] Reduce the list of referenced netcore assemblies. --- src/Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 56c9e9805f62..6be14615d237 100644 --- a/src/Makefile +++ b/src/Makefile @@ -26,21 +26,18 @@ TVOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/tvos GENERATOR_FLAGS=-process-enums -core -nologo -nostdlib -noconfig -native-exception-marshalling --ns:ObjCRuntime DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /target:library /debug /unsafe /define:DOTNET /define:DOTNET_TODO \ - /r:$(DOTNET_BCL_DIR)/mscorlib.dll \ /r:$(DOTNET_BCL_DIR)/System.Buffers.dll \ - /r:$(DOTNET_BCL_DIR)/System.Collections.dll \ /r:$(DOTNET_BCL_DIR)/System.Collections.Concurrent.dll \ + /r:$(DOTNET_BCL_DIR)/System.Collections.dll \ /r:$(DOTNET_BCL_DIR)/System.Collections.NonGeneric.dll \ /r:$(DOTNET_BCL_DIR)/System.Console.dll \ /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Debug.dll \ /r:$(DOTNET_BCL_DIR)/System.Diagnostics.Tools.dll \ - /r:$(DOTNET_BCL_DIR)/System.dll \ /r:$(DOTNET_BCL_DIR)/System.Drawing.Primitives.dll \ /r:$(DOTNET_BCL_DIR)/System.IO.Compression.dll \ /r:$(DOTNET_BCL_DIR)/System.IO.FileSystem.dll \ /r:$(DOTNET_BCL_DIR)/System.Linq.dll \ /r:$(DOTNET_BCL_DIR)/System.Memory.dll \ - /r:$(DOTNET_BCL_DIR)/System.Net.dll \ /r:$(DOTNET_BCL_DIR)/System.Net.Http.dll \ /r:$(DOTNET_BCL_DIR)/System.Net.NameResolution.dll \ /r:$(DOTNET_BCL_DIR)/System.Net.Primitives.dll \ @@ -48,19 +45,17 @@ DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /targe /r:$(DOTNET_BCL_DIR)/System.Net.Security.dll \ /r:$(DOTNET_BCL_DIR)/System.Net.ServicePoint.dll \ /r:$(DOTNET_BCL_DIR)/System.Net.Sockets.dll \ - /r:$(DOTNET_BCL_DIR)/System.ObjectModel.dll \ - /r:$(DOTNET_BCL_DIR)/System.Text.RegularExpressions.dll \ /r:$(DOTNET_BCL_DIR)/System.Resources.ResourceManager.dll \ /r:$(DOTNET_BCL_DIR)/System.Runtime.dll \ /r:$(DOTNET_BCL_DIR)/System.Runtime.Extensions.dll \ /r:$(DOTNET_BCL_DIR)/System.Runtime.InteropServices.dll \ /r:$(DOTNET_BCL_DIR)/System.Security.Cryptography.X509Certificates.dll \ + /r:$(DOTNET_BCL_DIR)/System.Text.RegularExpressions.dll \ /r:$(DOTNET_BCL_DIR)/System.Threading.dll \ /r:$(DOTNET_BCL_DIR)/System.Threading.Tasks.dll \ /r:$(DOTNET_BCL_DIR)/System.Threading.Thread.dll \ + /r:$(DOTNET_BCL_DIR)/System.Xml.dll \ /r:$(DOTNET_BCL_DIR)/System.Xml.ReaderWriter.dll \ - /r:$(DOTNET_BCL_DIR)/System.Xml.Serialization.dll \ - /r:$(DOTNET_BCL_DIR)/System.Xml.XmlSerializer.dll \ DOTNET_GENERATOR_FLAGS=$(GENERATOR_FLAGS) -compiler=$(SYSTEM_CSC) $(DOTNET_FLAGS) --lib=$(DOTNET_BCL_DIR) -attributelib:$(DOTNET_BINDING_ATTRIBUTES) DOTNET_GENERATOR=$(DOTNET_BUILD_DIR)/bgen/bgen From 1acba86f715fef6ae4542775817924766a574f55 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 11 Mar 2020 11:51:35 +0100 Subject: [PATCH 21/25] [Compression] Copy the TaskToApm implementation to provide a backwards compatible implementation of [Begin|End]|[Read|Write]. --- src/Compression/Compression.cs | 66 ++--------------- src/Compression/TaskToApm.cs | 129 +++++++++++++++++++++++++++++++++ src/frameworks.sources | 1 + 3 files changed, 138 insertions(+), 58 deletions(-) create mode 100644 src/Compression/TaskToApm.cs diff --git a/src/Compression/Compression.cs b/src/Compression/Compression.cs index e5e53ba31414..52f307bb35f2 100644 --- a/src/Compression/Compression.cs +++ b/src/Compression/Compression.cs @@ -300,37 +300,11 @@ private static void ThrowCannotWriteToDeflateStreamException() throw new InvalidOperationException ("Writing to the compression stream is not supported."); } -#if DOTNET - #pragma warning disable 0809 // Obsolete member 'CompressionStream.BeginRead(...)' overrides non-obsolete member 'Stream.BeginRead(...)' - [Obsolete ("Use 'ReadAsync' instead. This method is synchronous.")] -#endif - public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) - { -#if DOTNET - // TaskToApm is internal API in mscorlib, so we can't use it. - // In any case, the documentation recommends using ReadAsync instead, - // so obsolete this method and just call the base method implementation, - // which should still work (just synchronously). - return base.BeginRead (buffer, offset, count, asyncCallback, asyncState); -#else - return TaskToApm.Begin(ReadAsync (buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); -#endif - } - -#if DOTNET - [Obsolete ("Use 'EndRead' instead.")] -#endif - public override int EndRead (IAsyncResult asyncResult) - { -#if DOTNET - return base.EndRead (asyncResult); -#else - return TaskToApm.End (asyncResult); -#endif - } -#if DOTNET - #pragma warning restore 0809 -#endif + public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + TaskToApm.Begin(ReadAsync (buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + + public override int EndRead (IAsyncResult asyncResult) => + TaskToApm.End (asyncResult); public override Task ReadAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { @@ -573,34 +547,10 @@ protected override void Dispose (bool disposing) } } -#if DOTNET - #pragma warning disable 0809 // Obsolete member 'CompressionStream.BeginWrite(...)' overrides non-obsolete member 'Stream.BeginWrite(...)' - [Obsolete ("Use 'BeginWrite' instead. This method is synchronous.")] -#endif - public override IAsyncResult BeginWrite (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) - { -#if DOTNET - // See comment about TaskToApm elsewhere in this file. - return base.BeginWrite (array, offset, count, asyncCallback, asyncState); -#else - return TaskToApm.Begin(WriteAsync (array, offset, count, CancellationToken.None), asyncCallback, asyncState); -#endif - } + public override IAsyncResult BeginWrite (byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + TaskToApm.Begin(WriteAsync (array, offset, count, CancellationToken.None), asyncCallback, asyncState); -#if DOTNET - [Obsolete ("Use 'EndWrite' instead.")] -#endif - public override void EndWrite (IAsyncResult asyncResult) - { -#if DOTNET - base.EndWrite (asyncResult); -#else - TaskToApm.End (asyncResult); -#endif - } -#if DOTNET - #pragma warning restore 0809 -#endif + public override void EndWrite (IAsyncResult asyncResult) => TaskToApm.End (asyncResult); public override Task WriteAsync (byte[] array, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Compression/TaskToApm.cs b/src/Compression/TaskToApm.cs new file mode 100644 index 000000000000..32d0759e1d3d --- /dev/null +++ b/src/Compression/TaskToApm.cs @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// Helper methods for using Tasks to implement the APM pattern. +// +// Example usage, wrapping a Task-returning FooAsync method with Begin/EndFoo methods: +// +// public IAsyncResult BeginFoo(..., AsyncCallback callback, object state) => +// TaskToApm.Begin(FooAsync(...), callback, state); +// +// public int EndFoo(IAsyncResult asyncResult) => +// TaskToApm.End(asyncResult); + +// +// Xamarin: +// This is a copy of this file: https://github.com/dotnet/runtime/blob/25d316cefafc4c3884f38acf7bdef971d2b9fe4b/src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs +// We need it to be backwards compatible in .NET 5 for the implementations of Compression.[Begin|End]|[Read|Write]. +// + +#if DOTNET +#nullable enable +using System.Diagnostics; + +namespace System.Threading.Tasks +{ + /// + /// Provides support for efficiently using Tasks to implement the APM (Begin/End) pattern. + /// + internal static class TaskToApm + { + /// + /// Marshals the Task as an IAsyncResult, using the supplied callback and state + /// to implement the APM pattern. + /// + /// The Task to be marshaled. + /// The callback to be invoked upon completion. + /// The state to be stored in the IAsyncResult. + /// An IAsyncResult to represent the task's asynchronous operation. + public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state) => + new TaskAsyncResult(task, state, callback); + + /// Processes an IAsyncResult returned by Begin. + /// The IAsyncResult to unwrap. + public static void End(IAsyncResult asyncResult) + { + if (asyncResult is TaskAsyncResult twar) + { + twar._task.GetAwaiter().GetResult(); + return; + } + + throw new ArgumentNullException(); + } + + /// Processes an IAsyncResult returned by Begin. + /// The IAsyncResult to unwrap. + public static TResult End(IAsyncResult asyncResult) + { + if (asyncResult is TaskAsyncResult twar && twar._task is Task task) + { + return task.GetAwaiter().GetResult(); + } + + throw new ArgumentNullException(); + } + + /// Provides a simple IAsyncResult that wraps a Task. + /// + /// We could use the Task as the IAsyncResult if the Task's AsyncState is the same as the object state, + /// but that's very rare, in particular in a situation where someone cares about allocation, and always + /// using TaskAsyncResult simplifies things and enables additional optimizations. + /// + internal sealed class TaskAsyncResult : IAsyncResult + { + /// The wrapped Task. + internal readonly Task _task; + /// Callback to invoke when the wrapped task completes. + private readonly AsyncCallback? _callback; + + /// Initializes the IAsyncResult with the Task to wrap and the associated object state. + /// The Task to wrap. + /// The new AsyncState value. + /// Callback to invoke when the wrapped task completes. + internal TaskAsyncResult(Task task, object? state, AsyncCallback? callback) + { + Debug.Assert(task != null); + _task = task; + AsyncState = state; + + if (task.IsCompleted) + { + // Synchronous completion. Invoke the callback. No need to store it. + CompletedSynchronously = true; + callback?.Invoke(this); + } + else if (callback != null) + { + // Asynchronous completion, and we have a callback; schedule it. We use OnCompleted rather than ContinueWith in + // order to avoid running synchronously if the task has already completed by the time we get here but still run + // synchronously as part of the task's completion if the task completes after (the more common case). + _callback = callback; + _task.ConfigureAwait(continueOnCapturedContext: false) + .GetAwaiter() + .OnCompleted(InvokeCallback); // allocates a delegate, but avoids a closure + } + } + + /// Invokes the callback. + private void InvokeCallback() + { + Debug.Assert(!CompletedSynchronously); + Debug.Assert(_callback != null); + _callback.Invoke(this); + } + + /// Gets a user-defined object that qualifies or contains information about an asynchronous operation. + public object? AsyncState { get; } + /// Gets a value that indicates whether the asynchronous operation completed synchronously. + /// This is set lazily based on whether the has completed by the time this object is created. + public bool CompletedSynchronously { get; } + /// Gets a value that indicates whether the asynchronous operation has completed. + public bool IsCompleted => _task.IsCompleted; + /// Gets a that is used to wait for an asynchronous operation to complete. + public WaitHandle AsyncWaitHandle => ((IAsyncResult)_task).AsyncWaitHandle; + } + } +} +#endif diff --git a/src/frameworks.sources b/src/frameworks.sources index 95e18b5fbc17..fd9ce631fa53 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -351,6 +351,7 @@ COMPRESSION_SOURCES = \ Compression/Deflater.cs \ Compression/Enums.cs \ Compression/Inflater.cs \ + Compression/TaskToApm.cs \ # Contacts From 53b54fad133aaf9e889ce5532a83671516717147 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 11 Mar 2020 11:54:34 +0100 Subject: [PATCH 22/25] [src] Define NET[_TODO] instead of DOTNET[_TODO]. --- src/CFNetwork/Content.cs | 2 +- src/CFNetwork/MessageHandler.cs | 2 +- src/Compression/TaskToApm.cs | 2 +- src/Foundation/NSUrlSessionHandler.cs | 4 ++-- src/Makefile | 2 +- src/ObjCRuntime/Runtime.cs | 10 +++++----- src/Security/Certificate.cs | 2 +- src/System.Net.Http/CFContentStream.cs | 2 +- src/System.Net.Http/CFNetworkHandler.cs | 6 +++--- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/CFNetwork/Content.cs b/src/CFNetwork/Content.cs index bc6bdd471acc..e281d1a04574 100644 --- a/src/CFNetwork/Content.cs +++ b/src/CFNetwork/Content.cs @@ -46,7 +46,7 @@ internal Content (WebResponseStream stream) this.responseStream = stream; } -#if (MONOMAC && XAMCORE_2_0) && !DOTNET +#if (MONOMAC && XAMCORE_2_0) && !NET internal #endif protected override bool TryComputeLength (out long length) diff --git a/src/CFNetwork/MessageHandler.cs b/src/CFNetwork/MessageHandler.cs index c002a2d78c33..081ae2a31691 100644 --- a/src/CFNetwork/MessageHandler.cs +++ b/src/CFNetwork/MessageHandler.cs @@ -78,7 +78,7 @@ public WorkerThread WorkerThread { CFHTTPAuthentication auth; #region implemented abstract members of HttpMessageHandler -#if (MONOMAC && XAMCORE_2_0) && !DOTNET +#if (MONOMAC && XAMCORE_2_0) && !NET internal #endif protected override async Task SendAsync (HttpRequestMessage request, diff --git a/src/Compression/TaskToApm.cs b/src/Compression/TaskToApm.cs index 32d0759e1d3d..8ca02686ca2e 100644 --- a/src/Compression/TaskToApm.cs +++ b/src/Compression/TaskToApm.cs @@ -18,7 +18,7 @@ // We need it to be backwards compatible in .NET 5 for the implementations of Compression.[Begin|End]|[Read|Write]. // -#if DOTNET +#if NET #nullable enable using System.Diagnostics; diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index e1beadafd0e7..1e54392f7673 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -473,7 +473,7 @@ async Task CreateRequest (HttpRequestMessage request) return nsrequest; } -#if (SYSTEM_NET_HTTP || MONOMAC) && !DOTNET +#if (SYSTEM_NET_HTTP || MONOMAC) && !NET internal #endif protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) @@ -935,7 +935,7 @@ protected override Task SerializeToStreamAsync (Stream stream, TransportContext return content.CopyToAsync (stream, bufferSize, cancellationToken); } -#if !DOTNET +#if !NET internal #endif protected override bool TryComputeLength (out long length) diff --git a/src/Makefile b/src/Makefile index 6be14615d237..a5ad48944331 100644 --- a/src/Makefile +++ b/src/Makefile @@ -25,7 +25,7 @@ TVOS_DOTNET_BUILD_DIR=$(DOTNET_BUILD_DIR)/tvos GENERATOR_FLAGS=-process-enums -core -nologo -nostdlib -noconfig -native-exception-marshalling --ns:ObjCRuntime -DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /target:library /debug /unsafe /define:DOTNET /define:DOTNET_TODO \ +DOTNET_FLAGS=/noconfig /nostdlib+ /deterministic /features:strict /nologo /target:library /debug /unsafe /define:NET /define:NET_TODO \ /r:$(DOTNET_BCL_DIR)/System.Buffers.dll \ /r:$(DOTNET_BCL_DIR)/System.Collections.Concurrent.dll \ /r:$(DOTNET_BCL_DIR)/System.Collections.dll \ diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index c94719f662e4..1b14c9f798f5 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -253,7 +253,7 @@ unsafe static void Initialize (InitializationOptions* options) Registrar = new DynamicRegistrar (); RegisterDelegates (options); Class.Initialize (options); -#if !DOTNET +#if !NET // This is not needed for .NET 5: // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-588331822 // * https://github.com/xamarin/xamarin-macios/issues/7924#issuecomment-589356481 @@ -261,8 +261,8 @@ unsafe static void Initialize (InitializationOptions* options) #endif InitializePlatform (options); -#if !XAMMAC_SYSTEM_MONO && !DOTNET_TODO - // DOTNET_TODO: https://github.com/dotnet/runtime/issues/32543 +#if !XAMMAC_SYSTEM_MONO && !NET_TODO + // NET_TODO: https://github.com/dotnet/runtime/issues/32543 UseAutoreleasePoolInThreadPool = true; #endif IsARM64CallingConvention = GetIsARM64CallingConvention (); // Can only be done after Runtime.Arch is set (i.e. InitializePlatform has been called). @@ -276,8 +276,8 @@ unsafe static void Initialize (InitializationOptions* options) #endif } -#if !XAMMAC_SYSTEM_MONO && !DOTNET_TODO - // DOTNET_TODO: https://github.com/dotnet/runtime/issues/32543 +#if !XAMMAC_SYSTEM_MONO && !NET_TODO + // NET_TODO: https://github.com/dotnet/runtime/issues/32543 static bool has_autoreleasepool_in_thread_pool; public static bool UseAutoreleasePoolInThreadPool { get { diff --git a/src/Security/Certificate.cs b/src/Security/Certificate.cs index af79c56a6a4b..0c0b70260ade 100644 --- a/src/Security/Certificate.cs +++ b/src/Security/Certificate.cs @@ -28,7 +28,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if (XAMARIN_APPLETLS || WATCH) && !DOTNET +#if (XAMARIN_APPLETLS || WATCH) && !NET #define NATIVE_APPLE_CERTIFICATE #endif diff --git a/src/System.Net.Http/CFContentStream.cs b/src/System.Net.Http/CFContentStream.cs index d964f3c569cd..6b671f018fcf 100644 --- a/src/System.Net.Http/CFContentStream.cs +++ b/src/System.Net.Http/CFContentStream.cs @@ -147,7 +147,7 @@ protected override async Task SerializeToStreamAsync (Stream stream, TransportCo } } -#if !DOTNET +#if !NET internal #endif protected override bool TryComputeLength (out long length) diff --git a/src/System.Net.Http/CFNetworkHandler.cs b/src/System.Net.Http/CFNetworkHandler.cs index f4fee5029e2d..d7a8abc23d32 100644 --- a/src/System.Net.Http/CFNetworkHandler.cs +++ b/src/System.Net.Http/CFNetworkHandler.cs @@ -194,7 +194,7 @@ CFHTTPMessage CreateWebRequestAsync (HttpRequestMessage request) return req; } -#if !DOTNET +#if !NET internal #endif protected override async Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) @@ -384,8 +384,8 @@ void HandleHasBytesAvailableEvent (object sender, CFStream.StreamEventArgs e) void AddCookie (string value, Uri uri, string header) { -#if !DOTNET_TODO - // DOTNET_TODO: CookieCollection.CookieCutter is internal to mscorlib: +#if !NET_TODO + // NET_TODO: CookieCollection.CookieCutter is internal to mscorlib: // https://github.com/microsoft/referencesource/blob/a7bd3242bd7732dec4aebb21fbc0f6de61c2545e/System/net/System/Net/cookiecontainer.cs#L632 // https://github.com/xamarin/xamarin-macios/issues/8072 CookieCollection cookies1 = null; From 067c88e2f41c75476a832b664ba98fded4e0d5d5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 11 Mar 2020 12:36:09 +0100 Subject: [PATCH 23/25] [xharness] Fix merge problem. --- tests/xharness/Jenkins/Jenkins.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xharness/Jenkins/Jenkins.cs b/tests/xharness/Jenkins/Jenkins.cs index 19bc9fe5e183..a2ad1a483dab 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -1103,7 +1103,7 @@ Task PopulateTasksAsync () var buildDotNetGenerator = new DotNetBuildTask { Jenkins = this, - TestProject = new TestProject (Path.GetFullPath (Path.Combine (DirectoryUtilities.RepositoryRootDirectory, "bgen", "bgen-tests.csproj"))), + TestProject = new TestProject (Path.GetFullPath (Path.Combine (Harness.RootDirectory, "bgen", "bgen-tests.csproj"))), SpecifyPlatform = false, SpecifyConfiguration = false, Platform = TestPlatform.iOS, From f56fe80b74538eb88847501de83c2babf5941b5c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 12 Mar 2020 10:02:37 +0100 Subject: [PATCH 24/25] Bump system mono to fix a csc compilation problem. --- Make.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Make.config b/Make.config index 3e22d3fa43b5..1c476a8acb7b 100644 --- a/Make.config +++ b/Make.config @@ -69,9 +69,9 @@ include $(TOP)/mk/mono.mk MONO_HASH := $(NEEDED_MONO_VERSION) # Minimum Mono version for building XI/XM -MIN_MONO_VERSION=6.10.0.1 +MIN_MONO_VERSION=6.10.0.91 MAX_MONO_VERSION=6.10.99 -MIN_MONO_URL=https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2019-12/3/7eb7a82f09094facd8772dcb745fd16c7bd401c1/MonoFramework-MDK-6.10.0.1.macos10.xamarin.universal.pkg +MIN_MONO_URL=https://xamjenkinsartifact.azureedge.net/build-package-osx-mono/2019-12/94/b27b2d7f6118dff79cc238a22040ee93da39bab4/MonoFramework-MDK-6.10.0.91.macos10.xamarin.universal.pkg # Minimum Mono version for Xamarin.Mac apps using the system mono MIN_XM_MONO_VERSION=6.4.0.94 From 5dda97a0ef9c1b4a8fa2f4ab3c421409ec0eea5b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 12 Mar 2020 10:36:59 +0100 Subject: [PATCH 25/25] [xharness] Unset a few environment variables when running .NET tests. --- .../Jenkins/TestTasks/DotNetBuildTask.cs | 17 +++++++++++++++++ .../Jenkins/TestTasks/DotNetTestTask.cs | 1 + 2 files changed, 18 insertions(+) diff --git a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs index 3806842c972b..3a59966be35a 100644 --- a/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs +++ b/tests/xharness/Jenkins/TestTasks/DotNetBuildTask.cs @@ -1,7 +1,14 @@ using System.Collections.Generic; +using System.Diagnostics; namespace Xharness.Jenkins.TestTasks { class DotNetBuildTask : MSBuildTask { + + public DotNetBuildTask () + { + SetDotNetEnvironmentVariables (Environment); + } + protected override string ToolName { get { return Harness.DOTNET; } } @@ -15,5 +22,15 @@ protected override List ToolArguments { return args; } } + + + public static void SetDotNetEnvironmentVariables (Dictionary environment) + { + environment ["MSBUILD_EXE_PATH"] = null; + environment ["MSBuildExtensionsPathFallbackPathsOverride"] = null; + environment ["MSBuildSDKsPath"] = null; + environment ["TargetFrameworkFallbackSearchPaths"] = null; + environment ["MSBuildExtensionsPathFallbackPathsOverride"] = null; + } } } diff --git a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs index 7ceaae0869e5..e018691e38af 100644 --- a/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs +++ b/tests/xharness/Jenkins/TestTasks/DotNetTestTask.cs @@ -8,6 +8,7 @@ class DotNetTestTask : RunTestTask { public DotNetTestTask (DotNetBuildTask build_task) : base (build_task) { + DotNetBuildTask.SetDotNetEnvironmentVariables (Environment); } protected override async Task RunTestAsync ()