32#include <wx/process.h>
33#include <wx/txtstrm.h>
34#include <wx/sstream.h>
35#include <wx/wfstream.h>
72 int result =
static_cast<int>( wxExecute( cmd, wxEXEC_SYNC, &
process ) );
74 wxInputStream* inputStream =
process.GetInputStream();
75 wxInputStream* errorStream =
process.GetErrorStream();
77 if( inputStream && errorStream )
79 wxTextInputStream inputTextStream( *inputStream );
80 wxTextInputStream errorTextStream( *errorStream );
82 while( !inputStream->Eof() )
85 while( !errorStream->Eof() )
92 wxFileName fn( aJob->
m_id );
93 fn.SetExt( wxT(
"log" ) );
99 if( !procOutput.IsOk() )
102 inputStream->Reset();
103 *inputStream >> procOutput;
120 if( source.IsEmpty() )
124 wxFileName sourceFn( source );
125 sourceFn.MakeAbsolute( projectPath );
129 if( !job->
m_dest.IsEmpty() )
130 destFn.AppendDir( job->
m_dest );
132 std::vector<wxString> exclusions;
135 exclusions.push_back( projectPath + destination.m_outputHandler->GetOutputPath() );
140 errors, copyCount, exclusions );
154 bool genOutputs =
true;
156 std::vector<JOBSET_JOB> jobsForDestination =
m_jobsFile->GetJobsForDestination( aDestination );
160 tmp.AssignDir( wxFileName::GetTempDir() );
161 tmp.AppendDir(
KIID().AsString() );
167 wxString tempDirPath = tmp.GetFullPath();
169 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
171 msg = wxString::Format( wxT(
"Failed to create temporary directory %s" ), tempDirPath );
183 msg = wxString::Format( wxT(
"Destination precheck failed for destination %s" ),
184 aDestination->
m_id );
191 msg += wxT(
"|--------------------------------\n" );
193 msg += wxString::Format( wxT(
"Running jobs for destination %s" ), aDestination->
m_id );
195 msg += wxT(
"|--------------------------------\n" );
197 msg += wxString::Format( wxT(
"|%-5s | %-50s\n" ), wxT(
"No." ), wxT(
"Description" ) );
201 for(
const JOBSET_JOB& job : jobsForDestination )
203 msg += wxString::Format( wxT(
"|%-5d | %-50s\n" ), jobNum, job.GetDescription() );
207 msg += wxT(
"|--------------------------------\n" );
213 std::vector<JOB_OUTPUT> outputs;
217 int successCount = 0;
221 for(
const JOBSET_JOB& job : jobsForDestination )
223 msg = wxT(
"|--------------------------------\n" );
225 msg += wxString::Format( wxT(
"| Running job %d: %s" ), jobNum, job.GetDescription() );
228 msg += wxT(
"|--------------------------------\n" );
234 msg.Printf(
_(
"Running job %d: %s" ), jobNum, job.GetDescription() );
243 job.m_job->SetTempOutputDirectory( tempDirPath );
261 result =
m_kiway->ProcessJob( iface, job.m_job.get(), &isolatedReporter,
267 if( job.m_job->GetType() ==
"special_execute" )
271 else if( job.m_job->GetType() ==
"special_copyfiles" )
281 wxString msg_fmt = wxT(
"\033[32;1m%s\033[0m\n" );
282 msg = wxString::Format( msg_fmt,
_(
"Job successful" ) );
288 wxString msg_fmt = wxT(
"\033[31;1m%s\033[0m\n" );
289 msg = wxString::Format( msg_fmt,
_(
"Job failed" ) );
294 msg += wxT(
"\n\n" );
323 msg = wxString::Format( wxT(
"\n\n\033[33;1m%d %s, %d %s\033[0m\n" ),
325 wxT(
"jobs succeeded" ),
327 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, 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 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< 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.