From a17568e93bc5effee32ce4ac7823f48d67b5cf0f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 20 Jul 2020 18:54:32 +0200 Subject: [PATCH] [xharness] Disable default inclusion behavior for the introspection .NET tests. It gets too annoying to keep track of which files are where with the project cloning we're doing, if files are implicitly included. --- .../iOS/introspection-ios-dotnet.csproj | 33 +++++++ .../TestProject.cs | 90 ++++++++++--------- .../Utilities/ProjectFileExtensions.cs | 8 ++ 3 files changed, 87 insertions(+), 44 deletions(-) diff --git a/tests/introspection/iOS/introspection-ios-dotnet.csproj b/tests/introspection/iOS/introspection-ios-dotnet.csproj index b174c92a949f..9c4c01d2c22f 100644 --- a/tests/introspection/iOS/introspection-ios-dotnet.csproj +++ b/tests/introspection/iOS/introspection-ios-dotnet.csproj @@ -12,6 +12,7 @@ xamarinios10;$(AssetTargetFallback) $(DefaultItemExcludes);packages/**; + false @@ -33,6 +34,18 @@ + + + + + + + + + + + + ApiBaseTest.cs @@ -103,6 +116,26 @@ ApiTypeTest.cs + + + Info.plist + + + + + + + + + + + + + + + + + xamarin1.png diff --git a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs index 1df1bb5d0706..ec81f7a75b8a 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/TestProject.cs @@ -95,50 +95,52 @@ public async Task CreateCopyAsync (ILog log, IProcessManager processManager, ITe doc.ResolveAllPaths (original_path); if (doc.IsDotNetProject ()) { - // Many types of files below the csproj directory are included by default, - // which means that we have to include them manually in the cloned csproj, - // because the cloned project is stored in a very different directory. - var test_dir = System.IO.Path.GetDirectoryName (original_path); - - // Get all the files in the project directory from git - using var process = new Process (); - process.StartInfo.FileName = "git"; - process.StartInfo.Arguments = "ls-files"; - process.StartInfo.WorkingDirectory = test_dir; - var stdout = new MemoryLog () { Timestamp = false }; - var result = await processManager.RunAsync (process, log, stdout, stdout, timeout: TimeSpan.FromSeconds (15)); - if (!result.Succeeded) - throw new Exception ($"Failed to list the files in the directory {test_dir} (TimedOut: {result.TimedOut} ExitCode: {result.ExitCode}):\n{stdout}"); - - var files = stdout.ToString ().Split ('\n'); - foreach (var file in files) { - var ext = System.IO.Path.GetExtension (file); - var full_path = System.IO.Path.Combine (test_dir, file); - var windows_file = full_path.Replace ('/', '\\'); - - if (file.Contains (".xcasset")) { - doc.AddInclude ("ImageAsset", file, windows_file, true); - continue; - } - - switch (ext.ToLowerInvariant ()) { - case ".cs": - doc.AddInclude ("Compile", file, windows_file, true); - break; - case ".plist": - doc.AddInclude ("None", file, windows_file, true); - break; - case ".storyboard": - doc.AddInclude ("InterfaceDefinition", file, windows_file, true); - break; - case ".gitignore": - case ".csproj": - case ".props": // Directory.Build.props - case "": // Makefile - break; // ignore these files - default: - Console.WriteLine ($"Unknown file: {file} (extension: {ext}). There might be a default inclusion behavior for this file."); - break; + if (doc.GetEnableDefaultItems () != false) { + // Many types of files below the csproj directory are included by default, + // which means that we have to include them manually in the cloned csproj, + // because the cloned project is stored in a very different directory. + var test_dir = System.IO.Path.GetDirectoryName (original_path); + + // Get all the files in the project directory from git + using var process = new Process (); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "ls-files"; + process.StartInfo.WorkingDirectory = test_dir; + var stdout = new MemoryLog () { Timestamp = false }; + var result = await processManager.RunAsync (process, log, stdout, stdout, timeout: TimeSpan.FromSeconds (15)); + if (!result.Succeeded) + throw new Exception ($"Failed to list the files in the directory {test_dir} (TimedOut: {result.TimedOut} ExitCode: {result.ExitCode}):\n{stdout}"); + + var files = stdout.ToString ().Split ('\n'); + foreach (var file in files) { + var ext = System.IO.Path.GetExtension (file); + var full_path = System.IO.Path.Combine (test_dir, file); + var windows_file = full_path.Replace ('/', '\\'); + + if (file.Contains (".xcasset")) { + doc.AddInclude ("ImageAsset", file, windows_file, true); + continue; + } + + switch (ext.ToLowerInvariant ()) { + case ".cs": + doc.AddInclude ("Compile", file, windows_file, true); + break; + case ".plist": + doc.AddInclude ("None", file, windows_file, true); + break; + case ".storyboard": + doc.AddInclude ("InterfaceDefinition", file, windows_file, true); + break; + case ".gitignore": + case ".csproj": + case ".props": // Directory.Build.props + case "": // Makefile + break; // ignore these files + default: + Console.WriteLine ($"Unknown file: {file} (extension: {ext}). There might be a default inclusion behavior for this file."); + break; + } } } 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 ef35445eee4a..0648d084329c 100644 --- a/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs +++ b/tests/xharness/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs @@ -588,6 +588,14 @@ public static bool IsDotNetProject (this XmlDocument csproj) return attrib != null; } + public static bool? GetEnableDefaultItems (this XmlDocument csproj) + { + var node = csproj.SelectSingleNode ($"/*/*/*[local-name() = 'EnableDefaultItems']"); + if (node == null) + return null; + return string.Equals (node.InnerText, "true", StringComparison.OrdinalIgnoreCase); + } + static XmlNode GetInfoPListNode (this XmlDocument csproj, bool throw_if_not_found = false) { var logicalNames = csproj.SelectNodes ("//*[local-name() = 'LogicalName']");