From 3ef12240ce86532266a04aab9dc2c9130f032c3b Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Mon, 19 Nov 2018 16:53:46 +0100 Subject: [PATCH 01/15] Fixes building mono tests --- tests/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 1be1d6a7e1..d3cda01c89 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -196,8 +196,7 @@ $(TOP)/tools/mtouch/SdkVersions.cs: $(TOP)/tools/common/SdkVersions.cs.in @touch $@ xharness/xharness.exe: $(wildcard xharness/*.cs) xharness/xharness.csproj $(TOP)/tools/mtouch/SdkVersions.cs test.config test-system.config .stamp-src-project-files - make -j8 -C $(TOP)/external/mono/mcs/class -i do-test PROFILE=MONOTOUCH # TODO: This should not be needed and we should get the dlls from the SDK. - make -j8 -C $(TOP)/external/mono/mcs/class -i do-xunit-test PROFILE=MONOTOUCH # TODO: This should not be needed and we should get the dlls from the SDK. + $(Q) $(MAKE) -C $(TOP)/external/mono/mcs/class -i do-test do-xunit-test PROFILE=monotouch # TODO: This should not be needed and we should get the dlls from the SDK. nuget restore xharness/xharness.csproj nuget restore bcl-test/BCLTests/BCLTests.csproj $(Q_GEN) $(SYSTEM_XIBUILD) -- $(MSBUILD_VERBOSITY_QUIET) xharness/xharness.csproj From 5c71a9fe2531591a7d5dc4b7f03f279ec539d40b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 20 Nov 2018 08:41:36 +0100 Subject: [PATCH 02/15] [ImageCaptureCore] Remove redundant availability attribute. --- src/imagecapturecore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/imagecapturecore.cs b/src/imagecapturecore.cs index 011f2c7971..1807f887ad 100644 --- a/src/imagecapturecore.cs +++ b/src/imagecapturecore.cs @@ -119,7 +119,6 @@ namespace ImageCaptureCore { [Field ("ICStatusNotificationKey")] NSString NotificationKey { get; } - [Mac (10, 8)] [Field ("ICStatusCodeKey")] NSString CodeKey { get; } From 428310c181f9b3be18be87da7a09cf4250993394 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 27 Nov 2018 08:45:16 +0100 Subject: [PATCH 03/15] [mtouch] Clear the MONO_THREADS_SUSPEND environment variable before calling the AOT compiler. Works around mono/mono#11765. Visual Studio for Mac may set MONO_THREADS_SUSPEND, and this ends up confusing the AOT compiler when compiling for watchOS. So unset the environment variable before calling the AOT compiler. Works around https://github.com/mono/mono/issues/11765. --- tools/mtouch/Assembly.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/mtouch/Assembly.cs b/tools/mtouch/Assembly.cs index ac37322c80..b33a862149 100644 --- a/tools/mtouch/Assembly.cs +++ b/tools/mtouch/Assembly.cs @@ -290,6 +290,12 @@ namespace Xamarin.Bundler { ProcessStartInfo = Driver.CreateStartInfo (App, aotCompiler, aotArgs, Path.GetDirectoryName (assembly_path)), AotInfo = aotInfo, }; + if (App.Platform == ApplePlatform.WatchOS) { + // Visual Studio for Mac sets this environment variable, and it confuses the AOT compiler. + // So unset it. + // See https://github.com/mono/mono/issues/11765 + task.ProcessStartInfo.EnvironmentVariables ["MONO_THREADS_SUSPEND"] = null; + } aotInfo.Task = task; } From ae13240b2098fd7dde953050f21d09a89245f6a2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 29 Nov 2018 16:33:57 +0100 Subject: [PATCH 04/15] [xharness] Don't recursively print diagnostics for processes when printing diagnostics times out in the first place. Fixes maccore#1163. (#5198) Recursively printing diagnostics can leave us with _many_ lldb processes, each pretty much hanging, and the system overloaded, which, in the worst case scenario, would require a hard reboot. Most commonly the "only" thing that happens is an OutOfMemoryException when the OS eventually tells xharness NO to launching new processes. Fixes https://github.com/xamarin/maccore/issues/1163. --- tests/xharness/Process_Extensions.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/xharness/Process_Extensions.cs b/tests/xharness/Process_Extensions.cs index 9ce335861b..6f0d9a3aae 100644 --- a/tests/xharness/Process_Extensions.cs +++ b/tests/xharness/Process_Extensions.cs @@ -56,17 +56,17 @@ namespace xharness public static class Process_Extensions { - public static async Task RunAsync (this Process process, Log log, CancellationToken? cancellation_token = null) + public static async Task RunAsync (this Process process, Log log, CancellationToken? cancellation_token = null, bool? diagnostics = null) { - return await RunAsync (process, log, log, log, cancellation_token: cancellation_token); + return await RunAsync (process, log, log, log, cancellation_token: cancellation_token, diagnostics: diagnostics); } - public static Task RunAsync (this Process process, Log log, bool append = true, TimeSpan? timeout = null, Dictionary environment_variables = null, CancellationToken? cancellation_token = null) + public static Task RunAsync (this Process process, Log log, bool append = true, TimeSpan? timeout = null, Dictionary environment_variables = null, CancellationToken? cancellation_token = null, bool? diagnostics = null) { - return RunAsync (process, log, log, log, timeout, environment_variables, cancellation_token); + return RunAsync (process, log, log, log, timeout, environment_variables, cancellation_token, diagnostics); } - public static async Task RunAsync (this Process process, Log log, TextWriter StdoutStream, TextWriter StderrStream, TimeSpan? timeout = null, Dictionary environment_variables = null, CancellationToken? cancellation_token = null) + public static async Task RunAsync (this Process process, Log log, TextWriter StdoutStream, TextWriter StderrStream, TimeSpan? timeout = null, Dictionary environment_variables = null, CancellationToken? cancellation_token = null, bool? diagnostics = null) { var stdout_completion = new TaskCompletionSource (); var stderr_completion = new TaskCompletionSource (); @@ -138,7 +138,7 @@ namespace xharness { if (timeout.HasValue) { if (!process.WaitForExit ((int) timeout.Value.TotalMilliseconds)) { - process.KillTreeAsync (log, true).Wait (); + process.KillTreeAsync (log, diagnostics ?? true).Wait (); rv.TimedOut = true; lock (StderrStream) log.WriteLine ($"Execution timed out after {timeout.Value.TotalSeconds} seconds and the process was killed."); @@ -164,22 +164,22 @@ namespace xharness return rv; } - public static Task KillTreeAsync (this Process @this, Log log, bool diagnostics = true) + public static Task KillTreeAsync (this Process @this, Log log, bool? diagnostics = true) { return KillTreeAsync (@this.Id, log, diagnostics); } - public static async Task KillTreeAsync (int pid, Log log, bool diagnostics = true) + public static async Task KillTreeAsync (int pid, Log log, bool? diagnostics = true) { var pids = new List (); GetChildrenPS (log, pids, pid); - if (diagnostics) { + if (diagnostics == true) { log.WriteLine ($"Pids to kill: {string.Join (", ", pids.Select ((v) => v.ToString ()).ToArray ())}"); using (var ps = new Process ()) { log.WriteLine ("Writing process list:"); ps.StartInfo.FileName = "ps"; ps.StartInfo.Arguments = "-A -o pid,ruser,ppid,pgid,%cpu=%CPU,%mem=%MEM,flags=FLAGS,lstart,rss,vsz,tty,state,time,command"; - await ps.RunAsync (log, true, TimeSpan.FromSeconds (5)); + await ps.RunAsync (log, true, TimeSpan.FromSeconds (5), diagnostics: false); } foreach (var diagnose_pid in pids) { @@ -197,7 +197,7 @@ namespace xharness File.WriteAllText (template, commands.ToString ()); log.WriteLine ($"Printing backtrace for pid={pid}"); - await dbg.RunAsync (log, true, TimeSpan.FromSeconds (30)); + await dbg.RunAsync (log, true, TimeSpan.FromSeconds (30), diagnostics: false); } } finally { try { From 9be55e2bf4ff52a187fa8d312b2472f7cb381780 Mon Sep 17 00:00:00 2001 From: Vincent Dondain Date: Thu, 29 Nov 2018 11:33:37 -0500 Subject: [PATCH 05/15] [xtro] Report incorrect 'ArgumentSemantic' enum value usage (#5114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ⚠️ Rule deactivated until we have an `xcode10.2` branch where we'll fix the issues. - We only report `copy` mistakes since they're the ones we really care about fixing (we can end up with invalid pointers). - Fixes #4018: [xtro] Report incorrect 'ArgumentSemantic' enum value usage (https://github.com/xamarin/xamarin-macios/issues/4018). - Performance with the added test: - Extrospection.SelectorCheck: Elapsed=00:00:00.7263742 - Extrospection.SelectorCheck: Elapsed=00:00:01.2136911 - Extrospection.SelectorCheck: Elapsed=00:00:01.2747602 - Extrospection.SelectorCheck: Elapsed=00:00:01.7494063 --- tests/xtro-sharpie/Helpers.cs | 38 ++++++++++++++++ tests/xtro-sharpie/SelectorCheck.cs | 69 ++++++++++++++++------------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/tests/xtro-sharpie/Helpers.cs b/tests/xtro-sharpie/Helpers.cs index 70e33a8062..4548745271 100644 --- a/tests/xtro-sharpie/Helpers.cs +++ b/tests/xtro-sharpie/Helpers.cs @@ -397,5 +397,43 @@ namespace Extrospection { else return (o1, o2); } + + public enum ArgumentSemantic { + None = -1, + Assign = 0, + Copy = 1, + Retain = 2, + Weak = 3, + Strong = Retain, + UnsafeUnretained = Assign, + } + + public static ArgumentSemantic ToArgumentSemantic (this ObjCPropertyAttributeKind attr) + { + if ((attr & ObjCPropertyAttributeKind.Retain) != 0) + return ArgumentSemantic.Retain; + else if ((attr & ObjCPropertyAttributeKind.Copy) != 0) + return ArgumentSemantic.Copy; + else if ((attr & ObjCPropertyAttributeKind.Assign) != 0) + return ArgumentSemantic.Assign; + else if ((attr & ObjCPropertyAttributeKind.Weak) != 0) + return ArgumentSemantic.Weak; + else if ((attr & ObjCPropertyAttributeKind.Strong) != 0) + return ArgumentSemantic.Strong; + else if ((attr & ObjCPropertyAttributeKind.UnsafeUnretained) != 0) + return ArgumentSemantic.UnsafeUnretained; + else + return ArgumentSemantic.Assign; // Default + } + + public static string ToUsableString (this ArgumentSemantic argSem) + { + if (argSem == ArgumentSemantic.Retain) + return "Strong|Retain"; + if (argSem == ArgumentSemantic.Assign) + return "UnsafeUnretained|Assign"; + + return argSem.ToString (); + } } } \ No newline at end of file diff --git a/tests/xtro-sharpie/SelectorCheck.cs b/tests/xtro-sharpie/SelectorCheck.cs index b4c080c896..d3b5323fff 100644 --- a/tests/xtro-sharpie/SelectorCheck.cs +++ b/tests/xtro-sharpie/SelectorCheck.cs @@ -4,9 +4,6 @@ // !missing-selector! // if headers defines a selector for which we have no bindings // -// !unknown-selector! -// if we have a selector that is not part of the header files -// using System; using System.Collections.Generic; @@ -18,24 +15,9 @@ using Clang.Ast; namespace Extrospection { public class SelectorCheck : BaseVisitor { -// Dictionary> exports = new Dictionary> (); - - // missing - // -> it's not in the type or ancestor or their interface (protocols) - // -> it's not in a category - - // unknown - // -> quick check (HashSet) to see if it's used anywhere - // -> - - // duplicate - // -> the selector is defined more than once for the same type - - HashSet known_selectors = new HashSet (); HashSet qualified_selectors = new HashSet (); - - //Dictionary> type_exports = new Dictionary> (); + Dictionary qualified_properties = new Dictionary (); // most selectors will be found in [Export] attribtues public override void VisitManagedMethod (MethodDefinition method) @@ -51,24 +33,49 @@ namespace Extrospection { foreach (var ca in method.CustomAttributes) { switch (ca.Constructor.DeclaringType.Name) { case "ExportAttribute": - string selector = ca.ConstructorArguments [0].Value as string; - if (!known_selectors.Contains (selector)) - known_selectors.Add (selector); + var methodDefinition = method.GetName (); + if (!string.IsNullOrEmpty (methodDefinition)) { + var argumentSemantic = Helpers.ArgumentSemantic.Assign; // Default + if (ca.ConstructorArguments.Count > 1) { + argumentSemantic = (Helpers.ArgumentSemantic)ca.ConstructorArguments [1].Value; + qualified_properties.Add (methodDefinition, argumentSemantic); + } + + qualified_selectors.Add (methodDefinition); + } - qualified_selectors.Add (method.GetName ()); -// -// TypeDefinition type = method.DeclaringType; -// HashSet list; -// if (!type_exports.TryGetValue (type, out list)) { -// list = new HashSet (); -// type_exports.Add (type, list); -// } -// list.Add (selector); break; } } } + public override void VisitObjCPropertyDecl (ObjCPropertyDecl decl) + { + // protocol members are checked in ObjCProtocolCheck + if (decl.DeclContext is ObjCProtocolDecl) + return; + + // check availability macros to see if the API is available on the OS and not deprecated + if (!decl.IsAvailable ()) + return; + + var framework = Helpers.GetFramework (decl); + if (framework == null) + return; + + var nativeArgumentSemantic = decl.Attributes.ToArgumentSemantic (); + var nativeMethodDefinition = decl.QualifiedName; + + bool found = qualified_properties.TryGetValue (nativeMethodDefinition, out var managedArgumentSemantic); + if (found && managedArgumentSemantic != nativeArgumentSemantic) { + // FIXME: only Copy mistakes are reported now + if (managedArgumentSemantic == Helpers.ArgumentSemantic.Copy || nativeArgumentSemantic == Helpers.ArgumentSemantic.Copy) { + // FIXME: rule disactivated for now + //Log.On (framework).Add ($"!incorrect-argument-semantic! Native '{nativeMethodDefinition}' is declared as ({nativeArgumentSemantic.ToUsableString ().ToLowerInvariant ()}) but mapped to 'ArgumentSemantic.{managedArgumentSemantic.ToUsableString ()}'"); + } + } + } + public override void VisitObjCMethodDecl (ObjCMethodDecl decl, VisitKind visitKind) { if (visitKind != VisitKind.Enter) From 82634c088a7af12c8311c350b0e71199f5cdcd03 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 29 Nov 2018 18:37:04 +0100 Subject: [PATCH 06/15] [jenkins] If provisioning an old mono fails with error 56, try again a few more times. Fixes maccore#1098. (#5200) It seems curl can randomly fail with error 56, so if that happens, try again a few more times before giving up. Fixes https://github.com/xamarin/maccore/issues/1098. --- jenkins/Jenkinsfile | 8 +------ jenkins/prepare-packaged-macos-tests.sh | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 3876f62797..c10da650ba 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -319,13 +319,7 @@ def runXamarinMacTests (url, macOS, maccore_hash, xamarin_macios_hash) def t = "dontlink (system)" try { // install oldest supported mono - sh (''' - cd mac-test-package - URL=`grep "^MIN_XM_MONO_URL=" Make.config | sed 's/.*=//'` - curl -L "$URL" --output old-mono.pkg - sudo installer -pkg old-mono.pkg -target / - mono --version - ''') + sh ("./prepare-packaged-macos-tests.sh --install-old-mono") // run dontlink tests using the system mono sh ("make -C mac-test-package/tests exec-mac-system-dontlink") } catch (error) { diff --git a/jenkins/prepare-packaged-macos-tests.sh b/jenkins/prepare-packaged-macos-tests.sh index 575263b102..fdfd456bc8 100755 --- a/jenkins/prepare-packaged-macos-tests.sh +++ b/jenkins/prepare-packaged-macos-tests.sh @@ -2,6 +2,35 @@ # don't change the current directory here +if [[ "$1" == "--install-old-mono" ]]; then + cd mac-test-package + URL=$(grep "^MIN_XM_MONO_URL=" Make.config | sed 's/.*=//') + + COUNTER=0 + EC=0 + echo "Downloading and installing $URL" + while [[ $COUNTER -lt 5 ]]; do + curl -s -L "$URL" --output old-mono.pkg || EC=$? + if [[ $EC -eq 56 ]]; then + # Sometimes we get spurious "curl: (56) SSLRead() return error -9806" errors. Trying again usually works, so lets try again a few more times. + # https://github.com/xamarin/maccore/issues/1098 + let COUNTER++ || true + continue + fi + break + done + + if [[ "x$EC" != "x0" ]]; then + echo "Failed to provision old mono (exit code: $EC)" + exit $EC + fi + + sudo installer -pkg old-mono.pkg -target / + mono --version + exit 0 +fi + + URL=$1 MACCORE_HASH=$2 if test -z "$URL"; then From 8a81607279c08a36021b562154f911e692a1c87b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 29 Nov 2018 19:36:04 +0100 Subject: [PATCH 07/15] [xharness] No need to spawn to kill, when we can just P/Invoke the corresponding function. (#5199) * [xharness] No need to spawn to kill, when we can just P/Invoke the corresponding function. * Revert accidental changes. --- tests/xharness/Process_Extensions.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/xharness/Process_Extensions.cs b/tests/xharness/Process_Extensions.cs index 6f0d9a3aae..813ac72476 100644 --- a/tests/xharness/Process_Extensions.cs +++ b/tests/xharness/Process_Extensions.cs @@ -209,20 +209,14 @@ namespace xharness } } - using (var kill = new Process ()) { - kill.StartInfo.FileName = "kill"; - // Send SIGABRT since that produces a crash report - // lldb may fail to attach to system processes, but crash reports will still be produced with potentially helpful stack traces. - kill.StartInfo.Arguments = "-6 " + string.Join (" ", pids.Select ((v) => v.ToString ()).ToArray ()); - await kill.RunAsync (log, true, TimeSpan.FromSeconds (2.5)); - } + // Send SIGABRT since that produces a crash report + // lldb may fail to attach to system processes, but crash reports will still be produced with potentially helpful stack traces. + for (int i = 0; i < pids.Count; i++) + ProcessHelper.kill (pids [i], 6); - using (var kill = new Process ()) { - kill.StartInfo.FileName = "kill"; - // send kill -9 anyway as a last resort - kill.StartInfo.Arguments = "-9 " + string.Join (" ", pids.Select ((v) => v.ToString ()).ToArray ()); - await kill.RunAsync (log, true, TimeSpan.FromSeconds (2.5)); - } + // send kill -9 anyway as a last resort + for (int i = 0; i < pids.Count; i++) + ProcessHelper.kill (pids [i], 9); } static void GetChildrenPS (Log log, List list, int pid) From 0999bbaf486876b40e8fb027399abd7d01a3bd53 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 30 Nov 2018 15:42:18 +0100 Subject: [PATCH 08/15] [xharness] Fix retry-download-on-error-56 logic to actually work. (#5206) Fix retry-download-on-error-56 logic to not fail forever if the first time failed by resetting the EC variable after each try. Fixes https://github.com/xamarin/maccore/issues/1098 (third time's the charm!) --- jenkins/prepare-packaged-macos-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/prepare-packaged-macos-tests.sh b/jenkins/prepare-packaged-macos-tests.sh index fdfd456bc8..fccee72da6 100755 --- a/jenkins/prepare-packaged-macos-tests.sh +++ b/jenkins/prepare-packaged-macos-tests.sh @@ -7,9 +7,9 @@ if [[ "$1" == "--install-old-mono" ]]; then URL=$(grep "^MIN_XM_MONO_URL=" Make.config | sed 's/.*=//') COUNTER=0 - EC=0 echo "Downloading and installing $URL" while [[ $COUNTER -lt 5 ]]; do + EC=0 curl -s -L "$URL" --output old-mono.pkg || EC=$? if [[ $EC -eq 56 ]]; then # Sometimes we get spurious "curl: (56) SSLRead() return error -9806" errors. Trying again usually works, so lets try again a few more times. @@ -58,8 +58,8 @@ unzip -o mac-test-package.zip cd mac-test-package COUNTER=0 -EC=0 while [[ $COUNTER -lt 5 ]]; do + EC=0 ./system-dependencies.sh --provision-mono --ignore-autotools --ignore-xamarin-studio --ignore-xcode --ignore-osx --ignore-cmake || EC=$? if [[ $EC -eq 56 ]]; then # Sometimes we get spurious "curl: (56) SSLRead() return error -9806" errors. Trying again usually works, so lets try again a few more times. From 544925738de4a724611c8743408ab9b637fa4605 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 30 Nov 2018 16:49:03 +0100 Subject: [PATCH 09/15] [xharness] Implement Process.WaitForExitAsync and use it instead of creating background threads. (#5207) Using fewer threads is always good. --- tests/xharness/Process_Extensions.cs | 64 +++++++++++++++++++--------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/tests/xharness/Process_Extensions.cs b/tests/xharness/Process_Extensions.cs index 813ac72476..0a2ff386ed 100644 --- a/tests/xharness/Process_Extensions.cs +++ b/tests/xharness/Process_Extensions.cs @@ -70,7 +70,6 @@ namespace xharness { var stdout_completion = new TaskCompletionSource (); var stderr_completion = new TaskCompletionSource (); - var exit_completion = new TaskCompletionSource (); var rv = new ProcessExecutionResult (); process.StartInfo.RedirectStandardError = true; @@ -123,37 +122,28 @@ namespace xharness log.WriteLine (sb); process.Start (); + var pid = process.Id; process.BeginErrorReadLine (); process.BeginOutputReadLine (); cancellation_token?.Register (() => { - if (!exit_completion.Task.IsCompleted) { + if (!process.HasExited) { StderrStream.WriteLine ($"Execution was cancelled."); ProcessHelper.kill (process.Id, 9); } }); - new Thread (() => - { - if (timeout.HasValue) { - if (!process.WaitForExit ((int) timeout.Value.TotalMilliseconds)) { - process.KillTreeAsync (log, diagnostics ?? true).Wait (); - rv.TimedOut = true; - lock (StderrStream) - log.WriteLine ($"Execution timed out after {timeout.Value.TotalSeconds} seconds and the process was killed."); - } + if (timeout.HasValue) { + if (!await process.WaitForExitAsync (timeout.Value)) { + await process.KillTreeAsync (log, diagnostics ?? true); + rv.TimedOut = true; + lock (StderrStream) + log.WriteLine ($"{pid} Execution timed out after {timeout.Value.TotalSeconds} seconds and the process was killed."); } - process.WaitForExit (); - exit_completion.TrySetResult (true); - Task.WaitAll (new Task [] { stderr_completion.Task, stdout_completion.Task }, TimeSpan.FromSeconds (1)); - stderr_completion.TrySetResult (false); - stdout_completion.TrySetResult (false); - }) { - IsBackground = true, - }.Start (); - - await Task.WhenAll (stderr_completion.Task, stdout_completion.Task, exit_completion.Task); + } + await process.WaitForExitAsync (); + Task.WaitAll (new Task [] { stderr_completion.Task, stdout_completion.Task }, TimeSpan.FromSeconds (1)); try { rv.ExitCode = process.ExitCode; @@ -164,6 +154,38 @@ namespace xharness return rv; } + public async static Task WaitForExitAsync (this Process process, TimeSpan? timeout = null) + { + if (process.HasExited) + return true; + + var tcs = new TaskCompletionSource (); + + void ProcessExited (object sender, EventArgs ea) + { + process.Exited -= ProcessExited; + tcs.TrySetResult (true); + } + + process.Exited += ProcessExited; + process.EnableRaisingEvents = true; + + // Check if process exited again, in case it exited after we checked + // the last time, but before we attached the event handler. + if (process.HasExited) { + process.Exited -= ProcessExited; + tcs.TrySetResult (true); + return true; + } + + if (timeout.HasValue) { + return await tcs.Task.TimeoutAfter (timeout.Value); + } else { + await tcs.Task; + return true; + } + } + public static Task KillTreeAsync (this Process @this, Log log, bool? diagnostics = true) { return KillTreeAsync (@this.Id, log, diagnostics); From a8c54e00b3c6ba3dd04f1df2ebba50fe423eb669 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 3 Dec 2018 11:49:26 +0100 Subject: [PATCH 10/15] [xibuild] Auto-make if not already made. (#5211) * [xibuild] Auto-make if not already made. Automatically make xibuild if it doesn't already exist. Also fix the script: * Use bash instead of sh, since it references BASH_SOURCE. * Don't hide errors (-e). * Fix shellcheck warnings * Use $(..) instead of backticks, because backticks are strongly discouraged [1]. * Sprinkle quotes. [1] For the curious: https://stackoverflow.com/a/4708569/183422 * Run make in the right directory. --- tools/xibuild/xibuild | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/xibuild/xibuild b/tools/xibuild/xibuild index c8ba9d578b..169b0579ad 100755 --- a/tools/xibuild/xibuild +++ b/tools/xibuild/xibuild @@ -1,5 +1,10 @@ -#!/bin/sh -ABSOLUTE_PATH=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)/`basename "${BASH_SOURCE[0]}"` -TOOL_DIR=`dirname $ABSOLUTE_PATH` +#!/bin/bash -e -mono $TOOL_DIR/bin/Debug/xibuild.exe "$@" +ABSOLUTE_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}") +TOOL_DIR=$(dirname "$ABSOLUTE_PATH") + +if ! test -f "$TOOL_DIR/bin/Debug/xibuild.exe"; then + make -C "$TOOL_DIR" +fi + +mono "$TOOL_DIR/bin/Debug/xibuild.exe" "$@" From 1af3903f1fb0c42815be7d633de454ec66cd15cf Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 3 Dec 2018 14:52:08 +0100 Subject: [PATCH 11/15] [xibuild] Don't redirect standard input. (#5209) It's not needed, and it prevents subprocesses from detecting a terminal (and thus no colors in the output). --- tools/xibuild/Main.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/xibuild/Main.cs b/tools/xibuild/Main.cs index bfdf48b564..b29d456e48 100644 --- a/tools/xibuild/Main.cs +++ b/tools/xibuild/Main.cs @@ -112,7 +112,6 @@ namespace xibuild { FileName = toolPath, Arguments = combinedArgs, UseShellExecute = false, - RedirectStandardInput = true, }); p.WaitForExit (); From c814ddb5674673317138befce2594c0ab136a33e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 3 Dec 2018 17:43:58 +0100 Subject: [PATCH 12/15] [monotouch-test] Tweak DnsFailure a bit. (#5208) * Make it clearer when a timeout happens that a timeout happened by asserting exactly that. * Don't assert after getting the (unexpected) result from the network request, since asserting will throw an exception, which will be caught and stored, and then later in the test we assert that an exception was thrown. So asserting just after a successful network request effectively hides any failures, since we're now passing because of the assertion exception. Ops. --- tests/monotouch-test/System.Net.Http/MessageHandlers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/monotouch-test/System.Net.Http/MessageHandlers.cs b/tests/monotouch-test/System.Net.Http/MessageHandlers.cs index f0a010ed80..cbeb348189 100644 --- a/tests/monotouch-test/System.Net.Http/MessageHandlers.cs +++ b/tests/monotouch-test/System.Net.Http/MessageHandlers.cs @@ -59,7 +59,6 @@ namespace MonoTests.System.Net.Http HttpClient client = new HttpClient (GetHandler (handlerType)); var s = await client.GetStringAsync ("http://doesnotexist.xamarin.com"); Console.WriteLine (s); - Assert.Fail ($"An exception should have been thrown, instead got:\n{s}"); } catch (Exception e) { ex = e; } finally { @@ -67,6 +66,7 @@ namespace MonoTests.System.Net.Http } }, () => done); + Assert.IsTrue (done, "Did not time out"); Assert.IsNotNull (ex, "Exception"); // The handlers throw different types of exceptions, so we can't assert much more than that something went wrong. } From b1feb2fd75a2e4b61e2e6d82fb4b3b7e74334292 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 3 Dec 2018 17:46:56 +0100 Subject: [PATCH 13/15] Bump maccore. (#5218) Diff: https://github.com/xamarin/maccore/compare/6e9b63e53755a74138b78dafd098836a79660edd...d2f171adaa35c8acb86a32b5935e93fb4fdd48d5 --- mk/xamarin.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/xamarin.mk b/mk/xamarin.mk index 1daa91b3cb..d97e215a86 100644 --- a/mk/xamarin.mk +++ b/mk/xamarin.mk @@ -1,5 +1,5 @@ ifdef ENABLE_XAMARIN -NEEDED_MACCORE_VERSION := 6e9b63e53755a74138b78dafd098836a79660edd +NEEDED_MACCORE_VERSION := d2f171adaa35c8acb86a32b5935e93fb4fdd48d5 NEEDED_MACCORE_BRANCH := master MACCORE_DIRECTORY := maccore From b88fb7066e6e1b1df5fbfe91ec0f9095a1b3df63 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 5 Dec 2018 07:31:24 +0100 Subject: [PATCH 14/15] Bump maccore. (#5225) Diff: https://github.com/xamarin/maccore/compare/d2f171adaa35c8acb86a32b5935e93fb4fdd48d5...e3d92b50d6beb38b154a3dfe9242720c67f8d7c3 --- mk/xamarin.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/xamarin.mk b/mk/xamarin.mk index d97e215a86..a52e6f542e 100644 --- a/mk/xamarin.mk +++ b/mk/xamarin.mk @@ -1,5 +1,5 @@ ifdef ENABLE_XAMARIN -NEEDED_MACCORE_VERSION := d2f171adaa35c8acb86a32b5935e93fb4fdd48d5 +NEEDED_MACCORE_VERSION := e3d92b50d6beb38b154a3dfe9242720c67f8d7c3 NEEDED_MACCORE_BRANCH := master MACCORE_DIRECTORY := maccore From 2e72e1aee04d33e5857981bcd3943db5bf806856 Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Thu, 6 Dec 2018 14:16:10 -0500 Subject: [PATCH 15/15] [mmp] Add rpath to MonoBundle folder if we copy any NativeLibraries in (#5214) - https://github.com/xamarin/xamarin-macios/issues/4435 - A common enough breakage in our handling of native references is if you have two native libraries with dependencies (with rpath) between them that get copied into MonoBundle - We did not add rpath to this location so we would not resolve them - This is a behavior change, as anything that touches library resolution in mmp, but should be safe enough - Add 2 ignore line for common swift libraries --- tools/mmp/driver.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/mmp/driver.cs b/tools/mmp/driver.cs index 894d955ae1..2c73486fb9 100644 --- a/tools/mmp/driver.cs +++ b/tools/mmp/driver.cs @@ -116,7 +116,8 @@ namespace Xamarin.Bundler { public static bool Force; static bool is_extension; - static bool frameworks_copied_to_bundle_dir; // Have we copied any frameworks to Foo.app/Contents/Frameworks? + static bool frameworks_copied_to_bundle_dir; // Have we copied any frameworks to Foo.app/Contents/Frameworks? + static bool dylibs_copied_to_bundle_dir => native_libraries_copied_in.Count > 0; const string pkg_config = "/Library/Frameworks/Mono.framework/Commands/pkg-config"; @@ -812,11 +813,16 @@ namespace Xamarin.Bundler { throw new MonoMacException (5103, true, String.Format ("Failed to compile. Error code - {0}. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new", ret)); } if (frameworks_copied_to_bundle_dir) { - int install_ret = XcodeRun ("install_name_tool", string.Format ("{0} -add_rpath @loader_path/../Frameworks", StringUtils.Quote (AppPath))); + int install_ret = XcodeRun ("install_name_tool", $"{StringUtils.Quote (AppPath)} -add_rpath @loader_path/../Frameworks"); if (install_ret != 0) throw new MonoMacException (5310, true, "install_name_tool failed with an error code '{0}'. Check build log for details.", ret); } - + if (dylibs_copied_to_bundle_dir) { + int install_ret = XcodeRun ("install_name_tool", $"{StringUtils.Quote (AppPath)} -add_rpath @loader_path/../{BundleName}"); + if (install_ret != 0) + throw new MonoMacException (5310, true, "install_name_tool failed with an error code '{0}'. Check build log for details.", ret); + } + if (generate_plist) GeneratePList (); @@ -1531,7 +1537,9 @@ namespace Xamarin.Bundler { case "winmm": // windows specific case "winspool": // windows specific case "c": // system provided - case "objc": // system provided + case "objc": // system provided + case "objc.a": // found in swift core libraries + case "system.b": // found in swift core libraries case "system": // system provided, libSystem.dylib -> CommonCrypto case "x11": // msvcrt pulled in case "winspool.drv": // msvcrt pulled in @@ -1610,8 +1618,6 @@ namespace Xamarin.Bundler { if (verbose > 1) Console.WriteLine ("Native library '{0}' copied to application bundle.", Path.GetFileName (real_src)); - // FIXME: should we strip extra architectures (e.g. x64) ? - // that could break the library signature and cause issues on the appstore :( if (GetRealPath (dest) == real_src) { Console.WriteLine ("Dependency {0} was already at destination, skipping.", Path.GetFileName (real_src)); }