Skip to content

Commit 1de84ce

Browse files
authored
Merge pull request #85 from guitarrapc/feature/shadererror
feat: Remove ShaderError Compile error filter from DefaultErrorFilter
2 parents cf54f29 + 688d96c commit 1de84ce

4 files changed

Lines changed: 243 additions & 53 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
6+
namespace UnityBuildRunner.Core;
7+
8+
public interface IErrorFilter
9+
{
10+
/// <summary>
11+
/// Filter value and treat on match
12+
/// </summary>
13+
/// <param name="value"></param>
14+
/// <param name="onMatch"></param>
15+
public void Filter(string value, Action<ErrorFilterResult> onMatch);
16+
}
17+
18+
public record ErrorFilterResult(string Message, string MatchPattern);
19+
20+
/// <summary>
21+
/// Error filter without Shader errors
22+
/// </summary>
23+
public class DefaultErrorFilter : IErrorFilter
24+
{
25+
private readonly IReadOnlyList<Regex> regexes;
26+
27+
public DefaultErrorFilter()
28+
{
29+
var options = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Compiled;
30+
regexes = ErrorMessages.CsharpErrors
31+
.Concat(ErrorMessages.UnityErrors)
32+
.Select(x => new Regex(x, options))
33+
.ToArray();
34+
}
35+
36+
public void Filter(string message, Action<ErrorFilterResult> onMatch)
37+
{
38+
foreach (var regex in regexes)
39+
{
40+
if (regex.IsMatch(message))
41+
{
42+
onMatch.Invoke(new ErrorFilterResult(message, regex.ToString()));
43+
}
44+
}
45+
}
46+
}
47+
48+
/// <summary>
49+
/// Error filter include Shader errors
50+
/// </summary>
51+
public class DefaultStrictErrorFilter : IErrorFilter
52+
{
53+
private readonly IReadOnlyList<Regex> regexes;
54+
55+
public DefaultStrictErrorFilter()
56+
{
57+
var options = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Compiled;
58+
regexes = ErrorMessages.CsharpErrors
59+
.Concat(ErrorMessages.ShaderErrors)
60+
.Concat(ErrorMessages.UnityErrors)
61+
.Select(x => new Regex(x, options))
62+
.ToArray();
63+
}
64+
65+
public void Filter(string message, Action<ErrorFilterResult> onMatch)
66+
{
67+
foreach (var regex in regexes)
68+
{
69+
if (regex.IsMatch(message))
70+
{
71+
onMatch.Invoke(new ErrorFilterResult(message, regex.ToString()));
72+
}
73+
}
74+
}
75+
}
76+
77+
file static class ErrorMessages
78+
{
79+
/// <summary>
80+
/// C# Error pattern
81+
/// </summary>
82+
public static readonly string[] CsharpErrors = new[]
83+
{
84+
"compilationhadfailure: True",
85+
"DisplayProgressNotification: Build Failed",
86+
@"error CS\d+",
87+
"Error building Player because scripts had compiler errors",
88+
};
89+
/// <summary>
90+
/// Shader Error pattern
91+
/// </summary>
92+
public static readonly string[] ShaderErrors = new[]
93+
{
94+
// Shader Error
95+
"Compilation failed",
96+
};
97+
/// <summary>
98+
/// Unity Error pattern
99+
/// </summary>
100+
public static readonly string[] UnityErrors = new[]
101+
{
102+
// Unity can open single Unity.exe process for same project path.
103+
"Multiple Unity instances cannot open the same project.",
104+
// License should be activated before build.
105+
"Unity has not been activated",
106+
};
107+
}

src/UnityBuildRunner.Core/ErrorFilter.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/UnityBuildRunner.Core.Tests/ErrorFilterTest.cs renamed to tests/UnityBuildRunner.Core.Tests/DefaultErrorFilterTest.cs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace UnityBuildRunner.Core.Tests;
66

