Update get_standard_cache_dir for macOS

Message ID 20180914145938.12186-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 14, 2018, 2:59 p.m. UTC
  On macOS the usual cache directory is ~/Library/Caches.  This patch
changes get_standard_cache_dir to use that instead of XDG.

gdb/ChangeLog
2018-09-14  Tom Tromey  <tom@tromey.com>

	* common/pathstuff.c (get_standard_cache_dir): Use
	~/Library/Caches on macOS.
	* common/pathstuff.h (get_standard_cache_dir): Update comment.

gdb/doc/ChangeLog
2018-09-14  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Index Files): Update for cache directory change on
	macOS.
---
 gdb/ChangeLog          |  6 ++++++
 gdb/common/pathstuff.c | 10 +++++++++-
 gdb/common/pathstuff.h | 10 +++++++---
 gdb/doc/ChangeLog      |  5 +++++
 gdb/doc/gdb.texinfo    | 12 ++++++++----
 5 files changed, 35 insertions(+), 8 deletions(-)
  

Comments

Eli Zaretskii Sept. 14, 2018, 6:38 p.m. UTC | #1
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Fri, 14 Sep 2018 08:59:38 -0600
> 
> On macOS the usual cache directory is ~/Library/Caches.  This patch
> changes get_standard_cache_dir to use that instead of XDG.
> 
> gdb/ChangeLog
> 2018-09-14  Tom Tromey  <tom@tromey.com>
> 
> 	* common/pathstuff.c (get_standard_cache_dir): Use
> 	~/Library/Caches on macOS.
> 	* common/pathstuff.h (get_standard_cache_dir): Update comment.
> 
> gdb/doc/ChangeLog
> 2018-09-14  Tom Tromey  <tom@tromey.com>
> 
> 	* gdb.texinfo (Index Files): Update for cache directory change on
> 	macOS.

OK for the documentation part.

