7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 05:06:55 +00:00

Fix output paths for jobs again

This commit is contained in:
Marek Roszko 2025-01-11 18:56:55 -05:00
parent 4cfd6f71e5
commit db56d51838
7 changed files with 63 additions and 26 deletions

View File

@ -463,9 +463,16 @@ wxString PATHS::GetLogsPath()
}
bool PATHS::EnsurePathExists( const wxString& aPath )
bool PATHS::EnsurePathExists( const wxString& aPath, bool aPathToFile )
{
wxFileName path( aPath );
wxString pathString = aPath;
if( !aPathToFile )
{
// ensures the path is treated fully as directory
pathString += wxFileName::GetPathSeparator();
}
wxFileName path( pathString );
if( !path.MakeAbsolute() )
{
return false;

View File

@ -210,6 +210,8 @@ const std::string FILEEXT::XaoFileExtension( "xao" );
const std::string FILEEXT::PlyFileExtension( "ply" );
const std::string FILEEXT::StlFileExtension( "stl" );
const std::string FILEEXT::GencadFileExtension( "cad" );
const wxString FILEEXT::GerberFileExtensionsRegex( "(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))" );
const std::string FILEEXT::FootprintLibraryTableFileName( "fp-lib-table" );
@ -498,7 +500,7 @@ wxString FILEEXT::ZipFileWildcard()
wxString FILEEXT::GencadFileWildcard()
{
return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { "cad" } );
return _( "GenCAD 1.4 board files" ) + AddFileExtListToFilter( { GencadFileExtension } );
}

View File

@ -471,7 +471,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
wxString outPath = aNetJob->GetFullOutputPath( &sch->Prj() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -681,7 +681,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
wxString outPath = aBomJob->GetFullOutputPath( &sch->Prj() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -801,7 +801,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
wxString outPath = aNetJob->GetFullOutputPath( &sch->Prj() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -1117,6 +1117,14 @@ int EESCHEMA_JOBS_HANDLER::JobSchErc( JOB* aJob )
ercJob->SetOutputPath( fn.GetFullName() );
}
wxString outPath = ercJob->GetFullOutputPath( &sch->Prj() );
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
EDA_UNITS units;
switch( ercJob->m_units )
@ -1148,8 +1156,6 @@ int EESCHEMA_JOBS_HANDLER::JobSchErc( JOB* aJob )
bool wroteReport = false;
wxString outPath = ercJob->GetFullOutputPath( &sch->Prj() );
if( ercJob->m_format == JOB_SCH_ERC::OUTPUT_FORMAT::JSON )
wroteReport = reportWriter.WriteJsonReport( outPath );
else

View File

@ -166,7 +166,7 @@ public:
/**
* Attempts to create a given path if it does not exist
*/
static bool EnsurePathExists( const wxString& aPath );
static bool EnsurePathExists( const wxString& aPath, bool aPathToFile = false );
/**
* Ensures/creates user default paths

View File

@ -199,6 +199,8 @@ public:
static const std::string PlyFileExtension;
static const std::string StlFileExtension;
static const std::string GencadFileExtension;
static const std::string KiCadJobSetFileExtension;
static const wxString GerberFileExtensionsRegex;

View File

@ -103,6 +103,7 @@ bool PCB_PLOTTER::Plot( const wxString& aOutputPath,
wxString fileExt( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
wxString sheetPath;
wxString msg;
bool success = true;
PLOTTER* plotter = nullptr;
for( size_t i = 0, pageNum = 1; i < layersToPlot.size(); i++ )
{
@ -241,10 +242,7 @@ bool PCB_PLOTTER::Plot( const wxString& aOutputPath,
msg.Printf( _( "Failed to create file '%s'." ), fn.GetFullPath() );
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
if( m_plotOpts.m_PDFSingle )
{
return false;
}
success = false;
}
pageNum++;
@ -265,7 +263,7 @@ bool PCB_PLOTTER::Plot( const wxString& aOutputPath,
m_reporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
return true;
return success;
}

View File

@ -364,7 +364,7 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob )
wxString outPath = aStepJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -496,6 +496,14 @@ int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob )
aRenderJob->SetOutputPath( fn.GetFullName() );
}
wxString outPath = aRenderJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
BOARD_ADAPTER boardAdapter;
boardAdapter.SetBoard( brd );
@ -674,7 +682,7 @@ int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob )
image = image.Mirror( false );
image.SetOption( wxIMAGE_OPTION_QUALITY, 90 );
image.SaveFile( aRenderJob->GetFullOutputPath( brd->GetProject() ),
image.SaveFile( outPath,
aRenderJob->m_format == JOB_PCB_RENDER::FORMAT::PNG ? wxBITMAP_TYPE_PNG
: wxBITMAP_TYPE_JPEG );
}
@ -718,6 +726,14 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
}
}
wxString outPath = aSvgJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath, aSvgJob->m_genMode == JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
loadOverrideDrawingSheet( brd, aSvgJob->m_drawingSheet );
brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() );
brd->SynchronizeProperties();
@ -743,7 +759,7 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
sheetPath = aSvgJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
}
if( !plotter.Plot( aSvgJob->GetFullOutputPath( brd->GetProject() ), aSvgJob->m_printMaskLayer,
if( !plotter.Plot( outPath, aSvgJob->m_printMaskLayer,
aSvgJob->m_printMaskLayersToIncludeOnAllLayers, false,
aSvgJob->m_genMode == JOB_EXPORT_PCB_SVG::GEN_MODE::SINGLE,
layerName,
@ -786,6 +802,14 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
}
}
wxString outPath = aDxfJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath, aDxfJob->m_genMode == JOB_EXPORT_PCB_DXF::GEN_MODE::SINGLE ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
PCB_PLOT_PARAMS plotOpts;
PCB_PLOTTER::PlotJobToPlotOpts( plotOpts, aDxfJob );
@ -807,7 +831,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
sheetPath = aDxfJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
}
if( !plotter.Plot( aDxfJob->GetFullOutputPath( brd->GetProject() ), aDxfJob->m_printMaskLayer,
if( !plotter.Plot( outPath, aDxfJob->m_printMaskLayer,
aDxfJob->m_printMaskLayersToIncludeOnAllLayers, false,
aDxfJob->m_genMode == JOB_EXPORT_PCB_DXF::GEN_MODE::SINGLE, layerName,
sheetName, sheetPath ) )
@ -860,7 +884,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
wxString outPath = aPdfJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, aPdfJob->m_pdfGenMode == JOB_EXPORT_PCB_PDF::GEN_MODE::ALL_LAYERS_ONE_FILE ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -1060,20 +1084,19 @@ int PCBNEW_JOBS_HANDLER::JobExportGencad( JOB* aJob )
{
wxFileName fn = brd->GetFileName();
fn.SetName( fn.GetName() );
fn.SetExt( GetDefaultPlotExtension( PLOT_FORMAT::DXF ) );
fn.SetExt( FILEEXT::GencadFileExtension );
aGencadJob->SetOutputPath( fn.GetFullName() );
}
wxString outPath = aGencadJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
}
if( !exporter.WriteFile( outPath ) )
{
wxString msg;
@ -1205,7 +1228,6 @@ int PCBNEW_JOBS_HANDLER::JobExportDrill( JOB* aJob )
if( !brd )
return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE;
wxString outPath = aDrillJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
@ -1343,7 +1365,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPos( JOB* aJob )
wxString outPath = aPosJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -1663,7 +1685,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
wxString outPath = drcJob->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;
@ -1832,7 +1854,7 @@ int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob )
wxString outPath = job->GetFullOutputPath( brd->GetProject() );
if( !PATHS::EnsurePathExists( outPath ) )
if( !PATHS::EnsurePathExists( outPath, true ) )
{
m_reporter->Report( _( "Failed to create output directory\n" ), RPT_SEVERITY_ERROR );
return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT;