-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from guitarrapc/feature/shadererror
feat: Remove ShaderError Compile error filter from DefaultErrorFilter
- Loading branch information
Showing
4 changed files
with
243 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
tests/UnityBuildRunner.Core.Tests/DefaultStrictErrorFilterTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |