31#include <wx/process.h>
32#include <wx/txtstrm.h>
33#include <wx/sstream.h>
34#include <wx/wfstream.h>
71 int result =
static_cast<int>( wxExecute( cmd, wxEXEC_SYNC, &
process ) );
73 wxInputStream* inputStream =
process.GetInputStream();
74 wxInputStream* errorStream =
process.GetErrorStream();
76 if( inputStream && errorStream )
78 wxTextInputStream inputTextStream( *inputStream );
79 wxTextInputStream errorTextStream( *errorStream );
81 while( !inputStream->Eof() )
84 while( !errorStream->Eof() )
91 wxFileName fn( aJob->
m_id );
92 fn.SetExt( wxT(
"log" ) );
98 if( !procOutput.IsOk() )
101 inputStream->Reset();
102 *inputStream >> procOutput;
119 if( source.IsEmpty() )
123 wxFileName sourceFn( source );
124 sourceFn.MakeAbsolute( projectPath );
128 if( !job->
m_dest.IsEmpty() )
129 destFn.AppendDir( job->
m_dest );
131 std::vector<wxString> exclusions;
134 exclusions.push_back( projectPath + destination.m_outputHandler->GetOutputPath() );
139 errors, copyCount, exclusions );
153 bool genOutputs =
true;
155 std::vector<JOBSET_JOB> jobsForDestination =
m_jobsFile->GetJobsForDestination( aDestination );
159 tmp.AssignDir( wxFileName::GetTempDir() );
160 tmp.AppendDir(
KIID().AsString() );
165 wxString tempDirPath = tmp.GetFullPath();
167 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
169 msg = wxString::Format( wxT(
"Failed to create temporary directory %s" ), tempDirPath );
181 msg = wxString::Format( wxT(
"Destination precheck failed for destination %s" ),
182 aDestination->
m_id );
189 msg += wxT(
"|--------------------------------\n" );
191 msg += wxString::Format( wxT(
"Running jobs for destination %s" ), aDestination->
m_id );
193 msg += wxT(
"|--------------------------------\n" );
195 msg += wxString::Format( wxT(
"|%-5s | %-50s\n" ), wxT(
"No." ), wxT(
"Description" ) );
199 for(
const JOBSET_JOB& job : jobsForDestination )
201 msg += wxString::Format( wxT(
"|%-5d | %-50s\n" ), jobNum, job.GetDescription() );
205 msg += wxT(
"|--------------------------------\n" );
211 std::vector<JOB_OUTPUT> outputs;
215 int successCount = 0;
219 for(
const JOBSET_JOB& job : jobsForDestination )
221 msg = wxT(
"|--------------------------------\n" );
223 msg += wxString::Format( wxT(
"| Running job %d: %s" ), jobNum, job.GetDescription() );
226 msg += wxT(
"|--------------------------------\n" );
232 msg.Printf(
_(
"Running job %d: %s" ), jobNum, job.GetDescription() );
241 job.m_job->SetTempOutputDirectory( tempDirPath );
259 result =
m_kiway->ProcessJob( iface, job.m_job.get(), &isolatedReporter,
265 if( job.m_job->GetType() ==
"special_execute" )
269 else if( job.m_job->GetType() ==
"special_copyfiles" )
279 wxString msg_fmt = wxT(
"\033[32;1m%s\033[0m\n" );
280 msg = wxString::Format( msg_fmt,
_(
"Job successful" ) );
286 wxString msg_fmt = wxT(
"\033[31;1m%s\033[0m\n" );
287 msg = wxString::Format( msg_fmt,
_(
"Job failed" ) );
292 msg += wxT(
"\n\n" );
319 msg = wxString::Format( wxT(
"\n\n\033[33;1m%d %s, %d %s\033[0m\n" ),
321 wxT(
"jobs succeeded" ),
323 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< JOB_OUTPUT > &aOutputsToHandle)=0
bool RunJobsAllDestinations(bool aBail=false)
JOBS_PROGRESS_REPORTER * m_progressReporter
bool RunJobsForDestination(JOBSET_DESTINATION *aDestination, bool aBail=false)
int runSpecialCopyFiles(const JOBSET_JOB *aJob, 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()
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
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.
bool CopyFilesOrDirectory(const wxString &aSourcePath, const wxString &aDestDir, wxString &aErrors, int &aFileCopiedCount, const std::vector< wxString > &aExclusions)
#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< 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.