Add BOM file extension to BOM plugin command line

Attempt to parse BOM output file extension from BOM plugin header, and
append it to the "%O" argument in the BOM plugin command line.

Fixes #6943

(cherry picked from commit f54ab830f6)
This commit is contained in:
Graham Keeth 2021-02-12 02:17:45 +00:00 committed by Jon Evans
parent db1bf4351b
commit 38d7ac6d9c
2 changed files with 40 additions and 7 deletions

View File

@ -48,24 +48,28 @@ BOM_PLUGIN::BOM_PLUGIN( const wxString& aFile )
if( extension == "xsl" )
{
m_info = readHeader( "-->" );
m_cmd = wxString::Format( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", m_file.GetFullPath() );
m_cmd = wxString::Format( "xsltproc -o \"%%O%s\" \"%s\" \"%%I\"",
getOutputExtension( m_info ), m_file.GetFullPath() );
}
else if( extension == "py" )
{
m_info = readHeader( "\"\"\"" );
#ifdef __WINDOWS__
m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O\"",
m_file.GetPath(), m_file.GetFullName() );
m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O%s\"",
m_file.GetPath(), m_file.GetFullName(),
getOutputExtension( m_info ) );
#else
m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O\"", m_file.GetFullPath() );
m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O%s\"", m_file.GetFullPath(),
getOutputExtension( m_info ) );
#endif
}
#ifdef __WINDOWS__
else if( extension == "pyw" )
{
m_info = readHeader( "\"\"\"" );
m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O\"",
m_file.GetPath(),m_file.GetFullName() );
m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O%s\"",
m_file.GetPath(), m_file.GetFullName(),
getOutputExtension( m_info ) );
}
#endif /* __WINDOWS__ */
else // fallback
@ -112,7 +116,7 @@ wxString BOM_PLUGIN::readHeader( const wxString& aEndSection )
strstart += header.Length();
int strend = data.find( aEndSection, strstart );
if( strend == wxNOT_FOUND)
if( strend == wxNOT_FOUND )
return wxEmptyString;
// Remove empty line if any
@ -121,3 +125,24 @@ wxString BOM_PLUGIN::readHeader( const wxString& aEndSection )
return data.SubString( strstart, strend - 1 );
}
wxString BOM_GENERATOR_HANDLER::getOutputExtension( const wxString& aHeader )
{
// search header for extension after %O (extension includes '.')
// looks for output argument of the form `"%O.extension"`
const wxString outputarg( "\"%O" );
int strstart = aHeader.Find( outputarg );
if( strstart == wxNOT_FOUND )
return wxEmptyString;
strstart += outputarg.Length();
int strend = aHeader.find( "\"", strstart );
if( strend == wxNOT_FOUND )
return wxEmptyString;
return aHeader.SubString( strstart, strend - 1 );
}

View File

@ -121,6 +121,14 @@ protected:
*/
wxString readHeader( const wxString& aEndSection );
/**
* Extracts the output BOM file's extension, including the '.', from the
* plugin file header. If the output extension cannot be determined from
* the plugin header, returns wxEmptyString.
* @param aHeader is the plugin file's header, as returned by readHeader()
**/
static wxString getOutputExtension( const wxString& aHeader );
///> true if the plugin is working (i.e. if the plugin file exists and was read
bool m_isOk;