Allow specifying {stdin} to specify that input is in stdin. Closes #709

This commit is contained in:
baldurk
2018-09-07 14:24:45 +01:00
parent c091dfa685
commit 6bfb426ab1
2 changed files with 19 additions and 6 deletions
@@ -56,9 +56,14 @@ static ShaderToolOutput RunTool(const ShaderProcessingTool &tool, QWidget *windo
QString input_file, QString output_file, QStringList &argList)
{
bool writesToFile = true;
bool readStdin = false;
if(input_file.isEmpty())
input_file = tmpPath(lit("shader_input"));
int idx = argList.indexOf(lit("{stdin}"));
if(idx >= 0)
{
argList.removeAt(idx);
readStdin = true;
}
if(output_file.isEmpty())
{
@@ -102,6 +107,9 @@ static ShaderToolOutput RunTool(const ShaderProcessingTool &tool, QWidget *windo
QProcess process;
LambdaThread *thread = new LambdaThread([&]() {
if(readStdin)
process.setStandardInputFile(input_file);
if(!writesToFile)
process.setStandardOutputFile(output_file);
else
@@ -183,11 +191,13 @@ ShaderToolOutput ShaderProcessingTool::DisassembleShader(QWidget *window,
QString input_file, output_file;
input_file = tmpPath(lit("shader_input"));
// replace arguments after expansion to avoid problems with quoting paths etc
for(QString &arg : argList)
{
if(arg == lit("{input_file}"))
arg = input_file = tmpPath(lit("shader_input"));
arg = input_file;
if(arg == lit("{output_file}"))
arg = output_file = tmpPath(lit("shader_output"));
if(arg == lit("{glsl_stage4}"))
@@ -223,11 +233,13 @@ ShaderToolOutput ShaderProcessingTool::CompileShader(QWidget *window, rdcstr sou
QString input_file, output_file;
input_file = tmpPath(lit("shader_input"));
// replace arguments after expansion to avoid problems with quoting paths etc
for(QString &arg : argList)
{
if(arg == lit("{input_file}"))
arg = input_file = tmpPath(lit("shader_input"));
arg = input_file;
if(arg == lit("{output_file}"))
arg = output_file = tmpPath(lit("shader_output"));
if(arg == lit("{entry_point}"))
@@ -638,10 +638,11 @@ bool SettingsDialog::editTool(int existing, ShaderProcessingTool &tool)
message = tr("Output type cannot be unknown.");
}
else if(tool.tool == KnownShaderTool::Unknown &&
!QString(tool.args).contains(lit("{input_file}")))
!QString(tool.args).contains(lit("{input_file}")) &&
!QString(tool.args).contains(lit("{stdin}")))
{
invalid = true;
message = tr("Custom tool arguments must include at least {input_file}.");
message = tr("Custom tool arguments must include at least {input_file} or {stdin}.");
}
else
{