This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 11/17] introduce relative_filename and use it


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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]