>From 847ffd151c1a46eaa2d1f764bf78ba72ae71ed08 Mon Sep 17 00:00:00 2001
From: Amar Singh
Date: Tue, 30 Apr 2019 23:17:51 +0530
Subject: [PATCH 01/10] Import: Add make-go-package.
* guix/import/golang.scm (make-go-package): New variable.
Signed-off-by: Amar Singh
---
guix/import/golang.scm | 121 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
create mode 100644 guix/import/golang.scm
diff --git a/guix/import/golang.scm b/guix/import/golang.scm
new file mode 100644
index 0000000000..ad822f6b69
--- /dev/null
+++ b/guix/import/golang.scm
@@ -0,0 +1,121 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 by Amar Singh
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see .
+
+(define-module (guix import golang))
+(use-modules
+ (guix import github) ;; latest-release
+ (guix download) ;; download-to-store
+ ((guix import utils) #:prefix utils:) ;; hash
+ (guix packages) ;; packages
+ (guix build-system go) ;; go-build-system
+ (guix store) ;; with-store
+ (gnu packages golang) ;; inherit (simple) go package
+ (ice-9 textual-ports) ;; to parse readme.md
+ )
+
+(define go-name* "github.com/gohugoio/hugo") ;; for tests
+
+(define (go-name->url go-name)
+ (string-append "https://" go-name))
+
+(define (go-name->tarball go-name version)
+ (string-append (go-name->url go-name) "/archive/v" version
+ ".tar.gz"))
+
+;;; Possible remove @@ if upstream exports the symbols
+(define (go-name->name go-name)
+ ((@@ (guix import github) github-repository)
+ (go-name->url go-name)))
+
+;;; Slow; accesses the network
+(define (latest-release go-name)
+ ((@@ (guix import github) latest-released-version)
+ (go-name->url go-name)
+ (go-name->name go-name)))
+
+;;; Slow; downloads the url from network;
+(define (url->store url)
+ (with-store store
+ (download-to-store store
+ url)))
+;;; Slow; download the source tarball from network and returns base32
+;;; nix-hash
+(define (go-name->sha256 go-name version)
+ (utils:guix-hash-url (url->store (go-name->tarball go-name version))))
+
+;;; Towards go-name->synopsis,description
+(define (go-name->readme go-name)
+ (string-append "https://raw.githubusercontent.com"
+ (substring go-name
+ (string-length "github.com"))
+ "/master/"
+ "README.md"))
+
+;;; Slow; network access
+(define (go-name->readme-string go-name)
+ "Slow; network access."
+ (call-with-input-file (url->store (go-name->readme go-name))
+ (lambda (port) (get-string-n port 4096))))
+
+;;; Maybe try to match the first sentence.
+(define (go-name->synopsis go-name readme-string)
+ (string-append (go-name->name go-name)
+ (substring readme-string 0 100)))
+
+;;; Maybe try to match the the next two sentences.
+(define (go-name->description go-name readme-string)
+ (string-append (go-name->name go-name)
+ (substring readme-string 100 300)))
+
+(define-public (make-go-package go-name)
+ ;; Do the expensive operations only once; query network for latest version
+ (let* ((version (latest-release go-name))
+ (sha256 (go-name->sha256 go-name version))
+ (readme-string (go-name->readme-string go-name)))
+ (package (inherit go-github-com-alsm-ioprogress)
+ (name (string-append "go-" (go-name->name go-name)))
+ (version version)
+ (source (origin (method url-fetch)
+ (uri (go-name->tarball go-name version))
+ (sha256 (base32
+ sha256))))
+ (home-page (go-name->url go-name))
+ (build-system go-build-system)
+ (arguments
+ `(#:import-path ,go-name))
+ ;; TODO: inputs
+ (synopsis
+ (go-name->synopsis go-name readme-string))
+ (description (go-name->description go-name readme-string))
+ ;; TODO: license
+ )))
+
+;;; STATUS
+;;; 1. latest-release DONE
+;;; 1.b latest-commit PENDING/STALLED
+;;; 2. go-name->name DONE
+;;; 4. go-name->url DONE
+;;; 4.b go-name->tarball DONE
+;;; 5. go-name->sha256 (go-name version) DONE
+;;; 6. go-name->synopsis DONE
+;;; 7. go-name->description DONE
+;;; 6-7.b try to extract sentences. TODO
+;;; 8. go-name->license TODO
+;;; 9. go-name->inputs TODO
+
+;;; golang.scm ends here
--
2.21.0