Skip to content

Commit 396630a

Browse files
author
jonas echterhoff
authored
CHANGE: Make CI run code analyzer (#642)
1 parent 47a9585 commit 396630a

20 files changed

Lines changed: 658 additions & 3 deletions

.gitmodules

Whitespace-only changes.

.yamato/analyze.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
code_analyser:
2+
name : Code Analyzer
3+
agent:
4+
type: Unity::VM::osx
5+
image: buildfarm/mac:stable
6+
flavor: m1.mac
7+
commands:
8+
- mkdir Tools/CodeAnalyzerTestProject/Microsoft.CodeQuality.Analyzers
9+
- curl -L https://www.nuget.org/api/v2/package/Microsoft.CodeQuality.Analyzers/2.9.2 -o Tools/CodeAnalyzerTestProject/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.zip
10+
- unzip Tools/CodeAnalyzerTestProject/Microsoft.CodeQuality.Analyzers/Microsoft.CodeQuality.Analyzers.zip -d Tools/CodeAnalyzerTestProject/Microsoft.CodeQuality.Analyzers
11+
- npm install upm-ci-utils@stable -g --registry https://api.bintray.com/npm/unity/unity-npm
12+
- upm-ci package pack --package-path ./Packages/com.unity.inputsystem/
13+
- upm-ci project test --project-path Tools/CodeAnalyzerTestProject -u 2019.1
14+
triggers:
15+
branches:
16+
only:
17+
- "/.*/"
18+
artifacts:
19+
UTR_Output.zip:
20+
paths:
21+
- "upm-ci~/test-results/**/*"

Packages/com.unity.inputsystem/InputSystem/Editor/Debugger/InputDeviceDebuggerWindow.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace UnityEngine.InputSystem.Editor
3333
{
3434
// Shows status and activity of a single input device in a separate window.
3535
// Can also be used to alter the state of a device by making up state events.
36-
public sealed class InputDeviceDebuggerWindow : EditorWindow, ISerializationCallbackReceiver
36+
public sealed class InputDeviceDebuggerWindow : EditorWindow, ISerializationCallbackReceiver, IDisposable
3737
{
3838
internal const int kMaxNumEventsInTrace = 64;
3939

@@ -81,11 +81,17 @@ internal void OnDestroy()
8181
RemoveFromList();
8282

8383
m_EventTrace?.Dispose();
84+
m_EventTrace = null;
8485

8586
InputSystem.onDeviceChange -= OnDeviceChange;
8687
}
8788
}
8889

90+
public void Dispose()
91+
{
92+
m_EventTrace?.Dispose();
93+
}
94+
8995
internal void OnGUI()
9096
{
9197
// Find device again if we've gone through a domain reload.

Packages/com.unity.inputsystem/Tests/InputSystem/InputTestFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public virtual void Setup()
9292
{
9393
Debug.LogError("Failed to set up input system for test " + TestContext.CurrentContext.Test.Name);
9494
Debug.LogException(exception);
95-
throw exception;
95+
throw;
9696
}
9797

9898
if (InputSystem.devices.Count > 0)
@@ -130,7 +130,7 @@ public virtual void TearDown()
130130
{
131131
Debug.LogError("Failed to shut down and restore input system after test " + TestContext.CurrentContext.Test.Name);
132132
Debug.LogException(exception);
133-
throw exception;
133+
throw;
134134
}
135135
}
136136

Tools/CodeAnalyzerTestProject/Assets/Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Assembly-CSharp-Editor-testable",
3+
"references": [
4+
"Unity.PackageValidationSuite.Editor"
5+
],
6+
"optionalUnityReferences": [
7+
"TestAssemblies"
8+
],
9+
"includePlatforms": [
10+
"Editor"
11+
],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": false,
15+
"precompiledReferences": [],
16+
"autoReferenced": true,
17+
"defineConstraints": []
18+
}

Tools/CodeAnalyzerTestProject/Assets/Tests/AccessInternals.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Threading;
5+
using NUnit.Framework;
6+
using UnityEditor.PackageManager;
7+
using UnityEngine;
8+
using UnityEngine.TestTools;
9+
using Is = UnityEngine.TestTools.Constraints.Is;
10+
11+
12+
namespace PackageTestSuite
13+
{
14+
public class CleanConsoleTest
15+
{
16+
// Make sure it is run before anything else that can affect the console
17+
[Test, Order(1)]
18+
public void TestCleanConsole()
19+
{
20+
string logs = Utilities.GetLogs();
21+
Assert.That(logs, Is.Empty, string.Format("Found logs in the console on project startup.\n\nLogs: {0}",logs));
22+
}
23+
}
24+
}

