From b5f05283548d1329672d23bf0cd9a9d31b9b364c Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 4 Apr 2019 23:24:57 -0400 Subject: 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(-) (limited to 'guix/build/go-build-system.scm') diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 282df19f24..973ee6e251 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -161,12 +161,12 @@ (define* (unpack #:key source import-path unpack-path #:allow-other-keys) (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)) -- cgit v1.2.3 From 7e84d3eef724ef18f8e1c1b0932b6f74d3ae3e35 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 4 Apr 2019 23:26:04 -0400 Subject: 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(+) (limited to 'guix/build/go-build-system.scm') diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 973ee6e251..92a5c86d6c 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -158,6 +158,10 @@ (define* (unpack #:key source import-path unpack-path #:allow-other-keys) ((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) -- cgit v1.2.3 From f42e4ebb56fe4f16991ca6c6e060c8f3535865cb Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Fri, 5 Apr 2019 00:00:08 -0400 Subject: 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 | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'guix/build/go-build-system.scm') diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 92a5c86d6c..d106e70d35 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016 Petter ;;; Copyright © 2017, 2019 Leo Famulari +;;; Copyright © 2019 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ (define-module (guix build go-build-system) #: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 +153,31 @@ (define* (setup-go-environment #:key inputs outputs #:allow-other-keys) #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 +188,7 @@ (define* (unpack #:key source import-path unpack-path #:allow-other-keys) (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)) -- cgit v1.2.3 From 2edec51c5eabeef6d7d9e1cbae2b2be379aaa6b8 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 5 May 2019 22:41:11 -0400 Subject: build: go-build-system: Follow-up commit. There was an extraneous pair of parens in commit 7e84d3eef7. Thanks for Mark Weaver for reporting the issue. * guix/build/go-build-system.scm (unpack): Remove the extraneous pair of parentheses surrounding the `display' function call. --- guix/build/go-build-system.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guix/build/go-build-system.scm') diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index d106e70d35..22427a80b3 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -179,7 +179,7 @@ (define (unpack-maybe-strip source dest) (delete-file-recursively scratch-dir))) (when (string-null? import-path) - ((display "WARNING: The Go import path is unset.\n"))) + (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))) -- cgit v1.2.3 From a321312e3aec8f2884ab3f3cb35e2020195b5a08 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 5 May 2019 23:01:03 -0400 Subject: build: go-build-system: Follow-up to commit f42e4ebb56. This follows commit f42e4ebb56, which made it so that the unpack phase return value could be left unspecified. * guix/build/go-build-system.scm (unpack): Ensure that the value returned upon a successful completion of the phase is #t. --- guix/build/go-build-system.scm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'guix/build/go-build-system.scm') diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 22427a80b3..858068ba98 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -174,8 +174,7 @@ (define (unpack-maybe-strip source dest) (when (file-is-directory? top-level-file) (copy-recursively top-level-file dest #:keep-mtime? #t))) (_ - (copy-recursively "." dest #:keep-mtime? #t))) - #t)) + (copy-recursively "." dest #:keep-mtime? #t))))) (delete-file-recursively scratch-dir))) (when (string-null? import-path) @@ -185,10 +184,9 @@ (define (unpack-maybe-strip source dest) (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) - (unpack-maybe-strip source dest)))) + (copy-recursively source dest #:keep-mtime? #t) + (unpack-maybe-strip source dest))) + #t) (define (go-package? name) (string-prefix? "go-" name)) -- cgit v1.2.3