unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 35263@debbugs.gnu.org
Subject: [bug#35263] [PATCH] build: go-build-system: Ensure uniform unpacking directory.
Date: Sun, 14 Apr 2019 00:03:05 -0400	[thread overview]
Message-ID: <87tvf1nshy.fsf@gmail.com> (raw)

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

This fixes a problem in the go-build-system's unpack phase.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-build-go-build-system-Re-ident.patch --]
[-- Type: text/x-patch, Size: 1259 bytes --]

From b1474516120cdc843d7c59c4d9db4b9ed5e299bf Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Thu, 4 Apr 2019 23:24:57 -0400
Subject: [PATCH 1/3] build: go-build-system: Re-ident.

* guix/build/go-build-system.scm (unpack): Fix indentation.
---
 guix/build/go-build-system.scm | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 1a716cea77..d03aefd018 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -161,12 +161,12 @@ unpacking."
   (let ((dest (string-append (getenv "GOPATH") "/src/" unpack-path)))
     (mkdir-p dest)
     (if (file-is-directory? source)
-      (begin
-        (copy-recursively source dest #:keep-mtime? #t)
-        #t)
-      (if (string-suffix? ".zip" source)
-        (invoke "unzip" "-d" dest source)
-        (invoke "tar" "-C" dest "-xvf" source)))))
+        (begin
+          (copy-recursively source dest #:keep-mtime? #t)
+          #t)
+        (if (string-suffix? ".zip" source)
+            (invoke "unzip" "-d" dest source)
+            (invoke "tar" "-C" dest "-xvf" source)))))
 
 (define (go-package? name)
   (string-prefix? "go-" name))
-- 
2.20.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-build-go-build-system-Use-WHEN-for-side-effect-condi.patch --]
[-- Type: text/x-patch, Size: 1068 bytes --]

From b7af3222730b20329e3b0da42e6cb591b9cd137c Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Thu, 4 Apr 2019 23:26:04 -0400
Subject: [PATCH 2/3] build: go-build-system: Use WHEN for side-effect
 conditionals.

* guix/build/go-build-system.scm (unpack): Replace single branch `if' by
`when'.
---
 guix/build/go-build-system.scm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index d03aefd018..e59aa59092 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -158,6 +158,10 @@ unpacking."
       ((display "WARNING: The Go import path is unset.\n")))
   (if (string-null? unpack-path)
       (set! unpack-path import-path))
+  (when (string-null? import-path)
+    ((display "WARNING: The Go import path is unset.\n")))
+  (when (string-null? unpack-path)
+    (set! unpack-path import-path))
   (let ((dest (string-append (getenv "GOPATH") "/src/" unpack-path)))
     (mkdir-p dest)
     (if (file-is-directory? source)
-- 
2.20.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-build-go-build-system-Ensure-uniform-unpacking-direc.patch --]
[-- Type: text/x-patch, Size: 3447 bytes --]

From 1f7535fbe28f7ac96e824b792e9f1a140b8c54cd Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Fri, 5 Apr 2019 00:00:08 -0400
Subject: [PATCH 3/3] build: go-build-system: Ensure uniform unpacking
 directory.

Depending on whether the source is a directory or an archive, we strip the
source directory or preserve it, respectively.  This change makes it so that
whether the type of the source, it is unpacked at the expected location given
by the IMPORT-PATH of the Go build system.

* guix/build/go-build-system.scm: Add the (ice-9 ftw) module.
(unpack): Add inner procedure to maybe strip the top level directory of an
archive, document it and use it.
---
 guix/build/go-build-system.scm | 35 +++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index e59aa59092..c1a0d6441c 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -22,6 +22,7 @@
   #:use-module (guix build union)
   #:use-module (guix build utils)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 ftw)
   #:use-module (srfi srfi-1)
   #:use-module (rnrs io ports)
   #:use-module (rnrs bytevectors)
@@ -151,13 +152,31 @@ dependencies, so it should be self-contained."
   #t)
 
 (define* (unpack #:key source import-path unpack-path #:allow-other-keys)
-  "Relative to $GOPATH, unpack SOURCE in the UNPACK-PATH, or the IMPORT-PATH is
-the UNPACK-PATH is unset.  When SOURCE is a directory, copy it instead of
+  "Relative to $GOPATH, unpack SOURCE in UNPACK-PATH, or IMPORT-PATH when
+UNPACK-PATH is unset.  If the SOURCE archive has a single top level directory,
+it is stripped so that the sources appear directly under UNPACK-PATH.  When
+SOURCE is a directory, copy its content into UNPACK-PATH instead of
 unpacking."
-  (if (string-null? import-path)
-      ((display "WARNING: The Go import path is unset.\n")))
-  (if (string-null? unpack-path)
-      (set! unpack-path import-path))
+  (define (unpack-maybe-strip source dest)
+    (let* ((scratch-dir (string-append (or (getenv "TMPDIR") "/tmp")
+                                       "/scratch-dir"))
+           (out (mkdir-p scratch-dir)))
+      (with-directory-excursion scratch-dir
+        (if (string-suffix? ".zip" source)
+            (invoke "unzip" source)
+            (invoke "tar" "-xvf" source))
+        (let ((top-level-files (remove (lambda (x)
+                                         (member x '("." "..")))
+                                       (scandir "."))))
+          (match top-level-files
+            ((top-level-file)
+             (when (file-is-directory? top-level-file)
+               (copy-recursively top-level-file dest #:keep-mtime? #t)))
+            (_
+             (copy-recursively "." dest #:keep-mtime? #t)))
+          #t))
+      (delete-file-recursively scratch-dir)))
+
   (when (string-null? import-path)
     ((display "WARNING: The Go import path is unset.\n")))
   (when (string-null? unpack-path)
@@ -168,9 +187,7 @@ unpacking."
         (begin
           (copy-recursively source dest #:keep-mtime? #t)
           #t)
-        (if (string-suffix? ".zip" source)
-            (invoke "unzip" "-d" dest source)
-            (invoke "tar" "-C" dest "-xvf" source)))))
+        (unpack-maybe-strip source dest))))
 
 (define (go-package? name)
   (string-prefix? "go-" name))
-- 
2.20.1


             reply	other threads:[~2019-04-14  4:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-14  4:03 Maxim Cournoyer [this message]
2019-05-06  0:10 ` [bug#35263] [PATCH] build: go-build-system: Ensure uniform unpacking directory Maxim Cournoyer

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=87tvf1nshy.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=35263@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).