From 50bb4912e1a04bb44e3569381428080ac66ed8f6 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 20 Nov 2018 07:06:37 -0500 Subject: [PATCH] Revert "[xharness] Only build the BCL tests when we need them. (#5139)" (#5149) This reverts commit 7277bbcd2b8a9977ec7640b84249c294a3f74371, it breaks building & running the new BCL tests. --- tests/Makefile | 7 +- .../BCLTestImportTargetFactory.cs | 12 +- tests/xharness/Harness.cs | 10 +- tests/xharness/Jenkins.cs | 6 - tests/xharness/TestProject.cs | 1 - .../BCLTestProjectGenerator.cs | 226 +++++++++--------- 6 files changed, 113 insertions(+), 149 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index aa3f1847ef..1be1d6a7e1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -195,14 +195,11 @@ $(TOP)/tools/mtouch/SdkVersions.cs: $(TOP)/tools/common/SdkVersions.cs.in @$(MAKE) -C $(TOP)/src project-files @touch $@ -.stamp-build-mono-unit-tests: $(TOP)/.git/modules/external/mono/HEAD +xharness/xharness.exe: $(wildcard xharness/*.cs) xharness/xharness.csproj $(TOP)/tools/mtouch/SdkVersions.cs test.config test-system.config .stamp-src-project-files make -j8 -C $(TOP)/external/mono/mcs/class -i do-test PROFILE=MONOTOUCH # TODO: This should not be needed and we should get the dlls from the SDK. make -j8 -C $(TOP)/external/mono/mcs/class -i do-xunit-test PROFILE=MONOTOUCH # TODO: This should not be needed and we should get the dlls from the SDK. - nuget restore bcl-test/BCLTests/BCLTests.csproj - $(Q) touch $@ - -xharness/xharness.exe: $(wildcard xharness/*.cs) xharness/xharness.csproj $(TOP)/tools/mtouch/SdkVersions.cs test.config test-system.config .stamp-src-project-files nuget restore xharness/xharness.csproj + nuget restore bcl-test/BCLTests/BCLTests.csproj $(Q_GEN) $(SYSTEM_XIBUILD) -- $(MSBUILD_VERBOSITY_QUIET) xharness/xharness.csproj killall: diff --git a/tests/xharness/BCLTestImporter/BCLTestImportTargetFactory.cs b/tests/xharness/BCLTestImporter/BCLTestImportTargetFactory.cs index a1bf2ac3c4..114719d3f8 100644 --- a/tests/xharness/BCLTestImporter/BCLTestImportTargetFactory.cs +++ b/tests/xharness/BCLTestImporter/BCLTestImportTargetFactory.cs @@ -27,22 +27,16 @@ namespace xharness.BCLTestImporter { } // generate all the different test targets. - public List GetBclTargets (Harness harness) + public List GetBclTargets () { var result = new List (); // generate all projects, then create a new iOSTarget per project - foreach (var (name, path, xunit, platforms, generate) in projectGenerator.GenerateAllTestProjects ()) { + foreach (var (name, path, xunit, platforms) in projectGenerator.GenerateAllTestProjects ()) { var prefix = xunit ? "xUnit" : "NUnit"; result.Add (new iOSTestProject (path) { Name = $"[{prefix}] Mono {name}", SkiptvOSVariation=!platforms.Contains (Platform.TvOS), - SkipwatchOSVariation=!platforms.Contains (Platform.WatchOS), - Dependency = async () => { - var rv = await harness.BuildBclTests (); - if (!rv.Succeeded) - throw new Exception ($"Failed to build BCL tests, exit code: {rv.ExitCode}. Check the harness log for more details."); - await generate (); - }, + SkipwatchOSVariation=!platforms.Contains (Platform.WatchOS) }); } return result; diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 3c3c4d0eda..d7ec7f442a 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -356,7 +356,7 @@ namespace xharness // add all the tests that are using the precompiled mono assemblies var monoImportTestFactory = new BCLTestImportTargetFactory (this); - foreach (var target in monoImportTestFactory.GetBclTargets (this)) { + foreach (var target in monoImportTestFactory.GetBclTargets ()) { IOSTestProjects.Add (target); } @@ -829,14 +829,6 @@ namespace xharness return rv; } - - Task build_bcl_tests; - public Task BuildBclTests () - { - if (build_bcl_tests == null) - build_bcl_tests = ProcessHelper.ExecuteCommandAsync ("make", $".stamp-build-mono-unit-tests -C {StringUtils.Quote (Path.GetFullPath (RootDirectory))}", HarnessLog, TimeSpan.FromMinutes (30)); - return build_bcl_tests; - } } public class CrashReportSnapshot diff --git a/tests/xharness/Jenkins.cs b/tests/xharness/Jenkins.cs index 9ae5da5fe2..aafd17f5ec 100644 --- a/tests/xharness/Jenkins.cs +++ b/tests/xharness/Jenkins.cs @@ -57,7 +57,6 @@ namespace xharness public Devices Devices = new Devices (); List Tasks = new List (); - Dictionary DependencyTasks = new Dictionary (); internal static Resource DesktopResource = new Resource ("Desktop", Environment.ProcessorCount); @@ -349,7 +348,6 @@ namespace xharness Platform = pair.Item2, Ignored = pair.Item3, TestName = project.Name, - Dependency = project.Dependency, }; derived.CloneTestProject (pair.Item1); var simTasks = CreateRunSimulatorTaskAsync (derived); @@ -2208,7 +2206,6 @@ function toggleAll (show) public string ProjectPlatform; public Dictionary Environment = new Dictionary (); - public Func Dependency; // a task that's feteched and awaited before this task's ExecuteAsync method public Task InitialTask; // a task that's executed before this task's ExecuteAsync method. public Task CompletedTask; // a task that's executed after this task's ExecuteAsync method. @@ -2405,9 +2402,6 @@ function toggleAll (show) ExecutionResult = (ExecutionResult & ~TestExecutingResult.StateMask) | TestExecutingResult.InProgress; try { - if (Dependency != null) - await Dependency (); - if (InitialTask != null) await InitialTask; diff --git a/tests/xharness/TestProject.cs b/tests/xharness/TestProject.cs index b9bdc123fa..67a5d50102 100644 --- a/tests/xharness/TestProject.cs +++ b/tests/xharness/TestProject.cs @@ -18,7 +18,6 @@ namespace xharness public bool IsNUnitProject; public bool GenerateVariations = true; public string [] Configurations; - public Func Dependency; public IEnumerable ProjectReferences; diff --git a/tools/bcl-test-importer/BCLTestImporter/BCLTestProjectGenerator.cs b/tools/bcl-test-importer/BCLTestImporter/BCLTestProjectGenerator.cs index f21e63632e..fce1b580bd 100644 --- a/tools/bcl-test-importer/BCLTestImporter/BCLTestProjectGenerator.cs +++ b/tools/bcl-test-importer/BCLTestImporter/BCLTestProjectGenerator.cs @@ -292,68 +292,10 @@ namespace BCLTestImporter { return false; } - async Task GenerateWatch (string generatedDir, BCLTestProjectDefinition projectDefinition, string rootProjectPath, (string name, string[] assemblies) def) - { - var generatedCodeDir = Path.Combine (generatedDir, projectDefinition.Name); - if (!Directory.Exists (generatedCodeDir)) { - Directory.CreateDirectory (generatedCodeDir); - } - var registerTypePath = Path.Combine (generatedCodeDir, "RegisterType.cs"); - var typesPerAssembly = projectDefinition.GetTypeForAssemblies (MonoRootPath, Platform.WatchOS); - var registerCode = await RegisterTypeGenerator.GenerateCodeAsync (typesPerAssembly, - projectDefinition.IsXUnit, RegisterTypesTemplatePath); - using (var file = new StreamWriter (registerTypePath, false)) { // false is do not append - await file.WriteAsync (registerCode); - } - // create the plist for each of the apps - var projectData = new Dictionary (); - foreach (var appType in new [] { WatchAppType.Extension, WatchAppType.App }) { - (string plist, string project) data; - var plistTemplate = Path.Combine (PlistTemplateRootPath, watchOSPlistTemplateMatches [appType]); - var plist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (plistTemplate, projectDefinition.Name); - data.plist = GetPListPath (generatedCodeDir, appType); - using (var file = new StreamWriter (data.plist, false)) { // false is do not append - await file.WriteAsync (plist); - } - - string generatedProject; - var projetTemplate = Path.Combine (ProjectTemplateRootPath, watchOSProjectTemplateMatches [appType]); - switch (appType) { - case WatchAppType.App: - generatedProject = await GenerateWatchAppAsync (projectDefinition.Name, projetTemplate, data.plist); - break; - default: - generatedProject = await GenerateWatchExtensionAsync (projectDefinition.Name, projetTemplate, data.plist, registerTypePath, projectDefinition.GetAssemblyInclusionInformation (MonoRootPath, Platform.WatchOS)); - break; - } - data.project = GetProjectPath (projectDefinition.Name, appType); - using (var file = new StreamWriter (data.project, false)) { // false is do not append - await file.WriteAsync (generatedProject); - } - - projectData [appType] = data; - } // foreach app type - - var rootPlistTemplate = Path.Combine (PlistTemplateRootPath, plistTemplateMatches [Platform.WatchOS]); - var rootPlist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (rootPlistTemplate, projectDefinition.Name); - var infoPlistPath = GetPListPath (generatedCodeDir, Platform.WatchOS); - using (var file = new StreamWriter (infoPlistPath, false)) { // false is do not append - await file.WriteAsync (rootPlist); - } - - var projectTemplatePath = Path.Combine (ProjectTemplateRootPath, projectTemplateMatches [Platform.WatchOS]); - using (var file = new StreamWriter (rootProjectPath, false)) // false is do not append - using (var reader = new StreamReader (projectTemplatePath)) { - var template = await reader.ReadToEndAsync (); - var generatedRootProject = GenerateWatchProject (def.name, template, infoPlistPath); - await file.WriteAsync (generatedRootProject); - } - } - - List<(string name, string path, bool xunit, Func generate)> GenerateWatchOSTestProjects ( + async Task> GenerateWatchOSTestProjectsAsync ( IEnumerable<(string name, string[] assemblies)> projects, string generatedDir) { - var projectPaths = new List<(string name, string path, bool xunit, Func generate)> (); + var projectPaths = new List<(string name, string path, bool xunit)> (); foreach (var def in projects) { // each watch os project requires 3 different ones: // 1. The app @@ -366,56 +308,75 @@ namespace BCLTestImporter { if (!projectDefinition.Validate ()) throw new InvalidOperationException ("xUnit and NUnit assemblies cannot be mixed in a test project."); - // we have the 3 projects we depend on, we need the root one, the one that will be used by harness + var generatedCodeDir = Path.Combine (generatedDir, projectDefinition.Name); + if (!Directory.Exists (generatedCodeDir)) { + Directory.CreateDirectory (generatedCodeDir); + } + var registerTypePath = Path.Combine (generatedCodeDir, "RegisterType.cs"); + var typesPerAssembly = projectDefinition.GetTypeForAssemblies (MonoRootPath, Platform.WatchOS); + var registerCode = await RegisterTypeGenerator.GenerateCodeAsync (typesPerAssembly, + projectDefinition.IsXUnit, RegisterTypesTemplatePath); + using (var file = new StreamWriter (registerTypePath, false)) { // false is do not append + await file.WriteAsync (registerCode); + } + // create the plist for each of the apps + var projectData = new Dictionary (); + foreach (var appType in new [] {WatchAppType.Extension, WatchAppType.App}) { + (string plist, string project) data; + var plistTemplate = Path.Combine (PlistTemplateRootPath, watchOSPlistTemplateMatches[appType]); + var plist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (plistTemplate, projectDefinition.Name); + data.plist = GetPListPath (generatedCodeDir, appType); + using (var file = new StreamWriter (data.plist, false)) { // false is do not append + await file.WriteAsync (plist); + } + + string generatedProject; + var projetTemplate = Path.Combine (ProjectTemplateRootPath, watchOSProjectTemplateMatches[appType]); + switch (appType) { + case WatchAppType.App: + generatedProject = await GenerateWatchAppAsync (projectDefinition.Name, projetTemplate, data.plist); + break; + default: + generatedProject = await GenerateWatchExtensionAsync (projectDefinition.Name, projetTemplate, data.plist, registerTypePath, projectDefinition.GetAssemblyInclusionInformation (MonoRootPath, Platform.WatchOS)); + break; + } + data.project = GetProjectPath (projectDefinition.Name, appType); + using (var file = new StreamWriter (data.project, false)) { // false is do not append + await file.WriteAsync (generatedProject); + } + + projectData[appType] = data; + } // foreach app type + + var rootPlistTemplate = Path.Combine (PlistTemplateRootPath, plistTemplateMatches[Platform.WatchOS]); + var rootPlist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (rootPlistTemplate, projectDefinition.Name); + var infoPlistPath = GetPListPath (generatedCodeDir, Platform.WatchOS); + using (var file = new StreamWriter (infoPlistPath, false)) { // false is do not append + await file.WriteAsync (rootPlist); + } + + var projectTemplatePath = Path.Combine (ProjectTemplateRootPath, projectTemplateMatches[Platform.WatchOS]); var rootProjectPath = GetProjectPath (projectDefinition.Name, Platform.WatchOS); - var generate = new Func (() => { - return GenerateWatch (generatedDir, projectDefinition, rootProjectPath, def); - }); - projectPaths.Add ((name: projectDefinition.Name, path: rootProjectPath, xunit: projectDefinition.IsXUnit, generate: generate)); + using (var file = new StreamWriter (rootProjectPath, false)) // false is do not append + using (var reader = new StreamReader (projectTemplatePath)){ + var template = await reader.ReadToEndAsync (); + var generatedRootProject = GenerateWatchProject (def.name, template, infoPlistPath); + await file.WriteAsync (generatedRootProject); + } + + // we have the 3 projects we depend on, we need the root one, the one that will be used by harness + projectPaths.Add ((name: projectDefinition.Name, path: rootProjectPath, xunit: projectDefinition.IsXUnit)); } // foreach project return projectPaths; } - - async Task Generate (string generatedDir, BCLTestProjectDefinition projectDefinition, string projectPath, Platform platform) - { - // generate the required type registration info - var generatedCodeDir = Path.Combine (generatedDir, projectDefinition.Name); - if (!Directory.Exists (generatedCodeDir)) { - Directory.CreateDirectory (generatedCodeDir); - } - var registerTypePath = Path.Combine (generatedCodeDir, "RegisterType.cs"); - - var typesPerAssembly = projectDefinition.GetTypeForAssemblies (MonoRootPath, platform); - var registerCode = await RegisterTypeGenerator.GenerateCodeAsync (typesPerAssembly, - projectDefinition.IsXUnit, RegisterTypesTemplatePath); - - using (var file = new StreamWriter (registerTypePath, false)) { // false is do not append - await file.WriteAsync (registerCode); - } - - var plistTemplate = Path.Combine (PlistTemplateRootPath, plistTemplateMatches [platform]); - var plist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (plistTemplate, projectDefinition.Name); - var infoPlistPath = GetPListPath (generatedCodeDir, platform); - using (var file = new StreamWriter (infoPlistPath, false)) { // false is do not append - await file.WriteAsync (plist); - } - - var projectTemplatePath = Path.Combine (ProjectTemplateRootPath, projectTemplateMatches [platform]); - var generatedProject = await GenerateAsync (projectDefinition.Name, registerTypePath, - projectDefinition.GetAssemblyInclusionInformation (MonoRootPath, platform), projectTemplatePath, infoPlistPath); - - using (var file = new StreamWriter (projectPath, false)) { // false is do not append - await file.WriteAsync (generatedProject); - } - } - - List<(string name, string path, bool xunit, Func generate)> GenerateiOSTestProjects ( + + async Task> GenerateiOSTestProjectsAsync ( IEnumerable<(string name, string[] assemblies)> projects, Platform platform, string generatedDir) { if (platform == Platform.WatchOS) throw new ArgumentException (nameof (platform)); - var projectPaths = new List<(string name, string path, bool xunit, Func generate)> (); + var projectPaths = new List<(string name, string path, bool xunit)> (); foreach (var def in projects) { var projectDefinition = new BCLTestProjectDefinition (def.name, def.assemblies); if (IsIgnored (projectDefinition, platform)) // some projects are ignored, so we just continue @@ -423,11 +384,36 @@ namespace BCLTestImporter { if (!projectDefinition.Validate ()) throw new InvalidOperationException ("xUnit and NUnit assemblies cannot be mixed in a test project."); + // generate the required type registration info + var generatedCodeDir = Path.Combine (generatedDir, projectDefinition.Name); + if (!Directory.Exists (generatedCodeDir)) { + Directory.CreateDirectory (generatedCodeDir); + } + var registerTypePath = Path.Combine (generatedCodeDir, "RegisterType.cs"); + + var typesPerAssembly = projectDefinition.GetTypeForAssemblies (MonoRootPath, platform); + var registerCode = await RegisterTypeGenerator.GenerateCodeAsync (typesPerAssembly, + projectDefinition.IsXUnit, RegisterTypesTemplatePath); + + using (var file = new StreamWriter (registerTypePath, false)) { // false is do not append + await file.WriteAsync (registerCode); + } + + var plistTemplate = Path.Combine (PlistTemplateRootPath, plistTemplateMatches[platform]); + var plist = await BCLTestInfoPlistGenerator.GenerateCodeAsync (plistTemplate, projectDefinition.Name); + var infoPlistPath = GetPListPath (generatedCodeDir, platform); + using (var file = new StreamWriter (infoPlistPath, false)) { // false is do not append + await file.WriteAsync (plist); + } + + var projectTemplatePath = Path.Combine (ProjectTemplateRootPath, projectTemplateMatches[platform]); + var generatedProject = await GenerateAsync (projectDefinition.Name, registerTypePath, + projectDefinition.GetAssemblyInclusionInformation (MonoRootPath, platform), projectTemplatePath, infoPlistPath); var projectPath = GetProjectPath (projectDefinition.Name, platform); - var generate = new Func (() => { - return Generate (generatedDir, projectDefinition, projectPath, platform); - }); - projectPaths.Add ((name: projectDefinition.Name, path: projectPath, xunit: projectDefinition.IsXUnit, generate: generate)); + projectPaths.Add ((name: projectDefinition.Name, path: projectPath, xunit: projectDefinition.IsXUnit)); + using (var file = new StreamWriter (projectPath, false)) { // false is do not append + await file.WriteAsync (generatedProject); + } } // foreach project return projectPaths; @@ -441,21 +427,21 @@ namespace BCLTestImporter { /// has its own details. /// The dir where the projects will be saved. /// - List<(string name, string path, bool xunit, Func generate)> GenerateTestProjects ( + async Task> GenerateTestProjectsAsync ( IEnumerable<(string name, string[] assemblies)> projects, Platform platform, string generatedDir) { - List<(string name, string path, bool xunit, Func generate)> result; + List<(string name, string path, bool xunit)> result; if (platform == Platform.WatchOS) - result = GenerateWatchOSTestProjects (projects, generatedDir); + result = await GenerateWatchOSTestProjectsAsync (projects, generatedDir); else - result = GenerateiOSTestProjects (projects, platform, generatedDir); + result = await GenerateiOSTestProjectsAsync (projects, platform, generatedDir); return result; } // generates a project per platform of the common projects. - List<(string name, string path, bool xunit, List platforms, Func generate)> GenerateAllCommonTestProjects () + async Task platforms)>> GenerateAllCommonTestProjectsAsync () { - var projectPaths = new List<(string name, string path, bool xunit, List platforms, Func generate)> (); + var projectPaths = new List<(string name, string path, bool xunit, List platforms)> (); if (!isCodeGeneration) throw new InvalidOperationException ("Project generator was instantiated to delete the generated code."); var generatedCodePathRoot = GeneratedCodePathRoot; @@ -463,12 +449,12 @@ namespace BCLTestImporter { Directory.CreateDirectory (generatedCodePathRoot); } - var projects = new Dictionary platforms, Func generate)> (); + var projects = new Dictionary platforms)> (); foreach (var platform in new [] {Platform.iOS, Platform.TvOS, Platform.WatchOS}) { - var generated = GenerateTestProjects (commonTestProjects, platform, generatedCodePathRoot); - foreach (var (name, path, xunit, generate) in generated) { + var generated = await GenerateTestProjectsAsync (commonTestProjects, platform, generatedCodePathRoot); + foreach (var (name, path, xunit) in generated) { if (!projects.ContainsKey (name)) { - projects [name] = (path, xunit, new List { platform }, generate); + projects [name] = (path, xunit, new List { platform }); } else { projects [name].platforms.Add (platform); } @@ -477,15 +463,15 @@ namespace BCLTestImporter { // return the grouped projects foreach (var name in projects.Keys) { - projectPaths.Add ((name, projects[name].path, projects[name].xunit, projects[name].platforms, projects [name].generate)); + projectPaths.Add ((name, projects[name].path, projects[name].xunit, projects[name].platforms)); } return projectPaths; } // creates all the projects that have already been defined - public List<(string name, string path, bool xunit, List platforms, Func generate)> GenerateAllTestProjects () + public async Task platforms)>> GenerateAllTestProjectsAsync () { - var projectPaths = new List<(string name, string path, bool xunit, List platforms, Func generate)> (); + var projectPaths = new List<(string name, string path, bool xunit, List platforms)> (); if (!isCodeGeneration) throw new InvalidOperationException ("Project generator was instantiated to delete the generated code."); var generatedCodePathRoot = GeneratedCodePathRoot; @@ -493,11 +479,13 @@ namespace BCLTestImporter { Directory.CreateDirectory (generatedCodePathRoot); } // generate all the common projects - projectPaths.AddRange (GenerateAllCommonTestProjects ()); + projectPaths.AddRange (await GenerateAllCommonTestProjectsAsync ()); return projectPaths; } + public List<(string name, string path, bool xunit, List platforms)> GenerateAllTestProjects () => GenerateAllTestProjectsAsync ().Result; + /// /// Generates an iOS project for testing purposes. The generated project will contain the references to the /// mono test assemblies to run.