unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.
@ 2020-02-24 16:01 Marius Bakke
  2020-02-24 21:01 ` Ludovic Courtès
  2020-03-06 12:26 ` bug#39767: " Marius Bakke
  0 siblings, 2 replies; 4+ messages in thread
From: Marius Bakke @ 2020-02-24 16:01 UTC (permalink / raw)
  To: 39767

* gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
use that to parse the response file.
---
 gnu/packages/ld-wrapper.in | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Guix,

Currently the ld-wrapper will fail inscrutably if a response file
contains double quotes.  This patch fixes that, and also preserves
whitespaces between quotes.

diff --git a/gnu/packages/ld-wrapper.in b/gnu/packages/ld-wrapper.in
index 16780c58f6..5d5756f6a3 100644
--- a/gnu/packages/ld-wrapper.in
+++ b/gnu/packages/ld-wrapper.in
@@ -16,6 +16,7 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line))
 !#
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -35,7 +36,7 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line))
 (define-module (gnu build-support ld-wrapper)
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 match)
-  #:autoload   (ice-9 rdelim) (read-string)
+  #:autoload   (ice-9 rdelim) (read-delimited)
   #:export (ld-wrapper))
 
 ;;; Commentary:
@@ -239,13 +240,28 @@ library outside of ~a: ~s~%"
   ;; Expand ARGS such that "response file" arguments, such as "@args.txt", are
   ;; expanded (info "(gcc) Overall Options").
   (define (response-file-arguments file)
+    (define (tokenize port)
+      ;; Return a list of all strings found in PORT.  Quote characters are removed,
+      ;; but whitespaces within quoted strings are preserved.
+      (let loop ((words '()))
+        (let* ((word (read-delimited " '\"" port 'split))
+               (token (car word))
+               (delim (cdr word)))
+          (if (eof-object? delim)
+              (reverse words)
+              (case delim
+                ((#\") (loop (cons (read-delimited "\"" port) words)))
+                ((#\') (loop (cons (read-delimited "'" port) words)))
+                ((#\ ) (if (> 0 (string-length token))
+                           (loop (cons token words))
+                           (loop words)))
+                (else (loop words)))))))
+
     (when %debug?
       (format (current-error-port)
               "ld-wrapper: attempting to read arguments from '~a'~%" file))
 
-    ;; FIXME: Options can contain whitespace if they are protected by single
-    ;; or double quotes; this is not implemented here.
-    (string-tokenize (call-with-input-file file read-string)))
+    (call-with-input-file file tokenize))
 
   (define result
     (fold-right (lambda (arg result)
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.
  2020-02-24 16:01 [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files Marius Bakke
@ 2020-02-24 21:01 ` Ludovic Courtès
  2020-02-24 21:14   ` Marius Bakke
  2020-03-06 12:26 ` bug#39767: " Marius Bakke
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2020-02-24 21:01 UTC (permalink / raw)
  To: Marius Bakke; +Cc: 39767

Hi Marius!

Marius Bakke <mbakke@fastmail.com> skribis:

> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
> use that to parse the response file.

LGTM!

> Currently the ld-wrapper will fail inscrutably if a response file
> contains double quotes.  This patch fixes that, and also preserves
> whitespaces between quotes.

Out of curiosity, where did you stumble upon response files with quotes?
Was it GHC?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.
  2020-02-24 21:01 ` Ludovic Courtès
@ 2020-02-24 21:14   ` Marius Bakke
  0 siblings, 0 replies; 4+ messages in thread
From: Marius Bakke @ 2020-02-24 21:14 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 39767

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> Hi Marius!
>
> Marius Bakke <mbakke@fastmail.com> skribis:
>
>> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
>> use that to parse the response file.
>
> LGTM!
>
>> Currently the ld-wrapper will fail inscrutably if a response file
>> contains double quotes.  This patch fixes that, and also preserves
>> whitespaces between quotes.
>
> Out of curiosity, where did you stumble upon response files with quotes?
> Was it GHC?

A variant of this wrapper will (hopefully!) soon show up on the 'master'
branch, required for version 80 of ungoogled-chromium.  It generates
response files where all "-lfoo" "-lbar" arguments are quoted, even
though they contain no spaces.

Thanks for the quick review, will merge it on core-updates after it hits
'master'.  :-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#39767: [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.
  2020-02-24 16:01 [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files Marius Bakke
  2020-02-24 21:01 ` Ludovic Courtès
@ 2020-03-06 12:26 ` Marius Bakke
  1 sibling, 0 replies; 4+ messages in thread
From: Marius Bakke @ 2020-03-06 12:26 UTC (permalink / raw)
  To: 39767-done

[-- Attachment #1: Type: text/plain, Size: 285 bytes --]

Marius Bakke <mbakke@fastmail.com> writes:

> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
> use that to parse the response file.

I simplified it a bit and also discarded newlines and pushed to
core-updates in feb8c5dac30294d72205ee21b3afcf1cf7a04675.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-06 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 16:01 [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files Marius Bakke
2020-02-24 21:01 ` Ludovic Courtès
2020-02-24 21:14   ` Marius Bakke
2020-03-06 12:26 ` bug#39767: " Marius Bakke

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).