34#include <wx/process.h>
35#include <wx/txtstrm.h>
36#include <wx/sstream.h>
37#include <wx/wfstream.h>
38#include <wx/mstream.h>
39#include <wx/tokenzr.h>
77 wxInputStream* inputStream =
process.GetInputStream();
78 wxInputStream* errorStream =
process.GetErrorStream();
81 auto streamToBuf = []( wxInputStream& aIs )
83 wxMemoryOutputStream memOut;
87 buf.AppendData( memOut.GetOutputStreamBuffer()->GetBufferStart(),
88 memOut.GetOutputStreamBuffer()->GetIntPosition() );
93 if( inputStream && errorStream )
95 wxMemoryBuffer memInBuf = streamToBuf( *inputStream );
96 wxMemoryBuffer memErrBuf = streamToBuf( *errorStream );
98 if( !memInBuf.IsEmpty() )
100 wxString str = wxString::FromUTF8( memInBuf, memInBuf.GetDataLen() );
101 wxStringTokenizer tokenizer( str,
"\r\n" );
103 while( tokenizer.HasMoreTokens() )
107 if( !memErrBuf.IsEmpty() )
109 wxString str = wxString::FromUTF8( memErrBuf, memErrBuf.GetDataLen() );
110 wxStringTokenizer tokenizer( str,
"\r\n" );
112 while( tokenizer.HasMoreTokens() )
120 wxFileName fn( aJob->
m_id );
121 fn.SetExt( wxT(
"log" ) );
127 if( !procOutput.IsOk() )
130 procOutput.WriteAll( memInBuf, memInBuf.GetDataLen() );
142 std::vector<wxString>& aPathsWritten )
146 if( source.IsEmpty() )
150 wxFileName sourceFn( source );
151 sourceFn.MakeAbsolute( projectPath );
155 if( !aJob->
m_dest.IsEmpty() )
160 errors, aPathsWritten );
193 bool genOutputs =
true;
195 std::vector<JOBSET_JOB> jobsForDestination =
m_jobsFile->GetJobsForDestination( aDestination );
199 tmp.AssignDir( wxFileName::GetTempDir() );
200 tmp.AppendDir(
KIID().AsString() );
206 wxString tempDirPath = tmp.GetFullPath();
208 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
210 msg = wxString::Format( wxT(
"Failed to create temporary directory %s" ), tempDirPath );
222 msg = wxString::Format( wxT(
"Destination precheck failed for destination %s" ),
223 aDestination->
m_id );
230 msg += wxT(
"|--------------------------------\n" );
232 msg += wxString::Format( wxT(
"Running jobs for destination %s" ), aDestination->
m_id );
234 msg += wxT(
"|--------------------------------\n" );
236 msg += wxString::Format( wxT(
"|%-5s | %-50s\n" ), wxT(
"No." ), wxT(
"Description" ) );
240 for(
const JOBSET_JOB& job : jobsForDestination )
242 msg += wxString::Format( wxT(
"|%-5d | %-50s\n" ), jobNum, job.GetDescription() );
246 msg += wxT(
"|--------------------------------\n" );
252 std::vector<wxString> pathsWithOverwriteDisallowed;
253 std::vector<JOB_OUTPUT> outputs;
257 int successCount = 0;
261 for(
const JOBSET_JOB& job : jobsForDestination )
263 msg = wxT(
"|--------------------------------\n" );
265 msg += wxString::Format( wxT(
"| Running job %d: %s" ), jobNum, job.GetDescription() );
268 msg += wxT(
"|--------------------------------\n" );
274 msg.Printf(
_(
"Running job %d: %s" ), jobNum, job.GetDescription() );
283 job.m_job->SetTempOutputDirectory( tempDirPath );
306 if( job.m_job->GetType() ==
"special_execute" )
310 else if( job.m_job->GetType() ==
"special_copyfiles" )
313 std::vector<wxString> pathsWritten;
319 pathsWithOverwriteDisallowed.insert( pathsWithOverwriteDisallowed.end(), pathsWritten.begin(),
320 pathsWritten.end() );
323 else if( job.m_job->GetType() ==
"special_archive" )
329 msg = wxString::Format( wxT(
"Unsupported job type '%s'" ), job.m_type );
339 wxString msg_fmt = wxT(
"\033[32;1m%s\033[0m\n" );
340 msg = wxString::Format( msg_fmt,
_(
"Job successful" ) );
346 wxString msg_fmt = wxT(
"\033[31;1m%s\033[0m\n" );
347 msg = wxString::Format( msg_fmt,
_(
"Job failed" ) );
352 msg += wxT(
"\n\n" );
382 msg = wxString::Format( wxT(
"\n\n\033[33;1m%d %s, %d %s\033[0m\n" ),
384 wxT(
"jobs succeeded" ),
386 wxT(
"job failed" ) );
virtual bool OutputPrecheck()
Checks if the output process can proceed before doing anything else This can include user prompts.
virtual bool HandleOutputs(const wxString &aBaseTempPath, PROJECT *aProject, const std::vector< wxString > &aPathsWithOverwriteDisallowed, const std::vector< JOB_OUTPUT > &aOutputsToHandle, std::optional< wxString > &aResolvedOutputPath)=0
bool RunJobsAllDestinations(bool aBail=false)
JOBS_PROGRESS_REPORTER * m_progressReporter
bool RunJobsForDestination(JOBSET_DESTINATION *aDestination, bool aBail=false)
int runSpecialCopyFiles(const JOB_SPECIAL_COPYFILES *aJob, PROJECT *aProject, std::vector< wxString > &aPathsWritten)
int runSpecialArchive(const JOBSET_JOB *aJob, REPORTER *aReporter, PROJECT *aProject)
int runSpecialExecute(const JOBSET_JOB *aJob, REPORTER *aReporter, PROJECT *aProject)
JOBS_RUNNER(KIWAY *aKiway, JOBSET *aJobsFile, PROJECT *aProject, REPORTER &aReporter, JOBS_PROGRESS_REPORTER *aProgressReporter)
static KIWAY::FACE_T GetKifaceType(const wxString &aName)
bool m_generateErrorOnNoCopy
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
FACE_T
Known KIFACE implementations.
static REPORTER & GetInstance()
static bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Create an archive of the project.
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
int ExecuteCommandThroughShell(const wxString &aCommand, wxProcess *aProcess)
Run a user-supplied command line through the platform shell so glob expansion, pipes,...
bool CopyFilesOrDirectory(const wxString &aSourcePath, const wxString &aDestDir, bool aAllowOverwrites, wxString &aErrors, std::vector< wxString > &aPathsWritten)
#define OUTPUT_TMP_PATH_VAR_NAME
static const int ERR_ARGS
static const int ERR_RC_VIOLATIONS
Rules check violation count was greater than 0.
static const int ERR_INVALID_OUTPUT_CONFLICT
static const int ERR_UNKNOWN
static PGM_BASE * process
std::unordered_map< wxString, std::shared_ptr< JOBSET_OUTPUT_REPORTER > > m_lastRunReporters
std::shared_ptr< JOBS_OUTPUT_HANDLER > m_outputHandler
std::optional< wxString > m_lastResolvedOutputPath
std::optional< bool > m_lastRunSuccess
std::unordered_map< wxString, std::optional< bool > > m_lastRunSuccessMap
std::shared_ptr< JOB > m_job
wxString result
Test unit parsing edge cases and error handling.