[binutils-gdb] gdb/testsuite: don't use source tree as temporary HOME directory

Andrew Burgess aburgess@sourceware.org
Mon May 10 16:56:33 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9344937b0462392f8996176c1f6d39ffc8eb84f5

commit 9344937b0462392f8996176c1f6d39ffc8eb84f5
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Mon May 10 16:49:56 2021 +0100

    gdb/testsuite: don't use source tree as temporary HOME directory
    
    In this commit:
    
      commit 1845e254645efbc02248345ccdb557d265dd8ae1
      Date:   Wed May 5 16:50:17 2021 +0100
    
          gdb/guile: perform tilde expansion when sourcing guile scripts
    
    A test was added that tries to source a guile script from the users
    HOME directory.  In order to achieve this the test (temporarily)
    modifies $HOME to point into the binutils-gdb source tree.
    
    The problem with this is that sourcing a guile script can cause the
    guile script to be byte compiled and written into a .cache/ directory,
    which is stored .... in the $HOME directory.
    
    The result was that the test added in the above commit would cause a
    .cache/ directory to be added into the binutils-gdb source tree.
    
    In this commit the test is updated to create a new directory in the
    build tree, the file we want to source is copied over, and $HOME is
    set to point at the location in the build tree.  Now when the test is
    run the .cache/ directory is created in the build tree, leaving the
    source tree untouched.
    
    gdb/testsuite/ChangeLog:
    
            * gdb.guile/guile.exp: Don't use the source directory as a
            temporary HOME directory.

Diff:
---
 gdb/testsuite/ChangeLog           |  5 +++++
 gdb/testsuite/gdb.guile/guile.exp | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a22e014b45a..b3a41bd5481 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-10  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* gdb.guile/guile.exp: Don't use the source directory as a
+	temporary HOME directory.
+
 2021-05-10  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* gdb.arch/amd64-osabi.exp (test_osabi_none): Use the
diff --git a/gdb/testsuite/gdb.guile/guile.exp b/gdb/testsuite/gdb.guile/guile.exp
index 0fb82284f46..33250ff6510 100644
--- a/gdb/testsuite/gdb.guile/guile.exp
+++ b/gdb/testsuite/gdb.guile/guile.exp
@@ -85,7 +85,18 @@ gdb_test "guile (print a)" "= .*aliases -- User-defined aliases of other command
 
 # Verify that we can source a guile script using ~ for the HOME directory.
 save_vars { env(HOME) } {
-    set env(HOME) $srcdir/$subdir
+    # Create a new directory to act as a temporary HOME directory.
+    set tmp_home [standard_output_file tmp_home]
+    file mkdir $tmp_home
+
+    # Copy the file we want to source into the new HOME directory.
+    gdb_remote_download host ${srcdir}/${subdir}/source2.scm \
+	${tmp_home}/source2.scm
+
+    # Arrange to use the new HOME directory.
+    set env(HOME) $tmp_home
     clean_restart
+
+    # Finally, source the file out of our new HOME directory.
     gdb_test "source ~/source2.scm" "yes"
 }


More information about the Gdb-cvs mailing list