From 6186e98de8dbccf5ec11a9037fae6bcbc7f0f273 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 14 Aug 2020 18:33:28 +0200 Subject: [PATCH 01/48] [tests] Fix binding project file path --- tests/bindings-test/dotnet/shared.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bindings-test/dotnet/shared.targets b/tests/bindings-test/dotnet/shared.targets index 76425ccb6818..ffc5acd1e740 100644 --- a/tests/bindings-test/dotnet/shared.targets +++ b/tests/bindings-test/dotnet/shared.targets @@ -45,7 +45,7 @@ Registrar.cs - + TestRuntime.cs From 98b52c7c3a21874b9030bb773417b52fe67c5597 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 10 Aug 2020 17:06:40 +0200 Subject: [PATCH 02/48] [tests] Port interdependent-binding-projects to .NET. --- tests/dotnet/UnitTests/ProjectTest.cs | 72 ++++++++++++++++++- .../dotnet/.gitignore | 3 + .../interdependent-binding-projects.csproj | 30 ++++++++ .../interdependent-binding-projects.csproj | 28 ++++++++ .../interdependent-binding-projects.csproj | 30 ++++++++ .../interdependent-binding-projects.csproj | 28 ++++++++ 6 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 tests/interdependent-binding-projects/dotnet/.gitignore create mode 100644 tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj create mode 100644 tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj create mode 100644 tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj create mode 100644 tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 8a42171ac432..33e5b6747529 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -258,11 +258,77 @@ public void BuildBindingsTest2 (string platform) Assert.That (ad.MainModule.Resources [0].Name, Is.EqualTo ("libtest2.a"), "libtest2.a"); } - void CopyDotNetSupportingFiles (string targetDirectory) + [TestCase ("iOS")] + [TestCase ("tvOS")] + // [TestCase ("watchOS")] // No watchOS Touch.Client project for .NET yet + // [TestCase ("macOS")] // No macOS Touch.Client project for .NET yet + public void BuildInterdependentBindingProjects (string platform) + { + var assemblyName = "interdependent-binding-projects"; + var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet"); + var project_dir = Path.Combine (dotnet_bindings_dir, platform); + var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj"); + + Clean (project_path); + CopyDotNetSupportingFiles (dotnet_bindings_dir); + CopyDotNetSupportingFiles (dotnet_bindings_dir.Replace (assemblyName, "bindings-test")); + CopyDotNetSupportingFiles (dotnet_bindings_dir.Replace (assemblyName, "bindings-test2")); + var cleanupSupportFiles = CopyDotNetSupportingFiles (Path.Combine (Configuration.SourceRoot, "external", "Touch.Unit", "Touch.Client/dotnet")); + try { + var result = DotNet.AssertBuild (project_path, verbosity); + var lines = result.StandardOutput.ToString ().Split ('\n'); + // Find the resulting binding assembly from the build log + var assemblies = lines. + Select (v => v.Trim ()). + Where (v => { + if (v.Length < 10) + return false; + if (v [0] != '/') + return false; + if (!v.EndsWith ($"{assemblyName}.dll", StringComparison.Ordinal)) + return false; + if (!v.Contains ("/bin/", StringComparison.Ordinal)) + return false; + if (!v.Contains ($"{assemblyName}.app", StringComparison.Ordinal)) + return false; + return true; + }); + Assert.That (assemblies, Is.Not.Empty, "Assemblies"); + // Make sure there's no other assembly confusing our logic + assemblies = assemblies.Distinct (); + Assert.That (assemblies.Count (), Is.EqualTo (1), $"Unique assemblies: {string.Join (", ", assemblies)}"); + var asm = assemblies.First (); + Assert.That (asm, Does.Exist, "Assembly existence"); + + // Verify that the resources + var asmDir = Path.GetDirectoryName (asm); + var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred }); + Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (0), "0 resources for interdependent-binding-projects.dll"); + + var ad1 = AssemblyDefinition.ReadAssembly (Path.Combine (asmDir, "bindings-test.dll"), new ReaderParameters { ReadingMode = ReadingMode.Deferred }); + Assert.That (ad1.MainModule.Resources.Count, Is.EqualTo (1), "1 resource for bindings-test.dll"); + Assert.That (ad1.MainModule.Resources [0].Name, Is.EqualTo ("libtest.a"), "libtest.a - bindings-test.dll"); + + var ad2 = AssemblyDefinition.ReadAssembly (Path.Combine (asmDir, "bindings-test2.dll"), new ReaderParameters { ReadingMode = ReadingMode.Deferred }); + Assert.That (ad2.MainModule.Resources.Count, Is.EqualTo (1), "1 resource for bindings-test2.dll"); + Assert.That (ad2.MainModule.Resources [0].Name, Is.EqualTo ("libtest2.a"), "libtest2.a - bindings-test2.dll"); + } finally { + foreach (var file in cleanupSupportFiles) + File.Delete (file); + } + } + + string[] CopyDotNetSupportingFiles (string targetDirectory) { var srcDirectory = Path.Combine (Configuration.SourceRoot, "tests", "dotnet"); - foreach (var fn in new string [] { "global.json", "NuGet.config" }) - File.Copy (Path.Combine (srcDirectory, fn), Path.Combine (targetDirectory, fn), true); + var files = new string [] { "global.json", "NuGet.config" }; + var targets = new string [files.Length]; + for (var i = 0; i < files.Length; i++) { + var fn = files [i]; + targets [i] = Path.Combine (targetDirectory, fn); + File.Copy (Path.Combine (srcDirectory, fn), targets [i], true); + } + return targets; } void AssertThatLinkerExecuted (ExecutionResult result) diff --git a/tests/interdependent-binding-projects/dotnet/.gitignore b/tests/interdependent-binding-projects/dotnet/.gitignore new file mode 100644 index 000000000000..71d64b865351 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/.gitignore @@ -0,0 +1,3 @@ +global.json +NuGet.config + diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj new file mode 100644 index 000000000000..ae16412d9e85 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -0,0 +1,30 @@ + + + + net5.0 + Exe + true + latest + ios-x64 + xamarinios10;$(AssetTargetFallback) + ..\..\..\ + + $(DefaultItemExcludes);packages/**; + $(RootTestsDirectory)\..\product.snk + + + + + + + + + + + + + Info.plist + + + + diff --git a/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj new file mode 100644 index 000000000000..4d81ebf640e0 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj @@ -0,0 +1,28 @@ + + + + net5.0 + Exe + true + latest + osx-x64 + ..\..\..\ + + $(DefaultItemExcludes);packages/**; + $(RootTestsDirectory)\..\product.snk + + + + + + + + + + + + Info.plist + + + + diff --git a/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj new file mode 100644 index 000000000000..c9fcc5da5596 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj @@ -0,0 +1,30 @@ + + + + net5.0 + Exe + true + latest + tvos-x64 + xamarintvos10;$(AssetTargetFallback) + ..\..\..\ + + $(DefaultItemExcludes);packages/**; + $(RootTestsDirectory)\..\product.snk + + + + + + + + + + + + + Info.plist + + + + diff --git a/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj new file mode 100644 index 000000000000..4c36213106f0 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj @@ -0,0 +1,28 @@ + + + + net5.0 + Exe + true + latest + watchos-x86 + ..\..\..\ + + $(DefaultItemExcludes);packages/**; + $(RootTestsDirectory)\..\product.snk + + + + + + + + + + + + Info.plist + + + + From 5a5a53e1a978e64dc3815381c2accd2c803d7920 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 12 Aug 2020 16:04:20 +0200 Subject: [PATCH 03/48] [xharness] Add the .NET version of interdependent-binding-projects to our lineup --- tests/xharness/Harness.cs | 4 +++- .../Utilities/ProjectFileExtensions.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index c2bb0ba34ba8..23afae10569a 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -371,7 +371,7 @@ int AutoConfigureMac (bool generate_projects) void AutoConfigureIOS () { - var test_suites = new string [] { "monotouch-test", "framework-test", "interdependent-binding-projects" }; + var test_suites = new string [] { "monotouch-test", "framework-test" }; var library_projects = new string [] { "BundledResources", "EmbeddedResources", "bindings-test2", "bindings-framework-test" }; var fsharp_test_suites = new string [] { "fsharp" }; var fsharp_library_projects = new string [] { "fsharplibrary" }; @@ -387,6 +387,8 @@ void AutoConfigureIOS () IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "bindings-test", "iOS", "bindings-test.csproj")), false) { Name = "bindings-test" }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "dotnet", "iOS", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios-dotnet.csproj"))) { Name = "introspection", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = false, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs index f935757b1f4b..b6c3701ea53e 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs @@ -942,7 +942,7 @@ public static void ResolveAllPaths (this XmlDocument csproj, string project_path new string [] { "ObjcBindingCoreSource", "Include" }, new string [] { "ObjcBindingNativeLibrary", "Include" }, new string [] { "ObjcBindingNativeFramework", "Include" }, - new string [] { "Import", "Project", "CustomBuildActions.targets" }, + new string [] { "Import", "Project", "CustomBuildActions.targets", "..\\shared.targets" }, new string [] { "FilesToCopy", "Include" }, new string [] { "FilesToCopyFoo", "Include" }, new string [] { "FilesToCopyFooBar", "Include" }, From 9fddbbda58525773a79703b52fd6508be2db112f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 13 Aug 2020 17:58:41 +0200 Subject: [PATCH 04/48] [xharness] Enhance ResolveAllPaths to understand $(RootTestsDirectory). This requires passing the root directory around in multiple places, since ResolveAllPaths doesn't have access to the static class where we define the root directory. Also call ResolveAllPaths in a few more places to ensure paths everywhere are resolved. --- tests/xharness/Jenkins/MacTestTasksEnumerable.cs | 2 +- tests/xharness/Jenkins/RunDeviceTasksFactory.cs | 12 ++++++------ tests/xharness/Jenkins/RunSimulatorTasksFactory.cs | 2 +- tests/xharness/Jenkins/TestVariationsFactory.cs | 2 +- .../Tasks/TestTask.cs | 4 ++-- .../TestProject.cs | 10 +++++----- .../Utilities/ProjectFileExtensions.cs | 6 +++++- tests/xharness/Targets/Target.cs | 1 + tests/xharness/Targets/TodayExtensionTarget.cs | 3 ++- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/tests/xharness/Jenkins/MacTestTasksEnumerable.cs b/tests/xharness/Jenkins/MacTestTasksEnumerable.cs index 0bdadab2d6c4..c56b7d5e7ad5 100644 --- a/tests/xharness/Jenkins/MacTestTasksEnumerable.cs +++ b/tests/xharness/Jenkins/MacTestTasksEnumerable.cs @@ -81,7 +81,7 @@ public IEnumerator GetEnumerator () foreach (var config in configurations) { MSBuildTask build = new MSBuildTask (jenkins: jenkins, testProject: project, processManager: processManager); build.Platform = platform; - build.CloneTestProject (jenkins.MainLog, processManager, project); + build.CloneTestProject (jenkins.MainLog, processManager, project, HarnessConfiguration.RootDirectory); build.ProjectConfiguration = config; build.ProjectPlatform = project.Platform; build.SpecifyPlatform = false; diff --git a/tests/xharness/Jenkins/RunDeviceTasksFactory.cs b/tests/xharness/Jenkins/RunDeviceTasksFactory.cs index 222bbef5a3d0..b94a5291be02 100644 --- a/tests/xharness/Jenkins/RunDeviceTasksFactory.cs +++ b/tests/xharness/Jenkins/RunDeviceTasksFactory.cs @@ -52,7 +52,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.iOS_Unified64, TestName = project.Name, }; - build64.CloneTestProject (jenkins.MainLog, processManager, project); + build64.CloneTestProject (jenkins.MainLog, processManager, project, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, @@ -69,7 +69,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.iOS_Unified32, TestName = project.Name, }; - build32.CloneTestProject (jenkins.MainLog, processManager, project); + build32.CloneTestProject (jenkins.MainLog, processManager, project, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, @@ -88,7 +88,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.iOS_TodayExtension64, TestName = project.Name, }; - buildToday.CloneTestProject (jenkins.MainLog, processManager, todayProject); + buildToday.CloneTestProject (jenkins.MainLog, processManager, todayProject, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, @@ -109,7 +109,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.tvOS, TestName = project.Name, }; - buildTV.CloneTestProject (jenkins.MainLog, processManager, tvOSProject); + buildTV.CloneTestProject (jenkins.MainLog, processManager, tvOSProject, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, @@ -130,7 +130,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.watchOS_32, TestName = project.Name, }; - buildWatch32.CloneTestProject (jenkins.MainLog, processManager, watchOSProject); + buildWatch32.CloneTestProject (jenkins.MainLog, processManager, watchOSProject, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, @@ -149,7 +149,7 @@ public Task> CreateAsync (Jenkins jenkins, IProcessManage Platform = TestPlatform.watchOS_64_32, TestName = project.Name, }; - buildWatch64_32.CloneTestProject (jenkins.MainLog, processManager, watchOSProject); + buildWatch64_32.CloneTestProject (jenkins.MainLog, processManager, watchOSProject, HarnessConfiguration.RootDirectory); projectTasks.Add (new RunDeviceTask ( jenkins: jenkins, devices: jenkins.Devices, diff --git a/tests/xharness/Jenkins/RunSimulatorTasksFactory.cs b/tests/xharness/Jenkins/RunSimulatorTasksFactory.cs index 5209ed75a3e6..716553721b8d 100644 --- a/tests/xharness/Jenkins/RunSimulatorTasksFactory.cs +++ b/tests/xharness/Jenkins/RunSimulatorTasksFactory.cs @@ -74,7 +74,7 @@ public async Task> CreateAsync (Jenkins jenkins, IProcess derived.Ignored = configIgnored; derived.TestName = project.Name; derived.Dependency = project.Dependency; - derived.CloneTestProject (jenkins.MainLog, processManager, pair.Item1); + derived.CloneTestProject (jenkins.MainLog, processManager, pair.Item1, HarnessConfiguration.RootDirectory); var simTasks = CreateAsync (jenkins, processManager, derived); runSimulatorTasks.AddRange (simTasks); foreach (var task in simTasks) { diff --git a/tests/xharness/Jenkins/TestVariationsFactory.cs b/tests/xharness/Jenkins/TestVariationsFactory.cs index 21c3349f7299..3853f8096aea 100644 --- a/tests/xharness/Jenkins/TestVariationsFactory.cs +++ b/tests/xharness/Jenkins/TestVariationsFactory.cs @@ -160,7 +160,7 @@ public IEnumerable CreateTestVariations (IEnumerable tests, Func { await task.BuildTask.InitialTask; // this is the project cloning above - await clone.CreateCopyAsync (jenkins.MainLog, processManager, task); + await clone.CreateCopyAsync (jenkins.MainLog, processManager, task, HarnessConfiguration.RootDirectory); var isMac = task.Platform.IsMac (); var canSymlink = task.Platform.CanSymlink(); diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Tasks/TestTask.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Tasks/TestTask.cs index bd37eb489b85..672cf23d50ad 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Tasks/TestTask.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Tasks/TestTask.cs @@ -242,7 +242,7 @@ protected Task VerifyDiskSpaceAsync () return Task.CompletedTask; } - public void CloneTestProject (ILog log, IProcessManager processManager, TestProject project) + public void CloneTestProject (ILog log, IProcessManager processManager, TestProject project, string rootDirectory) { // Don't build in the original project directory // We can build multiple projects in parallel, and if some of those @@ -252,7 +252,7 @@ public void CloneTestProject (ILog log, IProcessManager processManager, TestProj // So we clone the project file to a separate directory and build there instead. // This is done asynchronously to speed to the initial test load. TestProject = project.Clone (); - InitialTask = TestProject.CreateCopyAsync (log, processManager, this); + InitialTask = TestProject.CreateCopyAsync (log, processManager, this, rootDirectory); } protected Stopwatch waitingDuration = new Stopwatch (); diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs index 04300aaa4149..b6050377fc9b 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs @@ -69,14 +69,14 @@ public virtual TestProject Clone () return rv; } - internal async Task CreateCloneAsync (ILog log, IProcessManager processManager, ITestTask test) + internal async Task CreateCloneAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) { var rv = Clone (); - await rv.CreateCopyAsync (log, processManager, test); + await rv.CreateCopyAsync (log, processManager, test, rootDirectory); return rv; } - public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test) + public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) { var directory = DirectoryUtilities.CreateTemporaryDirectory (test?.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path)); Directory.CreateDirectory (directory); @@ -89,7 +89,7 @@ public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITe doc = new XmlDocument (); doc.LoadWithoutNetworkAccess (original_path); var original_name = System.IO.Path.GetFileName (original_path); - doc.ResolveAllPaths (original_path); + doc.ResolveAllPaths (original_path, rootDirectory); if (doc.IsDotNetProject ()) { if (doc.GetEnableDefaultItems () != false) { @@ -155,7 +155,7 @@ public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITe var projectReferences = new List (); foreach (var pr in doc.GetProjectReferences ()) { var tp = new TestProject (pr.Replace ('\\', '/')); - await tp.CreateCopyAsync (log, processManager, test); + await tp.CreateCopyAsync (log, processManager, test, rootDirectory); doc.SetProjectReferenceInclude (pr, tp.Path.Replace ('/', '\\')); projectReferences.Add (tp); } diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs index b6c3701ea53e..12c914572212 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs @@ -912,7 +912,7 @@ static IEnumerable SelectElementNodes (this XmlNode node, string name) } } - public static void ResolveAllPaths (this XmlDocument csproj, string project_path) + public static void ResolveAllPaths (this XmlDocument csproj, string project_path, string rootDirectory = null) { var dir = System.IO.Path.GetDirectoryName (project_path); var nodes_with_paths = new string [] @@ -967,6 +967,10 @@ public static void ResolveAllPaths (this XmlDocument csproj, string project_path if (input.StartsWith ("$(MSBuildBinPath)", StringComparison.Ordinal)) return input; // This is already a full path. input = input.Replace ('\\', '/'); // make unix-style + + if (rootDirectory != null) + input = input.Replace ("$(RootTestsDirectory)", rootDirectory); + input = System.IO.Path.GetFullPath (System.IO.Path.Combine (dir, input)); input = input.Replace ('/', '\\'); // make windows-style again return input; diff --git a/tests/xharness/Targets/Target.cs b/tests/xharness/Targets/Target.cs index 581fe6a1fbe1..9136db1d9e7d 100644 --- a/tests/xharness/Targets/Target.cs +++ b/tests/xharness/Targets/Target.cs @@ -199,6 +199,7 @@ protected virtual void UpdateInfoPList () protected void CreateLibraryProject () { ProcessProject (); + inputProject.ResolveAllPaths (TemplateProjectPath); inputProject.Save (ProjectPath, (l, m) => Harness.Log (l,m)); ProjectGuid = inputProject.GetProjectGuid (); diff --git a/tests/xharness/Targets/TodayExtensionTarget.cs b/tests/xharness/Targets/TodayExtensionTarget.cs index 552b850d8a34..aa3c68d17865 100644 --- a/tests/xharness/Targets/TodayExtensionTarget.cs +++ b/tests/xharness/Targets/TodayExtensionTarget.cs @@ -51,6 +51,7 @@ void CreateTodayContainerProject () TodayContainerGuid = "{" + Helpers.GenerateStableGuid ().ToString ().ToUpper () + "}"; ProjectGuid = TodayContainerGuid; csproj.SetProjectGuid (TodayContainerGuid); + csproj.ResolveAllPaths (Harness.TodayContainerTemplate); csproj.Save(TodayContainerProjectPath, (l, m) => Harness.Log (l,m)); XmlDocument info_plist = new XmlDocument (); @@ -79,7 +80,7 @@ void CreateTodayExtensionProject () csproj.AddInterfaceDefinition (Path.Combine (Harness.TodayExtensionTemplate, "TodayView.storyboard").Replace ('/', '\\')); csproj.SetExtraLinkerDefs ("extra-linker-defs" + ExtraLinkerDefsSuffix + ".xml"); csproj.FixProjectReferences (Path.Combine (ProjectsDir, GetTargetSpecificDir ()), "-today", FixProjectReference); - + csproj.ResolveAllPaths (TemplateProjectPath); csproj.Save (TodayExtensionProjectPath, (l,m) => Harness.Log (l,m)); TodayExtensionGuid = csproj.GetProjectGuid (); From 1b093b8a7fa6272ac63c2c9a9517ddafe04e2bc3 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 05/48] [dotnet-linker] Include code we need from mtouch/mmp into our .NET linker code. --- tools/dotnet-linker/dotnet-linker.csproj | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/tools/dotnet-linker/dotnet-linker.csproj b/tools/dotnet-linker/dotnet-linker.csproj index 13634632afff..bc11a7314b8f 100644 --- a/tools/dotnet-linker/dotnet-linker.csproj +++ b/tools/dotnet-linker/dotnet-linker.csproj @@ -18,6 +18,9 @@ src\ObjCRuntime\ErrorHelper.cs + + external\tools\common\CoreResolver.cs + tools\common\error.cs @@ -31,6 +34,123 @@ tools\common\Frameworks.cs + + external\tools\mtouch\Stripper.cs + + + external\tools\common\Application.cs + + + external\tools\common\cache.cs + + + external\tools\common\Assembly.cs + + + external\tools\common\Driver.cs + + + external\tools\common\Driver.execution.cs + + + external\tools\common\Execution.cs + + + external\tools\common\FileCopier.cs + + + external\tools\common\LinkMode.cs + + + external\tools\common\SdkVersions.cs + + + external\tools\common\Symbols.cs + + + external\tools\common\Assembly.cs + + + external\tools\common\DerivedLinkContext.cs + + + external\tools\common\Optimizations.cs + + + external\tools\common\PInvokeWrapperGenerator.cs + + + external\tools\common\PListExtensions.cs + + + external\tools\common\StaticRegistrar.cs + + + external\tools\common\StringUtils.cs + + + external\tools\common\TargetFramework.cs + + + external\tools\linker\CustomSymbolWriter.cs + + + external\src\ObjCRuntime\Registrar.cs + + + external\src\ObjCRuntime\Registrar.core.cs + + + external\src\ObjCRuntime\ArgumentSemantic.cs + + + external\src\ObjCRuntime\BindingImplAttribute.cs + + + external\src\ObjCRuntime\Constants.cs + + + external\src\Foundation\ExportAttribute.cs + + + external\src\Foundation\ConnectAttribute.cs + + + external\src\ObjCRuntime\ExceptionMode.cs + + + external\src\ObjCRuntime\LinkWithAttribute.cs + + + external\src\ObjCRuntime\PlatformAvailability2.cs + + + external\src\ObjCRuntime\RuntimeOptions.cs + + + external\tools\linker\MonoTouch.Tuner\Extensions.cs + + + external\tools\linker\MobileExtensions.cs + + + external\tools\linker\ObjCExtensions.cs + + + external\mono-archive\Mono.Tuner\Extensions.cs + + + external\mono-archive\Linker\AssemblyResolver.cs + + + external\mono-archive\Linker\I18nAssemblies.cs + + + external\mono-archive\Mono.Tuner\CecilRocks.cs + + + external\Xamarin.MacDev\Xamarin.MacDev\PListObject.cs + From 0ac3879e6d9dcf152162678627fcb4ee55b38799 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 06/48] [dotnet-linker] Enable unsafe code, since some of the bundler code is unsafe. --- tools/dotnet-linker/dotnet-linker.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/dotnet-linker/dotnet-linker.csproj b/tools/dotnet-linker/dotnet-linker.csproj index bc11a7314b8f..0e734c937200 100644 --- a/tools/dotnet-linker/dotnet-linker.csproj +++ b/tools/dotnet-linker/dotnet-linker.csproj @@ -3,6 +3,7 @@ net5.0 dotnet_linker $(DefineConstants);BUNDLER + true From 90914c1aab3f0e31003bd1f9ffcb18881717712a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 07/48] [dotnet-linker] Add a Constants class to the build. The bundler (mtouch/mmp) code needs it to compile. --- tools/dotnet-linker/Constants.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tools/dotnet-linker/Constants.cs diff --git a/tools/dotnet-linker/Constants.cs b/tools/dotnet-linker/Constants.cs new file mode 100644 index 000000000000..9c51e76ee345 --- /dev/null +++ b/tools/dotnet-linker/Constants.cs @@ -0,0 +1,15 @@ +using System; + +namespace Xamarin.Bundler { + public static partial class Constants { + public static string Version { + get { throw new NotImplementedException (); } + } + internal static string Revision { + get { throw new NotImplementedException (); } + } + public static string SdkVersion { + get { throw new NotImplementedException (); } + } + } +} From 08961a655b2f8bc737b03e88fcdd6e00ff42697a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 08/48] [dotnet-linker] Make Application take the input arguments, so that we can pass them to the cache to correctly determine cache validity. --- tools/common/cache.cs | 2 ++ tools/dotnet-linker/Compat.cs | 5 +++-- tools/dotnet-linker/LinkerConfiguration.cs | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/common/cache.cs b/tools/common/cache.cs index 934c8955cc45..acc318774491 100644 --- a/tools/common/cache.cs +++ b/tools/common/cache.cs @@ -13,6 +13,8 @@ public class Cache { const string NAME = "mmp"; #elif MTOUCH const string NAME = "mtouch"; +#elif BUNDLER + const string NAME = "dotnet-linker"; #else #error Wrong defines #endif diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 53253a97ce74..8ee9af3faa53 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -5,10 +5,11 @@ using Xamarin.Utils; namespace Xamarin.Bundler { - public class Application { + public partial class Application { public LinkerConfiguration Configuration { get; private set; } - public Application (LinkerConfiguration configuration) + public Application (LinkerConfiguration configuration, string[] arguments) + : this (arguments) { this.Configuration = configuration; } diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 3dc90438dd01..9e1afa253d5d 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -46,6 +46,7 @@ public static LinkerConfiguration GetInstance (LinkContext context) throw new FileNotFoundException ($"The custom linker file {linker_file} does not exist."); var lines = File.ReadAllLines (linker_file); + var significantLines = new List (); // This is the input the cache uses to verify if the cache is still valid for (var i = 0; i < lines.Length; i++) { var line = lines [i].TrimStart (); if (line.Length == 0 || line [0] == '#') @@ -55,6 +56,8 @@ public static LinkerConfiguration GetInstance (LinkContext context) if (eq == -1) throw new InvalidOperationException ($"Invalid syntax for line {i + 1} in {linker_file}: No equals sign."); + significantLines.Add (line); + var key = line [..eq]; var value = line [(eq + 1)..]; @@ -128,7 +131,9 @@ public static LinkerConfiguration GetInstance (LinkContext context) ErrorHelper.Platform = Platform; - Application = new Application (this); + Application = new Application (this, significantLines.ToArray ()); + Application.Cache.Location = CacheDirectory; + } public void Write () From 578d84a0fdd6ebfed4acc210ead64fc053247e70 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 09/48] [dotnet-linker] Set Application.BuildTarget so that the shared Application.IsSimulatorBuild implementation can be used. --- tools/dotnet-linker/Compat.cs | 4 ---- tools/dotnet-linker/LinkerConfiguration.cs | 10 ++++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 8ee9af3faa53..be800823732c 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -41,10 +41,6 @@ public Version DeploymentTarget { get { return Configuration.DeploymentTarget; } } - public bool IsSimulatorBuild { - get { return Configuration.IsSimulatorBuild; } - } - public ApplePlatform Platform { get { return Configuration.Platform; } } diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 9e1afa253d5d..2d13cb7453d8 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -134,6 +134,16 @@ public static LinkerConfiguration GetInstance (LinkContext context) Application = new Application (this, significantLines.ToArray ()); Application.Cache.Location = CacheDirectory; + switch (Platform) { + case ApplePlatform.iOS: + case ApplePlatform.TVOS: + case ApplePlatform.WatchOS: + Application.BuildTarget = IsSimulatorBuild ? BuildTarget.Simulator : BuildTarget.Device; + break; + case ApplePlatform.MacOSX: + default: + break; + } } public void Write () From 658d25f71e2a5c0c193b3d2e0491743889cc195a Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 10/48] [dotnet-linker] Add a Target instance The bundler (mtouch/mmp) code needs it to compile. --- tools/dotnet-linker/LinkerConfiguration.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 2d13cb7453d8..6a47f49b33b9 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -27,6 +27,7 @@ public class LinkerConfiguration { static ConditionalWeakTable configurations = new ConditionalWeakTable (); public Application Application { get; private set; } + public Target Target { get; private set; } public static LinkerConfiguration GetInstance (LinkContext context) { @@ -132,6 +133,8 @@ public static LinkerConfiguration GetInstance (LinkContext context) ErrorHelper.Platform = Platform; Application = new Application (this, significantLines.ToArray ()); + Target = new Target (Application); + Application.Cache.Location = CacheDirectory; switch (Platform) { From c4186268b932d59dc30099ef646198623ed2adae Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 11/48] =?UTF-8?q?[dotnet-linker]=C2=A0Adjust=20ifdefs=20to?= =?UTF-8?q?=20make=20existing/shared=20code=20compile=20correctly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ObjCRuntime/Registrar.cs | 38 +++++++++++++++---------------- src/ObjCRuntime/RuntimeOptions.cs | 6 ++--- tools/common/Driver.execution.cs | 2 +- tools/common/SdkVersions.cs.in | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ObjCRuntime/Registrar.cs b/src/ObjCRuntime/Registrar.cs index f7494e8f8765..995942bedd02 100644 --- a/src/ObjCRuntime/Registrar.cs +++ b/src/ObjCRuntime/Registrar.cs @@ -25,7 +25,7 @@ using Xamarin.Utils; using Xamarin.Bundler; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER using TAssembly=Mono.Cecil.AssemblyDefinition; using TType=Mono.Cecil.TypeReference; using TMethod=Mono.Cecil.MethodDefinition; @@ -41,11 +41,11 @@ using R=ObjCRuntime.Runtime; #endif -#if !(MTOUCH || MMP) +#if !(MTOUCH || MMP || BUNDLER) using ProductException=ObjCRuntime.RuntimeException; #endif -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER // static registrar needs them but they might not be marked (e.g. if System.Console is not used) [assembly: Preserve (typeof (System.Action))] [assembly: Preserve (typeof (System.Action))] @@ -84,7 +84,7 @@ public static List GetMT4127 (TMethod impl, List ifac } abstract partial class Registrar { -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER public Application App { get; protected set; } #endif @@ -124,7 +124,7 @@ internal class ObjCType { public bool IsInformalProtocol; public bool IsWrapper; public bool IsGeneric; -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER public IntPtr Handle; #else public TType ProtocolWrapperType; @@ -140,7 +140,7 @@ internal class ObjCType { public bool IsCategory { get { return CategoryAttribute != null; } } -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER HashSet all_protocols; // This contains all protocols in the type hierarchy. // Given a type T that implements a protocol with super protocols: @@ -585,7 +585,7 @@ public bool IsConstructor { } } -#if !MMP && !MTOUCH +#if !MMP && !MTOUCH && !BUNDLER // The ArgumentSemantic enum is public, and // I don't want to add another enum value there which // is just an internal implementation detail, so just @@ -832,7 +832,7 @@ public Trampoline Trampoline { if (trampoline != Trampoline.None) return trampoline; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER throw ErrorHelper.CreateError (8018, Errors.MT8018); #else var mi = (System.Reflection.MethodInfo) Method; @@ -1001,7 +1001,7 @@ public override string FullName { } internal class ObjCField : ObjCMember { -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER public int Size; public byte Alignment; #else @@ -1259,7 +1259,7 @@ internal static string AppKit { #if MONOMAC internal const string AssemblyName = "Xamarin.Mac"; #else -#if MTOUCH +#if MTOUCH || BUNDLER internal string AssemblyName { get { @@ -1305,7 +1305,7 @@ public string PlatformAssembly { } } -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER // "#if MTOUCH" code does not need locking when accessing 'types', because mtouch is single-threaded. public Dictionary Types { get { return types; } @@ -1884,7 +1884,7 @@ ObjCType RegisterCategory (TType type, CategoryAttribute attrib, ref List exceptions) isInformalProtocol = pAttr.IsInformal; isProtocol = true; -#if MMP || MTOUCH +#if MMP || MTOUCH || BUNDLER if (pAttr.FormalSinceVersion != null && pAttr.FormalSinceVersion > App.SdkVersion) isInformalProtocol = !isInformalProtocol; #endif @@ -1969,7 +1969,7 @@ ObjCType RegisterTypeUnsafe (TType type, ref List exceptions) objcType.VerifyAdoptedProtocolsNames (ref exceptions); objcType.BaseType = isProtocol ? null : (baseObjCType ?? objcType); objcType.Protocols = GetProtocols (objcType, ref exceptions); -#if MMP || MTOUCH +#if MMP || MTOUCH || BUNDLER objcType.ProtocolWrapperType = (isProtocol && !isInformalProtocol) ? GetProtocolAttributeWrapperType (objcType.Type) : null; #endif objcType.IsWrapper = (isProtocol && !isInformalProtocol) ? (GetProtocolAttributeWrapperType (objcType.Type) != null) : (objcType.RegisterAttribute != null && objcType.RegisterAttribute.IsWrapper); @@ -2064,7 +2064,7 @@ ObjCType RegisterTypeUnsafe (TType type, ref List exceptions) } } -#if MMP || MTOUCH +#if MMP || MTOUCH || BUNDLER // Special fields if (is_first_nonWrapper) { // static registrar @@ -2131,7 +2131,7 @@ ObjCType RegisterTypeUnsafe (TType type, ref List exceptions) } } else { TMethod method = null; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER method = attrib.Method; #endif var objcMethod = new ObjCMethod (this, objcType, method) { @@ -2180,7 +2180,7 @@ ObjCType RegisterTypeUnsafe (TType type, ref List exceptions) objcType.Add (new ObjCField () { DeclaringType = objcType, Name = ca.Name ?? GetPropertyName (property), -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER Size = Is64Bits ? 8 : 4, Alignment = (byte) (Is64Bits ? 3 : 2), #endif @@ -2460,7 +2460,7 @@ public void RegisterAssembly (TAssembly assembly) if (exceptions.Count > 0) { Exception ae = exceptions.Count == 1 ? exceptions [0] : new AggregateException (exceptions); -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER Runtime.NSLog (ae.ToString ()); #endif throw ae; @@ -2689,7 +2689,7 @@ protected void UnlockRegistrar () System.Threading.Monitor.Exit (types); } -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER internal static void NSLog (string format, params object [] args) { Console.WriteLine (format, args); diff --git a/src/ObjCRuntime/RuntimeOptions.cs b/src/ObjCRuntime/RuntimeOptions.cs index f99690ed17ae..24acb310ee95 100644 --- a/src/ObjCRuntime/RuntimeOptions.cs +++ b/src/ObjCRuntime/RuntimeOptions.cs @@ -2,7 +2,7 @@ using System.IO; using System.Text; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER using Mono.Cecil; using Xamarin.Linker; #else @@ -11,7 +11,7 @@ using ObjCRuntime; #endif -#if MMP || MMP_TEST || MTOUCH +#if MMP || MMP_TEST || MTOUCH || BUNDLER namespace Xamarin.Bundler { #else namespace ObjCRuntime { @@ -24,7 +24,7 @@ class RuntimeOptions string http_message_handler; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER /* * This section is only used by the tools */ diff --git a/tools/common/Driver.execution.cs b/tools/common/Driver.execution.cs index 1dde08fa9bff..2a6d7e3d1f59 100644 --- a/tools/common/Driver.execution.cs +++ b/tools/common/Driver.execution.cs @@ -139,7 +139,7 @@ public static Task RunCommandAsync (string path, IList args, Dictio return Task.Run (() => RunCommand (path, args, env, output, output, suppressPrintOnErrors, verbosity ?? Verbosity)); } -#if !MTOUCH && !MMP +#if !MTOUCH && !MMP && !BUNDLER internal static int Verbosity; #endif } diff --git a/tools/common/SdkVersions.cs.in b/tools/common/SdkVersions.cs.in index c80db22a9a35..d7d1fa7a47f6 100644 --- a/tools/common/SdkVersions.cs.in +++ b/tools/common/SdkVersions.cs.in @@ -1,6 +1,6 @@ using System; -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER using Xamarin.Bundler; using Xamarin.Utils; #endif @@ -62,7 +62,7 @@ namespace Xamarin { public static Version XcodeVersion { get { return new Version (Xcode); }} -#if MTOUCH || MMP +#if MTOUCH || MMP || BUNDLER public static Version GetVersion (Application app) { switch (app.Platform) { From f6cf39c72b40534e2c3c21cbb5e3521e38b44434 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 12/48] [dotnet-linker] Add a DotNetResolver. This is just a stub to make code compile, it's not needed at runtime. --- tools/common/Application.cs | 6 +++++- tools/common/Target.cs | 6 +++++- tools/dotnet-linker/DotNetResolver.cs | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tools/dotnet-linker/DotNetResolver.cs diff --git a/tools/common/Application.cs b/tools/common/Application.cs index c2abfc10af59..7bccce19232e 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -16,8 +16,12 @@ #if MONOTOUCH using PlatformResolver = MonoTouch.Tuner.MonoTouchResolver; -#else +#elif MMP using PlatformResolver = Xamarin.Bundler.MonoMacResolver; +#elif NET +using PlatformResolver = Xamarin.Linker.DotNetResolver; +#else +#error Invalid defines #endif namespace Xamarin.Bundler { diff --git a/tools/common/Target.cs b/tools/common/Target.cs index a54480f470f4..c8e5710ad527 100644 --- a/tools/common/Target.cs +++ b/tools/common/Target.cs @@ -26,10 +26,14 @@ using MonoTouch.Tuner; using PlatformResolver = MonoTouch.Tuner.MonoTouchResolver; using PlatformLinkContext = MonoTouch.Tuner.MonoTouchLinkContext; -#else +#elif MMP using MonoMac.Tuner; using PlatformResolver = Xamarin.Bundler.MonoMacResolver; using PlatformLinkContext = MonoMac.Tuner.MonoMacLinkContext; +#elif NET +using PlatformResolver = Xamarin.Linker.DotNetResolver; +#else +#error Invalid defines #endif namespace Xamarin.Bundler { diff --git a/tools/dotnet-linker/DotNetResolver.cs b/tools/dotnet-linker/DotNetResolver.cs new file mode 100644 index 000000000000..9f51e55ff716 --- /dev/null +++ b/tools/dotnet-linker/DotNetResolver.cs @@ -0,0 +1,14 @@ +using System; + +using Mono.Cecil; + +using Xamarin.Bundler; + +namespace Xamarin.Linker { + public class DotNetResolver : CoreResolver { + public override AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters) + { + throw new NotImplementedException (); + } + } +} From bb6e8d3f1b1c354e23172f1ad9e4ed4bc7258c91 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 13/48] [dotnet-linker] Create compat API to make DerivedLinkContext compile. --- tools/common/DerivedLinkContext.cs | 4 +++ tools/common/Target.cs | 2 ++ tools/dotnet-linker/Compat.cs | 54 ++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/tools/common/DerivedLinkContext.cs b/tools/common/DerivedLinkContext.cs index 4b44bc0afe69..6e7f3c2e6aa3 100644 --- a/tools/common/DerivedLinkContext.cs +++ b/tools/common/DerivedLinkContext.cs @@ -9,6 +9,10 @@ using Mono.Tuner; using Xamarin.Bundler; +#if NET +using LinkContext = Xamarin.Bundler.DotNetLinkContext; +#endif + namespace Xamarin.Tuner { public class DerivedLinkContext : LinkContext diff --git a/tools/common/Target.cs b/tools/common/Target.cs index c8e5710ad527..7d0b86af8966 100644 --- a/tools/common/Target.cs +++ b/tools/common/Target.cs @@ -31,6 +31,8 @@ using PlatformResolver = Xamarin.Bundler.MonoMacResolver; using PlatformLinkContext = MonoMac.Tuner.MonoMacLinkContext; #elif NET +using LinkerOptions = Xamarin.Linker.LinkerConfiguration; +using PlatformLinkContext = Xamarin.Tuner.DerivedLinkContext; using PlatformResolver = Xamarin.Linker.DotNetResolver; #else #error Invalid defines diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index be800823732c..d85f4e3ac57f 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -1,5 +1,10 @@ // Compat.cs: might not be ideal but it eases code sharing with existing code during the initial implementation. using System; +using System.Collections.Generic; + +using Mono.Cecil; +using Mono.Linker; +using Mono.Linker.Steps; using Xamarin.Linker; using Xamarin.Utils; @@ -45,4 +50,53 @@ public ApplePlatform Platform { get { return Configuration.Platform; } } } + + public class DotNetLinkContext { + public DotNetLinkContext () + { + throw new NotImplementedException (); + } + + public DotNetLinkContext (Pipeline pipeline, AssemblyResolver resolver) + { + throw new NotImplementedException (); + } + + public AssemblyAction UserAction { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + + public AnnotationStore Annotations { + get { + throw new NotImplementedException (); + } + } + + public AssemblyDefinition GetAssembly (string name) + { + throw new NotImplementedException (); + } + } + + public class Pipeline { + + } +} + +namespace Mono.Linker { + public static class LinkContextExtensions { + public static void LogMessage (this LinkContext context, string messsage) + { + throw new NotImplementedException (); + } + public static IEnumerable GetAssemblies (this LinkContext context) + { + throw new NotImplementedException (); + } + public static Dictionary GetCustomAnnotations (this AnnotationStore self, string name) + { + throw new NotImplementedException (); + } + } } From 31f7b6f84c12e58f2c5c1ba06556cc6c1f0a7cca Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 14/48] [dotnet-linker] Set Application.DeploymentTarget and Application.SdkVersion so that we can use the shared implementation. --- tools/dotnet-linker/Compat.cs | 8 -------- tools/dotnet-linker/LinkerConfiguration.cs | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index d85f4e3ac57f..0bbdb6e8c24f 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -38,14 +38,6 @@ public string GetProductName () } } - public Version SdkVersion { - get { return Configuration.SdkVersion; } - } - - public Version DeploymentTarget { - get { return Configuration.DeploymentTarget; } - } - public ApplePlatform Platform { get { return Configuration.Platform; } } diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 6a47f49b33b9..c8bd2be1b25b 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -136,6 +136,8 @@ public static LinkerConfiguration GetInstance (LinkContext context) Target = new Target (Application); Application.Cache.Location = CacheDirectory; + Application.DeploymentTarget = DeploymentTarget; + Application.SdkVersion = SdkVersion; switch (Platform) { case ApplePlatform.iOS: From f7d55eea24fcbd90adefe051b306fc4c5f12e7b6 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 15/48] [dotnet-linker] We don't need to stub out Application.LoadSymbols anymore. --- tools/dotnet-linker/Compat.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 0bbdb6e8c24f..c16b311b5850 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -19,11 +19,6 @@ public Application (LinkerConfiguration configuration, string[] arguments) this.Configuration = configuration; } - // This method is needed for ErrorHelper.tools.cs to compile. - public void LoadSymbols () - { - } - public string GetProductName () { switch (Platform) { From e304993c3e5302227a03df5e00bfdd81b4c05ca9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 16/48] [dotnet-linker] Stub out an Application.SelectRegistrar --- tools/dotnet-linker/Compat.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index c16b311b5850..2fa6e8b6cae9 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -33,6 +33,11 @@ public string GetProductName () } } + public void SelectRegistrar () + { + throw new NotImplementedException (); + } + public ApplePlatform Platform { get { return Configuration.Platform; } } From 48620b43e7d39d072ad48c07cc3c47edccd85316 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 17/48] [dotnet-linker] Stub out a few Driver members. --- tools/dotnet-linker/Compat.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 2fa6e8b6cae9..046ebec6f0df 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -43,6 +43,22 @@ public ApplePlatform Platform { } } + public partial class Driver { + public static string NAME { + get { return "xamarin-bundler"; } + } + + public static string GetArch32Directory (Application app) + { + throw new NotImplementedException (); + } + + public static string GetArch64Directory (Application app) + { + throw new NotImplementedException (); + } + } + public class DotNetLinkContext { public DotNetLinkContext () { From 693f9423eb2877feb5e8fe0f2f3830c3bf1a16fc Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 18/48] [dotnet-linker] Exclude Driver.Main from the build The .NET linker code is a library, so it doesn't need a Main method. --- tools/common/Driver.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/common/Driver.cs b/tools/common/Driver.cs index 8bd670f1950b..4f919ceb5467 100644 --- a/tools/common/Driver.cs +++ b/tools/common/Driver.cs @@ -28,6 +28,7 @@ public partial class Driver { public static bool Force { get; set; } static Version min_xcode_version = new Version (6, 0); +#if !NET public static int Main (string [] args) { try { @@ -322,6 +323,7 @@ static bool ParseOptions (Application app, Mono.Options.OptionSet options, strin return false; } +#endif // !NET static int Jobs; public static int Concurrency { From 17aabebb038741bb224e3c73f29f9d33bb7c9cff Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 19/48] [dotnet-linker] Add a using so that the static registrar sees LinkContext extension methods in the Mono.Linker namespace --- tools/common/StaticRegistrar.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 24cbd18108e8..7296f56e01be 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -20,6 +20,7 @@ using Foundation; using ObjCRuntime; using Mono.Cecil; +using Mono.Linker; using Mono.Tuner; namespace Registrar { From 3046ebc1d62e424376740be4ddfe964a3a368452 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 13 Aug 2020 18:56:36 +0200 Subject: [PATCH 20/48] [dotnet-linker] Add TargetFramework to the configuration and set Driver.TargetFramework. This way we can use the shared Application.Platform implementation. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 1 + tools/dotnet-linker/Compat.cs | 4 ---- tools/dotnet-linker/LinkerConfiguration.cs | 8 ++++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 635443931ed8..fc6768aec305 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -137,6 +137,7 @@ PlatformAssembly=$(_PlatformAssemblyName).dll SdkVersion=$(_SdkVersion) TargetArchitectures=$(TargetArchitectures) + TargetFramework=$(_ComputedTargetFrameworkMoniker) Verbosity=$(_BundlerVerbosity) <_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --custom-data "LinkerOptionsFile=$(_CustomLinkerOptionsFile)" diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 046ebec6f0df..4250a85c5456 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -37,10 +37,6 @@ public void SelectRegistrar () { throw new NotImplementedException (); } - - public ApplePlatform Platform { - get { return Configuration.Platform; } - } } public partial class Driver { diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index c8bd2be1b25b..3efa625a1f1a 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -120,6 +120,11 @@ public static LinkerConfiguration GetInstance (LinkContext context) Abis.Add (a); } break; + case "TargetFramework": + if (!TargetFramework.TryParse (value, out var tf)) + throw new InvalidOperationException ($"Invalid TargetFramework '{value}' in {linker_file}"); + Driver.TargetFramework = TargetFramework.Parse (value); + break; case "Verbosity": if (!int.TryParse (value, out var verbosity)) throw new InvalidOperationException ($"Invalid Verbosity '{value}' in {linker_file}"); @@ -149,6 +154,9 @@ public static LinkerConfiguration GetInstance (LinkContext context) default: break; } + + if (Driver.TargetFramework.Platform != Platform) + throw ErrorHelper.CreateError (99, "Inconsistent platforms. TargetFramework={0}, Platform={1}", Driver.TargetFramework.Platform, Platform); } public void Write () From 29fd334456af02b216c8a020c7b0190a66a7aba9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 14 Aug 2020 17:09:40 +0200 Subject: [PATCH 21/48] [dotnet-linker] Implement Application.ProductName instead of Application.GetProductName in dotnet-linker work better with the shared code. --- tools/dotnet-linker/Compat.cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 4250a85c5456..8ca426c02e83 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -19,17 +19,20 @@ public Application (LinkerConfiguration configuration, string[] arguments) this.Configuration = configuration; } - public string GetProductName () - { - switch (Platform) { - case ApplePlatform.iOS: - case ApplePlatform.TVOS: - case ApplePlatform.WatchOS: - return "Xamarin.iOS"; - case ApplePlatform.MacOSX: - return "Xamarin.Mac"; - default: - throw ErrorHelper.CreateError (177, Errors.MX0177 /* "Unknown platform: {0}. This usually indicates a bug; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case." */, Platform); + public string ProductName { + get { + switch (Platform) { + case ApplePlatform.iOS: + return "Microsoft.iOS"; + case ApplePlatform.TVOS: + return "Microsoft.tvOS"; + case ApplePlatform.WatchOS: + return "Microsoft.watchOS"; + case ApplePlatform.MacOSX: + return "Microsoft.macOS"; + default: + throw ErrorHelper.CreateError (177, Errors.MX0177 /* "Unknown platform: {0}. This usually indicates a bug; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case." */, Platform); + } } } From ebfc7e131c3c588437b6a750455f627a8f22309b Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 22/48] [mtouch/mmp] Simplify some code to add assemblies to a target. --- tools/common/Target.cs | 7 +++++++ tools/mmp/driver.cs | 3 +-- tools/mtouch/Target.mtouch.cs | 6 ++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/common/Target.cs b/tools/common/Target.cs index 7d0b86af8966..87368ff87230 100644 --- a/tools/common/Target.cs +++ b/tools/common/Target.cs @@ -86,6 +86,13 @@ public Target (Application app) this.StaticRegistrar = new StaticRegistrar (this); } + public Assembly AddAssembly (AssemblyDefinition assembly) + { + var asm = new Assembly (this, assembly); + Assemblies.Add (asm); + return asm; + } + // This will find the link context, possibly looking in container targets. public PlatformLinkContext GetLinkContext () { diff --git a/tools/mmp/driver.cs b/tools/mmp/driver.cs index f885579f843a..23f4ebbfadc9 100644 --- a/tools/mmp/driver.cs +++ b/tools/mmp/driver.cs @@ -1609,9 +1609,8 @@ static void ProcessAssemblyReferences (AssemblyDefinition assembly) { Target.PrintAssemblyReferences (assembly); - var asm = new Assembly (BuildTarget, assembly); + var asm = BuildTarget.AddAssembly (assembly); asm.ComputeSatellites (); - BuildTarget.Assemblies.Add (asm); resolved_assemblies.Add (fqname); diff --git a/tools/mtouch/Target.mtouch.cs b/tools/mtouch/Target.mtouch.cs index 09f8af52d605..361bbc1e5000 100644 --- a/tools/mtouch/Target.mtouch.cs +++ b/tools/mtouch/Target.mtouch.cs @@ -336,9 +336,8 @@ public void ComputeListOfAssemblies () // Load all the assemblies in the cached list of assemblies foreach (var assembly in assemblies) { var ad = ManifestResolver.Load (assembly); - var asm = new Assembly (this, ad); + var asm = AddAssembly (ad); asm.ComputeSatellites (); - this.Assemblies.Add (asm); } return; } @@ -381,9 +380,8 @@ void ComputeListOfAssemblies (HashSet assemblies, AssemblyDefinition ass PrintAssemblyReferences (assembly); assemblies.Add (fqname); - var asm = new Assembly (this, assembly); + var asm = AddAssembly (assembly); asm.ComputeSatellites (); - this.Assemblies.Add (asm); var main = assembly.MainModule; foreach (AssemblyNameReference reference in main.AssemblyReferences) { From 7a446f6531b2576cdee88686ebf398735a836436 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 23/48] [dotnet-linker] Add a LoadNonSkippedAssembliesStep. This step is used to load the result of the linker into our Application/Target/Assembly instances. --- tools/dotnet-linker/LinkerConfiguration.cs | 10 ++++- tools/dotnet-linker/SetupStep.cs | 1 + .../Steps/LoadNonSkippedAssembliesStep.cs | 40 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 3efa625a1f1a..4534bf0cdc9c 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -5,11 +5,14 @@ using System.Runtime.CompilerServices; using System.Xml.Linq; +using Mono.Cecil; using Mono.Linker; using Xamarin.Bundler; using Xamarin.Utils; +using ObjCRuntime; + namespace Xamarin.Linker { public class LinkerConfiguration { public List Abis; @@ -29,12 +32,17 @@ public class LinkerConfiguration { public Application Application { get; private set; } public Target Target { get; private set; } + public LinkContext Context { get; private set; } + public static LinkerConfiguration GetInstance (LinkContext context) { if (!configurations.TryGetValue (context, out var instance)) { if (!context.TryGetCustomData ("LinkerOptionsFile", out var linker_options_file)) throw new Exception ($"No custom linker options file was passed to the linker (using --custom-data LinkerOptionsFile=..."); - instance = new LinkerConfiguration (linker_options_file); + instance = new LinkerConfiguration (linker_options_file) { + Context = context, + }; + configurations.Add (context, instance); } diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs index 96884a3ac46e..c86b2b97a185 100644 --- a/tools/dotnet-linker/SetupStep.cs +++ b/tools/dotnet-linker/SetupStep.cs @@ -29,6 +29,7 @@ protected override void Process () // Don't use --custom-step to load each step, because this assembly // is loaded into the current process once per --custom-step, // which makes it very difficult to share state between steps. + Steps.Add (new LoadNonSkippedAssembliesStep ()); Steps.Add (new GenerateMainStep ()); Steps.Add (new GatherFrameworksStep ()); diff --git a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs new file mode 100644 index 000000000000..30dddea1085c --- /dev/null +++ b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs @@ -0,0 +1,40 @@ +using System; + +using Mono.Cecil; +using Mono.Linker; + +namespace Xamarin.Linker { + // List all the assemblies we care about (i.e. the ones that have not been linked away) + public class LoadNonSkippedAssembliesStep : ConfigurationAwareStep { + + protected override void ProcessAssembly (AssemblyDefinition assembly) + { + base.ProcessAssembly (assembly); + + // Figure out if an assembly is linked away or not + if (Context.Annotations.HasAction (assembly)) { + var action = Context.Annotations.GetAction (assembly); + switch (action) { + case AssemblyAction.Delete: + case AssemblyAction.Skip: + break; + case AssemblyAction.Copy: + case AssemblyAction.CopyUsed: + case AssemblyAction.Link: + case AssemblyAction.Save: + Configuration.Target.AddAssembly (assembly); + break; + case AssemblyAction.AddBypassNGen: // This should be turned into Save or Delete + case AssemblyAction.AddBypassNGenUsed: // This should be turned into Save or Delete + // Log this? + break; + default: + // Log this? + break; + } + } else { + // Log this? + } + } + } +} From dd3967bfafbe567abb318efd8464fe1aaa9112f8 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 24/48] [dotnet-linker] Work around a linker bug where the linker won't tell us the original path of an assembly. We need the path for several reasons, so poke into the linker using reflection to find the information we need. --- tools/dotnet-linker/LinkerConfiguration.cs | 9 +++++++++ .../dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 4534bf0cdc9c..16e00464d107 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -184,6 +184,15 @@ public void Write () } } + public string GetAssemblyFileName (AssemblyDefinition assembly) + { + // See: https://github.com/mono/linker/issues/1313 + // Call LinkContext.Resolver.GetAssemblyFileName (https://github.com/mono/linker/blob/da2cc0fcd6c3a8e8e5d1b5d4a655f3653baa8980/src/linker/Linker/AssemblyResolver.cs#L88) using reflection. + var resolver = typeof (LinkContext).GetProperty ("Resolver").GetValue (Context); + var filename = (string) resolver.GetType ().GetMethod ("GetAssemblyFileName", new Type [] { typeof (AssemblyDefinition) }).Invoke (resolver, new object [] { assembly }); + return filename; + } + public void WriteOutputForMSBuild (string itemName, List items) { var xmlNs = XNamespace.Get ("http://schemas.microsoft.com/developer/msbuild/2003"); diff --git a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs index 30dddea1085c..a6a7d99054b6 100644 --- a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs +++ b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs @@ -22,7 +22,9 @@ protected override void ProcessAssembly (AssemblyDefinition assembly) case AssemblyAction.CopyUsed: case AssemblyAction.Link: case AssemblyAction.Save: - Configuration.Target.AddAssembly (assembly); + var ad = Configuration.Target.AddAssembly (assembly); + var assemblyFileName = Configuration.GetAssemblyFileName (assembly); + ad.FullPath = assemblyFileName; break; case AssemblyAction.AddBypassNGen: // This should be turned into Save or Delete case AssemblyAction.AddBypassNGenUsed: // This should be turned into Save or Delete From e83dd1071bfbd411cb7d92bd033e56be075edccf Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 25/48] [bundlers] Refactor code to cope with not knowing whether a particular assembly is a framework assembly or not. Turns out we don't actually _need_ to know, in every case we use this knowledge it's a performance improvement to not process the framework assemblies, so skip this for now, since there's no harm done (except to the planet) to do some extra processing by processing all assemblies in these cases. --- tools/common/Assembly.cs | 10 +++++++--- tools/mtouch/mtouch.cs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index 0f3054e8c2dc..d5c7af2027a2 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -55,16 +55,20 @@ public partial class Assembly public AssemblyDefinition AssemblyDefinition; public Target Target; - public bool IsFrameworkAssembly { get { return is_framework_assembly.Value; } } + public bool? IsFrameworkAssembly { get { return is_framework_assembly; } } public string FullPath { get { return full_path; } set { full_path = value; - if (!is_framework_assembly.HasValue) { + if (!is_framework_assembly.HasValue && !string.IsNullOrEmpty (full_path)) { var real_full_path = Target.GetRealPath (full_path); +#if NET + // TODO: Figure out how to determine whether an assembly is a framework assembly or not (but it's not urgent to implement, it's just a performance improvement) +#else is_framework_assembly = real_full_path.StartsWith (Path.GetDirectoryName (Path.GetDirectoryName (Target.Resolver.FrameworkDirectory)), StringComparison.Ordinal); +#endif } } } @@ -143,7 +147,7 @@ void AddResourceToBeRemoved (string resource) public void ExtractNativeLinkInfo () { // ignore framework assemblies, they won't have any LinkWith attributes - if (IsFrameworkAssembly) + if (IsFrameworkAssembly == true) return; var assembly = AssemblyDefinition; diff --git a/tools/mtouch/mtouch.cs b/tools/mtouch/mtouch.cs index c7d569658c8d..3c8dca4d8a0e 100644 --- a/tools/mtouch/mtouch.cs +++ b/tools/mtouch/mtouch.cs @@ -1146,7 +1146,7 @@ public static void CalculateCompilerPath (Application app) static bool IsBoundAssembly (Assembly s) { - if (s.IsFrameworkAssembly) + if (s.IsFrameworkAssembly == true) return false; AssemblyDefinition ad = s.AssemblyDefinition; From 6f1b1c62bb576dd4b9231cf637be3e372779301e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 26/48] [mtouch/mmp] Make it possible to compute assembly identity even if an assembly doesn't have a filename. In .NET AssemblyDefinitions don't have MainModule.FileName set, because they're not loaded using FileStreams. Ref: https://github.com/mono/linker/issues/1313 --- tools/common/Assembly.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index d5c7af2027a2..6aceca94f358 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -73,11 +73,13 @@ public string FullPath { } } public string FileName { get { return Path.GetFileName (FullPath); } } - public string Identity { get { return GetIdentity (FullPath); } } + public string Identity { get { return GetIdentity (AssemblyDefinition); } } public static string GetIdentity (AssemblyDefinition ad) { - return Path.GetFileNameWithoutExtension (ad.MainModule.FileName); + if (!string.IsNullOrEmpty (ad.MainModule.FileName)) + return Path.GetFileNameWithoutExtension (ad.MainModule.FileName); + return ad.Name.Name; } public static string GetIdentity (string path) From 641a3fb4fc0bc41e31d101c00c15d1100cd4cfda Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 13 Aug 2020 15:51:47 +0200 Subject: [PATCH 27/48] [msbuild] Add support for passing LinkerFlags to the LinkNativeCode task --- .../Tasks/LinkNativeCodeTaskBase.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs index 0441bcb4130a..e2e9ba2dd54e 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs @@ -8,6 +8,8 @@ namespace Xamarin.MacDev.Tasks { public abstract class LinkNativeCodeTaskBase : XamarinTask { #region Inputs + public ITaskItem[] LinkerFlags { get; set; } + public ITaskItem[] LinkWithLibraries { get; set; } [Required] @@ -90,6 +92,11 @@ public override bool Execute () arguments.Add ("-o"); arguments.Add (Path.GetFullPath (OutputFile)); + if (LinkerFlags != null) { + foreach (var flag in LinkerFlags) + arguments.Add (flag.ItemSpec); + } + ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath).Wait (); return !Log.HasLoggedErrors; From 61b3cec57aedf5ed8d9a412e7c6213c7dcc82153 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 13 Aug 2020 15:22:09 +0200 Subject: [PATCH 28/48] [msbuild] Add support for passing -force_load to the native linker in the LinkNativeCode task. --- .../Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs index e2e9ba2dd54e..1b1b82f1338a 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/LinkNativeCodeTaskBase.cs @@ -50,6 +50,9 @@ public override bool Execute () var libExtension = Path.GetExtension (lib).ToLowerInvariant (); switch (libExtension) { case ".a": + var forceLoad = string.Equals (libSpec.GetMetadata ("ForceLoad"), "true", StringComparison.OrdinalIgnoreCase); + if (forceLoad) + arguments.Add ("-force_load"); arguments.Add (lib); break; case ".dylib": From d630495a5d976b9ff534e5d003413ff5b18d7753 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 29/48] [dotnet-linker] Add error reporting to ConfigurationAwareStep --- tools/dotnet-linker/Steps/ConfigurationAwareStep.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs index f784a673306c..04c96bcd23be 100644 --- a/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs +++ b/tools/dotnet-linker/Steps/ConfigurationAwareStep.cs @@ -1,9 +1,20 @@ +using System; +using System.Collections.Generic; using Mono.Linker.Steps; +using Xamarin.Bundler; + namespace Xamarin.Linker { public abstract class ConfigurationAwareStep : BaseStep { public LinkerConfiguration Configuration { get { return LinkerConfiguration.GetInstance (Context); } } + + protected void Report (List exceptions) + { + // Maybe there's a better way to show errors that integrates with the linker? + // We can't just throw an exception or exit here, since there might be only warnings in the list of exceptions. + ErrorHelper.Show (exceptions); + } } } From 1d303fe856ba6b660430b8bfa7850803b319c55f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 30/48] [dotnet-linker] Add an ExtractBindingLibrariesStep. This step will extract native libraries from binding assemblies, and adjust the native linker flags to link with those native libraries. --- tools/dotnet-linker/SetupStep.cs | 1 + .../Steps/ExtractBindingLibrariesStep.cs | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs index c86b2b97a185..ace37ceb6a99 100644 --- a/tools/dotnet-linker/SetupStep.cs +++ b/tools/dotnet-linker/SetupStep.cs @@ -30,6 +30,7 @@ protected override void Process () // is loaded into the current process once per --custom-step, // which makes it very difficult to share state between steps. Steps.Add (new LoadNonSkippedAssembliesStep ()); + Steps.Add (new ExtractBindingLibrariesStep ()); Steps.Add (new GenerateMainStep ()); Steps.Add (new GatherFrameworksStep ()); diff --git a/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs new file mode 100644 index 000000000000..0327986f0765 --- /dev/null +++ b/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; + +namespace Xamarin.Linker { + + public class ExtractBindingLibrariesStep : ConfigurationAwareStep { + protected override void EndProcess () + { + base.EndProcess (); + + // No attributes are currently linked away, which means we don't need to worry about linked away LinkWith attributes. + // Ref: https://github.com/mono/linker/issues/952 (still open as of this writing). + var exceptions = new List (); + Configuration.Target.ExtractNativeLinkInfo (exceptions); + Report (exceptions); + + // Tell MSBuild about the native libraries we found + var linkWith = new List (); + foreach (var asm in Configuration.Target.Assemblies) { + foreach (var arg in asm.LinkWith) { + var item = new MSBuildItem { + Include = arg, + Metadata = new Dictionary { + { "ForceLoad", "true" }, + { "Assembly", asm.Identity }, + }, + }; + linkWith.Add (item); + } + } + Configuration.WriteOutputForMSBuild ("_BindingLibraryLinkWith", linkWith); + + // Tell MSBuild about the frameworks libraries we found + var frameworks = new List (); + foreach (var asm in Configuration.Target.Assemblies) { + foreach (var fw in asm.Frameworks) { + var item = new MSBuildItem { + Include = fw, + Metadata = new Dictionary { + { "Assembly", asm.Identity }, + }, + }; + frameworks.Add (item); + } + foreach (var fw in asm.WeakFrameworks) { + var item = new MSBuildItem { + Include = fw, + Metadata = new Dictionary { + { "IsWeak", "true " }, + { "Assembly", asm.Identity }, + }, + }; + frameworks.Add (item); + } + } + Configuration.WriteOutputForMSBuild ("_BindingLibraryFrameworks", frameworks); + + // Tell MSBuild about any additional linker flags we found + var linkerFlags = new List (); + foreach (var asm in Configuration.Target.Assemblies) { + if (asm.LinkerFlags == null) + continue; + foreach (var arg in asm.LinkerFlags) { + var item = new MSBuildItem { + Include = arg, + Metadata = new Dictionary { + { "Assembly", asm.Identity }, + }, + }; + linkerFlags.Add (item); + } + } + Configuration.WriteOutputForMSBuild ("_BindingLibraryLinkerFlags", linkerFlags); + } + } +} From b8482ca160cb521a824f45523f8de084fcf59b23 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 17 Jul 2020 16:38:40 +0200 Subject: [PATCH 31/48] [dotnet] Read native linker flags from binding libraries from the managed linker. --- dotnet/targets/Xamarin.Shared.Sdk.targets | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index fc6768aec305..333eaf401f4f 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -182,6 +182,18 @@ + + + + + + + + + + + + @@ -316,8 +328,9 @@ Date: Fri, 14 Aug 2020 13:42:53 +0200 Subject: [PATCH 32/48] [dotnet-linker] Propagate the verbosity elsewhere. --- tools/dotnet-linker/LinkerConfiguration.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 16e00464d107..b77bd61c83d4 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -165,6 +165,9 @@ public static LinkerConfiguration GetInstance (LinkContext context) if (Driver.TargetFramework.Platform != Platform) throw ErrorHelper.CreateError (99, "Inconsistent platforms. TargetFramework={0}, Platform={1}", Driver.TargetFramework.Platform, Platform); + + Driver.Verbosity = Verbosity; + ErrorHelper.Verbosity = Verbosity; } public void Write () From 5795f11bf0c9966bfa0fd950eef8dd5bde24f8f5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 17 Aug 2020 09:30:33 +0200 Subject: [PATCH 33/48] [tests] Adjust the bindings-test2 project to work with xharness. xharness needs to inspect project files, but can't do so through imported projects, so move some of the logic from the imported shared.csproj to the main csproj. --- tests/bindings-test2/dotnet/iOS/bindings-test2.csproj | 5 +++++ tests/bindings-test2/dotnet/macOS/bindings-test2.csproj | 5 +++++ tests/bindings-test2/dotnet/shared.targets | 7 ------- tests/bindings-test2/dotnet/tvOS/bindings-test2.csproj | 5 +++++ tests/bindings-test2/dotnet/watchOS/bindings-test2.csproj | 5 +++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/bindings-test2/dotnet/iOS/bindings-test2.csproj b/tests/bindings-test2/dotnet/iOS/bindings-test2.csproj index 5a7c3cbd3442..662296c7d1dc 100644 --- a/tests/bindings-test2/dotnet/iOS/bindings-test2.csproj +++ b/tests/bindings-test2/dotnet/iOS/bindings-test2.csproj @@ -3,6 +3,11 @@ ios-fat iOS + ..\..\.. + + + + diff --git a/tests/bindings-test2/dotnet/macOS/bindings-test2.csproj b/tests/bindings-test2/dotnet/macOS/bindings-test2.csproj index e4c2fdcd477b..43be3f9d0097 100644 --- a/tests/bindings-test2/dotnet/macOS/bindings-test2.csproj +++ b/tests/bindings-test2/dotnet/macOS/bindings-test2.csproj @@ -3,6 +3,11 @@ macos macOS + ..\..\.. + + + + diff --git a/tests/bindings-test2/dotnet/shared.targets b/tests/bindings-test2/dotnet/shared.targets index db29771015b1..ef600332be1b 100644 --- a/tests/bindings-test2/dotnet/shared.targets +++ b/tests/bindings-test2/dotnet/shared.targets @@ -8,17 +8,10 @@ latest true - $(MSBuildThisFileDirectory)\..\.. $(RootTestsDirectory)\bindings-test2 $(RootTestsDirectory)\test-libraries - - - - - - diff --git a/tests/bindings-test2/dotnet/tvOS/bindings-test2.csproj b/tests/bindings-test2/dotnet/tvOS/bindings-test2.csproj index de9b244243fe..9bf780dbaf79 100644 --- a/tests/bindings-test2/dotnet/tvOS/bindings-test2.csproj +++ b/tests/bindings-test2/dotnet/tvOS/bindings-test2.csproj @@ -3,6 +3,11 @@ tvos-fat tvOS + ..\..\.. + + + + diff --git a/tests/bindings-test2/dotnet/watchOS/bindings-test2.csproj b/tests/bindings-test2/dotnet/watchOS/bindings-test2.csproj index 09be0a846bdc..332cb51a9c89 100644 --- a/tests/bindings-test2/dotnet/watchOS/bindings-test2.csproj +++ b/tests/bindings-test2/dotnet/watchOS/bindings-test2.csproj @@ -3,6 +3,11 @@ watchos-fat watchOS + ..\..\.. + + + + From ea30bc9cea56eb10344c3cb5a933aa361e2b6fbf Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 17 Aug 2020 11:09:06 +0200 Subject: [PATCH 34/48] [xharness] Make sure MSBUILD_EXE_PATH is not set when executing dotnet. Something ends up confused, and dotnet hangs. --- .../Utilities/ProjectFileExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs index 12c914572212..6d35e5a68284 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs @@ -1068,9 +1068,12 @@ public static async Task GetPropertyByMSBuildEvaluationAsync (this XmlDo foreach (var prop in properties) args.Add ($"/p:{prop.Key}={prop.Value}"); args.Add (inspector); + var env = new Dictionary { + { "MSBUILD_EXE_PATH", null }, + }; proc.StartInfo.Arguments = StringUtils.FormatArguments (args); proc.StartInfo.WorkingDirectory = dir; - var rv = await processManager.RunAsync (proc, log, timeout: TimeSpan.FromSeconds (15)); + var rv = await processManager.RunAsync (proc, log, environment_variables: env, timeout: TimeSpan.FromSeconds (15)); if (!rv.Succeeded) throw new Exception ($"Unable to evaluate the property {evaluateProperty}."); return File.ReadAllText (output).Trim (); From 138ebc72885929cf304dff54f35641f1973e3f33 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 17 Aug 2020 19:59:04 +0200 Subject: [PATCH 35/48] [xharness] Bump timeout for the .NET tests. More tests take longer to run! --- 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 281764cf8576..2007e2d15b18 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -223,7 +223,7 @@ Task PopulateTasksAsync () TestProject = buildDotNetTestsProject, Platform = TestPlatform.All, TestName = "DotNet tests", - Timeout = TimeSpan.FromMinutes (5), + Timeout = TimeSpan.FromMinutes (15), Ignored = !IncludeDotNet, }; Tasks.Add (runDotNetTests); From b84e5e80494007e5d942f3797c8cd61ebcbd0dc7 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 18 Aug 2020 11:35:42 +0200 Subject: [PATCH 36/48] [tests] Add a reference to System.Json in the interdependent-binding-projects test. --- .../dotnet/iOS/interdependent-binding-projects.csproj | 2 ++ .../dotnet/tvOS/interdependent-binding-projects.csproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index ae16412d9e85..dd8e86a06e18 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -16,6 +16,8 @@ + + diff --git a/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj index c9fcc5da5596..611b4f3e7e35 100644 --- a/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj @@ -16,6 +16,8 @@ + + From 695ca8d680e3b5c4aa91596144c87ee020dac876 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 18 Aug 2020 15:20:23 +0200 Subject: [PATCH 37/48] [xharness] Don't clone the same project multiple times when reached through different project references. Problem: 1. interdependent-binding-project references binding-test and bindings-test2. 2. bindings-test2 references bindings-test. This means bindings-test is reached through 2 projects: both interdependent-binding-projects and bindings-test2, and previously we'd process each of these references separately, effectively making two separate clones of the bindings-test project. Instead keep track of all referenced projects from the leaf project, and if we encounter a project we've already cloned, use that directly. --- .../TestProject.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs index b6050377fc9b..fe10b822eea0 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs @@ -76,7 +76,13 @@ internal async Task CreateCloneAsync (ILog log, IProcessManager pro return rv; } - public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) + public Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory) + { + var pr = new Dictionary (); + return CreateCopyAsync (log, processManager, test, rootDirectory, pr); + } + + async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITestTask test, string rootDirectory, Dictionary allProjectReferences) { var directory = DirectoryUtilities.CreateTemporaryDirectory (test?.TestName ?? System.IO.Path.GetFileNameWithoutExtension (Path)); Directory.CreateDirectory (directory); @@ -154,8 +160,12 @@ public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITe var projectReferences = new List (); foreach (var pr in doc.GetProjectReferences ()) { - var tp = new TestProject (pr.Replace ('\\', '/')); - await tp.CreateCopyAsync (log, processManager, test, rootDirectory); + var prPath = pr.Replace ('\\', '/'); + if (!allProjectReferences.TryGetValue (prPath, out var tp)) { + tp = new TestProject (pr.Replace ('\\', '/')); + await tp.CreateCopyAsync (log, processManager, test, rootDirectory, allProjectReferences); + allProjectReferences.Add (prPath, tp); + } doc.SetProjectReferenceInclude (pr, tp.Path.Replace ('/', '\\')); projectReferences.Add (tp); } From 8a959d38c77c0d724dadb1f3660c2a2ea2c5f51c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 18 Aug 2020 15:19:49 +0200 Subject: [PATCH 38/48] [xharness] Add some debugging to track down app crash I can't reproduce locally. --- tests/xharness/AppRunner.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/xharness/AppRunner.cs b/tests/xharness/AppRunner.cs index 4ff8c4e85074..18db64edf091 100644 --- a/tests/xharness/AppRunner.cs +++ b/tests/xharness/AppRunner.cs @@ -297,6 +297,8 @@ public async Task RunAsync () args.AddRange (harness.EnvironmentVariables.Select (kvp => new SetEnvVariableArgument (kvp.Key, kvp.Value))); + await processManager.ExecuteCommandAsync ("ls", new string [] { "-laR", AppInformation.LaunchAppPath }, log: MainLog, timeout: TimeSpan.FromSeconds (15)); + if (IsExtension) { switch (AppInformation.Extension) { case Extension.TodayExtension: From f1f802d2bef67bc2b0991cc936a1f4342c2a9975 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 18 Aug 2020 19:10:52 +0200 Subject: [PATCH 39/48] Try not signing to see if that fixes anything. --- .../dotnet/iOS/interdependent-binding-projects.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index dd8e86a06e18..d970d3b6dc80 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -3,7 +3,6 @@ net5.0 Exe - true latest ios-x64 xamarinios10;$(AssetTargetFallback) From 42aac77b4ba7f78ebed026f1f34ed7a32e1251d4 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 07:50:28 +0200 Subject: [PATCH 40/48] [tests] Remove bindings-test2 to see if that fixes the crash. --- tests/interdependent-binding-projects/Main.cs | 2 +- .../dotnet/iOS/interdependent-binding-projects.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/interdependent-binding-projects/Main.cs b/tests/interdependent-binding-projects/Main.cs index 71b7e7861aff..6a8578dbb06d 100644 --- a/tests/interdependent-binding-projects/Main.cs +++ b/tests/interdependent-binding-projects/Main.cs @@ -20,7 +20,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) runner = new TouchRunner (window); runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); - runner.Add (typeof (Xamarin.BindingTests2.BindingTest).Assembly); + // runner.Add (typeof (Xamarin.BindingTests2.BindingTest).Assembly); runner.Add (typeof (Xamarin.BindingTests.ProtocolTest).Assembly); window.RootViewController = new UINavigationController (runner.GetViewController ()); diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index d970d3b6dc80..9b2b0bd0c12d 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -19,7 +19,7 @@ - + From fdf41d9226d2f532aa7ce4e87e3158f7d75e81cf Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 09:12:53 +0200 Subject: [PATCH 41/48] [tests] Remove the other binding project reference as well. --- tests/interdependent-binding-projects/Main.cs | 2 +- .../dotnet/iOS/interdependent-binding-projects.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/interdependent-binding-projects/Main.cs b/tests/interdependent-binding-projects/Main.cs index 6a8578dbb06d..1b3a473828e1 100644 --- a/tests/interdependent-binding-projects/Main.cs +++ b/tests/interdependent-binding-projects/Main.cs @@ -21,7 +21,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) runner = new TouchRunner (window); runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); // runner.Add (typeof (Xamarin.BindingTests2.BindingTest).Assembly); - runner.Add (typeof (Xamarin.BindingTests.ProtocolTest).Assembly); + // runner.Add (typeof (Xamarin.BindingTests.ProtocolTest).Assembly); window.RootViewController = new UINavigationController (runner.GetViewController ()); window.MakeKeyAndVisible (); diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index 9b2b0bd0c12d..72c92274f05e 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -18,7 +18,7 @@ - + From 89303c6bb5d03b8a96f5a5a074ac1b9c87509921 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 12:50:52 +0200 Subject: [PATCH 42/48] Trip down test suite to speed up turnaround --- tests/xharness/Harness.cs | 38 +++++++++++++++---------------- tests/xharness/Jenkins/Jenkins.cs | 34 +++++++++++++-------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 23afae10569a..0fc4cc321f65 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -376,39 +376,39 @@ void AutoConfigureIOS () var fsharp_test_suites = new string [] { "fsharp" }; var fsharp_library_projects = new string [] { "fsharplibrary" }; - foreach (var p in test_suites) - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj"))) { Name = p }); + //foreach (var p in test_suites) + // IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj"))) { Name = p }); foreach (var p in fsharp_test_suites) IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".fsproj"))) { Name = p }); - foreach (var p in library_projects) - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj")), false) { Name = p }); + //foreach (var p in library_projects) + // IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj")), false) { Name = p }); foreach (var p in fsharp_library_projects) IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".fsproj")), false) { Name = p }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "bindings-test", "iOS", "bindings-test.csproj")), false) { Name = "bindings-test" }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); + //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "dotnet", "iOS", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); + //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios-dotnet.csproj"))) { Name = "introspection", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = false, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) { - var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log); - var iosTestProject = new iOSTestProject (monoNativeInfo.ProjectPath) { - MonoNativeInfo = monoNativeInfo, - Name = monoNativeInfo.ProjectName, - SkipwatchOSARM64_32Variation = monoNativeInfo.ProjectName.Contains ("compat"), - }; + //foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) { + // var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log); + // var iosTestProject = new iOSTestProject (monoNativeInfo.ProjectPath) { + // MonoNativeInfo = monoNativeInfo, + // Name = monoNativeInfo.ProjectName, + // SkipwatchOSARM64_32Variation = monoNativeInfo.ProjectName.Contains ("compat"), + // }; - IOSTestProjects.Add (iosTestProject); - } + // IOSTestProjects.Add (iosTestProject); + //} // add all the tests that are using the precompiled mono assemblies var monoImportTestFactory = new BCLTestImportTargetFactory (this); - IOSTestProjects.AddRange (monoImportTestFactory.GetiOSBclTargets ()); + //IOSTestProjects.AddRange (monoImportTestFactory.GetiOSBclTargets ()); WatchOSContainerTemplate = Path.GetFullPath (Path.Combine (RootDirectory, "templates/WatchContainer")); WatchOSAppTemplate = Path.GetFullPath (Path.Combine (RootDirectory, "templates/WatchApp")); diff --git a/tests/xharness/Jenkins/Jenkins.cs b/tests/xharness/Jenkins/Jenkins.cs index 2007e2d15b18..b4cfa0f45839 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -210,23 +210,23 @@ Task PopulateTasksAsync () }; Tasks.Add (runDotNetGenerator); - var buildDotNetTestsProject = new TestProject (Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "dotnet", "UnitTests", "DotNetUnitTests.csproj"))) { - IsDotNetProject = true, - }; - var buildDotNetTests = new DotNetBuildTask (this, testProject: buildDotNetTestsProject, processManager: processManager) { - SpecifyPlatform = false, - Platform = TestPlatform.All, - ProjectConfiguration = "Debug", - Ignored = !IncludeDotNet, - }; - var runDotNetTests = new DotNetTestTask (this, buildDotNetTests, processManager) { - TestProject = buildDotNetTestsProject, - Platform = TestPlatform.All, - TestName = "DotNet tests", - Timeout = TimeSpan.FromMinutes (15), - Ignored = !IncludeDotNet, - }; - Tasks.Add (runDotNetTests); + //var buildDotNetTestsProject = new TestProject (Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "dotnet", "UnitTests", "DotNetUnitTests.csproj"))) { + // IsDotNetProject = true, + //}; + //var buildDotNetTests = new DotNetBuildTask (this, testProject: buildDotNetTestsProject, processManager: processManager) { + // SpecifyPlatform = false, + // Platform = TestPlatform.All, + // ProjectConfiguration = "Debug", + // Ignored = !IncludeDotNet, + //}; + //var runDotNetTests = new DotNetTestTask (this, buildDotNetTests, processManager) { + // TestProject = buildDotNetTestsProject, + // Platform = TestPlatform.All, + // TestName = "DotNet tests", + // Timeout = TimeSpan.FromMinutes (15), + // Ignored = !IncludeDotNet, + //}; + //Tasks.Add (runDotNetTests); var deviceTestFactory = new RunDeviceTasksFactory (); var loaddev = deviceTestFactory.CreateAsync (this, processManager, testVariationsFactory).ContinueWith ((v) => { From fcc40eedc549d32b11a634b3abd33925118ca31e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 12:52:39 +0200 Subject: [PATCH 43/48] Try to make it more like introspection, which seems to work just fine. --- .../iOS/interdependent-binding-projects.csproj | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index 72c92274f05e..deae25de0922 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -9,7 +9,7 @@ ..\..\..\ $(DefaultItemExcludes);packages/**; - $(RootTestsDirectory)\..\product.snk + false @@ -20,6 +20,16 @@ + + + + + + + + + + From 70f85a714558fefb9361eccb2c00cfaf6242dc87 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 13:44:26 +0200 Subject: [PATCH 44/48] Does this crash? --- .../dotnet/iOS/interdependent-binding-projects.csproj | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index deae25de0922..1817e07b37fd 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -20,16 +20,6 @@ - - - - - - - - - - From 1a444fe055ad612887e3263560558eb80418a298 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 14:30:18 +0200 Subject: [PATCH 45/48] What about this? --- .../dotnet/iOS/interdependent-binding-projects.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index 1817e07b37fd..df3795ec8aa0 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -10,6 +10,7 @@ $(DefaultItemExcludes);packages/**; false + $(RootTestsDirectory)\..\product.snk From 6efae5bf7bffe9de10dde31754b3f4ac7ff7c846 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 15:12:15 +0200 Subject: [PATCH 46/48] And now? --- .../dotnet/iOS/interdependent-binding-projects.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index df3795ec8aa0..72c92274f05e 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -9,7 +9,6 @@ ..\..\..\ $(DefaultItemExcludes);packages/**; - false $(RootTestsDirectory)\..\product.snk From e97d27c678660c4a2480dc4c29c82f1ec745d64e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Aug 2020 17:22:52 +0200 Subject: [PATCH 47/48] Revert all the debug code to track down the crash. --- tests/interdependent-binding-projects/Main.cs | 4 +- .../interdependent-binding-projects.csproj | 5 ++- tests/xharness/AppRunner.cs | 2 - tests/xharness/Harness.cs | 38 +++++++++---------- tests/xharness/Jenkins/Jenkins.cs | 34 ++++++++--------- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/tests/interdependent-binding-projects/Main.cs b/tests/interdependent-binding-projects/Main.cs index 1b3a473828e1..71b7e7861aff 100644 --- a/tests/interdependent-binding-projects/Main.cs +++ b/tests/interdependent-binding-projects/Main.cs @@ -20,8 +20,8 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options) runner = new TouchRunner (window); runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); - // runner.Add (typeof (Xamarin.BindingTests2.BindingTest).Assembly); - // runner.Add (typeof (Xamarin.BindingTests.ProtocolTest).Assembly); + runner.Add (typeof (Xamarin.BindingTests2.BindingTest).Assembly); + runner.Add (typeof (Xamarin.BindingTests.ProtocolTest).Assembly); window.RootViewController = new UINavigationController (runner.GetViewController ()); window.MakeKeyAndVisible (); diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index 72c92274f05e..dd8e86a06e18 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -3,6 +3,7 @@ net5.0 Exe + true latest ios-x64 xamarinios10;$(AssetTargetFallback) @@ -18,8 +19,8 @@ - - + + diff --git a/tests/xharness/AppRunner.cs b/tests/xharness/AppRunner.cs index 18db64edf091..4ff8c4e85074 100644 --- a/tests/xharness/AppRunner.cs +++ b/tests/xharness/AppRunner.cs @@ -297,8 +297,6 @@ public async Task RunAsync () args.AddRange (harness.EnvironmentVariables.Select (kvp => new SetEnvVariableArgument (kvp.Key, kvp.Value))); - await processManager.ExecuteCommandAsync ("ls", new string [] { "-laR", AppInformation.LaunchAppPath }, log: MainLog, timeout: TimeSpan.FromSeconds (15)); - if (IsExtension) { switch (AppInformation.Extension) { case Extension.TodayExtension: diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 0fc4cc321f65..23afae10569a 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -376,39 +376,39 @@ void AutoConfigureIOS () var fsharp_test_suites = new string [] { "fsharp" }; var fsharp_library_projects = new string [] { "fsharplibrary" }; - //foreach (var p in test_suites) - // IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj"))) { Name = p }); + foreach (var p in test_suites) + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj"))) { Name = p }); foreach (var p in fsharp_test_suites) IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".fsproj"))) { Name = p }); - //foreach (var p in library_projects) - // IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj")), false) { Name = p }); + foreach (var p in library_projects) + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".csproj")), false) { Name = p }); foreach (var p in fsharp_library_projects) IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, p + "/" + p + ".fsproj")), false) { Name = p }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "bindings-test", "iOS", "bindings-test.csproj")), false) { Name = "bindings-test" }); - //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "interdependent-binding-projects", "dotnet", "iOS", "interdependent-binding-projects.csproj"))) { Name = "interdependent-binding-projects", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); - //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios.csproj"))) { Name = "introspection" }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "introspection", "iOS", "introspection-ios-dotnet.csproj"))) { Name = "introspection", IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = false, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, }); - //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - //IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - //foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) { - // var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log); - // var iosTestProject = new iOSTestProject (monoNativeInfo.ProjectPath) { - // MonoNativeInfo = monoNativeInfo, - // Name = monoNativeInfo.ProjectName, - // SkipwatchOSARM64_32Variation = monoNativeInfo.ProjectName.Contains ("compat"), - // }; + foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) { + var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log); + var iosTestProject = new iOSTestProject (monoNativeInfo.ProjectPath) { + MonoNativeInfo = monoNativeInfo, + Name = monoNativeInfo.ProjectName, + SkipwatchOSARM64_32Variation = monoNativeInfo.ProjectName.Contains ("compat"), + }; - // IOSTestProjects.Add (iosTestProject); - //} + IOSTestProjects.Add (iosTestProject); + } // add all the tests that are using the precompiled mono assemblies var monoImportTestFactory = new BCLTestImportTargetFactory (this); - //IOSTestProjects.AddRange (monoImportTestFactory.GetiOSBclTargets ()); + IOSTestProjects.AddRange (monoImportTestFactory.GetiOSBclTargets ()); WatchOSContainerTemplate = Path.GetFullPath (Path.Combine (RootDirectory, "templates/WatchContainer")); WatchOSAppTemplate = Path.GetFullPath (Path.Combine (RootDirectory, "templates/WatchApp")); diff --git a/tests/xharness/Jenkins/Jenkins.cs b/tests/xharness/Jenkins/Jenkins.cs index b4cfa0f45839..2007e2d15b18 100644 --- a/tests/xharness/Jenkins/Jenkins.cs +++ b/tests/xharness/Jenkins/Jenkins.cs @@ -210,23 +210,23 @@ Task PopulateTasksAsync () }; Tasks.Add (runDotNetGenerator); - //var buildDotNetTestsProject = new TestProject (Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "dotnet", "UnitTests", "DotNetUnitTests.csproj"))) { - // IsDotNetProject = true, - //}; - //var buildDotNetTests = new DotNetBuildTask (this, testProject: buildDotNetTestsProject, processManager: processManager) { - // SpecifyPlatform = false, - // Platform = TestPlatform.All, - // ProjectConfiguration = "Debug", - // Ignored = !IncludeDotNet, - //}; - //var runDotNetTests = new DotNetTestTask (this, buildDotNetTests, processManager) { - // TestProject = buildDotNetTestsProject, - // Platform = TestPlatform.All, - // TestName = "DotNet tests", - // Timeout = TimeSpan.FromMinutes (15), - // Ignored = !IncludeDotNet, - //}; - //Tasks.Add (runDotNetTests); + var buildDotNetTestsProject = new TestProject (Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "dotnet", "UnitTests", "DotNetUnitTests.csproj"))) { + IsDotNetProject = true, + }; + var buildDotNetTests = new DotNetBuildTask (this, testProject: buildDotNetTestsProject, processManager: processManager) { + SpecifyPlatform = false, + Platform = TestPlatform.All, + ProjectConfiguration = "Debug", + Ignored = !IncludeDotNet, + }; + var runDotNetTests = new DotNetTestTask (this, buildDotNetTests, processManager) { + TestProject = buildDotNetTestsProject, + Platform = TestPlatform.All, + TestName = "DotNet tests", + Timeout = TimeSpan.FromMinutes (15), + Ignored = !IncludeDotNet, + }; + Tasks.Add (runDotNetTests); var deviceTestFactory = new RunDeviceTasksFactory (); var loaddev = deviceTestFactory.CreateAsync (this, processManager, testVariationsFactory).ContinueWith ((v) => { From 95bb82863a26f3bde6928405bebcd64c44503530 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 18 Aug 2020 15:19:49 +0200 Subject: [PATCH 48/48] [tests] Make sure the .NET version of the independent-binding-projects test have a unique bundle identifier. Otherwise there could be a problem when installing a test app into the simulator if there's already an existing app there with the same bundle identifer, because that doesn't remove existing files, and if there are existing files in the bundle, the app might end up crashing (in particular there may be files in a .monotouch-32/64 subdirectory which are not removed, and those take precedence when looking for assemblies, eventually causing a conflict). --- .../dotnet/iOS/Info.plist | 19 ++++++++++ .../interdependent-binding-projects.csproj | 4 +-- .../dotnet/macOS/Info.plist | 14 ++++++++ .../interdependent-binding-projects.csproj | 4 +-- .../dotnet/tvOS/Info.plist | 18 ++++++++++ .../interdependent-binding-projects.csproj | 4 +-- .../dotnet/watchOS/Info.plist | 35 +++++++++++++++++++ .../interdependent-binding-projects.csproj | 4 +-- 8 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 tests/interdependent-binding-projects/dotnet/iOS/Info.plist create mode 100644 tests/interdependent-binding-projects/dotnet/macOS/Info.plist create mode 100644 tests/interdependent-binding-projects/dotnet/tvOS/Info.plist create mode 100644 tests/interdependent-binding-projects/dotnet/watchOS/Info.plist diff --git a/tests/interdependent-binding-projects/dotnet/iOS/Info.plist b/tests/interdependent-binding-projects/dotnet/iOS/Info.plist new file mode 100644 index 000000000000..0c59aa4d9d24 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/iOS/Info.plist @@ -0,0 +1,19 @@ + + + + + CFBundleDisplayName + InterdependentBindingProject + CFBundleIdentifier + com.xamarin.dotnet.interdependentbindingprojects + CFBundleName + InterdependentBindingProject + MinimumOSVersion + 7.0 + UIDeviceFamily + + 1 + 2 + + + diff --git a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj index dd8e86a06e18..2f752a63f4eb 100644 --- a/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/iOS/interdependent-binding-projects.csproj @@ -24,9 +24,7 @@ - - Info.plist - + diff --git a/tests/interdependent-binding-projects/dotnet/macOS/Info.plist b/tests/interdependent-binding-projects/dotnet/macOS/Info.plist new file mode 100644 index 000000000000..3a70a4c31924 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/macOS/Info.plist @@ -0,0 +1,14 @@ + + + + + CFBundleDisplayName + InterdependentBindingProject + CFBundleIdentifier + com.xamarin.dotnet.interdependentbindingprojects + CFBundleName + CFBundleIdentifier + LSMinimumSystemVersion + 10.9 + + diff --git a/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj index 4d81ebf640e0..9b8c2d552887 100644 --- a/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/macOS/interdependent-binding-projects.csproj @@ -20,9 +20,7 @@ - - Info.plist - + diff --git a/tests/interdependent-binding-projects/dotnet/tvOS/Info.plist b/tests/interdependent-binding-projects/dotnet/tvOS/Info.plist new file mode 100644 index 000000000000..041970719dff --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/tvOS/Info.plist @@ -0,0 +1,18 @@ + + + + + CFBundleDisplayName + InterdependentBindingProject + CFBundleIdentifier + com.xamarin.dotnet.interdependentbindingprojects + CFBundleName + InterdependentBindingProject + MinimumOSVersion + 9.0 + UIDeviceFamily + + 3 + + + \ No newline at end of file diff --git a/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj index 611b4f3e7e35..7629282f02db 100644 --- a/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/tvOS/interdependent-binding-projects.csproj @@ -24,9 +24,7 @@ - - Info.plist - + diff --git a/tests/interdependent-binding-projects/dotnet/watchOS/Info.plist b/tests/interdependent-binding-projects/dotnet/watchOS/Info.plist new file mode 100644 index 000000000000..1eeb05ec2ea5 --- /dev/null +++ b/tests/interdependent-binding-projects/dotnet/watchOS/Info.plist @@ -0,0 +1,35 @@ + + + + + CFBundleDisplayName + InterdependentBindingProject + CFBundleIdentifier + com.xamarin.dotnet.interdependentbindingprojects_watch.watchkitapp.watchkitextension + CFBundleName + InterdependentBindingProject + MinimumOSVersion + 2.0 + UIDeviceFamily + + 4 + + RemoteInterfacePrincipleClass + InterfaceController + NSExtension + + NSExtensionAttributes + + WKAppBundleIdentifier + com.xamarin.dotnet.interdependentbindingprojects_watch.watchkitapp + + NSExtensionPointIdentifier + com.apple.watchkit + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + + \ No newline at end of file diff --git a/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj b/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj index 4c36213106f0..76227cb41e5c 100644 --- a/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj +++ b/tests/interdependent-binding-projects/dotnet/watchOS/interdependent-binding-projects.csproj @@ -20,9 +20,7 @@ - - Info.plist - +