unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Federico Beffa <beffa@ieee.org>
Cc: 25882@debbugs.gnu.org
Subject: bug#25882: gcc-wrapper doesn't handle response files
Date: Sat, 11 Mar 2017 14:47:38 +0100	[thread overview]
Message-ID: <87shmk6i2t.fsf@gnu.org> (raw)
In-Reply-To: <878togudsp.fsf@lupo.i-did-not-set--mail-host-address--so-tickle-me> (Federico Beffa's message of "Wed, 08 Mar 2017 13:57:10 +0100")

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

Federico Beffa <beffa@ieee.org> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> On closer inspection, it’s an easy change to make.
>>
>> Could you test the attached patch with GHC?
>
> Thanks for the patch.  I've tested it with GHC 8.0.2 and seems to work
> for it.  However, this is an excerpt of the description of the use of
> response files from the GCC manual:
>
> '@FILE'
>      Read command-line options from FILE.  The options read are inserted
>      in place of the original @FILE option.  If FILE does not exist, or
>      cannot be read, then the option will be treated literally, and not
>      removed.
>
>      Options in FILE are separated by whitespace.  A whitespace
>      character may be included in an option by surrounding the entire
>      option in either single or double quotes.  Any character (including
>      a backslash) may be included by prefixing the character to be
>      included with a backslash.  The FILE may itself contain additional
>      @FILE options; any such options will be processed recursively.

Oh, nice, I hadn’t seen this doc.

The attached version adds handling of unreadable files and recursion.
It does not address parsing of quote-delimited options though, but I’m
tempted to punt on that one.

Thoughts?

Thanks,
Ludo’.


[-- Attachment #2: Type: text/x-patch, Size: 2851 bytes --]

diff --git a/gnu/packages/ld-wrapper.in b/gnu/packages/ld-wrapper.in
index ebfd8332c..82bd2196c 100644
--- a/gnu/packages/ld-wrapper.in
+++ b/gnu/packages/ld-wrapper.in
@@ -15,7 +15,7 @@ main="(@ (gnu build-support ld-wrapper) ld-wrapper)"
 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 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -35,6 +35,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)
   #:export (ld-wrapper))
 
 ;;; Commentary:
@@ -222,9 +223,44 @@ impure library ~s~%"
               '()
               library-files))
 
+(define (expand-arguments args)
+  ;; Expand ARGS such that "response file" arguments, such as "@args.txt", are
+  ;; expanded (info "(gcc) Overall Options").
+  (define (response-file-arguments file)
+    (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)))
+
+  (define result
+    (fold-right (lambda (arg result)
+                  (if (string-prefix? "@" arg)
+                      (let ((file (string-drop arg 1)))
+                        (append (catch 'system-error
+                                  (lambda ()
+                                    (response-file-arguments file))
+                                  (lambda args
+                                    ;; FILE doesn't exist or cannot be read so
+                                    ;; leave ARG as is.
+                                    (list arg)))
+                                result))
+                      (cons arg result)))
+                '()
+                args))
+
+  ;; If there are "@" arguments in RESULT *and* we can expand them (they don't
+  ;; refer to nonexistent files), then recurse.
+  (if (equal? result args)
+      result
+      (expand-arguments result)))
+
 (define (ld-wrapper . args)
   ;; Invoke the real `ld' with ARGS, augmented with `-rpath' switches.
-  (let* ((path (library-search-path args))
+  (let* ((args (expand-arguments args))
+         (path (library-search-path args))
          (libs (library-files-linked args path))
          (args (append args (rpath-arguments libs))))
     (when %debug?

  reply	other threads:[~2017-03-11 13:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26 16:58 bug#25882: gcc-wrapper doesn't handle response files Federico Beffa
2017-03-06 16:22 ` Ludovic Courtès
2017-03-06 17:16   ` Federico Beffa
2017-03-07 10:53     ` Ludovic Courtès
2017-03-08 12:57       ` Federico Beffa
2017-03-11 13:47         ` Ludovic Courtès [this message]
2017-03-12 11:36           ` Federico Beffa
2017-05-25 12:42             ` Ludovic Courtès

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=87shmk6i2t.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=25882@debbugs.gnu.org \
    --cc=beffa@ieee.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).