Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…ode/pull/24

VSC-14 - synchronize solution file when adding new assembly
  • Loading branch information
miniwolf authored and Package Release Automation committed Sep 4, 2020
2 parents 4395bd8 + 1e5bc5e commit d4564da
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 41 deletions.
25 changes: 15 additions & 10 deletions .yamato/CI.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
codeeditor: vscode
test_suite_name: VisualStudioCode

editors:
- version: 2019.2
- version: 2019.3
Expand Down Expand Up @@ -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:
Expand All @@ -46,7 +47,7 @@ commit_ci:
only:
- "/.*/"
except:
- "*master*"
- next/master
- publish-release
dependencies:
{% for editor in editors %}
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand All @@ -145,7 +150,7 @@ create_pull_request:
triggers:
branches:
only:
- master
- master
dependencies:
- .yamato/CI.yml#prepare_promotion
- .yamato/CI.yml#pack
Expand All @@ -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 <nicklas@unity3d.com>" upm-ci~/packages/packages.json
- python3 /tmp/Nicklas-CI/start_katana.py "Nicklas Pingel <nicklas@unity3d.com>" upm-ci~/packages/packages.json
101 changes: 77 additions & 24 deletions Packages/com.unity.ide.vscode.tests/Tests/Editor/SolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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(
3,
m_Builder.WriteTimes,
"When content doesn't change we shouldn't re-sync");
}

[Test]
Expand Down Expand Up @@ -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")]
Expand All @@ -88,11 +98,13 @@ public void AfterSync_WillResync_WhenReimportWithSpecialFileExtensions(string re
{
var synchronizer = m_Builder.Build();

Assert.IsFalse(synchronizer.SyncIfNeeded(new List<string>(), new[] { $"reimport.{reimportedFile}" }), "Before sync has been called, we should not allow SyncIfNeeded");
Assert.IsFalse(
synchronizer.SyncIfNeeded(new List<string>(), new[] {$"reimport.{reimportedFile}"}),
"Before sync has been called, we should not allow SyncIfNeeded");

synchronizer.Sync();

Assert.IsTrue(synchronizer.SyncIfNeeded(new List<string>(), new[] { $"reimport.{reimportedFile}" }));
Assert.That(synchronizer.SyncIfNeeded(new List<string>(), new[] {$"reimport.{reimportedFile}"}));
}

[Test]
Expand All @@ -102,71 +114,112 @@ public void AfterSync_WontResync_WhenReimportWithoutSpecialFileExtensions()

synchronizer.Sync();

Assert.IsFalse(synchronizer.SyncIfNeeded(new List<string>(), new[] { "ShouldNotSync.txt" }));
Assert.IsFalse(synchronizer.SyncIfNeeded(new List<string>(), 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<string> { " reimport.random" }, new string[0]));
Assert.IsFalse(synchronizer.SyncIfNeeded(new List<string> {" 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<string> {"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<string> { "X.cs" }, new string[0]);
var res = synchronizer.SyncIfNeeded(new List<string> {"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(
3,
m_Builder.WriteTimes,
"Should not have rewritten neither csproj, sln, nor vscode setting files");
}

[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<string> { "X.cs" }, new string[0]);
var res = synchronizer.SyncIfNeeded(new List<string> {"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(
3,
m_Builder.WriteTimes,
"Should only rewrite sln file");
}

[Test, TestCaseSource(nameof(s_ExtensionsRequireReSync))]
public void AfterSync_WillResync_WhenAffectedFileTypes(string fileExtension)
{
var synchronizer = m_Builder.Build();

Assert.IsFalse(synchronizer.SyncIfNeeded(new List<string> { $"reimport.{fileExtension}" }, new string[0]), "Before sync has been called, we should not allow SyncIfNeeded");
Assert.IsFalse(
synchronizer.SyncIfNeeded(new List<string> {$"reimport.{fileExtension}"}, new string[0]),
"Before sync has been called, we should not allow SyncIfNeeded");

synchronizer.Sync();

Assert.IsTrue(synchronizer.SyncIfNeeded(new List<string> { $"reimport.{fileExtension}" }, new string[0]));
Assert.That(synchronizer.SyncIfNeeded(new List<string> {$"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"
};
}

Expand All @@ -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]);
Expand Down Expand Up @@ -231,4 +284,4 @@ public void DefaultSyncSettings_WhenSynced_CreatesSolutionFileFromDefaultTemplat
}
}
}
}
}
2 changes: 1 addition & 1 deletion Packages/com.unity.ide.vscode.tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "com.unity.ide.vscode.tests",
"displayName": "Visual Studio Code Editor",
"description": "Code editor integration for supporting Visual Studio Code as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "1.2.1",
"version": "1.2.2",
"unity": "2019.2",
"unityRelease": "0a12",
"dependencies": {
Expand Down
5 changes: 5 additions & 0 deletions Packages/com.unity.ide.vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Code Editor Package for Visual Studio Code

## [1.2.2] - 2020-09-04

VSC-14 - synchronize solution file when adding new assembly


## [1.2.1] - 2020-05-15

Source filtering adds support for asmref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public bool SyncIfNeeded(List<string> 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]);
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.unity.ide.vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "com.unity.ide.vscode",
"displayName": "Visual Studio Code Editor",
"description": "Code editor integration for supporting Visual Studio Code as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "1.2.1",
"version": "1.2.2",
"unity": "2019.2",
"unityRelease": "0a12",
"dependencies": {},
"relatedPackages": {
"com.unity.ide.vscode.tests": "1.2.1"
"com.unity.ide.vscode.tests": "1.2.2"
}
}
4 changes: 2 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading

0 comments on commit d4564da

Please sign in to comment.