unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Marius Bakke <mbakke@fastmail.com>
To: 39767@debbugs.gnu.org
Subject: [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.
Date: Mon, 24 Feb 2020 17:01:32 +0100	[thread overview]
Message-ID: <20200224160132.21037-1-mbakke@fastmail.com> (raw)

* 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

             reply	other threads:[~2020-02-24 16:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24 16:01 Marius Bakke [this message]
2020-02-24 21:01 ` [bug#39767] [PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files Ludovic Courtès
2020-02-24 21:14   ` Marius Bakke
2020-03-06 12:26 ` bug#39767: " Marius Bakke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200224160132.21037-1-mbakke@fastmail.com \
    --to=mbakke@fastmail.com \
    --cc=39767@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).