From fe276ae4a7f0216701f3d55c12340207b2c38914 Mon Sep 17 00:00:00 2001 From: nicklas Date: Wed, 26 Aug 2020 14:37:17 +0200 Subject: [PATCH 1/3] [Test] Solution file resync after touching csproj --- .../Tests/Editor/SolutionTests.cs | 101 +++++++++++++----- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs b/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs index b16326a..4c8e571 100644 --- a/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs +++ b/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs @@ -16,7 +16,9 @@ public void EmptyProject_WhenSynced_ShouldNotGenerateSolutionFile() synchronizer.Sync(); - Assert.False(m_Builder.ReadFile(synchronizer.SolutionFile()).Contains("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\")"), "Should not create project entry with no assemblies."); + Assert.False( + m_Builder.ReadFile(synchronizer.SolutionFile()).Contains("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\")"), + "Should not create project entry with no assemblies."); } [Test] @@ -39,7 +41,9 @@ public void WhenSynced_ThenDeleted_SolutionFileDoesNotExist() synchronizer.Sync(); m_Builder.DeleteFile(synchronizer.SolutionFile()); - Assert.False(synchronizer.SolutionExists(), "Synchronizer should sync state with file system, after file has been deleted."); + Assert.False( + synchronizer.SolutionExists(), + "Synchronizer should sync state with file system, after file has been deleted."); } [Test] @@ -51,7 +55,10 @@ public void ContentWithoutChanges_WhenSynced_DoesNotReSync() Assert.AreEqual(3, m_Builder.WriteTimes); // Once for csproj, once for solution, and once for vscode settings synchronizer.Sync(); - Assert.AreEqual(3, m_Builder.WriteTimes, "When content doesn't change we shouldn't re-sync"); + Assert.AreEqual( + 5, + m_Builder.WriteTimes, + "Solution file is not rewritten (but csproj and vscode settings are)"); } [Test] @@ -79,7 +86,10 @@ public void EmptySolutionFile_WhenSynced_OverwritesTheFile() synchronizer.Sync(); - Assert.AreNotEqual(solutionText, m_Builder.ReadFile(synchronizer.SolutionFile()), "Should rewrite solution text"); + Assert.AreNotEqual( + solutionText, + m_Builder.ReadFile(synchronizer.SolutionFile()), + "Should rewrite solution text"); } [TestCase("dll")] @@ -88,11 +98,13 @@ public void AfterSync_WillResync_WhenReimportWithSpecialFileExtensions(string re { var synchronizer = m_Builder.Build(); - Assert.IsFalse(synchronizer.SyncIfNeeded(new List(), new[] { $"reimport.{reimportedFile}" }), "Before sync has been called, we should not allow SyncIfNeeded"); + Assert.IsFalse( + synchronizer.SyncIfNeeded(new List(), new[] {$"reimport.{reimportedFile}"}), + "Before sync has been called, we should not allow SyncIfNeeded"); synchronizer.Sync(); - Assert.IsTrue(synchronizer.SyncIfNeeded(new List(), new[] { $"reimport.{reimportedFile}" })); + Assert.That(synchronizer.SyncIfNeeded(new List(), new[] {$"reimport.{reimportedFile}"})); } [Test] @@ -102,54 +114,92 @@ public void AfterSync_WontResync_WhenReimportWithoutSpecialFileExtensions() synchronizer.Sync(); - Assert.IsFalse(synchronizer.SyncIfNeeded(new List(), new[] { "ShouldNotSync.txt" })); + Assert.IsFalse(synchronizer.SyncIfNeeded(new List(), new[] {"ShouldNotSync.txt"})); } [Test] - public void AfterSync_WontReimport_WithoutSpeciifcAffectedFileExtension() + public void AfterSync_WontReimport_WithoutSpecificAffectedFileExtension() { var synchronizer = m_Builder.Build(); synchronizer.Sync(); - Assert.IsFalse(synchronizer.SyncIfNeeded(new List { " reimport.random" }, new string[0])); + Assert.IsFalse(synchronizer.SyncIfNeeded(new List {" reimport.random"}, new string[0])); + } + + [Test] + public void AfterSync_WillReimportSolutionFile_WhenNewAssemblyIsBeingAdded() + { + var synchronizer = m_Builder.Build(); + + synchronizer.Sync(); + + var newAssembly = new Assembly( + "MyAssembly", + "myOutput/path", + new[] {"MyFile.cs"}, + new string[0], + new Assembly[0], + new string[0], + AssemblyFlags.None); + var newAssemblies = new[] {m_Builder.Assembly, newAssembly}; + m_Builder.WithAssemblies(newAssemblies); + m_Builder.AssignFilesToAssembly(new[] {"MyFile.cs"}, newAssembly); + + synchronizer.SyncIfNeeded(new List {"MyFile.cs"}, new string[0]); + + var solutionFileContent = m_Builder.ReadFile(synchronizer.SolutionFile()); + StringAssert.Contains( + "Project(\"{}\") = \"MyAssembly\", \"MyAssembly.csproj\"", + solutionFileContent, + "After synchronizing a new file from a new Assembly. The new assembly should be added to solution file."); } [Test] public void AssetNotBelongingToAssembly_WillSync_ButWontWriteFiles() { var synchronizer = m_Builder.Build(); - + synchronizer.Sync(); // Generate solution and csproj Assert.AreEqual(3, m_Builder.WriteTimes, "Should have written csproj, sln, and vscode setting files"); - m_Builder.WithAssetFiles(new[] { "X.cs" }); + m_Builder.WithAssetFiles(new[] {"X.cs"}); - var res = synchronizer.SyncIfNeeded(new List { "X.cs" }, new string[0]); + var res = synchronizer.SyncIfNeeded(new List {"X.cs"}, new string[0]); Assert.IsTrue(res, "Should support file extension"); - Assert.AreEqual(3, m_Builder.WriteTimes, "Should not have rewritten neither csproj, sln, nor vscode setting files"); + Assert.AreEqual( + 4, + m_Builder.WriteTimes, + "Should only rewrite sln file"); } [Test] public void AssetBelongingToAssemblyWithNoName_WillSync_ButWontWriteFiles() { var synchronizer = m_Builder.Build(); - + synchronizer.Sync(); // Generate solution and csproj Assert.AreEqual(3, m_Builder.WriteTimes, "Should have written csproj, sln, and vscode setting files"); - string[] files = new[] { "X.cs" }; - m_Builder.WithAssetFiles(files).AssignFilesToAssembly(files, new Assembly("", "", files, new string[0], new Assembly[0], new string[0], AssemblyFlags.EditorAssembly)); + string[] files = {"X.cs"}; + m_Builder + .WithAssetFiles(files) + .AssignFilesToAssembly( + files, + new Assembly("", "", files, new string[0], new Assembly[0], new string[0], AssemblyFlags.EditorAssembly)); - var res = synchronizer.SyncIfNeeded(new List { "X.cs" }, new string[0]); + var res = synchronizer.SyncIfNeeded(new List {"X.cs"}, new string[0]); Assert.IsTrue(res, "Should support file extension"); - Assert.AreEqual(3, m_Builder.WriteTimes, "Should not have rewritten neither csproj, sln, nor vscode setting files"); + Assert.AreEqual( + 4, + m_Builder.WriteTimes, + "Should only rewrite sln file"); } [Test, TestCaseSource(nameof(s_ExtensionsRequireReSync))] @@ -157,16 +207,19 @@ public void AfterSync_WillResync_WhenAffectedFileTypes(string fileExtension) { var synchronizer = m_Builder.Build(); - Assert.IsFalse(synchronizer.SyncIfNeeded(new List { $"reimport.{fileExtension}" }, new string[0]), "Before sync has been called, we should not allow SyncIfNeeded"); + Assert.IsFalse( + synchronizer.SyncIfNeeded(new List {$"reimport.{fileExtension}"}, new string[0]), + "Before sync has been called, we should not allow SyncIfNeeded"); synchronizer.Sync(); - Assert.IsTrue(synchronizer.SyncIfNeeded(new List { $"reimport.{fileExtension}" }, new string[0])); + Assert.That(synchronizer.SyncIfNeeded(new List {$"reimport.{fileExtension}"}, new string[0])); } static string[] s_ExtensionsRequireReSync = { - "dll", "asmdef", "cs", "uxml", "uss", "shader", "compute", "cginc", "hlsl", "glslinc", "template", "raytrace" + "dll", "asmdef", "cs", "uxml", "uss", "shader", "compute", "cginc", "hlsl", "glslinc", "template", + "raytrace" }; } @@ -179,8 +232,8 @@ public void SyncSettings_WhenSynced_HeaderMatchesVSVersion() synchronizer.Sync(); - string[] syncedSolutionText = m_Builder.ReadFile(synchronizer.SolutionFile()).Split(new[] { "\r\n" }, StringSplitOptions.None); - Assert.IsTrue(syncedSolutionText.Length >= 4); + string[] syncedSolutionText = m_Builder.ReadFile(synchronizer.SolutionFile()).Split(new[] {"\r\n"}, StringSplitOptions.None); + Assert.That(syncedSolutionText.Length, Is.GreaterThanOrEqualTo(4)); Assert.AreEqual("", syncedSolutionText[0]); Assert.AreEqual("Microsoft Visual Studio Solution File, Format Version 11.00", syncedSolutionText[1]); Assert.AreEqual("# Visual Studio 2010", syncedSolutionText[2]); @@ -231,4 +284,4 @@ public void DefaultSyncSettings_WhenSynced_CreatesSolutionFileFromDefaultTemplat } } } -} +} \ No newline at end of file From 270af4df3e23bf6236269fa2955dbfe98e9e11c5 Mon Sep 17 00:00:00 2001 From: nicklas Date: Wed, 26 Aug 2020 14:38:56 +0200 Subject: [PATCH 2/3] Resync solution file after sync In case of newly added assemblies, we need to regenerate the sln file To add the new assembly's csproj to the list we do a resync on the solution file. --- .../Tests/Editor/SolutionTests.cs | 10 +-- .../ProjectGeneration/ProjectGeneration.cs | 2 + Packages/manifest.json | 4 +- Packages/packages-lock.json | 73 +++++++++++++++++++ ProjectSettings/ProjectVersion.txt | 4 +- 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 Packages/packages-lock.json diff --git a/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs b/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs index 4c8e571..9853f36 100644 --- a/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs +++ b/Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs @@ -56,9 +56,9 @@ public void ContentWithoutChanges_WhenSynced_DoesNotReSync() synchronizer.Sync(); Assert.AreEqual( - 5, + 3, m_Builder.WriteTimes, - "Solution file is not rewritten (but csproj and vscode settings are)"); + "When content doesn't change we shouldn't re-sync"); } [Test] @@ -171,9 +171,9 @@ public void AssetNotBelongingToAssembly_WillSync_ButWontWriteFiles() Assert.IsTrue(res, "Should support file extension"); Assert.AreEqual( - 4, + 3, m_Builder.WriteTimes, - "Should only rewrite sln file"); + "Should not have rewritten neither csproj, sln, nor vscode setting files"); } [Test] @@ -197,7 +197,7 @@ public void AssetBelongingToAssemblyWithNoName_WillSync_ButWontWriteFiles() Assert.IsTrue(res, "Should support file extension"); Assert.AreEqual( - 4, + 3, m_Builder.WriteTimes, "Should only rewrite sln file"); } diff --git a/Packages/com.unity.ide.vscode/Editor/ProjectGeneration/ProjectGeneration.cs b/Packages/com.unity.ide.vscode/Editor/ProjectGeneration/ProjectGeneration.cs index ab109a1..b5cf363 100644 --- a/Packages/com.unity.ide.vscode/Editor/ProjectGeneration/ProjectGeneration.cs +++ b/Packages/com.unity.ide.vscode/Editor/ProjectGeneration/ProjectGeneration.cs @@ -179,6 +179,8 @@ public bool SyncIfNeeded(List affectedFiles, string[] reimportedFiles) { var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution); var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList(); + SyncSolution(allProjectAssemblies); + var allAssetProjectParts = GenerateAllAssetProjectParts(); var affectedNames = affectedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)).Where(name => !string.IsNullOrWhiteSpace(name)).Select(name => name.Split(new [] {".dll"}, StringSplitOptions.RemoveEmptyEntries)[0]); diff --git a/Packages/manifest.json b/Packages/manifest.json index a4805a4..a33a41f 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,7 +1,7 @@ { "disableProjectUpdate": true, "dependencies": { - "com.unity.package-validation-suite": "0.7.8-preview", - "com.unity.test-framework": "1.1.3" + "com.unity.ide.rider": "2.0.7", + "com.unity.test-framework": "1.1.16" } } diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json new file mode 100644 index 0000000..2343ad2 --- /dev/null +++ b/Packages/packages-lock.json @@ -0,0 +1,73 @@ +{ + "dependencies": { + "com.unity.ext.nunit": { + "version": "1.0.0", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "com.unity.ide.rider": { + "version": "2.0.7", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.test-framework": "1.1.1" + }, + "url": "https://packages.unity.com" + }, + "com.unity.ide.vscode": { + "version": "file:com.unity.ide.vscode", + "depth": 0, + "source": "embedded", + "dependencies": {} + }, + "com.unity.ide.vscode.tests": { + "version": "file:com.unity.ide.vscode.tests", + "depth": 0, + "source": "embedded", + "dependencies": { + "nuget.moq": "1.0.0" + } + }, + "com.unity.test-framework": { + "version": "1.1.16", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.ext.nunit": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + }, + "url": "https://packages.unity.com" + }, + "nuget.castle-core": { + "version": "1.0.1", + "depth": 2, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, + "nuget.moq": { + "version": "1.0.0", + "depth": 1, + "source": "registry", + "dependencies": { + "nuget.castle-core": "1.0.1" + }, + "url": "https://packages.unity.com" + }, + "com.unity.modules.imgui": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.jsonserialize": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + } + } +} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index f42b706..76580b9 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.1.0a23 -m_EditorVersionWithRevision: 2020.1.0a23 (681041f4fc14) +m_EditorVersion: 2020.2.0a21 +m_EditorVersionWithRevision: 2020.2.0a21 (3e0d5f775006) From 1e5bc5e38869d59aaef576eff258c595067d345c Mon Sep 17 00:00:00 2001 From: nicklas Date: Wed, 26 Aug 2020 14:51:25 +0200 Subject: [PATCH 3/3] Updated to new CI script. --- .yamato/CI.yml | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/.yamato/CI.yml b/.yamato/CI.yml index 601cb49..6453d97 100644 --- a/.yamato/CI.yml +++ b/.yamato/CI.yml @@ -1,5 +1,6 @@ codeeditor: vscode test_suite_name: VisualStudioCode + editors: - version: 2019.2 - version: 2019.3 @@ -31,7 +32,7 @@ pack: image: package-ci/win10:stable flavor: b1.large commands: - - npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm + - npm install upm-ci-utils@latest -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm - upm-ci project pack artifacts: packages: @@ -46,7 +47,7 @@ commit_ci: only: - "/.*/" except: - - "*master*" + - next/master - publish-release dependencies: {% for editor in editors %} @@ -68,10 +69,14 @@ run_test_project_{{ platform.name }}_{{ editor.version }}: DISPLAY: ":0" {% endif %} commands: - - pip install unity-downloader-cli --user --upgrade --extra-index-url https://artifactory.eu-cph-1.unityops.net/api/pypi/common-python/simple +{% if platform.name == "linux" -%} + - pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade --user +{% else -%} + - pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade +{% endif -%} - {{ platform.envsetup }} - unity-downloader-cli -u {{editor.version}} -c editor -c linux -c macos -c windows --wait --published-only - - npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm + - npm install upm-ci-utils@latest -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm - upm-ci project test -u .Editor --project-path . --platform editmode artifacts: logs: @@ -94,12 +99,12 @@ prepare_release: - next/master agent: type: Unity::VM - image: cds-ops/ubuntu-18.04-agent:latest + image: cds-ops/ubuntu-18.04-agent:stable flavor: b1.large commands: - git clone git@github.cds.internal.unity3d.com:nicklas/Nicklas-CI.git /tmp/Nicklas-CI - python3 /tmp/Nicklas-CI/prepare_release.py - - git push origin HEAD:refs/heads/publish-release + - git push origin HEAD:refs/heads/publish-release -f publish_release: @@ -120,7 +125,7 @@ publish_release: image: package-ci/win10:stable flavor: b1.large commands: - - npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm + - npm install upm-ci-utils@latest -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm - upm-ci project publish - git push origin HEAD:refs/heads/next/master HEAD:refs/heads/master -f @@ -131,7 +136,7 @@ prepare_promotion: - .yamato/CI.yml#pack agent: type: Unity::VM - image: cds-ops/win10-katana-agent:stable + image: build-system/unity-windows-10-katana:latest flavor: b1.large commands: - if NOT "%GIT_BRANCH%" == "master" echo %GIT_BRANCH% && exit 1 @@ -145,7 +150,7 @@ create_pull_request: triggers: branches: only: - - master + - master dependencies: - .yamato/CI.yml#prepare_promotion - .yamato/CI.yml#pack @@ -156,4 +161,4 @@ create_pull_request: commands: - git clone git@github.cds.internal.unity3d.com:nicklas/Nicklas-CI.git /tmp/Nicklas-CI - python3 /tmp/Nicklas-CI/create_pullrequest.py nicklas upm-ci~/packages/packages.json - - python3 /tmp/Nicklas-CI/start_katana.py "Nicklas Pingel " upm-ci~/packages/packages.json + - python3 /tmp/Nicklas-CI/start_katana.py "Nicklas Pingel " upm-ci~/packages/packages.json \ No newline at end of file