Update user dir config file search path
Search in XDG_CONFIG_HOME as per XDG Base Directory Specification in addition to $HOME/.openocd. On Darwin, search in ~/Library/Preferences/org.openocd/ which appears to be one of the conventional locations. Make $OPENOCD_SCRIPTS highest priority on all platforms, previously it was only higher on WIN32. Update the documentation to reflect the search order. Change-Id: Ibaf4b59b51fdf452712d91b47ea2b5312bb5ada9 Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/3890 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
2ff1824a87
commit
87d2651edc
|
@ -724,8 +724,11 @@ Configuration files and scripts are searched for in
|
||||||
@item the current directory,
|
@item the current directory,
|
||||||
@item any search dir specified on the command line using the @option{-s} option,
|
@item any search dir specified on the command line using the @option{-s} option,
|
||||||
@item any search dir specified using the @command{add_script_search_dir} command,
|
@item any search dir specified using the @command{add_script_search_dir} command,
|
||||||
@item @file{$HOME/.openocd} (not on Windows),
|
|
||||||
@item a directory in the @env{OPENOCD_SCRIPTS} environment variable (if set),
|
@item a directory in the @env{OPENOCD_SCRIPTS} environment variable (if set),
|
||||||
|
@item @file{%APPDATA%/OpenOCD} (only on Windows),
|
||||||
|
@item @file{$HOME/Library/Preferences/org.openocd} (only on Darwin),
|
||||||
|
@item @file{$XDG_CONFIG_HOME/openocd} (@env{$XDG_CONFIG_HOME} defaults to @file{$HOME/.config}),
|
||||||
|
@item @file{$HOME/.openocd},
|
||||||
@item the site wide script library @file{$pkgdatadir/site} and
|
@item the site wide script library @file{$pkgdatadir/site} and
|
||||||
@item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}.
|
@item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}.
|
||||||
@end enumerate
|
@end enumerate
|
||||||
|
|
|
@ -178,6 +178,63 @@ static char *find_relative_path(const char *from, const char *to)
|
||||||
return relpath;
|
return relpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_user_dirs(void)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
#if IS_WIN32
|
||||||
|
const char *appdata = getenv("APPDATA");
|
||||||
|
|
||||||
|
if (appdata) {
|
||||||
|
path = alloc_printf("%s/OpenOCD", appdata);
|
||||||
|
if (path) {
|
||||||
|
/* Convert path separators to UNIX style, should work on Windows also. */
|
||||||
|
for (char *p = path; *p; p++) {
|
||||||
|
if (*p == '\\')
|
||||||
|
*p = '/';
|
||||||
|
}
|
||||||
|
add_script_search_dir(path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* WIN32 may also have HOME defined, particularly under Cygwin, so add those paths below too */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
#if IS_DARWIN
|
||||||
|
if (home) {
|
||||||
|
path = alloc_printf("%s/Library/Preferences/org.openocd", home);
|
||||||
|
if (path) {
|
||||||
|
add_script_search_dir(path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
const char *xdg_config = getenv("XDG_CONFIG_HOME");
|
||||||
|
|
||||||
|
if (xdg_config) {
|
||||||
|
path = alloc_printf("%s/openocd", xdg_config);
|
||||||
|
if (path) {
|
||||||
|
add_script_search_dir(path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
} else if (home) {
|
||||||
|
path = alloc_printf("%s/.config/openocd", home);
|
||||||
|
if (path) {
|
||||||
|
add_script_search_dir(path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (home) {
|
||||||
|
path = alloc_printf("%s/.openocd", home);
|
||||||
|
if (path) {
|
||||||
|
add_script_search_dir(path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void add_default_dirs(void)
|
static void add_default_dirs(void)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
@ -194,32 +251,11 @@ static void add_default_dirs(void)
|
||||||
* listed last in the built-in search order, so the user can
|
* listed last in the built-in search order, so the user can
|
||||||
* override these scripts with site-specific customizations.
|
* override these scripts with site-specific customizations.
|
||||||
*/
|
*/
|
||||||
const char *home = getenv("HOME");
|
|
||||||
|
|
||||||
if (home) {
|
|
||||||
path = alloc_printf("%s/.openocd", home);
|
|
||||||
if (path) {
|
|
||||||
add_script_search_dir(path);
|
|
||||||
free(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path = getenv("OPENOCD_SCRIPTS");
|
path = getenv("OPENOCD_SCRIPTS");
|
||||||
|
|
||||||
if (path)
|
if (path)
|
||||||
add_script_search_dir(path);
|
add_script_search_dir(path);
|
||||||
|
|
||||||
#ifdef _WIN32
|
add_user_dirs();
|
||||||
const char *appdata = getenv("APPDATA");
|
|
||||||
|
|
||||||
if (appdata) {
|
|
||||||
path = alloc_printf("%s/OpenOCD", appdata);
|
|
||||||
if (path) {
|
|
||||||
add_script_search_dir(path);
|
|
||||||
free(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
path = alloc_printf("%s/%s/%s", exepath, bin2data, "site");
|
path = alloc_printf("%s/%s/%s", exepath, bin2data, "site");
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
Loading…
Reference in New Issue