From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id 6F916387102C for ; Wed, 11 Mar 2020 19:09:12 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id D2DC327B2A0; Wed, 11 Mar 2020 15:09:11 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id QeZ0KhH4s7bA; Wed, 11 Mar 2020 15:09:11 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 830E827B060; Wed, 11 Mar 2020 15:09:11 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 830E827B060 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Gel1OcMIAbo6; Wed, 11 Mar 2020 15:09:11 -0400 (EDT) Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id 57E0227B249; Wed, 11 Mar 2020 15:09:11 -0400 (EDT) Subject: Re: [PATCH] testsuite: use cygpath to convert from Unix to Windows paths To: Christian Biesinger Cc: gdb-patches , Eli Zaretskii References: <20200311183212.28601-1-simon.marchi@efficios.com> From: Simon Marchi Message-ID: Date: Wed, 11 Mar 2020 15:09:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2020 19:09:13 -0000 On 2020-03-11 2:40 p.m., Christian Biesinger wrote: >> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp >> index 9614e8dc87cd..ac16e0e85c99 100644 >> --- a/gdb/testsuite/lib/gdb.exp >> +++ b/gdb/testsuite/lib/gdb.exp >> @@ -4899,8 +4899,10 @@ proc standard_output_file {basename} { >> file mkdir $dir >> # If running on MinGW, replace /c/foo with c:/foo >> if { [ishost *-*-mingw*] } { >> - set dir [regsub {^/([a-z])/} $dir {\1:/}] >> + set dir [exec cygpath --mixed "${dir}"] > > This is fine, but out of curiosity, why --mixed instead of --windows? --mixed produces paths with forward slashes: C:/hello/christian rather than back slashes: C:\hello\christian And the backslashes wreak havoc (we would need to escape them): C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file C:msys64homesmarchi^Huild^Hinutils-gdbgdb estsuiteoutputsgdb.archi386-bp_permanent/i386-bp_permanent.exe: Invalid argument Since the tools understand forward slashes, it's just easier to use that. > >> + >> } > > Why the empty line above? A leftover from fighting with Windows, I'll make sure to remove it. However, the solution I proposed won't work with the non-MinGW-w64 MinGW, as it does not ship with cygpath. Here is another version of the patch that uses `pwd -W` to get the same information. >From b1da3b3b78b92887eeed61b72ca765be45ce3ce2 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 11 Mar 2020 14:16:17 -0400 Subject: [PATCH] testsuite: use `pwd -W` to convert from Unix to Windows paths When on a MinGW host, standard_output_file uses a regular expression to convert Unix-style paths of the form "/c/foo" to "c:/foo". This is needed because the paths we pass to GDB (for example, with the "file" command) need to be in the Windows form. However, the regexp only works if your binutils-gdb repo is under a `/[a-z]/...` path (the Unix paths mapping to Windows drives). Presumably, that works if you clone the repo in Windows, then access it through `/c/...`. In my case, I've cloned the repository directly inside my MinGW shell, so in /home/smarchi. The regexp therefore doesn't work for me. The path doesn't get transformed, and the file command fails when running any test: (gdb) file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent: No such file or directory. A safer way to do this is to execute `pwd -W` while in the directory we want the path for, this is what this patch does. I have also considered using the using the cygpath utility to do the conversion. It can be used to convert any MinGW path into its Windows equivalent. Despite originally coming from Cygwin, the cygpath utility is distributed by MinGW-w64 and can be used in that environment. However, it's not distributed with the non-MinGW-w64 MinGW. The `pwd -W` trick only works with directories that exist, which is the case here, so it's sufficient. With this, the file command in the test succeeds: (gdb) file C:/msys64/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent Reading symbols from C:/msys64/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent... gdb/testsuite/ChangeLog: * lib/gdb.exp (standard_output_file): Use `pwd -W` to convert from Unix to Windows path. --- gdb/testsuite/lib/gdb.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 9614e8dc87cd..9e903ba34776 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4899,7 +4899,7 @@ proc standard_output_file {basename} { file mkdir $dir # If running on MinGW, replace /c/foo with c:/foo if { [ishost *-*-mingw*] } { - set dir [regsub {^/([a-z])/} $dir {\1:/}] + set dir [exec sh -c "cd ${dir} && pwd -W"] } return [file join $dir $basename] } -- 2.25.1