Skip to content

Commit

Permalink
Merge pull request #85 from guitarrapc/feature/shadererror
Browse files Browse the repository at this point in the history
feat: Remove ShaderError Compile error filter from DefaultErrorFilter
  • Loading branch information
guitarrapc authored Oct 10, 2023
2 parents cf54f29 + 688d96c commit 1de84ce
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 53 deletions.
107 changes: 107 additions & 0 deletions src/UnityBuildRunner.Core/DefaultErrorFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace UnityBuildRunner.Core;

public interface IErrorFilter
{
/// <summary>
/// Filter value and treat on match
/// </summary>
/// <param name="value"></param>
/// <param name="onMatch"></param>
public void Filter(string value, Action<ErrorFilterResult> onMatch);
}

public record ErrorFilterResult(string Message, string MatchPattern);

/// <summary>
/// Error filter without Shader errors
/// </summary>
public class DefaultErrorFilter : IErrorFilter
{
private readonly IReadOnlyList<Regex> regexes;

public DefaultErrorFilter()
{
var options = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Compiled;
regexes = ErrorMessages.CsharpErrors
.Concat(ErrorMessages.UnityErrors)
.Select(x => new Regex(x, options))
.ToArray();
}

public void Filter(string message, Action<ErrorFilterResult> onMatch)
{
foreach (var regex in regexes)
{
if (regex.IsMatch(message))
{
onMatch.Invoke(new ErrorFilterResult(message, regex.ToString()));
}
}
}
}

/// <summary>
/// Error filter include Shader errors
/// </summary>
public class DefaultStrictErrorFilter : IErrorFilter
{
private readonly IReadOnlyList<Regex> regexes;

public DefaultStrictErrorFilter()
{
var options = RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Compiled;
regexes = ErrorMessages.CsharpErrors
.Concat(ErrorMessages.ShaderErrors)
.Concat(ErrorMessages.UnityErrors)
.Select(x => new Regex(x, options))
.ToArray();
}

public void Filter(string message, Action<ErrorFilterResult> onMatch)
{
foreach (var regex in regexes)
{
if (regex.IsMatch(message))
{
onMatch.Invoke(new ErrorFilterResult(message, regex.ToString()));
}
}
}
}

file static class ErrorMessages
{
/// <summary>
/// C# Error pattern
/// </summary>
public static readonly string[] CsharpErrors = new[]
{
"compilationhadfailure: True",
"DisplayProgressNotification: Build Failed",
@"error CS\d+",
"Error building Player because scripts had compiler errors",
};
/// <summary>
/// Shader Error pattern
/// </summary>
public static readonly string[] ShaderErrors = new[]
{
// Shader Error
"Compilation failed",
};
/// <summary>
/// Unity Error pattern
/// </summary>
public static readonly string[] UnityErrors = new[]
{
// Unity can open single Unity.exe process for same project path.
"Multiple Unity instances cannot open the same project.",
// License should be activated before build.
"Unity has not been activated",
};
}
50 changes: 0 additions & 50 deletions src/UnityBuildRunner.Core/ErrorFilter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UnityBuildRunner.Core.Tests;

public class ErrorFilterTest
public class DefaultErrorFilterTest
{
[Theory]
[InlineData(
Expand All @@ -24,7 +24,7 @@ Unloading 64 Unused Serialized files (Serialized files now loaded: 0)
"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?",
@"BatchMode: Unity has not been activated with a valid License. Could be a new activation or renewal...
DisplayProgressbar: Unity license")]
public void ContainsFilterMessage(params string[] inputs)
public void DetectCSharpCompileError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultErrorFilter();
var results = new List<string>();
Expand All @@ -36,11 +36,51 @@ public void ContainsFilterMessage(params string[] inputs)
results.Should().NotBeEmpty();
}

[Theory]
[InlineData("Multiple Unity instances cannot open the same project.")]
[InlineData("Unity has not been activated")]
public void DetectUnityError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}
results.Should().NotBeEmpty();
}