7-
public class ErrorFilterTest
7+
public class DefaultErrorFilterTest
88
{
99
[Theory]
1010
[InlineData(
@@ -24,7 +24,7 @@ Unloading 64 Unused Serialized files (Serialized files now loaded: 0)
2424
"Assets/Externals/Plugins/Zenject/Source/Binding/Binders/NonLazyBinder.cs(10,16): error CS0246: The type or namespace name `IfNotBoundBinder' could not be found. Are you missing an assembly reference?",
2525
@"BatchMode: Unity has not been activated with a valid License. Could be a new activation or renewal...
2626
DisplayProgressbar: Unity license")]
27-
public void ContainsFilterMessage(params string[] inputs)
27+
public void DetectCSharpCompileError(params string[] inputs)
2828
{
2929
IErrorFilter errorFilter = new DefaultErrorFilter();
3030
var results = new List<string>();
@@ -36,11 +36,51 @@ public void ContainsFilterMessage(params string[] inputs)
3636
results.Should().NotBeEmpty();
3737
}
3838

39+
[Theory]
40+
[InlineData("Multiple Unity instances cannot open the same project.")]
41+
[InlineData("Unity has not been activated")]
42+
public void DetectUnityError(params string[] inputs)
43+
{
44+
IErrorFilter errorFilter = new DefaultErrorFilter();
45+
var results = new List<string>();
46+
foreach (var input in inputs)
47+
{
48+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
49+
}
50+
results.Should().NotBeEmpty();
51+
}
52+
53+
[Theory]
54+
[InlineData(
55+
"Compiling shader \"Shader Graphs/UrpFoo\" pass \"\" (vp)",
56+
" Full variant space: 2",
57+
" After settings filtering: 2",
58+
" After built-in stripping: 2",
59+
" After scriptable stripping: 2",
60+
" Processed in 0.02 seconds",
61+
" starting compilation...",
62+
" finished in 0.22 seconds. Local cache hits 0 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 2 variants (0.42s CPU time), skipped 0 variants",
63+
" Prepared data for serialisation in 0.00s",
64+
"Serialized binary data for shader Shader Graphs/UrpTriplanar in 0.00s",
65+
" glcore (total internal programs: 21, unique: 21)",
66+
" vulkan (total internal programs: 34, unique: 34)",
67+
"Shader error in 'Shader Graphs/UrpFoo': Compilation failed (other error) 'out of memory during compilation")]
68+
public void SkipShaderError(params string[] inputs)
69+
{
70+
IErrorFilter errorFilter = new DefaultErrorFilter();
71+
var results = new List<string>();
72+
foreach (var input in inputs)
73+
{
74+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
75+
}
76+
results.Should().BeEmpty();
77+
}
78+
3979
[Theory]
4080
[InlineData(
4181
"Unloading 64 Unused Serialized files (Serialized files now loaded: 0)",
4282
"System memory in use before: 63.0 MB.", "DisplayProgressbar: Unity Package Manager")]
43-
public void NotContainsFilterMessage(params string[] inputs)
83+
public void SkipNormalMessage(params string[] inputs)
4484
{
4585
IErrorFilter errorFilter = new DefaultErrorFilter();
4686
var results = new List<string>();
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using FluentAssertions;
2+
using System.Collections.Generic;
3+
using Xunit;
4+
5+
namespace UnityBuildRunner.Core.Tests;
6+
7+
public class DefaultStrictErrorFilterTest
8+
{
9+
[Theory]
10+
[InlineData(
11+
"-----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll",
12+
"DisplayProgressNotification: Build Failed",
13+
"Error building Player because scripts had compiler errors",
14+
@"2018-11-05T00:53:44.2566426Z DisplayProgressNotification: Build Failed
15+
Error building Player because scripts had compiler errors
16+
(Filename: Line: -1)
17+
Unloading 64 Unused Serialized files (Serialized files now loaded: 0)
18+
System memory in use before: 63.0 MB.
19+
System memory in use after: 63.4 MB.
20+
21+
Unloading 47 unused Assets to reduce memory usage. Loaded Objects now: 5728.
22+
Total: 13.359500 ms (FindLiveObjects: 1.689200 ms CreateObjectMapping: 0.289900 ms MarkObjects: 11.349100 ms DeleteObjects: 0.029600 ms)",
23+
"Compilation failed: 634 error(s), 0 warnings",
24+
"Assets/Externals/Plugins/Zenject/Source/Binding/Binders/NonLazyBinder.cs(10,16): error CS0246: The type or namespace name `IfNotBoundBinder' could not be found. Are you missing an assembly reference?",
25+
@"BatchMode: Unity has not been activated with a valid License. Could be a new activation or renewal...
26+
DisplayProgressbar: Unity license")]
27+
public void DetectCSharpCompileError(params string[] inputs)
28+
{
29+
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
30+
var results = new List<string>();
31+
foreach (var input in inputs)
32+
{
33+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
34+
}
35+
36+
results.Should().NotBeEmpty();
37+
}
38+
39+
[Theory]
40+
[InlineData("Multiple Unity instances cannot open the same project.")]
41+
[InlineData("Unity has not been activated")]
42+
public void DetectUnityError(params string[] inputs)
43+
{
44+
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
45+
var results = new List<string>();
46+
foreach (var input in inputs)
47+
{
48+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
49+
}
50+
results.Should().NotBeEmpty();
51+
}
52+
53+
[Theory]
54+
[InlineData(
55+
"Compiling shader \"Shader Graphs/UrpFoo\" pass \"\" (vp)",
56+
" Full variant space: 2",
57+
" After settings filtering: 2",
58+
" After built-in stripping: 2",
59+
" After scriptable stripping: 2",
60+
" Processed in 0.02 seconds",
61+
" starting compilation...",
62+
" finished in 0.22 seconds. Local cache hits 0 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 2 variants (0.42s CPU time), skipped 0 variants",
63+
" Prepared data for serialisation in 0.00s",
64+
"Serialized binary data for shader Shader Graphs/UrpTriplanar in 0.00s",
65+
" glcore (total internal programs: 21, unique: 21)",
66+
" vulkan (total internal programs: 34, unique: 34)",
67+
"Shader error in 'Shader Graphs/UrpFoo': Compilation failed (other error) 'out of memory during compilation")]
68+
public void SkipShaderError(params string[] inputs)
69+
{
70+
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
71+
var results = new List<string>();
72+
foreach (var input in inputs)
73+
{
74+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
75+
}
76+
results.Should().NotBeEmpty();
77+
}
78+
79+
[Theory]
80+
[InlineData(
81+
"Unloading 64 Unused Serialized files (Serialized files now loaded: 0)",
82+
"System memory in use before: 63.0 MB.", "DisplayProgressbar: Unity Package Manager")]
83+
public void SkipNormalMessage(params string[] inputs)
84+
{
85+
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
86+
var results = new List<string>();
87+
foreach (var input in inputs)
88+
{
89+
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
90+
}
91+
results.Should().BeEmpty();
92+
}
93+
}

0 commit comments

Comments
 (0)