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;
115 std::vector<wxString>& aPathsWritten )
119 if( source.IsEmpty() )
123 wxFileName sourceFn( source );
124 sourceFn.MakeAbsolute( projectPath );
128 if( !aJob->
m_dest.IsEmpty() )
129 destFn.AppendDir( aJob->
m_dest );
133 errors, aPathsWritten );
147 bool genOutputs =
true;
149 std::vector<JOBSET_JOB> jobsForDestination =
m_jobsFile->GetJobsForDestination( aDestination );
153 tmp.AssignDir( wxFileName::GetTempDir() );
154 tmp.AppendDir(
KIID().AsString() );
160 wxString tempDirPath = tmp.GetFullPath();
162 if( !wxFileName::Mkdir( tempDirPath, wxS_DIR_DEFAULT ) )
164 msg = wxString::Format( wxT(
"Failed to create temporary directory %s" ), tempDirPath );
176 msg = wxString::Format( wxT(
"Destination precheck failed for destination %s" ),
177 aDestination->
m_id );
184 msg += wxT(
"|--------------------------------\n" );
186 msg += wxString::Format( wxT(
"Running jobs for destination %s" ), aDestination->
m_id );
188 msg += wxT(
"|--------------------------------\n" );
190 msg += wxString::Format( wxT(
"|%-5s | %-50s\n" ), wxT(
"No." ), wxT(
"Description" ) );
194 for(
const JOBSET_JOB& job : jobsForDestination )
196 msg += wxString::Format( wxT(
"|%-5d | %-50s\n" ), jobNum, job.GetDescription() );
200 msg += wxT(
"|--------------------------------\n" );
206 std::vector<wxString> pathsWithOverwriteDisallowed;
207 std::vector<JOB_OUTPUT> outputs;
211 int successCount = 0;
215 for(
const JOBSET_JOB& job : jobsForDestination )
217 msg = wxT(
"|--------------------------------\n" );
219 msg += wxString::Format( wxT(
"| Running job %d: %s" ), jobNum, job.GetDescription() );
222 msg += wxT(
"|--------------------------------\n" );
228 msg.Printf(
_(
"Running job %d: %s" ), jobNum, job.GetDescription() );
237 job.m_job->SetTempOutputDirectory( tempDirPath );
260 if( job.m_job->GetType() ==
"special_execute" )
264 else if( job.m_job->GetType() ==
"special_copyfiles" )
267 std::vector<wxString> pathsWritten;
273 pathsWithOverwriteDisallowed.insert( pathsWithOverwriteDisallowed.end(), pathsWritten.begin(),
274 pathsWritten.end() );
283 wxString msg_fmt = wxT(
"\033[32;1m%s\033[0m\n" );
284 msg = wxString::Format( msg_fmt,
_(
"Job successful" ) );
290 wxString msg_fmt = wxT(
"\033[31;1m%s\033[0m\n" );
291 msg = wxString::Format( msg_fmt,
_(
"Job failed" ) );
296 msg += wxT(
"\n\n" );
326 msg = wxString::Format( wxT(
"\n\n\033[33;1m%d %s, %d %s\033[0m\n" ),
328 wxT(
"jobs succeeded" ),
330 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 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, 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.