Skip to content

Commit

Permalink
More info if GRASS modules fails. G__getenv to see if it moves forwar…
Browse files Browse the repository at this point in the history
…d on Windows.
  • Loading branch information
blazek committed Dec 11, 2012
1 parent d5bc39c commit c4d8e5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(

QProcess process( this );

QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
if ( mDirect )
{
// Set path to GRASS gis fake library
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();

QgsGrassModule::setDirectLibraryPath( environment );
environment.insert( "QGIS_PREFIX", QgsApplication::prefixPath() );
environment.insert( "QGIS_PREFIX_PATH", QgsApplication::prefixPath() );
// Window to avoid crash in G__gisinit
environment.insert( "GRASS_REGION", "west:0;south:0;east:1;north:1;cols:1;rows:1;proj:0;zone:0" );
process.setProcessEnvironment( environment );
Expand All @@ -361,8 +361,11 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(
|| ( process.exitCode() != 0 && process.exitCode() != 255 &&
( !cmd.endsWith( ".py" ) || process.exitCode() != 1 ) ) )
{
QString pathVariable = QgsGrassModule::libraryPathVariable();
QgsDebugMsg( "process.exitCode() = " + QString::number( process.exitCode() ) );
QString msg = tr( "Cannot start module %1" ).arg( mXName )
+ "<br>" + pathVariable + "=" + environment.value( pathVariable )
+ "<br>QGIS_PREFIX_PATH=" + environment.value( "QGIS_PREFIX_PATH" )
+ tr( "<br>command: %1 %2<br>%3<br>%4" )
.arg( cmd ).arg( arguments.join( " " ) )
.arg( process.readAllStandardOutput().constData() )
Expand Down Expand Up @@ -1996,18 +1999,26 @@ QDomNode QgsGrassModule::nodeByKey( QDomElement elem, QString key )
return QDomNode();
}

QString QgsGrassModule::libraryPathVariable()
{
#ifdef Q_OS_WIN
return "PATH";
#elif defined(Q_OS_MAC)
return "DYLD_LIBRARY_PATH";
#else
return "LD_LIBRARY_PATH";
#endif
}

void QgsGrassModule::setDirectLibraryPath( QProcessEnvironment & environment )
{
QString pathVariable;
QString pathVariable = libraryPathVariable();
QString separator;
#ifdef Q_OS_WIN
pathVariable = "PATH";
separator = ";";
#elif defined(Q_OS_MAC)
pathVariable = "DYLD_LIBRARY_PATH";
separator = ":";
#else
pathVariable = "LD_LIBRARY_PATH";
separator = ":";
#endif
QString lp = environment.value( pathVariable );
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
//! Returns true if module is direct
bool isDirect() { return mDirect; }

//! Get name of library path environment variable
static QString libraryPathVariable();

//! Set LD_LIBRARY_PATH or equivalent to GRASS Direct library
static void setDirectLibraryPath( QProcessEnvironment & environment );

Expand Down
1 change: 1 addition & 0 deletions src/providers/grass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SET ( FUNCTIONS
"G_define_standard_option"
"G_free"
"G_free_raster_cats"
"G__getenv"
"G_get_fp_range_min_max"
"G_get_range_min_max"
"G_get_window"
Expand Down

0 comments on commit c4d8e5a

Please sign in to comment.