mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 03:18:23 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
77 lines
1.7 KiB
C#
77 lines
1.7 KiB
C#
using System.Diagnostics;
|
|
using static Facepunch.Constants;
|
|
|
|
namespace Facepunch.Steps;
|
|
|
|
internal class BuildShaders( string name, bool forced = false ) : Step( name )
|
|
{
|
|
protected override ExitCode RunInternal()
|
|
{
|
|
try
|
|
{
|
|
string rootDir = Directory.GetCurrentDirectory();
|
|
string gameDir = Path.Combine( rootDir, "game" );
|
|
string shaderCompilerPath = Path.Combine( gameDir, "bin", "managed", "shadercompiler.exe" );
|
|
|
|
// Verify shader compiler exists
|
|
if ( !File.Exists( shaderCompilerPath ) )
|
|
{
|
|
Log.Error( $"Error: Shader compiler executable not found at {shaderCompilerPath}" );
|
|
return ExitCode.Failure;
|
|
}
|
|
|
|
return RunShaderCompiler( shaderCompilerPath, gameDir );
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
Log.Error( $"Shader compilation failed with error: {ex}" );
|
|
return ExitCode.Failure;
|
|
}
|
|
}
|
|
|
|
private ExitCode RunShaderCompiler( string shaderCompilerPath, string workingDirectory )
|
|
{
|
|
// Build arguments - only include -f if forced is true
|
|
string arguments = "*";
|
|
if ( forced )
|
|
{
|
|
arguments += " -f";
|
|
}
|
|
|
|
// Track if any shaders were compiled
|
|
var shaderCompiled = false;
|
|
|
|
bool success = Utility.RunProcess(
|
|
shaderCompilerPath,
|
|
arguments,
|
|
workingDirectory,
|
|
onDataReceived: ( sender, e ) =>
|
|
{
|
|
if ( e.Data != null )
|
|
{
|
|
Log.Info( e.Data );
|
|
|
|
if ( e.Data.Contains( "Compiled successfully in" ) )
|
|
{
|
|
shaderCompiled = true;
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
if ( !success )
|
|
{
|
|
Log.Error( $"Shader compiler failed" );
|
|
return ExitCode.Failure;
|
|
}
|
|
|
|
if ( shaderCompiled && Utility.IsCi() )
|
|
{
|
|
Log.Error( $"Step Failed because at least one shader had to be recompiled, please compile shaders locally before committing." );
|
|
return ExitCode.Failure;
|
|
}
|
|
|
|
return ExitCode.Success;
|
|
}
|
|
}
|