Tools/CodeAnalyzerTestProject/Assets/Tests/CleanConsoleTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Text.RegularExpressions;
7+
using NUnit.Framework.Interfaces;
8+
using UnityEditor;
9+
using UnityEditor.TestTools.TestRunner.Api;
10+
using UnityEditor.TestTools.TestRunner.GUI;
11+
using UnityEngine;
12+
using UnityEngine.TestTools;
13+
14+
namespace PackageTestSuite
15+
{
16+
public static class Utilities
17+
{
18+
public static string GetLogs()
19+
{
20+
var result = new StringBuilder();
21+
var logCount = LogEntries.GetCount();
22+
23+
LogEntries.StartGettingEntries();
24+
25+
for (var i = 0; i < logCount; i++)
26+
{
27+
var entry = new LogEntry();
28+
LogEntries.GetEntryInternal(i, entry);
29+
string logMessage = GetLogEntryMessage(entry);
30+
31+
// Ignore any log after the test runner logs message
32+
if (logMessage.StartsWith("Running tests for "))
33+
break;
34+
35+
// Ignore log synchronization messages caused by the integration tests framework
36+
if (logMessage.StartsWith("Synchronize_"))
37+
continue;
38+
39+
// Ignore the "ReadyToStart" message logged by the framework too
40+
if (logMessage.StartsWith("ReadyToStart"))
41+
continue;
42+
43+
// Ignore the assembly reload messages. Not entirely sure why these are ending up in the Console rather than
44+
// only the on-disk log, but it's not something this test needs to worry about.
45+
if (logMessage.StartsWith("Mono: successfully reloaded assembly"))
46+
continue;
47+
48+
// Ignore test environment conditions
49+
if (logMessage.StartsWith("Rebuilding Library because the asset database could not be found!"))
50+
continue;
51+
52+
// Ignore bad conversion message
53+
// NOTE: PAI-423 will explain this exemption
54+
// basically creating a new project from the command line was creating this error
55+
// when run on Mac with Editor 2019.1. Something about processing of the dependency packages
56+
if (logMessage.StartsWith("Unsupported image when converting from NSImage"))
57+
continue;
58+
59+
// We disable updates in the input system code analyzer project, so we
60+
// don't end up analyzing other packages.
61+
if (logMessage.StartsWith("Project manifest update is not allowed on this project."))
62+
continue;
63+
64+
65+
// Ignore render pipeline messages until they are fixed
66+
if (logMessage.StartsWith("Package missing for Virtual Reality SDK Oculus.") || logMessage.StartsWith("Shader warning in '") ||
67+
logMessage.StartsWith("Package missing for Virtual Reality SDK OpenVR.") || logMessage.Contains("Use Metal API instead.") ||
68+
logMessage.Contains("is not supported, no rendering will occur"))
69+
continue;
70+
71+
// Ignore Validation Suite's Empty Assembly Definition test messages since the editor indicates
72+
// that it will not compile an assembly definition with no associated scripts
73+
if (logMessage.StartsWith("Assembly for Assembly Definition File") && logMessage.Contains("EmptyAsmdefAdd/AFolder/NewAsmdef.asmdef"))
74+
continue;
75+
76+
// When doing a project upgrade, this log can occur and it is normal (and good)
77+
if (logMessage.Contains("Packages were changed.")) {
78+
continue;
79+
}
80+
81+
// When running code coverage from utr
82+
if (logMessage.Contains("Code Coverage collection is enabled for this Unity session. Note that Code Coverage lowers Editor performance.")){
83+
continue;
84+
}
85+
86+
result.AppendFormat("{0}", logMessage);
87+
if (!string.IsNullOrEmpty(entry.file))
88+
result.AppendFormat(" ({0}:{1})", entry.file, entry.line);
89+
result.AppendLine();
90+
}
91+
92+
LogEntries.EndGettingEntries();
93+
94+
return result.ToString();
95+
}
96+
97+
static public bool HasField(this Type type, string name)
98+
{
99+
return type
100+
.GetFields()
101+
.Any(p => p.Name == name);
102+
}
103+
104+
private static string GetLogEntryMessage(LogEntry entry) {
105+
// 2019.1-
106+
if (HasField(entry.GetType(), "condition")) {
107+
return (string)entry.GetType().GetField("condition").GetValue(entry);
108+
}
109+
110+
// 2019.2+
111+
if (HasField(entry.GetType(), "message")) {
112+
return (string)entry.GetType().GetField("message").GetValue(entry);
113+
}
114+
115+
return "";
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)