(I thought that "on most systems" is the way to avoid describing what
happens on each system out there, and I don't see why we should be
eager to cater to macOS so much.  But that's me.)
  
Tom Tromey Sept. 14, 2018, 6:45 p.m. UTC | #2
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

Eli> (I thought that "on most systems" is the way to avoid describing what
Eli> happens on each system out there, and I don't see why we should be
Eli> eager to cater to macOS so much.  But that's me.)

I can't tell if this is a critique of the documentation or the code.

For the code, I think gdb should do what local users expect if it is
reasonable.  In this case, for example, backup tools know to avoid
backing up the standard cache directory.

For the documentation, I'm happy to change it however you like.

Tom
  
Eli Zaretskii Sept. 14, 2018, 6:56 p.m. UTC | #3
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
> Date: Fri, 14 Sep 2018 12:45:04 -0600
> 
> >>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> 
> Eli> (I thought that "on most systems" is the way to avoid describing what
> Eli> happens on each system out there, and I don't see why we should be
> Eli> eager to cater to macOS so much.  But that's me.)
> 
> I can't tell if this is a critique of the documentation or the code.

Documentation only, of course.

> For the documentation, I'm happy to change it however you like.

I just voiced my opinion that this detail about macOS, and only about
it, seems at odds with our general tendency not to describe
proprietary systems in too much detail.  But I'm not going to block
this change just because I was surprised.  I wonder what others think.
  
Tom Tromey Sept. 14, 2018, 7:07 p.m. UTC | #4
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

>> For the documentation, I'm happy to change it however you like.

Eli> I just voiced my opinion that this detail about macOS, and only about
Eli> it, seems at odds with our general tendency not to describe
Eli> proprietary systems in too much detail.  But I'm not going to block
Eli> this change just because I was surprised.  I wonder what others think.

I guess I didn't really give it much thought.  I wouldn't mind being
more vague.  What about something like:

    The default value for this directory depends on the host platform.  On
    most systems, the index is cached in the @file{gdb} subdirectory of
    the directory pointed to by the @env{XDG_CACHE_HOME} environment
    variable, if it is defined, else in the @file{.cache/gdb} subdirectory
    of your home directory.  However, on some systems, the default may
    differ according to local convention.

I think it's no big deal for users to use "show index-cache directory" 
if they really care about the value.

Tom
  
Eli Zaretskii Sept. 14, 2018, 8:03 p.m. UTC | #5
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
> Date: Fri, 14 Sep 2018 13:07:46 -0600
> 
>     The default value for this directory depends on the host platform.  On
>     most systems, the index is cached in the @file{gdb} subdirectory of
>     the directory pointed to by the @env{XDG_CACHE_HOME} environment
>     variable, if it is defined, else in the @file{.cache/gdb} subdirectory
>     of your home directory.  However, on some systems, the default may
>     differ according to local convention.

Fine with me, thanks.

> I think it's no big deal for users to use "show index-cache directory" 
> if they really care about the value.

Right.
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 49bcd9ff8a..59b47bd9aa 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-09-14  Tom Tromey  <tom@tromey.com>
+
+	* common/pathstuff.c (get_standard_cache_dir): Use
+	~/Library/Caches on macOS.
+	* common/pathstuff.h (get_standard_cache_dir): Update comment.
+
 2018-09-14  Tom Tromey  <tom@tromey.com>
 
 	* infcall.c (call_function_by_hand_dummy): Remove unnecessary
diff --git a/gdb/common/pathstuff.c b/gdb/common/pathstuff.c
index 2d9dcb25d4..3dd58e31aa 100644
--- a/gdb/common/pathstuff.c
+++ b/gdb/common/pathstuff.c
@@ -164,6 +164,13 @@  contains_dir_separator (const char *path)
 std::string
 get_standard_cache_dir ()
 {
+#ifdef __APPLE__
+#define HOME_CACHE_DIR "Library/Caches"
+#else
+#define HOME_CACHE_DIR ".cache"
+#endif
+
+#ifndef __APPLE__
   char *xdg_cache_home = getenv ("XDG_CACHE_HOME");
   if (xdg_cache_home != NULL)
     {
@@ -171,13 +178,14 @@  get_standard_cache_dir ()
       gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_cache_home));
       return string_printf ("%s/gdb", abs.get ());
     }
+#endif
 
   char *home = getenv ("HOME");
   if (home != NULL)
     {
       /* Make sure the path is absolute and tilde-expanded.  */
       gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
-      return string_printf ("%s/.cache/gdb", abs.get ());
+      return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.get ());
     }
 
   return {};
diff --git a/gdb/common/pathstuff.h b/gdb/common/pathstuff.h
index d1aa6b306c..a43b963651 100644
--- a/gdb/common/pathstuff.h
+++ b/gdb/common/pathstuff.h
@@ -53,10 +53,14 @@  extern bool contains_dir_separator (const char *path);
 /* Get the usual user cache directory for the current platform.
 
    On Linux, it follows the XDG Base Directory specification: use
-   $XDG_CACHE_HOME/gdb if the XDG_CACHE_HOME environment variable is defined,
-   otherwise $HOME/.cache.  The return value is absolute and tilde-expanded.
+   $XDG_CACHE_HOME/gdb if the XDG_CACHE_HOME environment variable is
+   defined, otherwise $HOME/.cache.
 
-   Return an empty string if neither XDG_CACHE_HOME or HOME are defined.  */
+   On macOS, it follows the local convention and uses
+   ~/Library/Caches/gdb.
+
+  The return value is absolute and tilde-expanded.  Return an empty
+  string if neither XDG_CACHE_HOME (on Linux) or HOME are defined.  */
 
 extern std::string get_standard_cache_dir ();
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 1a5c70bfc8..bb494362bc 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-09-14  Tom Tromey  <tom@tromey.com>
+
+	* gdb.texinfo (Index Files): Update for cache directory change on
+	macOS.
+
 2018-09-13  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* python.texi (Objfiles In Python): Update gdb.objfiles() doc.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index efbec3debf..ad090ba17b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20128,10 +20128,14 @@  Enable or disable the use of the symbol index cache.
 
 @item set index-cache directory @var{directory}
 @itemx show index-cache directory
-Set/show the directory where index files will be saved.  By default, the index
-is cached in the @file{gdb} subdirectory of the directory pointed to by the
-@env{XDG_CACHE_HOME} environment variable, if it is defined, else in the
-@file{.cache/gdb} subdirectory of your home directory.
+Set/show the directory where index files will be saved.
+
+The default value for this directory depends on the host platform.  On
+most systems, the index is cached in the @file{gdb} subdirectory of
+the directory pointed to by the @env{XDG_CACHE_HOME} environment
+variable, if it is defined, else in the @file{.cache/gdb} subdirectory
+of your home directory.  However, on macOS, the index is cached in the
+@file{~/Library/Caches/gdb/}.
 
 There is no limit on the disk space used by index cache.  It is perfectly safe
 to delete the content of that directory to free up disk space.