[Theory]
[InlineData(
"Compiling shader \"Shader Graphs/UrpFoo\" pass \"\" (vp)",
" Full variant space: 2",
" After settings filtering: 2",
" After built-in stripping: 2",
" After scriptable stripping: 2",
" Processed in 0.02 seconds",
" starting compilation...",
" 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",
" Prepared data for serialisation in 0.00s",
"Serialized binary data for shader Shader Graphs/UrpTriplanar in 0.00s",
" glcore (total internal programs: 21, unique: 21)",
" vulkan (total internal programs: 34, unique: 34)",
"Shader error in 'Shader Graphs/UrpFoo': Compilation failed (other error) 'out of memory during compilation")]
public void SkipShaderError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}
results.Should().BeEmpty();
}

[Theory]
[InlineData(
"Unloading 64 Unused Serialized files (Serialized files now loaded: 0)",
"System memory in use before: 63.0 MB.", "DisplayProgressbar: Unity Package Manager")]
public void NotContainsFilterMessage(params string[] inputs)
public void SkipNormalMessage(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultErrorFilter();
var results = new List<string>();
Expand Down
93 changes: 93 additions & 0 deletions tests/UnityBuildRunner.Core.Tests/DefaultStrictErrorFilterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using FluentAssertions;
using System.Collections.Generic;
using Xunit;

namespace UnityBuildRunner.Core.Tests;

public class DefaultStrictErrorFilterTest
{
[Theory]
[InlineData(
"-----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll",
"DisplayProgressNotification: Build Failed",
"Error building Player because scripts had compiler errors",
@"2018-11-05T00:53:44.2566426Z DisplayProgressNotification: Build Failed
Error building Player because scripts had compiler errors
(Filename: Line: -1)
Unloading 64 Unused Serialized files (Serialized files now loaded: 0)
System memory in use before: 63.0 MB.
System memory in use after: 63.4 MB.
Unloading 47 unused Assets to reduce memory usage. Loaded Objects now: 5728.
Total: 13.359500 ms (FindLiveObjects: 1.689200 ms CreateObjectMapping: 0.289900 ms MarkObjects: 11.349100 ms DeleteObjects: 0.029600 ms)",
"Compilation failed: 634 error(s), 0 warnings",
"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?",
@"BatchMode: Unity has not been activated with a valid License. Could be a new activation or renewal...
DisplayProgressbar: Unity license")]
public void DetectCSharpCompileError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}

results.Should().NotBeEmpty();
}

[Theory]
[InlineData("Multiple Unity instances cannot open the same project.")]
[InlineData("Unity has not been activated")]
public void DetectUnityError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}
results.Should().NotBeEmpty();
}

[Theory]
[InlineData(
"Compiling shader \"Shader Graphs/UrpFoo\" pass \"\" (vp)",
" Full variant space: 2",
" After settings filtering: 2",
" After built-in stripping: 2",
" After scriptable stripping: 2",
" Processed in 0.02 seconds",
" starting compilation...",
" 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",
" Prepared data for serialisation in 0.00s",
"Serialized binary data for shader Shader Graphs/UrpTriplanar in 0.00s",
" glcore (total internal programs: 21, unique: 21)",
" vulkan (total internal programs: 34, unique: 34)",
"Shader error in 'Shader Graphs/UrpFoo': Compilation failed (other error) 'out of memory during compilation")]
public void SkipShaderError(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}
results.Should().NotBeEmpty();
}

[Theory]
[InlineData(
"Unloading 64 Unused Serialized files (Serialized files now loaded: 0)",
"System memory in use before: 63.0 MB.", "DisplayProgressbar: Unity Package Manager")]
public void SkipNormalMessage(params string[] inputs)
{
IErrorFilter errorFilter = new DefaultStrictErrorFilter();
var results = new List<string>();
foreach (var input in inputs)
{
errorFilter.Filter(input, result => results.Add(result.MatchPattern));
}
results.Should().BeEmpty();
}
}

0 comments on commit 1de84ce

Please sign in to comment.