This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2 11/17] introduce relative_filename and use it
- From: Doug Evans <dje at google dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Mon, 28 Oct 2013 12:01:45 -0700
- Subject: Re: [PATCH v2 11/17] introduce relative_filename and use it
- Authentication-results: sourceware.org; auth=none
- References: <1382129374-18344-1-git-send-email-tromey at redhat dot com> <1382129374-18344-12-git-send-email-tromey at redhat dot com>
On Fri, Oct 18, 2013 at 1:49 PM, Tom Tromey <tromey@redhat.com> wrote:
> This introduces a new relative_filename proc to gdb.exp and changes
> some tests to use it. This helps make these tests parallel-safe.
>
> * gdb.base/fullname.exp: Use standard_output_file,
> relative_filename.
> * gdb.base/hashline1.exp: Use standard_testfile,
> standard_output_file, relative_filename, clean_restart.
> * gdb.base/hashline2.exp: Use standard_testfile,
> standard_output_file, relative_filename.
> * gdb.base/hashline3.exp: Use standard_testfile,
> standard_output_file, relative_filename.
> * lib/gdb.exp (relative_filename): New proc.
> [...]
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -4320,6 +4320,21 @@ proc set_remotetimeout { timeout } {
> }
> }
>
> +# ROOT and FULL are file names. Returns the relative path from ROOT
> +# to FULL. Note that FULL must be in a subdirectory of ROOT.
> +# For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
> +# will return "ls".
> +
> +proc relative_filename {root full} {
> + if {[string compare [string range $full 0 \
> + [expr {[string length $root] - 1}]] $root] != 0} {
> + error "$full not a subdir of $root"
> + }
> +
> + set len [llength [file split $root]]
> + return [eval file join [lrange [file split $full] $len end]]
> +}
> +
There's also string compare -length.
Or maybe for some incremental robustness, do the file splits first and
then compare that?