From 087550ebd368cf40a852b387fda05c2da7c4ae90 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Thu, 8 Sep 2022 21:44:02 -0400 Subject: [PATCH] Get 3d plugins working for running from build dir --- 3d-viewer/3d_cache/3d_plugin_manager.cpp | 59 +++++++++++------------- common/paths.cpp | 10 +++- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index 100d2dd2cc..cc35ee295e 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -120,36 +120,37 @@ S3D_PLUGIN_MANAGER::~S3D_PLUGIN_MANAGER() void S3D_PLUGIN_MANAGER::loadPlugins( void ) { - std::list< wxString > searchpaths; - std::list< wxString > pluginlist; - wxFileName fn; + std::list searchpaths; + std::list pluginlist; + wxFileName fn; #ifndef __WXMAC__ - -#ifdef DEBUG - // set up to work from the build directory - fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); - fn.AppendDir( wxT( ".." ) ); - fn.AppendDir( wxT( "plugins" ) ); - fn.AppendDir( wxT( "3d" ) ); - - std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() ); - checkPluginPath( testpath, searchpaths ); - - // add subdirectories too - wxDir debugPluginDir; - wxString subdir; - - debugPluginDir.Open( testpath ); - - if( debugPluginDir.IsOpened() && debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) ) + if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) { - checkPluginPath( testpath + subdir, searchpaths ); + // set up to work from the build directory + fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); + fn.AppendDir( wxT( ".." ) ); + fn.AppendDir( wxT( "plugins" ) ); + fn.AppendDir( wxT( "3d" ) ); - while( debugPluginDir.GetNext( &subdir ) ) + std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() ); + checkPluginPath( testpath, searchpaths ); + + // add subdirectories too + wxDir debugPluginDir; + wxString subdir; + + debugPluginDir.Open( testpath ); + + if( debugPluginDir.IsOpened() + && debugPluginDir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) ) + { checkPluginPath( testpath + subdir, searchpaths ); + + while( debugPluginDir.GetNext( &subdir ) ) + checkPluginPath( testpath + subdir, searchpaths ); + } } -#endif fn.AssignDir( PATHS::GetStockPlugins3DPath() ); checkPluginPath( std::string( fn.GetPathWithSep().ToUTF8() ), searchpaths ); @@ -312,20 +313,14 @@ void S3D_PLUGIN_MANAGER::checkPluginName( const wxString& aPath, void S3D_PLUGIN_MANAGER::checkPluginPath( const wxString& aPath, std::list< wxString >& aSearchList ) { - // check the existence of a path and add it to the path search list if( aPath.empty() ) return; - wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * [INFO] checking for 3D plugins in '%s'\n" ), + wxLogTrace( MASK_3D_PLUGINMGR, wxT( " * [INFO] checking if valid plugin directory '%s'\n" ), aPath.GetData() ); wxFileName path; - - if( aPath.StartsWith( wxT( "${" ) ) || aPath.StartsWith( wxT( "$(" ) ) ) - path.Assign( ExpandEnvVarSubstitutions( aPath, nullptr ), wxEmptyString ); - else - path.Assign( aPath, wxT( "" ) ); - + path.AssignDir( aPath ); path.Normalize( FN_NORMALIZE_FLAGS ); if( !wxFileName::DirExists( path.GetFullPath() ) ) diff --git a/common/paths.cpp b/common/paths.cpp index bc50550768..a74cdd997c 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -289,7 +289,15 @@ wxString PATHS::GetStockPlugins3DPath() #elif defined( __WXMAC__ ) fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString ); #else - fn.AssignDir( Pgm().GetExecutablePath() ); + if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) + { + fn.AssignDir( getWindowsKiCadRoot() ); + } + else + { + fn.AssignDir( Pgm().GetExecutablePath() ); + } + fn.AppendDir( wxT( "plugins" ) ); #endif