← Back to team overview

kicad-developers team mailing list archive

Re: XDG_CONFIG_HOME on all platforms

 

Attached is a revised patch.  It now only checks for XDG_CONFIG_HOME
when wxWidgets is <= 3.1.1 and not windows or macos.  KICAD_CONFIG_HOME
takes precedence over everything if it's defined.  I don't have
wxWidgets 3.1.1 on my linux box so if someone with linux and wx 3.1.1
can test this to make sure the user confing path is correct I would
appreciate it.

Thanks,

Wayne

On 4/24/2018 6:54 AM, Strontium wrote:
> Hi Wayne,
> 
> I have no personal problem with your patch, but from a standards point
> of view I want to raise this.
> 
> As per:
> https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
> |"$XDG_CONFIG_HOME| defines the base directory relative to which user
> specific configuration files should be stored. If |$XDG_CONFIG_HOME| is
> either not set or empty, a default equal to |$HOME|/.config should be used."
> 
> The way I read your patch is that, XDG_CONFIG_HOME is being used to
> specify the absolute path of the kicad configuration directory, not it's
> relative base directory.
> 
> My concern is that if XDG_CONFIG_HOME is set to someones "relative base
> config directory", then that relative base config directory is going to
> get filled with kicad config files.
> 
> Also, on unix, wxStandardPaths::Get().GetUserConfigDir() uses
> XDG_CONFIG_HOME internally, so the current kicad specific support for
> XDG_CONFIG_HOME (as a relative base directory) is redundant.
> see:
> https://github.com/wxWidgets/wxWidgets/blob/master/src/unix/stdpaths.cpp
> 
> Maybe its better to just define a new Kicad specific environment
> variable for the purpose, "KICAD_CONFIG_HOME" for example.  Then there
> is no conflict with any existing uses or standards, your patch as
> written, would also then remove the redundant of processing XDG_CONFIG_HOME.
> 
> Steven
>  
> On 24/04/18 01:10, Wayne Stambaugh wrote:
>> Attached is a patch that allows users to have multiple configuration
>> paths using the XDG_CONFIG_HOME environment variable on all platforms.
>> I tested it on windows and it seems to work just fine.  I can test it on
>> linux tonight when I get home but if someone can get to it before then I
>> would appreciate the help.  Would one of our macos devs please test it
>> as well before I merge it.
>>
>> Thanks,
>>
>> Wayne
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
> 
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 
From 1c0bdae998b383a0b98b743d6e1788b669f3dbdc Mon Sep 17 00:00:00 2001
From: Wayne Stambaugh <stambaughw@xxxxxxxxx>
Date: Tue, 24 Apr 2018 11:53:59 -0400
Subject: [PATCH] Allow for multiple user configurations.

Use KICAD_CONFIG_HOME environment variable on all platforms so users can
maintain multiple configurations of KiCad.
---
 common/common.cpp | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/common/common.cpp b/common/common.cpp
index f5b8abce4..b96a96437 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -219,29 +219,32 @@ wxString GetKicadConfigPath()
 {
     wxFileName cfgpath;
 
-    // From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
-    //      Unix: ~ (the home directory)
-    //      Windows: "C:\Documents and Settings\username\Application Data"
-    //      Mac: ~/Library/Preferences
+    // http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
     cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
 
-#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
     wxString envstr;
 
-    if( !wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) || envstr.IsEmpty() )
-    {
-        // XDG_CONFIG_HOME is not set, so use the fallback
-        cfgpath.AppendDir( wxT( ".config" ) );
-    }
-    else
+    // wxStandardPaths does not default to ~/.config which is the current standard config
+    // location on Linux.  This has been fixed in wxWidgets 3.1.1.
+#if !wxCHECK_VERSION( 3, 1, 1 ) && !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
+    if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
     {
         // Override the assignment above with XDG_CONFIG_HOME
         cfgpath.AssignDir( envstr );
     }
+
+    cfgpath.AppendDir( wxT( ".config" ) );
 #endif
 
     cfgpath.AppendDir( wxT( "kicad" ) );
 
+    // Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path.
+    if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
+    {
+        // Override the assignment above with XDG_CONFIG_HOME
+        cfgpath.AssignDir( envstr );
+    }
+
     if( !cfgpath.DirExists() )
     {
         cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
-- 
2.17.0


References